Class: Serenade::Renderer
- Inherits:
-
Object
- Object
- Serenade::Renderer
- Defined in:
- lib/serenade/renderer.rb
Overview
Serenade::Renderer compiles Serenade views into a Serenade AST.
Instance Attribute Summary collapse
-
#content ⇒ String
readonly
Content of the serenade view, before compilation.
-
#name ⇒ String
readonly
Name of the serenade view.
Instance Method Summary collapse
-
#initialize(name, content) ⇒ Renderer
constructor
A new instance of Renderer.
-
#parse ⇒ Hash
Parse the Serenade view in #content.
- #render ⇒ String
Constructor Details
#initialize(name, content) ⇒ Renderer
Returns a new instance of Renderer.
19 20 21 22 |
# File 'lib/serenade/renderer.rb', line 19 def initialize(name, content) @name = name @content = content end |
Instance Attribute Details
#content ⇒ String (readonly)
Returns content of the serenade view, before compilation.
17 18 19 |
# File 'lib/serenade/renderer.rb', line 17 def content @content end |
#name ⇒ String (readonly)
Returns name of the serenade view.
14 15 16 |
# File 'lib/serenade/renderer.rb', line 14 def name @name end |
Instance Method Details
#parse ⇒ Hash
Parse the Serenade view in #content.
27 28 29 30 31 |
# File 'lib/serenade/renderer.rb', line 27 def parse context = ExecJS.compile(File.read(SERENADEJS_PATH)) code = "Serenade.view(#{MultiJson.dump(content)}).parse()" context.eval(code) end |
#render ⇒ String
39 40 41 |
# File 'lib/serenade/renderer.rb', line 39 def render "Serenade.view(#{MultiJson.dump(name)}, #{MultiJson.dump(parse)});" end |