nanoc 4.1.0a1 → 4.1.0b1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (41) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile.lock +4 -4
  3. data/NEWS.md +10 -0
  4. data/lib/nanoc/base/checksummer.rb +2 -1
  5. data/lib/nanoc/base/compilation/compiler.rb +33 -43
  6. data/lib/nanoc/base/compilation/outdatedness_checker.rb +4 -8
  7. data/lib/nanoc/base/entities/rule_memory.rb +5 -1
  8. data/lib/nanoc/base/entities.rb +0 -1
  9. data/lib/nanoc/base/services/action_provider.rb +22 -0
  10. data/lib/nanoc/base/services/compiler_loader.rb +5 -14
  11. data/lib/nanoc/base/services/executor.rb +1 -1
  12. data/lib/nanoc/base/services/item_rep_builder.rb +4 -12
  13. data/lib/nanoc/base/services/item_rep_router.rb +3 -4
  14. data/lib/nanoc/base/services.rb +1 -5
  15. data/lib/nanoc/base.rb +0 -3
  16. data/lib/nanoc/cli/commands/create-site.rb +2 -5
  17. data/lib/nanoc/cli/commands/show-rules.rb +9 -1
  18. data/lib/nanoc/helpers/rendering.rb +1 -1
  19. data/lib/nanoc/rule_dsl/action_provider.rb +76 -0
  20. data/lib/nanoc/{base/compilation → rule_dsl}/compiler_dsl.rb +9 -9
  21. data/lib/nanoc/{base/services → rule_dsl}/recording_executor.rb +6 -11
  22. data/lib/nanoc/{base/compilation → rule_dsl}/rule.rb +3 -3
  23. data/lib/nanoc/{base/compilation → rule_dsl}/rule_context.rb +2 -2
  24. data/lib/nanoc/{base/services → rule_dsl}/rule_memory_calculator.rb +16 -11
  25. data/lib/nanoc/{base/entities → rule_dsl}/rules_collection.rb +1 -1
  26. data/lib/nanoc/{base/services → rule_dsl}/rules_loader.rb +2 -2
  27. data/lib/nanoc/rule_dsl.rb +8 -0
  28. data/lib/nanoc/version.rb +1 -1
  29. data/lib/nanoc.rb +1 -0
  30. data/test/base/test_compiler.rb +45 -147
  31. data/test/filters/test_erb.rb +1 -1
  32. data/test/helper.rb +2 -2
  33. data/test/rule_dsl/test_action_provider.rb +70 -0
  34. data/test/{base → rule_dsl}/test_compiler_dsl.rb +25 -86
  35. data/test/{base → rule_dsl}/test_rule.rb +1 -1
  36. data/test/rule_dsl/test_rules_collection.rb +89 -0
  37. metadata +17 -16
  38. data/lib/nanoc/base/services/postprocessor.rb +0 -26
  39. data/lib/nanoc/base/services/preprocessor.rb +0 -26
  40. data/nanoc-4.0.2.gem +0 -0
  41. data/tags +0 -1175
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b94aa5a5e85a4af832830570cce9b72348c5adb9
4
- data.tar.gz: 6b3673b4bb01436955145ae3b431f167d1ce755a
3
+ metadata.gz: 97c006e6e64be4a26d31842364fcc8a5377264a3
4
+ data.tar.gz: 96a6fb9d6ca291ddbdc8efe52564326a1691e601
5
5
  SHA512:
6
- metadata.gz: 1865850b88750976c1f682ce6b0aa7449c1d5ddc267bbe44f04de861456724a119bafe5eed0ede7054a14416b100d43bfe5062495a259e82e694dcefaa3ab918
7
- data.tar.gz: c1a98668b8491a04f194c87ee00c59f2c61deb0127dba2d2be6aa0ab5daf74708d56fc3f9f1bc3a4ac170e1384d06b8397a5763f4fa7744d0f983c9426aa4283
6
+ metadata.gz: 3966392f10098cc3d5d386d8e7004b130f11c9b54365542b4912fdba467c1847c00f4cc3861ae2de7d5f5c2286117a5498770772694d0e147de77ba5a07ac11e
7
+ data.tar.gz: 34175a88270c6c092c22ac8a30b90674489bf98d971a7984c3731653ff3b3f259e8dcbcc76fd247c187a85509c40593a45ca247808b8eb9fd029ca22946c9c9e
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- nanoc (4.1.0a1)
4
+ nanoc (4.1.0b1)
5
5
  cri (~> 2.3)
