Module: CleanShaved::Helpers

Includes:
Tagz
Defined in:
lib/clean_shaved/helpers.rb

Instance Method Summary collapse

Instance Method Details

#template_for(*args, &block) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/clean_shaved/helpers.rb', line 7

def template_for(*args, &block)
  name = args.first
  options = args.extract_options!.to_options!

  tmpl = capture(&block)

  if CleanShaved.config.compile?
    script_ type: 'text/javascript' do
      "Handlebars.templates['#{name}'] = Handlebars.template(#{CleanShaved.compile(name, tmpl)});"
        .gsub(/\s+/, ' ')
    end
  else
    options[:type] ||= "text/x-handlebars-template"
    options[:class] ||= "template"
    options[:name] ||= name

    script_(options) do
      tmpl
    end
  end
end