Class: Serenade::Template

Inherits:
Tilt::Template
  • Object
show all
Defined in:
lib/serenade/template.rb

Overview

Tilt template for Serenade views. Tilt is used by Sprocket engines.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.default_mime_typeString

Returns mime type assigned to all Serenade templates.

Returns:

  • (String)

    mime type assigned to all Serenade templates


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

def self.default_mime_type
  "application/javascript"
end

Instance Method Details

#evaluate(scope, locals, &block) ⇒ String

Used by tilt to render the template.

Parameters:

  • scope
  • locals (Hash)

Returns:

  • (String)

    JavaScript output: `Serenade.view('view_name', view_ast)`


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

def evaluate(scope, locals, &block)
  name = scope.logical_path.gsub(/^views\//, "")
  Serenade::Renderer.new(name, data.dup).render
end

#prepareObject

Tilt forces us to override this, or it will raise a NotImplementedError.


13
14
# File 'lib/serenade/template.rb', line 13

def prepare
end