6
6
 
7
7
  GEM
@@ -9,7 +9,7 @@ GEM
9
9
  specs:
10
10
  CFPropertyList (2.3.2)
11
11
  RedCloth (4.2.9)
12
- addressable (2.3.8)
12
+ addressable (2.4.0)
13
13
  adsf (1.2.0)
14
14
  rack (>= 1.0.0)
15
15
  ast (2.1.0)
@@ -137,7 +137,7 @@ GEM
137
137
  fog-core
138
138
  fog-json
139
139
  fog-xml
140
- fog-sakuracloud (1.4.0)
140
+ fog-sakuracloud (1.5.0)
141
141
  fog-core
142
142
  fog-json
143
143
  fog-serverlove (0.1.2)
@@ -267,7 +267,7 @@ GEM
267
267
  ruby-progressbar (1.7.5)
268
268
  rubypants (0.2.0)
269
269
  safe_yaml (1.0.4)
270
- sass (3.4.19)
270
+ sass (3.4.20)
271
271
  shellany (0.0.1)
272
272
  simplecov (0.11.1)
273
273
  docile (~> 1.1.0)
data/NEWS.md CHANGED
@@ -1,5 +1,15 @@
1
1
  # Nanoc news
2
2
 
3
+ ## 4.1.0b1 (2015-12-11)
4
+
5
+ Fixes:
6
+
7
+ * Fixed issue with `:pre` snapshot not being generated properly (#764)
8
+
9
+ Enhancements:
10
+
11
+ * Updated default site to use `#write` (#759)
12
+
3
13
  ## 4.1.0a1 (2015-12-05)
4
14
 
5
15
  Features:
@@ -83,7 +83,8 @@ module Nanoc::Int
83
83
  digest.update(obj.to_i.to_s)
84
84
  when Nanoc::Identifier
85
85
  update(obj.to_s, digest)
86
- when Nanoc::Int::RulesCollection, Nanoc::Int::CodeSnippet
86
+ # TODO: Use RuleMemory rather than RulesCollection
87
+ when Nanoc::RuleDSL::RulesCollection, Nanoc::Int::CodeSnippet
87
88
  update(obj.data, digest)
88
89
  when Nanoc::Int::TextualContent
89
90
  update(obj.string, digest)
@@ -48,9 +48,6 @@ module Nanoc::Int
48
48
  # @return [Array] The compilation stack
49
49
  attr_reader :stack
50
50
 
51
- # @api private
52
- attr_reader :rules_collection
53
-
54
51
  # @api private
55
52
  attr_reader :compiled_content_cache
56
53
 
@@ -61,7 +58,7 @@ module Nanoc::Int
61
58
  attr_reader :rule_memory_store
62
59
 
63
60
  # @api private
64
- attr_reader :rule_memory_calculator
61
+ attr_reader :action_provider
65
62
 
66
63
  # @api private
67
64
  attr_reader :dependency_store
@@ -72,41 +69,25 @@ module Nanoc::Int
72
69
  # @api private
73
70
  attr_reader :reps
74
71
 
75
- def initialize(site, rules_collection, compiled_content_cache:, checksum_store:, rule_memory_store:, rule_memory_calculator:, dependency_store:, outdatedness_checker:, reps:)
72
+ def initialize(site, compiled_content_cache:, checksum_store:, rule_memory_store:, action_provider:, dependency_store:, outdatedness_checker:, reps:)
76
73
  @site = site
77
- @rules_collection = rules_collection
78
74
 
79
75
  @compiled_content_cache = compiled_content_cache
80
76
  @checksum_store = checksum_store
81
77
  @rule_memory_store = rule_memory_store
82
- @rule_memory_calculator = rule_memory_calculator
83
78
  @dependency_store = dependency_store
84
79
  @outdatedness_checker = outdatedness_checker
85
80
  @reps = reps
81
+ @action_provider = action_provider
86
82
 
87
83
  @stack = []
88
84
  end
89
85
 
90
- # 1. Load site
91
- # 2. Load rules
92
- # 3. Preprocess
93
- # 4. Build item reps
94
- # 5. Compile
95
- # 6. Postprocess
96
-
97
- # TODO: move elsewhere
98
86
  def run_all
99
- # Preprocess
100
- Nanoc::Int::Preprocessor.new(site: @site, rules_collection: @rules_collection).run
101
-
102
- # Build reps
87
+ @action_provider.preprocess(@site)
103
88
  build_reps
104
-
105
- # Compile
106
89
  run
107
-
108
- # Postprocess
109
- Nanoc::Int::Postprocessor.new(create_view_context, site: @site, rules_collection: @rules_collection).run
90
+ @action_provider.postprocess(@site, @reps)
110
91
  end
111
92
 
112
93
  def run
@@ -139,11 +120,13 @@ module Nanoc::Int
139
120
  def store
140
121
  # Calculate rule memory
141
122
  (@reps.to_a + @site.layouts.to_a).each do |obj|
142
- rule_memory_store[obj] = rule_memory_calculator[obj].serialize
123
+ rule_memory_store[obj] = action_provider.memory_for(obj).serialize
143
124
  end
144
125
 
145
126
  # Calculate checksums
146
- objects.each do |obj|
127
+ objects_to_checksum =
128
+ site.items.to_a + site.layouts.to_a + site.code_snippets + [site.config]
129
+ objects_to_checksum.each do |obj|
147
130
  checksum_store[obj] = Nanoc::Int::Checksummer.calc(obj)
148
131
  end
149
132
 
@@ -151,18 +134,9 @@ module Nanoc::Int
151
134
  stores.each(&:store)
152
135
  end
153
136
 
154
- # Returns all objects managed by the site (items, layouts, code snippets,
155
- # site configuration and the rules).
156
- #
157
- # @api private
158
- def objects
159
- site.items.to_a + site.layouts.to_a + site.code_snippets +
160
- [site.config, rules_collection]
161
- end
162
-
163
137
  def build_reps
164
138
  builder = Nanoc::Int::ItemRepBuilder.new(
165
- site, rules_collection, rule_memory_calculator, @reps)
139
+ site, action_provider, @reps)
166
140
  builder.run
167
141
  end
168
142
 
@@ -198,6 +172,16 @@ module Nanoc::Int
198
172
  Nanoc::ViewContext.new(reps: @reps, items: @site.items)
199
173
  end
200
174
 
175
+ # @api private
176
+ def filter_name_and_args_for_layout(layout)
177
+ mem = action_provider.memory_for(layout)
178
+ if mem.nil? || mem.size != 1 || !mem[0].is_a?(Nanoc::Int::RuleMemoryActions::Filter)
179
+ # FIXME: Provide a nicer error message
180
+ raise Nanoc::Int::Errors::Generic, "No rule memory found for #{layout.identifier}"
181
+ end
182
+ [mem[0].filter_name, mem[0].params]
183
+ end
184
+
201
185
  private
202
186
 
203
187
  def compile_reps
@@ -207,7 +191,7 @@ module Nanoc::Int
207
191
 
208
192
  # Assign snapshots
209
193
  @reps.each do |rep|
210
- rep.snapshot_defs = rule_memory_calculator.snapshots_defs_for(rep)
194
+ rep.snapshot_defs = action_provider.snapshots_defs_for(rep)
211
195
  end
212
196
 
213
197
  # Find item reps to compile and compile them
@@ -264,12 +248,18 @@ module Nanoc::Int
264
248
  def recalculate_content_for_rep(rep)
265
249
  executor = Nanoc::Int::Executor.new(self)
266
250
 
267
- executor.snapshot(rep, :raw)
268
- executor.snapshot(rep, :pre, final: false)
269
- rules_collection.compilation_rule_for(rep)
270
- .apply_to(rep, executor: executor, site: @site, view_context: create_view_context)
271
- executor.snapshot(rep, :post) if rep.has_snapshot?(:post)
272
- executor.snapshot(rep, :last)
251
+ action_provider.memory_for(rep).each do |action|
252
+ case action
253
+ when Nanoc::Int::RuleMemoryActions::Filter
254
+ executor.filter(rep, action.filter_name, action.params)
255
+ when Nanoc::Int::RuleMemoryActions::Layout
256
+ executor.layout(rep, action.layout_identifier, action.params)
257
+ when Nanoc::Int::RuleMemoryActions::Snapshot
258
+ executor.snapshot(rep, action.snapshot_name, final: action.final?, path: action.path)
259
+ else
260
+ raise "Internal inconsistency: unknown action #{action.inspect}"
261
+ end
262
+ end
273
263
  end
274
264
 
275
265
  # Clears the list of dependencies for items that will be recompiled.
@@ -7,9 +7,7 @@ module Nanoc::Int
7
7
 
8
8
  attr_reader :checksum_store
9
9
  attr_reader :dependency_store
10
- attr_reader :rule_memory_calculator
11
10
  attr_reader :rule_memory_store
12
- attr_reader :rules_collection
13
11
  attr_reader :site
14
12
 
15
13
  Reasons = Nanoc::Int::OutdatednessReasons
@@ -17,17 +15,15 @@ module Nanoc::Int
17
15
  # @param [Nanoc::Int::Site] site
18
16
  # @param [Nanoc::Int::ChecksumStore] checksum_store
19
17
  # @param [Nanoc::Int::DependencyStore] dependency_store
20
- # @param [Nanoc::Int::RulesCollection] rules_collection
21
18
  # @param [Nanoc::Int::RuleMemoryStore] rule_memory_store
22
- # @param [Nanoc::Int::RuleMemoryCalculator] rule_memory_calculator
19
+ # @param [Nanoc::Int::ActionProvider] action_provider
23
20
  # @param [Nanoc::Int::ItemRepRepo] reps
24
- def initialize(site:, checksum_store:, dependency_store:, rules_collection:, rule_memory_store:, rule_memory_calculator:, reps:)
21
+ def initialize(site:, checksum_store:, dependency_store:, rule_memory_store:, action_provider:, reps:)
25
22
  @site = site
26
23
  @checksum_store = checksum_store
27
24
  @dependency_store = dependency_store
28
- @rules_collection = rules_collection
29
25
  @rule_memory_store = rule_memory_store
30
- @rule_memory_calculator = rule_memory_calculator
26
+ @action_provider = action_provider
31
27
  @reps = reps
32
28
 
33
29
  @basic_outdatedness_reasons = {}
@@ -172,7 +168,7 @@ module Nanoc::Int
172
168
  # @return [Boolean] true if the rule memory for the given item
173
169
  # represenation has changed, false otherwise
174
170
  def rule_memory_differs_for(obj)
175
- !rule_memory_store[obj].eql?(rule_memory_calculator[obj].serialize)
171
+ !rule_memory_store[obj].eql?(@action_provider.memory_for(obj).serialize)
176
172
  end
177
173
  memoize :rule_memory_differs_for
178
174
 
@@ -24,7 +24,7 @@ module Nanoc::Int
24
24
  end
25
25
 
26
26
  def add_snapshot(snapshot_name, final, path)
27
- will_add_snapshot(snapshot_name)
27
+ will_add_snapshot(snapshot_name) if final
28
28
  @actions << Nanoc::Int::RuleMemoryActions::Snapshot.new(snapshot_name, final, path)
29
29
  end
30
30
 
@@ -32,6 +32,10 @@ module Nanoc::Int
32
32
  @actions.select { |a| a.is_a?(Nanoc::Int::RuleMemoryActions::Snapshot) }
33
33
  end
34
34
 
35
+ def any_layouts?
36
+ @actions.any? { |a| a.is_a?(Nanoc::Int::RuleMemoryActions::Layout) }
37
+ end
38
+
35
39
  def serialize
36
40
  map(&:serialize)
37
41
  end
@@ -11,6 +11,5 @@ require_relative 'entities/pattern'
11
11
  require_relative 'entities/rule_memory'
12
12
  require_relative 'entities/rule_memory_action'
13
13
  require_relative 'entities/rule_memory_actions'
14
- require_relative 'entities/rules_collection'
15
14
  require_relative 'entities/site'
16
15
  require_relative 'entities/snapshot_def'
@@ -0,0 +1,22 @@
1
+ module Nanoc::Int
2
+ # @private
3
+ class ActionProvider
4
+ extend Nanoc::Int::PluginRegistry::PluginMethods
5
+
6
+ def self.for(_site)
7
+ raise NotImplementedError
8
+ end
9
+
10
+ def rep_names_for(_item)
11
+ raise NotImplementedError
12
+ end
13
+
14
+ def memory_for(_rep)
15
+ raise NotImplementedError
16
+ end
17
+
18
+ def snapshots_defs_for(_rep)
19
+ raise NotImplementedError
20
+ end
21
+ end
22
+ end
@@ -2,14 +2,8 @@ module Nanoc::Int
2
2
  # @api private
3
3
  class CompilerLoader
4
4
  def load(site)
5
- rules_collection = Nanoc::Int::RulesCollection.new
6
-
7
5
  rule_memory_store = Nanoc::Int::RuleMemoryStore.new
8
6
 
9
- rule_memory_calculator =
10
- Nanoc::Int::RuleMemoryCalculator.new(
11
- rules_collection: rules_collection, site: site)
12
-
13
7
  dependency_store =
14
8
  Nanoc::Int::DependencyStore.new(site.items.to_a + site.layouts.to_a)
15
9
 
@@ -18,14 +12,15 @@ module Nanoc::Int
18
12
 
19
13
  item_rep_repo = Nanoc::Int::ItemRepRepo.new
20
14
 
15
+ action_provider = Nanoc::Int::ActionProvider.named(:rule_dsl).for(site)
16
+
21
17
  outdatedness_checker =
22
18
  Nanoc::Int::OutdatednessChecker.new(
23
19
  site: site,
24
20
  checksum_store: checksum_store,
25
21
  dependency_store: dependency_store,
26
- rules_collection: rules_collection,
27
22
  rule_memory_store: rule_memory_store,
28
- rule_memory_calculator: rule_memory_calculator,
23
+ action_provider: action_provider,
29
24
  reps: item_rep_repo,
30
25
  )
31
26
 
@@ -33,17 +28,13 @@ module Nanoc::Int
33
28
  compiled_content_cache: Nanoc::Int::CompiledContentCache.new,
34
29
  checksum_store: checksum_store,
35
30
  rule_memory_store: rule_memory_store,
36
- rule_memory_calculator: rule_memory_calculator,
37
31
  dependency_store: dependency_store,
38
32
  outdatedness_checker: outdatedness_checker,
39
33
  reps: item_rep_repo,
34
+ action_provider: action_provider,
40
35
  }
