Class: Nanoc::RuleDSL::RuleContext Private

Inherits:
Int::Context show all
Defined in:
lib/nanoc/rule_dsl/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.

Instance Method Summary collapse

Methods inherited from Int::Context

#get_binding

Constructor Details

#initialize(rep:, site:, executor:, view_context:) ⇒ 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.



12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/nanoc/rule_dsl/rule_context.rb', line 12

def initialize(rep:, site:, executor:, view_context:)
  @_executor = executor

  super({
    item: Nanoc::ItemWithoutRepsView.new(rep.item, view_context),
    rep: Nanoc::ItemRepView.new(rep, view_context),
    item_rep: Nanoc::ItemRepView.new(rep, view_context),
    items: Nanoc::ItemCollectionWithoutRepsView.new(site.items, view_context),
    layouts: Nanoc::LayoutCollectionView.new(site.layouts, view_context),
    config: Nanoc::ConfigView.new(site.config, view_context),
  })
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 Int::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:

  • Int::ItemRep#filter


37
38
39
# File 'lib/nanoc/rule_dsl/rule_context.rb', line 37

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

#layout(layout_identifier, extra_filter_args = nil) ⇒ 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 Int::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:

  • Int::ItemRep#layout


50
51
52
# File 'lib/nanoc/rule_dsl/rule_context.rb', line 50

def layout(layout_identifier, extra_filter_args = nil)
  @_executor.layout(rep.unwrap, layout_identifier, extra_filter_args)
end

#snapshot(snapshot_name, path: nil) ⇒ 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 Int::ItemRep#snapshot with the given arguments on the rep.

Parameters:

  • snapshot_name (Symbol)

    The name of the snapshot to create

  • path (String, nil) (defaults to: nil)

See Also:

  • Int::ItemRep#snapshot


64
65
66
# File 'lib/nanoc/rule_dsl/rule_context.rb', line 64

def snapshot(snapshot_name, path: nil)
  @_executor.snapshot(rep.unwrap, snapshot_name, path: path)
end

#write(path) ⇒ 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 named :last the current compiled item content, with the given path. This is a convenience method for #snapshot.

Parameters:

See Also:



76
77
78
# File 'lib/nanoc/rule_dsl/rule_context.rb', line 76

def write(path)
  snapshot(:last, path: path)
end