Class: Pakman::LiquidTemplate
- Inherits:
-
Object
- Object
- Pakman::LiquidTemplate
- Defined in:
- lib/pakman/liquid/template.rb
Class Method Summary collapse
- .from_file(path) ⇒ Object
-
.from_string(text) ⇒ Object
use parse as alias - why?? why not??.
Instance Method Summary collapse
-
#initialize(text, opts = {}) ⇒ LiquidTemplate
constructor
A new instance of LiquidTemplate.
- #render(hash) ⇒ Object
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 |