Class: Inversion::TiltWrapper
- Inherits:
-
Tilt::Template
- Object
- Tilt::Template
- Inversion::TiltWrapper
- Defined in:
- lib/inversion/tilt.rb
Overview
An adapter class for Tilt (github.com/rtomayko/tilt) :TODO: Add an example or two.
Class Method Summary collapse
-
.engine_initialized? ⇒ Boolean
Tilt::Template API: returns true if Inversion is loaded.
Instance Method Summary collapse
-
#evaluate(scope, locals, &block) ⇒ Object
Tilt::Template API: render the template with the given
scope
,locals
, andblock
. -
#initialize_engine ⇒ Object
Tilt::Template API: lazy-load Inversion.
-
#prepare ⇒ Object
Tilt::Template API: load a template.
-
#render(*args) ⇒ Object
Hook the template’s render phase.
Class Method Details
.engine_initialized? ⇒ Boolean
Tilt::Template API: returns true if Inversion is loaded.
15 16 17 |
# File 'lib/inversion/tilt.rb', line 15 def self::engine_initialized? return defined?( Inversion::Template ) end |
Instance Method Details
#evaluate(scope, locals, &block) ⇒ Object
Tilt::Template API: render the template with the given scope
, locals
, and block
.
40 41 42 43 44 45 |
# File 'lib/inversion/tilt.rb', line 40 def evaluate( scope, locals, &block ) @template.attributes.merge!( scope.to_h ) if scope.respond_to?( :to_h ) @template.attributes.merge!( locals ) return @template.render( &block ) end |
#initialize_engine ⇒ Object
Tilt::Template API: lazy-load Inversion
21 22 23 |
# File 'lib/inversion/tilt.rb', line 21 def initialize_engine require_template_library 'inversion' end |
#prepare ⇒ Object
Tilt::Template API: load a template
27 28 29 30 31 |
# File 'lib/inversion/tilt.rb', line 27 def prepare # Load the instance and set the path to the source @template = Inversion::Template.new( self.data, self. ) @template.source_file = self.file end |
#render(*args) ⇒ Object
Hook the template’s render phase.
35 36 37 |
# File 'lib/inversion/tilt.rb', line 35 def render( *args ) self.evaluate( *args ) end |