41
36
 
42
- compiler = Nanoc::Int::Compiler.new(site, rules_collection, params)
43
-
44
- Nanoc::Int::RulesLoader.new(site.config, rules_collection).load
45
-
46
- compiler
37
+ Nanoc::Int::Compiler.new(site, params)
47
38
  end
48
39
  end
49
40
  end
@@ -55,7 +55,7 @@ module Nanoc
55
55
 
56
56
  def layout(rep, layout_identifier, extra_filter_args = nil)
57
57
  layout = find_layout(layout_identifier)
58
- filter_name, filter_args = @compiler.rules_collection.filter_for_layout(layout)
58
+ filter_name, filter_args = *@compiler.filter_name_and_args_for_layout(layout)
59
59
  if filter_name.nil?
60
60
  raise Nanoc::Int::Errors::Generic, "Cannot find rule for layout matching #{layout_identifier}"
61
61
  end
@@ -3,28 +3,20 @@ module Nanoc::Int
3
3
  class ItemRepBuilder
4
4
  attr_reader :reps
5
5
 
6
- def initialize(site, rules_collection, rule_memory_calculator, reps)
6
+ def initialize(site, action_provider, reps)
7
7
  @site = site
8
- @rules_collection = rules_collection
9
- @rule_memory_calculator = rule_memory_calculator
8
+ @action_provider = action_provider
10
9
  @reps = reps
