Class: Inversion::TiltWrapper

Inherits:
Tilt::Template
  • Object
show all
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

Instance Method Summary collapse

Class Method Details

.engine_initialized?Boolean

Tilt::Template API: returns true if Inversion is loaded.

Returns:

  • (Boolean)


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_engineObject

Tilt::Template API: lazy-load Inversion



21
22
23
# File 'lib/inversion/tilt.rb', line 21

def initialize_engine
  require_template_library 'inversion'
end

#prepareObject

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.options )
  @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