Class: Nanoc3::RuleContext Private

Inherits:
Context
  • Object
show all
Defined in:
lib/nanoc3/base/compilation/rule_context.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Provides a context in which compilation and routing rules can be executed. It provides access to the item representation that is being compiled or routed.

The following variables will be available in this rules context:

  • ‘rep` (ItemRep) - The current item rep

  • ‘item` (Item) - The current item

  • ‘site` (Site) - The site

  • ‘config` (Hash) - The site configuration

  • ‘items` (Array<Item>) - A list of all items

  • ‘layouts` (Array<Layout>) - A list of all layouts

Instance Method Summary collapse

Methods inherited from Context

#get_binding

Constructor Details

#initialize(params = {}) ⇒ RuleContext

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of RuleContext.

Parameters:

  • params (Hash) (defaults to: {})

    a customizable set of options

Options Hash (params):

  • :rep (Nanoc3::ItemRep)

    The item representation that will be processed in this rule context

  • :compiler (Nanoc3::Compiler)

    The compiler that is being used to compile the site

Raises:

  • (ArgumentError)

    if the ‘:rep` or the `:compiler` option is missing



27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/nanoc3/base/compilation/rule_context.rb', line 27

def initialize(params={})
  rep      = params[:rep]      or raise ArgumentError, "Required :rep option is missing"
  compiler = params[:compiler] or raise ArgumentError, "Required :compiler option is missing"

  super({
    :rep     => rep,
    :item    => rep.item,
    :site    => compiler.site,
    :config  => compiler.site.config,
    :items   => compiler.site.items,
    :layouts => compiler.site.layouts
  })
end

Instance Method Details

#filter(filter_name, filter_args = {}) ⇒ void

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

This method returns an undefined value.

Filters the current representation (calls ItemRep#filter with the given arguments on the rep).

Parameters:

  • filter_name (Symbol)

    The name of the filter to run the item representations’ content through

  • filter_args (Hash) (defaults to: {})

    The filter arguments that should be passed to the filter’s #run method

See Also:



53
54
55
# File 'lib/nanoc3/base/compilation/rule_context.rb', line 53

def filter(filter_name, filter_args={})
  rep.filter(filter_name, filter_args)
end

#layout(layout_identifier) ⇒ void

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

This method returns an undefined value.

Layouts the current representation (calls ItemRep#layout with the given arguments on the rep).

Parameters:

  • layout_identifier (String)

    The identifier of the layout the item should be laid out with

See Also:



66
67
68
# File 'lib/nanoc3/base/compilation/rule_context.rb', line 66

def layout(layout_identifier)
  rep.layout(layout_identifier)
end

#snapshot(snapshot_name) ⇒ void

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

This method returns an undefined value.

Creates a snapshot of the current compiled item content. Calls ItemRep#snapshot with the given arguments on the rep.

Parameters:

  • snapshot_name (Symbol)

    The name of the snapshot to create

See Also:



78
79
80
# File 'lib/nanoc3/base/compilation/rule_context.rb', line 78

def snapshot(snapshot_name)
  rep.snapshot(snapshot_name)
end