11
10
  end
12
11
 
13
12
  def run
14
13
  @site.items.each do |item|
15
- rep_names_for(item).each do |rep_name|
14
+ @action_provider.rep_names_for(item).each do |rep_name|
16
15
  @reps << Nanoc::Int::ItemRep.new(item, rep_name)
17
16
  end
18
17
  end
19
18
 
20
- Nanoc::Int::ItemRepRouter.new(@reps, @rule_memory_calculator, @site).run
21
- end
22
-
23
- def rep_names_for(item)
24
- matching_rules = @rules_collection.item_compilation_rules_for(item)
25
- raise Nanoc::Int::Errors::NoMatchingCompilationRuleFound.new(item) if matching_rules.empty?
26
-
27
- matching_rules.map(&:rep_name).uniq
19
+ Nanoc::Int::ItemRepRouter.new(@reps, @action_provider, @site).run
28
20
  end
29
21
  end
30
22
  end
@@ -9,17 +9,16 @@ module Nanoc::Int
9
9
  end
10
10
  end
11
11
 
12
- # TODO: Replace rule_memory_calculator with { rep => rule_memory }
13
- def initialize(reps, rule_memory_calculator, site)
12
+ def initialize(reps, action_provider, site)
14
13
  @reps = reps
15
- @rule_memory_calculator = rule_memory_calculator
14
+ @action_provider = action_provider
16
15
  @site = site
