Class: Nanoc::RuleDSL::ActionProvider

Inherits:
Int::ActionProvider show all
Defined in:
lib/nanoc/rule_dsl/action_provider.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Int::PluginRegistry::PluginMethods

#all, #identifier, #identifiers, #named, #register

Constructor Details

#initialize(rules_collection, rule_memory_calculator) ⇒ ActionProvider

Returns a new instance of ActionProvider.



23
24
25
26
# File 'lib/nanoc/rule_dsl/action_provider.rb', line 23

def initialize(rules_collection, rule_memory_calculator)
  @rules_collection = rules_collection
  @rule_memory_calculator = rule_memory_calculator
end

Instance Attribute Details

#rules_collectionObject (readonly)

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.



6
7
8
# File 'lib/nanoc/rule_dsl/action_provider.rb', line 6

def rules_collection
  @rules_collection
end

Class Method Details

.for(site) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/nanoc/rule_dsl/action_provider.rb', line 8

def self.for(site)
  rules_collection = Nanoc::RuleDSL::RulesCollection.new

  rule_memory_calculator =
    Nanoc::RuleDSL::RuleMemoryCalculator.new(
      rules_collection: rules_collection, site: site,
    )

  action_provider = new(rules_collection, rule_memory_calculator)

  Nanoc::RuleDSL::RulesLoader.new(site.config, rules_collection).load

  action_provider
end

Instance Method Details

#memory_for(rep) ⇒ Object



35
36
37
# File 'lib/nanoc/rule_dsl/action_provider.rb', line 35

def memory_for(rep)
  @rule_memory_calculator[rep]
end

#new_postprocessor_context(site, view_context) ⇒ Object

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.



86
87
88
89
90
91
# File 'lib/nanoc/rule_dsl/action_provider.rb', line 86

def new_postprocessor_context(site, view_context)
  Nanoc::Int::Context.new(
    config: Nanoc::ConfigView.new(site.config, view_context),
    items: Nanoc::PostCompileItemCollectionView.new(site.items, view_context),
  )
end

#new_preprocessor_context(site) ⇒ Object

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.



68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/nanoc/rule_dsl/action_provider.rb', line 68

def new_preprocessor_context(site)
  dependency_tracker = Nanoc::Int::DependencyTracker::Null.new
  view_context =
    Nanoc::ViewContext.new(
      reps: nil,
      items: nil,
      dependency_tracker: dependency_tracker,
      compiler: nil,
    )

  Nanoc::Int::Context.new(
    config: Nanoc::MutableConfigView.new(site.config, view_context),
    items: Nanoc::MutableItemCollectionView.new(site.items, view_context),
    layouts: Nanoc::MutableLayoutCollectionView.new(site.layouts, view_context),
  )
end

#postprocess(site, reps) ⇒ Object



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/nanoc/rule_dsl/action_provider.rb', line 51

def postprocess(site, reps)
  dependency_tracker = Nanoc::Int::DependencyTracker::Null.new
  view_context =
    Nanoc::ViewContext.new(
      reps: reps,
      items: site.items,
      dependency_tracker: dependency_tracker,
      compiler: site.compiler,
    )
  ctx = new_postprocessor_context(site, view_context)

  @rules_collection.postprocessors.each_value do |postprocessor|
    ctx.instance_eval(&postprocessor)
  end
end

#preprocess(site) ⇒ Object



43
44
45
46
47
48
49
# File 'lib/nanoc/rule_dsl/action_provider.rb', line 43

def preprocess(site)
  ctx = new_preprocessor_context(site)

  @rules_collection.preprocessors.each_value do |preprocessor|
    ctx.instance_eval(&preprocessor)
  end
end

#rep_names_for(item) ⇒ Object



28
29
30
31
32
33
# File 'lib/nanoc/rule_dsl/action_provider.rb', line 28

def rep_names_for(item)
  matching_rules = @rules_collection.item_compilation_rules_for(item)
  raise Nanoc::Int::Errors::NoMatchingCompilationRuleFound.new(item) if matching_rules.empty?

  matching_rules.map(&:rep_name).uniq
end

#snapshots_defs_for(rep) ⇒ Object



39
40
41
# File 'lib/nanoc/rule_dsl/action_provider.rb', line 39

def snapshots_defs_for(rep)
  @rule_memory_calculator.snapshots_defs_for(rep)
end