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)


14
15
16
# File 'lib/inversion/tilt.rb', line 14

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`.



39
40
41
42
43
44
# File 'lib/inversion/tilt.rb', line 39

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



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

def initialize_engine
	require_template_library 'inversion'
end

#prepareObject

Tilt::Template API: load a template



26
27
28
29
30
# File 'lib/inversion/tilt.rb', line 26

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.



34
35
36
# File 'lib/inversion/tilt.rb', line 34

def render( *args )
	self.evaluate( *args )
end