Class: Sapling::JavascriptGenerator

Inherits:
Object
  • Object
show all
Defined in:
lib/sapling/generators/javascript_generator.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(sapling) ⇒ JavascriptGenerator

Returns a new instance of JavascriptGenerator.



6
7
8
# File 'lib/sapling/generators/javascript_generator.rb', line 6

def initialize(sapling)
  @sapling=sapling
end

Instance Attribute Details

#saplingObject

Returns the value of attribute sapling.



4
5
6
# File 'lib/sapling/generators/javascript_generator.rb', line 4

def sapling
  @sapling
end

Instance Method Details

#generate(options = {}) ⇒ Object

options options is passed directly into sapling.active_features

One useful option is to override the user:
  :user => user


19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/sapling/generators/javascript_generator.rb', line 19

def generate(options={})
  features = sapling.features.keys
  active_features = sapling.active_features(options).keys
  inactive_features = features - active_features

  <<-END
(function() {
if (window.MooTools) {
  html = $$('html')[0];
  #{inactive_features.map{|f| mootools_for_feature(f,false) }.join}
  #{active_features.map{|f| mootools_for_feature(f,true) }.join}
}
})();
END
end

#mootools_for_feature(feature, on) ⇒ Object

see Sapling::API::Client for options



11
12
13
# File 'lib/sapling/generators/javascript_generator.rb', line 11

def mootools_for_feature(feature, on)
  "html.removeClass('" + sapling.css_toggle_class(feature,!on) + "');html.addClass('" + sapling.css_toggle_class(feature,on) + "');"
end