Class: Benoit::Filters::ContentPageFilter
- Inherits:
-
Rake::Pipeline::Filter
- Object
- Rake::Pipeline::Filter
- Benoit::Filters::ContentPageFilter
- Defined in:
- lib/benoit/filters/content_page_filter.rb
Instance Attribute Summary collapse
-
#current_site ⇒ Object
Returns the value of attribute current_site.
Instance Method Summary collapse
- #additional_dependencies(input = nil) ⇒ Object
- #generate_output(inputs, output) ⇒ Object
-
#initialize ⇒ ContentPageFilter
constructor
A new instance of ContentPageFilter.
- #page_layouts_for_input(input) ⇒ Object
Constructor Details
#initialize ⇒ ContentPageFilter
Returns a new instance of ContentPageFilter.
7 8 9 10 |
# File 'lib/benoit/filters/content_page_filter.rb', line 7 def initialize super @page_layouts = {} end |
Instance Attribute Details
#current_site ⇒ Object
Returns the value of attribute current_site.
5 6 7 |
# File 'lib/benoit/filters/content_page_filter.rb', line 5 def current_site @current_site end |
Instance Method Details
#additional_dependencies(input = nil) ⇒ Object
35 36 37 38 39 40 41 42 |
# File 'lib/benoit/filters/content_page_filter.rb', line 35 def additional_dependencies(input=nil) if input output = current_site.paths_map[input.path] page_layouts_for_input(input) else [] end end |
#generate_output(inputs, output) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/benoit/filters/content_page_filter.rb', line 12 def generate_output(inputs, output) inputs.each do |input| layout = page_layouts_for_input(input).first template = if layout # TODO: Only use this for files that don't extend already but have specified a layout, if the file extends, then just replace the extends line with the normalized layout "{% extends '#{layout}' %}\n\n" end.to_s template << input.read output.write(template) end end |
#page_layouts_for_input(input) ⇒ Object
30 31 32 33 |
# File 'lib/benoit/filters/content_page_filter.rb', line 30 def page_layouts_for_input(input) @page_layouts[input.path] ||= FindsLayoutsForTemplate(input, root: input.root, load_paths: ["_layouts"]) end |