Class: Nanoc::RuleDSL::ActionProvider Private

Inherits:
Core::ActionProvider
  • Object
show all
Defined in:
lib/nanoc/rule_dsl/action_provider.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 Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(rules_collection, action_sequence_calculator) ⇒ ActionProvider

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



25
26
27
28
# File 'lib/nanoc/rule_dsl/action_provider.rb', line 25

def initialize(rules_collection, action_sequence_calculator)
  @rules_collection = rules_collection
  @action_sequence_calculator = action_sequence_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.



8
9
10
# File 'lib/nanoc/rule_dsl/action_provider.rb', line 8

def rules_collection
  @rules_collection
end

Class Method Details

.for(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.



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

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

  action_sequence_calculator =
    Nanoc::RuleDSL::ActionSequenceCalculator.new(
      rules_collection:, site:,
    )

  action_provider = new(rules_collection, action_sequence_calculator)

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

  action_provider
end

Instance Method Details

#action_sequence_for(obj) ⇒ 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.



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

def action_sequence_for(obj)
  @action_sequence_calculator[obj]
end

#need_preprocessing?Boolean

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:

  • (Boolean)


41
42
43
# File 'lib/nanoc/rule_dsl/action_provider.rb', line 41

def need_preprocessing?
  @rules_collection.preprocessors.any?
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.



90
91
92
93
94
95
# File 'lib/nanoc/rule_dsl/action_provider.rb', line 90

def new_postprocessor_context(site, view_context)
  Nanoc::Core::Context.new(
    config: Nanoc::Core::ConfigView.new(site.config, view_context),
    items: Nanoc::Core::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.



78
79
80
81
82
83
84
85
86
87
# File 'lib/nanoc/rule_dsl/action_provider.rb', line 78

def new_preprocessor_context(site)
  view_context =
    Nanoc::Core::ViewContextForPreCompilation.new(items: site.items)

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

#postprocess(site, compiler) ⇒ 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.



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/nanoc/rule_dsl/action_provider.rb', line 56

def postprocess(site, compiler)
  dependency_tracker = Nanoc::Core::DependencyTracker::Null.new

  res = compiler.run_until_reps_built
  reps = res.fetch(:reps)

  view_context =
    Nanoc::Core::ViewContextForCompilation.new(
      reps:,
      items: site.items,
      dependency_tracker:,
      compilation_context: compiler.compilation_context(reps:),
      compiled_content_store: Nanoc::Core::CompiledContentStore.new,
    )
  ctx = new_postprocessor_context(site, view_context)

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

#preprocess(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.



45
46
47
48
49
50
51
52
53
54
# File 'lib/nanoc/rule_dsl/action_provider.rb', line 45

def preprocess(site)
  ctx = new_preprocessor_context(site)

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

  site.data_source =
    Nanoc::Core::InMemoryDataSource.new(ctx.items._unwrap, ctx.layouts._unwrap, site.data_source)
end

#rep_names_for(item) ⇒ 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.



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

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

  matching_rules.map(&:rep_name).uniq
end