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

- old
+ new

@@ -3,10 +3,15 @@ module Nanoc # Contains methods that will be executed by the site’s `Rules` file. class CompilerDSL + # The current rules filename. + # + # @return [String] The current rules filename. + attr_accessor :rules_filename + # Creates a new compiler DSL for the given collection of rules. # # @api private # # @param [Nanoc::RulesCollection] rules_collection The collection of @@ -23,16 +28,15 @@ # # @yield The block that will be executed before site compilation starts # # @return [void] def preprocess(&block) - if @rules_collection.preprocessor + if @rules_collection.preprocessors[rules_filename] warn 'WARNING: A preprocess block is already defined. Defining ' \ 'another preprocess block overrides the previously one.' end - - @rules_collection.preprocessor = block + @rules_collection.preprocessors[rules_filename] = block end # Creates a compilation rule for all items whose identifier match the # given identifier, which may either be a string containing the * # wildcard, or a regular expression. @@ -244,10 +248,10 @@ # include_rules 'rules/content' def include_rules(name) filename = [ "#{name}", "#{name}.rb", "./#{name}", "./#{name}.rb" ].find { |f| File.file?(f) } raise Nanoc::Errors::NoRulesFileFound.new if filename.nil? - instance_eval(File.read(filename), filename) + @rules_collection.parse(filename) end private # Converts the given identifier, which can contain the '*' or '+'