Class: Sprockets::Mustache::Template::Generator

Inherits:
Object
  • Object
show all
Defined in:
lib/sprockets_spacely/mustache/template/generator.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(namespace, logical_path, template_string, library) ⇒ Generator

Returns a new instance of Generator.



8
9
10
11
12
13
# File 'lib/sprockets_spacely/mustache/template/generator.rb', line 8

def initialize(namespace, logical_path, template_string, library)
  @template_name = logical_path
  @namespace = namespace
  @template_string = template_string
  @library = library
end

Instance Attribute Details

#template_nameObject (readonly)

Returns the value of attribute template_name.



6
7
8
# File 'lib/sprockets_spacely/mustache/template/generator.rb', line 6

def template_name
  @template_name
end

Instance Method Details

#generateObject



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/sprockets_spacely/mustache/template/generator.rb', line 15

def generate

  js_function = "(function($) {\n\n  \#{@namespace}.mustache['\#{@template_name}'] = {\n    template: \"\#{@template_string}\",\n    render: render\n  };\n\n  function render(obj, partials) {\n    return Mustache.to_html(\#{@namespace}.mustache['\#{@template_name}'].template, obj, partials);\n  }\n}(\#{@library}));\n  JS\n\nend\n"