Class: Nanoc::RuleDSL::RecordingExecutor

Inherits:
Object
  • Object
show all
Defined in:
lib/nanoc/rule_dsl/recording_executor.rb

Defined Under Namespace

Classes: PathWithoutInitialSlashError

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(item_rep, rules_collection, site) ⇒ RecordingExecutor

Returns a new instance of RecordingExecutor



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

def initialize(item_rep, rules_collection, site)
  @item_rep = item_rep
  @rules_collection = rules_collection
  @site = site

  @rule_memory = Nanoc::Int::RuleMemory.new(item_rep)
end

Instance Attribute Details

#rule_memoryObject (readonly)

Returns the value of attribute rule_memory



10
11
12
# File 'lib/nanoc/rule_dsl/recording_executor.rb', line 10

def rule_memory
  @rule_memory
end

Instance Method Details

#basic_path_from_rules_for(rep, snapshot_name) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/nanoc/rule_dsl/recording_executor.rb', line 37

def basic_path_from_rules_for(rep, snapshot_name)
  routing_rules = @rules_collection.routing_rules_for(rep)
  routing_rule = routing_rules[snapshot_name]
  return nil if routing_rule.nil?

  dependency_tracker = Nanoc::Int::DependencyTracker::Null.new
  view_context = Nanoc::ViewContext.new(reps: nil, items: nil, dependency_tracker: dependency_tracker, compiler: nil)
  basic_path = routing_rule.apply_to(rep, executor: nil, site: @site, view_context: view_context)
  if basic_path && !basic_path.start_with?('/')
    raise PathWithoutInitialSlashError.new(rep, basic_path)
  end
  basic_path
end

#filter(_rep, filter_name, filter_args = {}) ⇒ Object



20
21
22
# File 'lib/nanoc/rule_dsl/recording_executor.rb', line 20

def filter(_rep, filter_name, filter_args = {})
  @rule_memory.add_filter(filter_name, filter_args)
end

#layout(_rep, layout_identifier, extra_filter_args = {}) ⇒ Object



24
25
26
27
28
29
30
# File 'lib/nanoc/rule_dsl/recording_executor.rb', line 24

def layout(_rep, layout_identifier, extra_filter_args = {})
  unless @rule_memory.any_layouts?
    @rule_memory.add_snapshot(:pre, true, nil)
  end

  @rule_memory.add_layout(layout_identifier, extra_filter_args)
end

#snapshot(rep, snapshot_name, final: true, path: nil) ⇒ Object



32
33
34
35
# File 'lib/nanoc/rule_dsl/recording_executor.rb', line 32

def snapshot(rep, snapshot_name, final: true, path: nil)
  actual_path = final ? (path || basic_path_from_rules_for(rep, snapshot_name)) : nil
  @rule_memory.add_snapshot(snapshot_name, final, actual_path)
end