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.4.0"

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.configurationObject



87
88
89
# File 'lib/dusty_rails_renderer.rb', line 87

def self.configuration
  @configuration ||= Configuration.new
end

Class Method Details

.configure {|configuration| ... } ⇒ Object

Yields:



83
84
85
# File 'lib/dusty_rails_renderer.rb', line 83

def self.configure
  yield(configuration)
end

.get_template(template_name) ⇒ Object



21
22
23
# File 'lib/dusty_rails_renderer.rb', line 21

def get_template(template_name)
  @precompiled_templates[template_name]
end

.initializeObject

Initialize, load Dust.js library, and precompile Dust.js templates



10
11
12
13
14
15
16
17
18
19
# 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
  @last_modification_hash = Hash.new
  @context = V8::Context.new
  @context.eval(@dust_library, 'dustjs') 

  read_dust_files
end

.render(template_name, json) ⇒ Object



30
31
32
33
34
35
36
37
# File 'lib/dusty_rails_renderer.rb', line 30

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

.templatesObject

Return precompiled templates in JSON format (Client-side)



26
27
28
# File 'lib/dusty_rails_renderer.rb', line 26

def templates
  @precompiled_templates.to_json
end