class Pakman::LiquidTemplate
Public Class Methods
from_file( path )
click to toggle source
# File lib/pakman/liquid/template.rb, line 8 def self.from_file( path ) puts " Loading template (from file) >#{path}<..." text = File.open( path, 'r:bom|utf-8' ).read ## note: assume utf8 self.new( text, path: path ) ## note: pass along path as an option end
from_string( text )
click to toggle source
# File lib/pakman/liquid/template.rb, line 14 def self.from_string( text ) ### use parse as alias - why?? why not?? self.new( text ) end
new( text, opts={} )
click to toggle source
# File lib/pakman/liquid/template.rb, line 18 def initialize( text, opts={} ) @template = Liquid::Template.parse( text ) # parses and compiles the template end
Public Instance Methods
render( hash )
click to toggle source
# 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 res = @template.render( hash, { strict_variables: true, strict_filters: true } ) ### ## issue warnings/errors if present errors = @template.errors if errors.size > 0 puts "!! WARN - #{errors.size} liquid error(s) when rendering template:" pp errors end res end