Class: Sapling::JavascriptGenerator
- Inherits:
-
Object
- Object
- Sapling::JavascriptGenerator
- Defined in:
- lib/sapling/generators/javascript_generator.rb
Instance Attribute Summary collapse
-
#sapling ⇒ Object
Returns the value of attribute sapling.
Instance Method Summary collapse
-
#generate(options = {}) ⇒ Object
options options is passed directly into sapling.active_features One useful option is to override the user: :user => user.
-
#initialize(sapling) ⇒ JavascriptGenerator
constructor
A new instance of JavascriptGenerator.
-
#mootools_for_feature(feature, on) ⇒ Object
see Sapling::API::Client for options.
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
#sapling ⇒ Object
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(={}) features = sapling.features.keys active_features = sapling.active_features().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 |