class Photish::Render::Template
Attributes
layout_file[R]
output_dir[R]
template_file[R]
Public Class Methods
new(layout_file, template_file, output_dir)
click to toggle source
# File lib/photish/render/template.rb, line 6 def initialize(layout_file, template_file, output_dir) @layout_file = layout_file @template_file = template_file @output_dir = output_dir end
Public Instance Methods
render(models)
click to toggle source
# File lib/photish/render/template.rb, line 12 def render(models) return template_missing unless File.exist?(template_file) render_all(models) end
Private Instance Methods
layout()
click to toggle source
# File lib/photish/render/template.rb, line 54 def layout @layout ||= Tilt.new(layout_file) end
relative_to_output_dir(url_parts)
click to toggle source
# File lib/photish/render/template.rb, line 40 def relative_to_output_dir(url_parts) File.join(output_dir, url_parts) end
render_all(models)
click to toggle source
# File lib/photish/render/template.rb, line 23 def render_all(models) Array(models).each do |model| rendered_model = render_template_and_layout(model) output_model_file = relative_to_output_dir(model.url_parts) output_model_dir = relative_to_output_dir(model.base_url_parts) log.debug "Rendering #{model.url} with template #{template_file} to #{output_model_file}" FileUtils.mkdir_p(output_model_dir) File.write(output_model_file, rendered_model) end end
render_template_and_layout(model)
click to toggle source
# File lib/photish/render/template.rb, line 44 def render_template_and_layout(model) layout.render(model) do template.render(model) end end
template()
click to toggle source
# File lib/photish/render/template.rb, line 50 def template @template ||= Tilt.new(template_file) end
template_missing()
click to toggle source
# File lib/photish/render/template.rb, line 36 def template_missing log.debug "Template not found #{template_file}, skipping rendering" end