Class: SerenadeRails::Template

Inherits:
Object
  • Object
show all
Defined in:
lib/serenade_rails/template.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, content) ⇒ Template

Returns a new instance of Template.



10
11
12
13
# File 'lib/serenade_rails/template.rb', line 10

def initialize(name, content)
  @name = name
  @content = content
end

Instance Attribute Details

#contentObject (readonly)

Returns the value of attribute content.



8
9
10
# File 'lib/serenade_rails/template.rb', line 8

def content
  @content
end

#nameObject (readonly)

Returns the value of attribute name.



8
9
10
# File 'lib/serenade_rails/template.rb', line 8

def name
  @name
end

Instance Method Details

#parseObject



15
16
17
18
19
# File 'lib/serenade_rails/template.rb', line 15

def parse
  context = ExecJS.compile(File.read(SERENADE_PATH))
  code = "Serenade.view(#{content.to_json}).parse()"
  context.eval(code)
end

#renderObject



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

def render
  "Serenade.view(#{name.to_json}, #{parse.to_json});"
end