class Textigniter::Parsers::TemplateParser
This class parses templates. Currently it only parses liquid templates
Public Instance Methods
parse(layout_file, item, blogs)
click to toggle source
# File lib/textigniter/parsers/template_parser.rb, line 24 def parse(layout_file, item, blogs) # merge item and blogs if item has blog key # if item.has_key? 'blog' blogs.each do |key, value| item["#{key}"] = value end # end # require liquid lib require 'liquid' #parse the template Liquid::Template.file_system = Liquid::LocalFileSystem.new("#{$twd}/layouts") template = Liquid::Template.parse(layout_file) # render the template output = template.render(item) # return the output return output end
process(item_list)
click to toggle source
# File lib/textigniter/parsers/template_parser.rb, line 4 def process(item_list) # Output message STDOUT.puts "Rendering ".yellow_on_black + "[liquid]".blue_on_black + " templates ".yellow_on_black + "[OK]".green_on_black # create an array to store processed templates items = Array.new # iterate through the item list and parse templates item_list['items'].each do |item| # specifiy the template file = File.open("#{$twd}/layouts/" + item['layout'] + '.liquid', 'rb') # load the template template_from_file = file.read # render the output item['output'] = parse(template_from_file, item, item_list['blogs']) # push the item onto the array items.push item end # return the items return items end