Class: Nanoc::RuleDSL::CompilationRuleContext Private

Inherits:
RuleContext
  • Object
show all
Includes:
Core::ContractsSupport
Defined in:
lib/nanoc/rule_dsl/compilation_rule_context.rb

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.

Instance Method Summary collapse

Constructor Details

#initialize(rep:, site:, recorder:, view_context:) ⇒ CompilationRuleContext

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 CompilationRuleContext.



13
14
15
16
17
# File 'lib/nanoc/rule_dsl/compilation_rule_context.rb', line 13

def initialize(rep:, site:, recorder:, view_context:)
  @_recorder = recorder

  super(rep:, site:, 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 Core::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:

  • Core::ItemRep#filter


31
32
33
# File 'lib/nanoc/rule_dsl/compilation_rule_context.rb', line 31

def filter(filter_name, filter_args = {})
  @_recorder.filter(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 Core::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:

  • Core::ItemRep#layout


44
45
46
# File 'lib/nanoc/rule_dsl/compilation_rule_context.rb', line 44

def layout(layout_identifier, extra_filter_args = nil)
  @_recorder.layout(layout_identifier, extra_filter_args)
end

#snapshot(snapshot_name, path: Nanoc::Core::UNDEFINED) ⇒ 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 Core::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: Nanoc::Core::UNDEFINED)

See Also:

  • Core::ItemRep#snapshot


58
59
60
# File 'lib/nanoc/rule_dsl/compilation_rule_context.rb', line 58

def snapshot(snapshot_name, path: Nanoc::Core::UNDEFINED)
  @_recorder.snapshot(snapshot_name, path:)
end

#write(arg) ⇒ 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:

  • arg (String)

See Also:



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/nanoc/rule_dsl/compilation_rule_context.rb', line 70

def write(arg)
  @_write_snapshot_counter ||= 0
  snapshot_name = :"_#{@_write_snapshot_counter}"
  @_write_snapshot_counter += 1

  case arg
  when String, Nanoc::Core::Identifier, nil
    snapshot(snapshot_name, path: arg)
  when Hash
    if arg.key?(:ext)
      ext = arg[:ext].sub(/\A\./, '')
      path = @item.identifier.without_exts + '.' + ext
      snapshot(snapshot_name, path:)
    else
      raise ArgumentError, 'Cannot call #write this way (need path or :ext)'
    end
  else
    raise ArgumentError, 'Cannot call #write this way (need path or :ext)'
  end
end