lib/nanoc/base/compilation/rules_collection.rb in nanoc-3.6.11 vs lib/nanoc/base/compilation/rules_collection.rb in nanoc-3.7.0

- old
+ new

@@ -26,21 +26,25 @@ # ordered: iterating over the hash will happen in insertion order. # # @return [Hash] The layout-to-filter mapping rules attr_reader :layout_filter_mapping - # @return [Proc] The code block that will be executed after all data is - # loaded but before the site is compiled - attr_accessor :preprocessor + # The hash containing preprocessor code blocks that will be executed after + # all data is loaded but before the site is compiled. + # + # @return [Hash] The hash containing the preprocessor code blocks that will + # be executed after all data is loaded but before the site is compiled + attr_accessor :preprocessors # @param [Nanoc::Compiler] compiler The site’s compiler def initialize(compiler) @compiler = compiler - @item_compilation_rules = [] - @item_routing_rules = [] - @layout_filter_mapping = OrderedHash.new + @item_compilation_rules = [] + @item_routing_rules = [] + @layout_filter_mapping = OrderedHash.new + @preprocessors = OrderedHash.new end # Add the given rule to the list of item compilation rules. # # @param [Nanoc::Rule] rule The item compilation rule to add @@ -74,23 +78,32 @@ # Find rules file rules_filenames = [ 'Rules', 'rules', 'Rules.rb', 'rules.rb' ] rules_filename = rules_filenames.find { |f| File.file?(f) } raise Nanoc::Errors::NoRulesFileFound.new if rules_filename.nil? + parse(rules_filename) + end + + def parse(rules_filename) + rules_filename = File.absolute_path(rules_filename) + # Get rule data @data = File.read(rules_filename) - # Load DSL - dsl.instance_eval(@data, "./#{rules_filename}") + old_rules_filename = dsl.rules_filename + dsl.rules_filename = rules_filename + dsl.instance_eval(@data, rules_filename) + dsl.rules_filename = old_rules_filename end # Unloads this site’s rules. # # @return [void] def unload - @item_compilation_rules = [] - @item_routing_rules = [] - @layout_filter_mapping = OrderedHash.new + @item_compilation_rules = [] + @item_routing_rules = [] + @layout_filter_mapping = OrderedHash.new + @preprocessors = OrderedHash.new end # Finds the first matching compilation rule for the given item # representation. #