lib/nanoc/base/compilation/compiler_dsl.rb in nanoc-4.0.0a1 vs lib/nanoc/base/compilation/compiler_dsl.rb in nanoc-4.0.0a2

- old
+ new

@@ -75,11 +75,11 @@ # Get rep name rep_name = params[:rep] || :default # Create rule - rule = Nanoc::Int::Rule.new(identifier_to_regex(identifier), rep_name, block) + rule = Nanoc::Int::Rule.new(create_pattern(identifier), rep_name, block) @rules_collection.add_item_compilation_rule(rule) end # Creates a routing rule for all items whose identifier match the # given identifier, which may either be a string containing the `*` @@ -120,11 +120,11 @@ # Get rep name rep_name = params[:rep] || :default snapshot_name = params[:snapshot] || :last # Create rule - rule = Nanoc::Int::Rule.new(identifier_to_regex(identifier), rep_name, block, snapshot_name: snapshot_name) + rule = Nanoc::Int::Rule.new(create_pattern(identifier), rep_name, block, snapshot_name: snapshot_name) @rules_collection.add_item_routing_rule(rule) end # Creates a layout rule for all layouts whose identifier match the given # identifier, which may either be a string containing the * wildcard, or a @@ -149,11 +149,12 @@ # # @example Using custom filter arguments for a layout # # layout '/custom/', :haml, :format => :html5 def layout(identifier, filter_name, params = {}) - @rules_collection.layout_filter_mapping[identifier_to_regex(identifier)] = [filter_name, params] + pattern = Nanoc::Int::Pattern.from(create_pattern(identifier)) + @rules_collection.layout_filter_mapping[pattern] = [filter_name, params] end # Creates a pair of compilation and routing rules that indicate that the # specified item(s) should be copied to the output folder as-is. The items # are selected using an identifier, which may either be a string @@ -186,22 +187,22 @@ # Get rep name rep_name = params[:rep] || :default # Create compilation rule compilation_block = proc {} - compilation_rule = Nanoc::Int::Rule.new(identifier_to_regex(identifier), rep_name, compilation_block) + compilation_rule = Nanoc::Int::Rule.new(create_pattern(identifier), rep_name, compilation_block) @rules_collection.add_item_compilation_rule(compilation_rule) # Create routing rule routing_block = proc do # This is a temporary solution until an item can map back to its data # source. # ATM item[:content_filename] is nil for items coming from the static # data source. item[:extension].nil? || (item[:content_filename].nil? && item.identifier =~ %r{#{item[:extension]}/$}) ? item.identifier.chop : item.identifier.chop + '.' + item[:extension] end - routing_rule = Nanoc::Int::Rule.new(identifier_to_regex(identifier), rep_name, routing_block, snapshot_name: :last) + routing_rule = Nanoc::Int::Rule.new(create_pattern(identifier), rep_name, routing_block, snapshot_name: :last) @rules_collection.add_item_routing_rule(routing_rule) end # Creates a pair of compilation and routing rules that indicate that the # specified item(s) should be ignored, e.g. compiled and routed with an @@ -225,14 +226,14 @@ def ignore(identifier, params = {}) raise ArgumentError.new('#ignore does not require a block') if block_given? rep_name = params[:rep] || :default - compilation_rule = Nanoc::Int::Rule.new(identifier_to_regex(identifier), rep_name, proc {}) + compilation_rule = Nanoc::Int::Rule.new(create_pattern(identifier), rep_name, proc {}) @rules_collection.add_item_compilation_rule(compilation_rule) - routing_rule = Nanoc::Int::Rule.new(identifier_to_regex(identifier), rep_name, proc {}, snapshot_name: :last) + routing_rule = Nanoc::Int::Rule.new(create_pattern(identifier), rep_name, proc {}, snapshot_name: :last) @rules_collection.add_item_routing_rule(routing_rule) end # Includes an additional rules file in the current rules collection. # @@ -249,9 +250,22 @@ def include_rules(name) filename = ["#{name}", "#{name}.rb", "./#{name}", "./#{name}.rb"].find { |f| File.file?(f) } raise Nanoc::Int::Errors::NoRulesFileFound.new if filename.nil? @rules_collection.parse(filename) + end + + # @api private + def create_pattern(arg) + case @config[:pattern_syntax] + when 'glob' + Nanoc::Int::Pattern.from(arg) + when nil + Nanoc::Int::Pattern.from(identifier_to_regex(arg)) + else + raise Nanoc::Int::Errors::GenericTrivial, + "Invalid pattern_syntax: #{@config[:pattern_syntax]}" + end end private # Converts the given identifier, which can contain the '*' or '+'