Class: Nanoc3::RuleContext

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

Overview

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

- (RuleContext) initialize(rep)

Creates a new rule context for the given item representation.

a new rule context.

Parameters:



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/nanoc3/base/rule_context.rb', line 21

def initialize(rep)
  item    = rep.item
  site    = item.site
  config  = site.config
  items   = site.items
  layouts = site.layouts

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

Instance Method Details

- (void) filter(filter_name, filter_args = {})

This method returns an undefined value.

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

representations' content through

the filter's #run method

Parameters:

  • filter_name (Symbol)

    The name of the filter to run the item

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

    The filter arguments that should be passed to

See Also:



50
51
52
# File 'lib/nanoc3/base/rule_context.rb', line 50

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

- (void) layout(layout_identifier)

This method returns an undefined value.

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

should be laid out with

Parameters:

  • layout_identifier (String)

    The identifier of the layout the item

See Also:



63
64
65
# File 'lib/nanoc3/base/rule_context.rb', line 63

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

- (void) snapshot(snapshot_name)

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:



75
76
77
# File 'lib/nanoc3/base/rule_context.rb', line 75

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