Module: HandlebarWax
- Defined in:
- lib/handlebar_wax.rb,
lib/handlebar_wax/railtie.rb,
lib/handlebar_wax/version.rb,
lib/handlebar_wax/middleware.rb,
lib/handlebar_wax/template_handler.rb
Defined Under Namespace
Classes: Middleware, Railtie, TemplateHandler
Constant Summary
collapse
- VERSION =
"0.0.4"
Class Method Summary
collapse
Class Method Details
.generate_templates ⇒ Object
29
30
31
32
33
34
35
36
37
38
39
40
|
# File 'lib/handlebar_wax.rb', line 29
def self.generate_templates
templates = {}
template_files.each do |template_file|
name = template_file.scan(/app\/views\/(.*)\.[^\.]+\.hbs$/).flatten.first
templates[name] = File.read(template_file)
end
script = File.read(File.join(File.dirname(__FILE__), 'handlebar_wax', 'templates', 'handlebars_templates.js.hbs'))
script.sub!("{{templates}}", Yajl::Encoder.encode(templates))
File.open(output_path, 'w') { |f| f.puts script }
end
|
.output_path ⇒ Object
24
25
26
27
|
# File 'lib/handlebar_wax.rb', line 24
def self.output_path
base = defined?(Rails.root) ? Rails.root : '.'
"#{base}/public/javascripts/handlebars_templates.js"
end
|
.register_expansion(timestamp = nil) ⇒ Object
9
10
11
12
13
14
15
16
17
18
|
# File 'lib/handlebar_wax.rb', line 9
def self.register_expansion(timestamp=nil)
querystring = "?#{timestamp.to_i}" if timestamp
expansions = {
:handlebar_wax => [
"/javascripts/handlebars.js",
"/javascripts/handlebars_templates.js#{querystring}"
]
}
ActionView::Helpers::AssetTagHelper.register_javascript_expansion(expansions)
end
|
.template_files ⇒ Object
20
21
22
|
# File 'lib/handlebar_wax.rb', line 20
def self.template_files
Dir[File.join(%w(app views), '**', '*.hbs')]
end
|