17
16
  end
18
17
 
19
18
  def run
20
19
  paths_to_reps = {}
21
20
  @reps.each do |rep|
22
- mem = @rule_memory_calculator[rep]
21
+ mem = @action_provider.memory_for(rep)
23
22
  mem.snapshot_actions.each do |snapshot_action|
24
23
  route_rep(rep, snapshot_action, paths_to_reps)
25
24
  end
@@ -1,3 +1,4 @@
1
+ require_relative 'services/action_provider'
1
2
  require_relative 'services/compiler_loader'
2
3
  require_relative 'services/executor'
3
4
  require_relative 'services/item_rep_builder'
@@ -5,9 +6,4 @@ require_relative 'services/item_rep_router'
5
6
  require_relative 'services/item_rep_selector'
6
7
  require_relative 'services/item_rep_writer'
7
8
  require_relative 'services/notification_center'
8
- require_relative 'services/preprocessor'
9
- require_relative 'services/postprocessor'
10
- require_relative 'services/recording_executor'
11
- require_relative 'services/rule_memory_calculator'
12
- require_relative 'services/rules_loader'
13
9
  require_relative 'services/temp_filename_factory'
data/lib/nanoc/base.rb CHANGED
@@ -15,13 +15,10 @@ module Nanoc::Int
15
15
 
