Module: Laze::Plugins::JsRequires

Defined in:
lib/laze/plugins/js_requires.rb

Overview

This plugin introduces the require statement to your javascript files. This is a simple mechanism to concatenate all your javascript files into a single library and thereby reduce the number of HTTP requests (improving your website load time).

You can include another javascript file with a special comment like so:

# foo.js
var foo = 'foo';

# bar.js
// require 'foo.js'
alert(foo);

This will compile into the following file:

# bar.js
var foo = 'foo';
alert(foo);

Note that this leaves the original files untouched, so your website will end up with both files. The point is you only have to reference the one with that is concatenated.

This plugin is a decorator for Target and fires before Target#save.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.applies_to?(kind) ⇒ Boolean

This plugin is a decorator for Target and fires before Target#save.

Returns:

  • (Boolean)


30
31
32
# File 'lib/laze/plugins/js_requires.rb', line 30

def self.applies_to?(kind) #:nodoc:
  kind == :target
end

Instance Method Details

#saveObject



34
35
36
37
# File 'lib/laze/plugins/js_requires.rb', line 34

def save
  expand_js_requires
  super
end