class Serenade::Renderer

Serenade::Renderer compiles Serenade views into a Serenade AST.

Attributes

content[R]

@return [String] content of the serenade view, before compilation

name[R]

@return [String] name of the serenade view

Public Class Methods

new(name, content) click to toggle source
# File lib/serenade/renderer.rb, line 19
def initialize(name, content)
  @name = name
  @content = content
end

Public Instance Methods

parse() click to toggle source

Parse the Serenade view in {#content}.

@return [Hash] Serenade view AST.

# 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() click to toggle source

Parse the Serenade view in {#content} and return a JavaScript string that will register the view with the designated {#name} in Serenade.

This is the compiled output of a Serenade view template in Sprockets.

@return [String] JavaScript output: ‘Serenade.view(’view_name’, view_ast)‘

# File lib/serenade/renderer.rb, line 39
def render
  "Serenade.view(#{MultiJson.dump(name)}, #{MultiJson.dump(parse)});"
end