class Kojo::FrontMatterTemplate
The FrontMatterTemplate
class handles a single template file, that contains a YAML front matter.
Attributes
args[R]
file[R]
template[R]
Public Class Methods
new(file)
click to toggle source
# File lib/kojo/front_matter_template.rb, line 9 def initialize(file) @file = file end
Public Instance Methods
render(additional_args = nil) { |outfile, content| ... }
click to toggle source
# File lib/kojo/front_matter_template.rb, line 13 def render(additional_args = nil) additional_args ||= {} config, @template = read_file file config.each do |outfile, args| content = handle args.merge(additional_args) yield outfile, content end end
Private Instance Methods
handle(args = {})
click to toggle source
# File lib/kojo/front_matter_template.rb, line 25 def handle(args = {}) content = template content = content.eval_erb args, file content = content.eval_vars args, file content end
read_file(file)
click to toggle source
# File lib/kojo/front_matter_template.rb, line 32 def read_file(file) raise Kojo::NotFoundError, "File not found: #{file}" unless File.exist? file config = YAML.load_file file content = File.read(file)[/^---\s*$\n(.*)/m, 1] [config, content] end