lib/nanoc/base/compilation/compiler_dsl.rb in nanoc-3.8.0 vs lib/nanoc/base/compilation/compiler_dsl.rb in nanoc-4.0.0a1
- old
+ new
@@ -1,20 +1,22 @@
# encoding: utf-8
-module Nanoc
+module Nanoc::Int
# Contains methods that will be executed by the site’s `Rules` file.
class CompilerDSL
# The current rules filename.
#
# @return [String] The current rules filename.
+ #
+ # @api private
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
+ # @param [Nanoc::Int::RulesCollection] rules_collection The collection of
# rules to modify when loading this DSL
#
# @param [Hash] config The site configuration
def initialize(rules_collection, config)
@rules_collection = rules_collection
@@ -73,11 +75,11 @@
# Get rep name
rep_name = params[:rep] || :default
# Create rule
- rule = Rule.new(identifier_to_regex(identifier), rep_name, block)
+ rule = Nanoc::Int::Rule.new(identifier_to_regex(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 `*`
@@ -118,11 +120,11 @@
# Get rep name
rep_name = params[:rep] || :default
snapshot_name = params[:snapshot] || :last
# Create rule
- rule = Rule.new(identifier_to_regex(identifier), rep_name, block, snapshot_name: snapshot_name)
+ rule = Nanoc::Int::Rule.new(identifier_to_regex(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
@@ -184,22 +186,22 @@
# Get rep name
rep_name = params[:rep] || :default
# Create compilation rule
compilation_block = proc {}
- compilation_rule = Rule.new(identifier_to_regex(identifier), rep_name, compilation_block)
+ compilation_rule = Nanoc::Int::Rule.new(identifier_to_regex(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 = Rule.new(identifier_to_regex(identifier), rep_name, routing_block, snapshot_name: :last)
+ routing_rule = Nanoc::Int::Rule.new(identifier_to_regex(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
@@ -223,14 +225,14 @@
def ignore(identifier, params = {})
raise ArgumentError.new('#ignore does not require a block') if block_given?
rep_name = params[:rep] || :default
- compilation_rule = Rule.new(identifier_to_regex(identifier), rep_name, proc {})
+ compilation_rule = Nanoc::Int::Rule.new(identifier_to_regex(identifier), rep_name, proc {})
@rules_collection.add_item_compilation_rule(compilation_rule)
- routing_rule = Rule.new(identifier_to_regex(identifier), rep_name, proc {}, snapshot_name: :last)
+ routing_rule = Nanoc::Int::Rule.new(identifier_to_regex(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.
#
@@ -244,10 +246,10 @@
#
# include_rules 'rules/assets'
# 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?
+ raise Nanoc::Int::Errors::NoRulesFileFound.new if filename.nil?
@rules_collection.parse(filename)
end
private