16
16
  # Load compilation classes
17
17
  autoload 'Compiler', 'nanoc/base/compilation/compiler'
18
- autoload 'CompilerDSL', 'nanoc/base/compilation/compiler_dsl'
19
18
  autoload 'DependencyTracker', 'nanoc/base/compilation/dependency_tracker'
20
19
  autoload 'ItemRepRepo', 'nanoc/base/compilation/item_rep_repo'
21
20
  autoload 'OutdatednessChecker', 'nanoc/base/compilation/outdatedness_checker'
22
21
  autoload 'OutdatednessReasons', 'nanoc/base/compilation/outdatedness_reasons'
23
- autoload 'Rule', 'nanoc/base/compilation/rule'
24
- autoload 'RuleContext', 'nanoc/base/compilation/rule_context'
25
22
  end
26
23
 
27
24
  require_relative 'base/core_ext'
@@ -124,9 +124,6 @@ end
124
124
  # layout '/default.*'
125
125
  #end
126
126
 
127
- compile '/**/*' do
128
- end
129
-
130
127
  route '/**/*.{html,md}' do
131
128
  if item.identifier =~ '/index.*'
132
129
  '/index.html'
@@ -135,8 +132,8 @@ route '/**/*.{html,md}' do
135
132
  end
136
133
  end
137
134
 
138
- route '/**/*' do
139
- item.identifier.to_s
135
+ compile '/**/*' do
136
+ write item.identifier.to_s
140
137
  end
141
138
 
142
139
  layout '/**/*', :erb
@@ -11,9 +11,17 @@ module Nanoc::CLI::Commands
11
11
  require_site
12
12
 
13
13
  @c = Nanoc::CLI::ANSIStringColorizer
14
- @rules = site.compiler.rules_collection
15
14
  @reps = site.compiler.reps
16
15
 
