Class: Pakman::LiquidTemplate

Inherits:
Object
  • Object
show all
Defined in:
lib/pakman/liquid/template.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(text, opts = {}) ⇒ LiquidTemplate

Returns a new instance of LiquidTemplate.



18
19
20
# File 'lib/pakman/liquid/template.rb', line 18

def initialize( text, opts={} )
  @template = Liquid::Template.parse( text )   # parses and compiles the template
end

Class Method Details

.from_file(path) ⇒ Object



8
9
10
11
12
# File 'lib/pakman/liquid/template.rb', line 8

def self.from_file( path )
  puts "  Loading template (from file) >#{path}<..."
  text = File.read( path )     ## use/todo: use read utf8 - why? why not??
  self.new( text, path: path )   ## note: pass along path as an option
end

.from_string(text) ⇒ Object

use parse as alias - why?? why not??



14
15
16
# File 'lib/pakman/liquid/template.rb', line 14

def self.from_string( text )  ### use parse as alias - why?? why not??
  self.new( text )
end

Instance Method Details

#render(hash) ⇒ Object



22
23
24
25
26
# File 'lib/pakman/liquid/template.rb', line 22

def render( hash )
  ## note: hash keys MUST be strings (not symbols) e.g. 'name' => 'Toby'
  ## pp hash
  @template.render( hash )
end