Module: HandlebarWax

Defined in:
lib/handlebar_wax.rb,
lib/handlebar_wax/engine.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: Engine, Middleware, Railtie, TemplateHandler

Constant Summary collapse

VERSION =
"0.2.0"

Class Method Summary collapse

Class Method Details

.generate_templatesObject



19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/handlebar_wax.rb', line 19

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)) # How ironic is this?
 
  File.open(output_path, 'w') { |f| f.puts script }
end

.output_pathObject



14
15
16
17
# File 'lib/handlebar_wax.rb', line 14

def self.output_path
  assets = File.join(File.dirname(__FILE__),'..','app','assets')
  "#{assets}/javascripts/handlebars_templates.js"
end

.template_filesObject



10
11
12
# File 'lib/handlebar_wax.rb', line 10

def self.template_files
  Dir[File.join(%w(app views), '**', '*.hbs')]
end