16
+ action_provider = site.compiler.action_provider
17
+ unless action_provider.respond_to?(:rules_collection)
18
+ raise(
19
+ ::Nanoc::Int::Errors::GenericTrivial,
20
+ 'The show-rules command can only be used for sites with the Rule DSL action provider.',
21
+ )
22
+ end
23
+ @rules = action_provider.rules_collection
24
+
17
25
  site.items.sort_by(&:identifier).each { |e| explain_item(e) }
18
26
  site.layouts.sort_by(&:identifier).each { |e| explain_layout(e) }
19
27
  end
@@ -99,7 +99,7 @@ module Nanoc::Helpers
99
99
  }.merge(other_assigns)
100
100
 
101
101
  # Get filter name
102
- filter_name, filter_args = @site.unwrap.compiler.rules_collection.filter_for_layout(layout)
102
+ filter_name, filter_args = *@site.unwrap.compiler.filter_name_and_args_for_layout(layout)
103
103
  raise Nanoc::Int::Errors::CannotDetermineFilter.new(layout.identifier) if filter_name.nil?
104
104
 
105
105
  # Get filter class
@@ -0,0 +1,76 @@
1
+ module Nanoc::RuleDSL
2
+ class ActionProvider < Nanoc::Int::ActionProvider
3
+ identifier :rule_dsl
4
+
5
+ # @api private
6
+ attr_reader :rules_collection
7
+
8
+ def self.for(site)
9
+ rules_collection = Nanoc::RuleDSL::RulesCollection.new
10
+
11
+ rule_memory_calculator =
12
+ Nanoc::RuleDSL::RuleMemoryCalculator.new(
13
+ rules_collection: rules_collection, site: site)
14
+
15
+ action_provider = new(rules_collection, rule_memory_calculator)
16
+
17
+ Nanoc::RuleDSL::RulesLoader.new(site.config, rules_collection).load
18
+
19
+ action_provider
20
+ end
21
+
22
+ def initialize(rules_collection, rule_memory_calculator)
23
+ @rules_collection = rules_collection
24
+ @rule_memory_calculator = rule_memory_calculator
25
+ end
26
+
27
+ def rep_names_for(item)
28
+ matching_rules = @rules_collection.item_compilation_rules_for(item)
29
+ raise Nanoc::Int::Errors::NoMatchingCompilationRuleFound.new(item) if matching_rules.empty?
30
+
31
+ matching_rules.map(&:rep_name).uniq
32
+ end
33
+
34
+ def memory_for(rep)
35
+ @rule_memory_calculator[rep]
36
+ end
37
+
38
+ def snapshots_defs_for(rep)
39
+ @rule_memory_calculator.snapshots_defs_for(rep)
40
+ end
41
+
42
+ def preprocess(site)
43
+ ctx = new_preprocessor_context(site)
44
+
45
+ @rules_collection.preprocessors.each_value do |preprocessor|
46
+ ctx.instance_eval(&preprocessor)
47
+ end
48
+ end
49
+
50
+ def postprocess(site, reps)
51
+ view_context = Nanoc::ViewContext.new(reps: reps, items: site.items)
52
+ ctx = new_postprocessor_context(site, view_context)
53
+
54
+ @rules_collection.postprocessors.each_value do |postprocessor|
55
+ ctx.instance_eval(&postprocessor)
56
+ end
57
+ end
58
+
59
+ # @api private
60
+ def new_preprocessor_context(site)
61
+ Nanoc::Int::Context.new(
62
+ config: Nanoc::MutableConfigView.new(site.config, nil),
63
+ items: Nanoc::MutableItemCollectionView.new(site.items, nil),
64
+ layouts: Nanoc::MutableLayoutCollectionView.new(site.layouts, nil),
65
+ )
66
+ end
67
+
68
+ # @api private
69
+ def new_postprocessor_context(site, view_context)
70
+ Nanoc::Int::Context.new(
71
+ config: Nanoc::ConfigView.new(site.config, view_context),
72
+ items: Nanoc::PostCompileItemCollectionView.new(site.items, view_context),
73
+ )
74
+ end
75
+ end
76
+ end
@@ -1,4 +1,4 @@
1
- module Nanoc::Int
1
+ module Nanoc::RuleDSL
2
2
  # Contains methods that will be executed by the site’s `Rules` file.
3
3
  #
4
4
  # @api private
@@ -14,7 +14,7 @@ module Nanoc::Int
14
14
  #
