Class: SerenadeRails::Template
- Inherits:
-
Object
- Object
- SerenadeRails::Template
- Defined in:
- lib/serenade_rails/template.rb
Instance Attribute Summary collapse
-
#content ⇒ Object
readonly
Returns the value of attribute content.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
-
#initialize(name, content) ⇒ Template
constructor
A new instance of Template.
- #parse ⇒ Object
- #render ⇒ Object
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
#content ⇒ Object (readonly)
Returns the value of attribute content.
8 9 10 |
# File 'lib/serenade_rails/template.rb', line 8 def content @content end |
#name ⇒ Object (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
#parse ⇒ Object
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 |
#render ⇒ Object
21 22 23 |
# File 'lib/serenade_rails/template.rb', line 21 def render "Serenade.view(#{name.to_json}, #{parse.to_json});" end |