Module: DustyRailsRenderer
- Extended by:
- ActionView::Helpers::JavaScriptHelper
- Defined in:
- lib/dusty_rails_renderer.rb,
lib/dusty_rails_renderer/version.rb,
lib/generators/dusty_rails_renderer/install_generator.rb
Defined Under Namespace
Modules: Generators Classes: Configuration
Constant Summary collapse
- VERSION =
"0.2.8"
Class Attribute Summary collapse
Class Method Summary collapse
- .configure {|configuration| ... } ⇒ Object
-
.initialize ⇒ Object
Initialize, load Dust.js library, and precompile Dust.js templates.
- .render(template_name, json) ⇒ Object
-
.templates ⇒ Object
Return precompiled templates in JSON format (Client-side).
Class Attribute Details
.configuration ⇒ Object
76 77 78 |
# File 'lib/dusty_rails_renderer.rb', line 76 def self.configuration @configuration ||= Configuration.new end |
Class Method Details
.configure {|configuration| ... } ⇒ Object
72 73 74 |
# File 'lib/dusty_rails_renderer.rb', line 72 def self.configure yield(configuration) end |
.initialize ⇒ Object
Initialize, load Dust.js library, and precompile Dust.js templates
10 11 12 13 14 15 16 17 18 |
# File 'lib/dusty_rails_renderer.rb', line 10 def initialize @dust_config = YAML.load_file(self.configuration.dust_config_path) @dust_library = File.read(self.configuration.dust_js_library_path) @precompiled_templates = Hash.new @context = V8::Context.new @context.eval(@dust_library, 'dustjs') read_dust_files end |
.render(template_name, json) ⇒ Object
25 26 27 28 29 30 31 32 |
# File 'lib/dusty_rails_renderer.rb', line 25 def render(template_name, json) if self.configuration.production @context.eval("(function() { var result; dust.render('#{template_name}', #{json}, function(err, out) { result = out; }); return result; })()") else read_dust_files @context.eval("(function() { var result; dust.render('#{template_name}', #{json}, function(err, out) { result = out; }); return result; })()") end end |
.templates ⇒ Object
Return precompiled templates in JSON format (Client-side)
21 22 23 |
# File 'lib/dusty_rails_renderer.rb', line 21 def templates @precompiled_templates.to_json end |