15
15
  # @api private
16
16
  #
17
- # @param [Nanoc::Int::RulesCollection] rules_collection The collection of
17
+ # @param [Nanoc::RuleDSL::RulesCollection] rules_collection The collection of
18
18
  # rules to modify when loading this DSL
19
19
  #
20
20
  # @param [Hash] config The site configuration
@@ -71,7 +71,7 @@ module Nanoc::Int
71
71
  def compile(identifier, rep: :default, &block)
72
72
  raise ArgumentError.new('#compile requires a block') unless block_given?
73
73
 
74
- rule = Nanoc::Int::Rule.new(create_pattern(identifier), rep, block)
74
+ rule = Nanoc::RuleDSL::Rule.new(create_pattern(identifier), rep, block)
75
75
  @rules_collection.add_item_compilation_rule(rule)
76
76
  end
77
77
 
@@ -109,7 +109,7 @@ module Nanoc::Int
109
109
  def route(identifier, rep: :default, snapshot: :last, &block)
110
110
  raise ArgumentError.new('#route requires a block') unless block_given?
111
111
 
112
- rule = Nanoc::Int::Rule.new(create_pattern(identifier), rep, block, snapshot_name: snapshot)
112
+ rule = Nanoc::RuleDSL::Rule.new(create_pattern(identifier), rep, block, snapshot_name: snapshot)
113
113
  @rules_collection.add_item_routing_rule(rule)
114
114
  end
115
115
 
@@ -170,7 +170,7 @@ module Nanoc::Int
170
170
  raise ArgumentError.new('#passthrough does not require a block') if block_given?
171
171
 
172
172
  compilation_block = proc {}
173
- compilation_rule = Nanoc::Int::Rule.new(create_pattern(identifier), rep, compilation_block)
173
+ compilation_rule = Nanoc::RuleDSL::Rule.new(create_pattern(identifier), rep, compilation_block)
174
174
  @rules_collection.add_item_compilation_rule(compilation_rule)
175
175
 
176
176
  # Create routing rule
@@ -185,7 +185,7 @@ module Nanoc::Int
185
185
  item[:extension].nil? || (item[:content_filename].nil? && item.identifier =~ %r{#{item[:extension]}/$}) ? item.identifier.chop : item.identifier.chop + '.' + item[:extension]
186
186
  end
187
187
  end
188
- routing_rule = Nanoc::Int::Rule.new(create_pattern(identifier), rep, routing_block, snapshot_name: :last)
188
+ routing_rule = Nanoc::RuleDSL::Rule.new(create_pattern(identifier), rep, routing_block, snapshot_name: :last)
189
189
  @rules_collection.add_item_routing_rule(routing_rule)
190
190
  end
191
191
 
@@ -210,10 +210,10 @@ module Nanoc::Int
210
210
  def ignore(identifier, rep: :default)
211
211
  raise ArgumentError.new('#ignore does not require a block') if block_given?
212
212
 
213
- compilation_rule = Nanoc::Int::Rule.new(create_pattern(identifier), rep, proc {})
213
+ compilation_rule = Nanoc::RuleDSL::Rule.new(create_pattern(identifier), rep, proc {})
214
214
  @rules_collection.add_item_compilation_rule(compilation_rule)
215
215
 
216
- routing_rule = Nanoc::Int::Rule.new(create_pattern(identifier), rep, proc {}, snapshot_name: :last)
216
+ routing_rule = Nanoc::RuleDSL::Rule.new(create_pattern(identifier), rep, proc {}, snapshot_name: :last)
217
217
  @rules_collection.add_item_routing_rule(routing_rule)
218
218
  end
219
219
 
@@ -233,7 +233,7 @@ module Nanoc::Int
233
233
  filename = ["#{name}", "#{name}.rb", "./#{name}", "./#{name}.rb"].find { |f| File.file?(f) }
234
234
  raise Nanoc::Int::Errors::NoRulesFileFound.new if filename.nil?
235
235
 
236
- Nanoc::Int::RulesLoader.new(@config, @rules_collection).parse(filename)
236
+ Nanoc::RuleDSL::RulesLoader.new(@config, @rules_collection).parse(filename)
237
237
  end
238
238
 
239
239
  # Creates a postprocessor block that will be executed after all data is