lib/nanoc/base/compilation/rule_context.rb in nanoc-4.0.2 vs lib/nanoc/base/compilation/rule_context.rb in nanoc-4.1.0a1
- old
+ new
@@ -3,25 +3,25 @@
# It provides access to the item representation that is being compiled or
# routed.
#
# @api private
class RuleContext < Nanoc::Int::Context
- # @option params [Nanoc::Int::ItemRep] :rep
- # @option params [Nanoc::Int::Compiler] :compiler
- def initialize(params = {})
- rep = params.fetch(:rep)
- compiler = params.fetch(:compiler)
- @_executor = params.fetch(:executor)
+ # @param [Nanoc::Int::ItemRep] rep
+ # @param [Nanoc::Int::Site] site
+ # @param [Nanoc::Int::Executor, Nanoc::Int::RecordingExecutor] executor
+ # @param [Nanoc::ViewContext] view_context
+ def initialize(rep:, site:, executor:, view_context:)
+ @_executor = executor
super({
- item: Nanoc::ItemView.new(rep.item),
- rep: Nanoc::ItemRepView.new(rep),
- item_rep: Nanoc::ItemRepView.new(rep),
- items: Nanoc::ItemCollectionView.new(compiler.site.items),
- layouts: Nanoc::LayoutCollectionView.new(compiler.site.layouts),
- config: Nanoc::ConfigView.new(compiler.site.config),
- site: Nanoc::SiteView.new(compiler.site),
+ item: Nanoc::ItemView.new(rep.item, view_context),
+ rep: Nanoc::ItemRepView.new(rep, view_context),
+ item_rep: Nanoc::ItemRepView.new(rep, view_context),
+ items: Nanoc::ItemCollectionView.new(site.items, view_context),
+ layouts: Nanoc::LayoutCollectionView.new(site.layouts, view_context),
+ config: Nanoc::ConfigView.new(site.config, view_context),
+ site: Nanoc::SiteView.new(site, view_context),
})
end
# Filters the current representation (calls {Nanoc::Int::ItemRep#filter} with
# the given arguments on the rep).
@@ -57,11 +57,25 @@
#
# @see Nanoc::Int::ItemRep#snapshot
#
# @param [Symbol] snapshot_name The name of the snapshot to create
#
+ # @param [String, nil] path
+ #
# @return [void]
- def snapshot(snapshot_name)
- @_executor.snapshot(rep.unwrap, snapshot_name)
+ def snapshot(snapshot_name, path: nil)
+ @_executor.snapshot(rep.unwrap, snapshot_name, path: path)
+ end
+
+ # Creates a snapshot named :last the current compiled item content, with
+ # the given path. This is a convenience method for {#snapshot}.
+ #
+ # @see #snapshot
+ #
+ # @param [String] path
+ #
+ # @return [void]
+ def write(path)
+ snapshot(:last, path: path)
end
end
end