Class: Benoit::Filters::CadenzaFilter
- Inherits:
-
Rake::Pipeline::Filter
- Object
- Rake::Pipeline::Filter
- Benoit::Filters::CadenzaFilter
- Includes:
- Benoit
- Defined in:
- lib/benoit/filters/cadenza_filter.rb
Constant Summary
Constants included from Benoit
Instance Attribute Summary collapse
-
#current_site ⇒ Object
Returns the value of attribute current_site.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
- #additional_dependencies(input = nil) ⇒ Object
- #generate_output(inputs, output) ⇒ Object
-
#initialize ⇒ CadenzaFilter
constructor
A new instance of CadenzaFilter.
- #page_layouts_for_input(input) ⇒ Object
Methods included from Configuration
Constructor Details
#initialize ⇒ CadenzaFilter
Returns a new instance of CadenzaFilter.
9 10 11 12 |
# File 'lib/benoit/filters/cadenza_filter.rb', line 9 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/cadenza_filter.rb', line 5 def current_site @current_site end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
4 5 6 |
# File 'lib/benoit/filters/cadenza_filter.rb', line 4 def end |
Instance Method Details
#additional_dependencies(input = nil) ⇒ Object
70 71 72 73 74 75 76 |
# File 'lib/benoit/filters/cadenza_filter.rb', line 70 def additional_dependencies(input=nil) if input page_layouts_for_input(input) else [] end end |
#generate_output(inputs, output) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/benoit/filters/cadenza_filter.rb', line 14 def generate_output(inputs, output) # site_context = current_site.to_context inputs.each do |input| load_paths = [input.root, Dir.pwd, "#{Dir.pwd}/_layouts"] Benoit::Cadenza.load_output_filters! load_paths.each do |load_path| ::Cadenza::BaseContext.add_load_path load_path end # page = current_site[input.path].to_hash # Leave the original page for paginated pages blank # otherwise we will get an "iteration reached an end" error # from trying to iterate past the end of the enumerator # if input.path !~ /\d+.html/ && page.keys.any? { |key| key =~ /\w+_per_page/ } # output.write("") # next # end # context_hash = { # "site" => site_context, # "page" => page # } context_hash = {} begin compiled = ::Cadenza.render_template input.path, context_hash rescue ::Cadenza::TemplateNotFoundError => ex error = Benoit::FileMissingError.new(ex., nil, input.path, ex) raise error rescue ::Cadenza::FilterNotDefinedError => ex missing_filter = ex.to_s.scan(/undefined filter '([\w\-]*)'/).flatten.first error = Benoit::CompilerError.new(nil, input.path, ex) error. = "You used a filter named #{missing_filter.inspect}, but I could not find it. Maybe it's misspelled?" raise error rescue ::Cadenza::BlockNotDefinedError => ex missing_block = ex.to_s.scan(/undefined block '([\w\-]*)'/).flatten.first error = Benoit::CompilerError.new(nil, input.path, ex) error. = "You used a block named #{missing_block.inspect}, but I could not find it. Maybe it's misspelled?" raise error end output.write compiled end end |
#page_layouts_for_input(input) ⇒ Object
65 66 67 68 |
# File 'lib/benoit/filters/cadenza_filter.rb', line 65 def page_layouts_for_input(input) @page_layouts[input.path] ||= FindsLayoutsForTemplate(input, root: input.root, load_paths: ["_layouts"]) end |