Git Product home page Git Product logo

frontcompiler's Introduction

Welcome!
========

FrontCompiler is a simple collection of compactors for the JavaScript,
CSS and HTML source code. It removes trailing whitespaces, comments and
transformates the local variables to make the sourcecode shorter.

The library can be used as a plugin for rails. See description below.


Usage
=====

It's pretty simple

@c = FrontCompiler.new

@compact_js = @c.compact_js(File.open('src/something.js', 'r'));
@compact_css = @c.compact_css(File.open('src/something.css', 'r'));
@compact_html = @c.compact_html(File.open('src/something.css', 'r'));

or shorter

@compact_js = @c.compact_file('src/something.js');
@compact_css = @c.compact_file('src/something.css');
@compact_html = @c.compact_file('src/something.css');

or you can compact several files at once like that

@library_code = @c.compact_files(%w{
  src/lib.js
  src/lib/something.js
  src/lib/another.js
})

Same for the other file-types


CSS Inlining
============

With the tool you can convert your css source in some javascript
definition so you could put the styles in the same file as your
javascript and have -1 (or several) hits to your sever.

File('public/javascripts/all_in_one.js', 'w') do |file|
  file.write @c.compact_files(%w{
    public/javascripts/prototype.js
    public/javascripts/effects.js
    public/javascripts/application.js
  })

  file.write @c.inline(
    File.open('public/stylesheets/application.css').read
  )
end

Now you have a single javascript file which contains both, javascript
and the application stylesheets in one.

NOTE: if the user have JavaScript switched off, then he won't see the
styles.


Rails Usage
===========

The project can be used as a usual rails plugin. Just clone the
project into your vendor/plugins/front_compiler directory and you will
have the following methods aviable both in your controllers and
templates


* compact_files(list) - compacts the files fromt the given list and
                        puts them in a single string. You can specify
                        a list of file-names here.

* compact_file(file)  - compacts the given file (can be a file-name)

* compact_js(source)  - returns compacted version of the given source
* compact_css(source)
* compact_html(source)

* inline_css(source)    - converts the css-source in javascript
* inline_css_file(file) - converts the given css-file in a javascript
                          source (can be a file-name)


Enjoy!

--
The code released under terms of the MIT License
Copyright (C) 2008 Nikolay V. Nemshilov aka St.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.