nanoc 4.6.1 → 4.6.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (96) hide show
  1. checksums.yaml +4 -4
  2. data/Appraisals +1 -1
  3. data/Gemfile.lock +22 -22
  4. data/NEWS.md +12 -0
  5. data/lib/nanoc/base/entities/document.rb +7 -0
  6. data/lib/nanoc/base/entities/identifiable_collection.rb +12 -9
  7. data/lib/nanoc/base/entities/item_rep.rb +24 -28
  8. data/lib/nanoc/base/entities/processing_actions/snapshot.rb +15 -11
  9. data/lib/nanoc/base/entities/rule_memory.rb +15 -5
  10. data/lib/nanoc/base/entities/site.rb +15 -10
  11. data/lib/nanoc/base/entities/snapshot_def.rb +8 -2
  12. data/lib/nanoc/base/repos.rb +3 -0
  13. data/lib/nanoc/base/repos/aggregate_data_source.rb +20 -0
  14. data/lib/nanoc/base/repos/in_mem_data_source.rb +13 -0
  15. data/lib/nanoc/base/repos/prefixed_data_source.rb +19 -0
  16. data/lib/nanoc/base/repos/site_loader.rb +8 -16
  17. data/lib/nanoc/base/repos/snapshot_repo.rb +10 -5
  18. data/lib/nanoc/base/services/action_provider.rb +12 -0
  19. data/lib/nanoc/base/services/compiler/phases/recalculate.rb +5 -2
  20. data/lib/nanoc/base/services/compiler/phases/write.rb +1 -3
  21. data/lib/nanoc/base/services/compiler/stages/preprocess.rb +6 -3
  22. data/lib/nanoc/base/services/executor.rb +2 -4
  23. data/lib/nanoc/base/services/filter.rb +7 -12
  24. data/lib/nanoc/base/services/item_rep_router.rb +40 -16
  25. data/lib/nanoc/base/services/item_rep_writer.rb +19 -3
  26. data/lib/nanoc/base/services/pruner.rb +1 -1
  27. data/lib/nanoc/base/views/item_rep_view.rb +12 -3
  28. data/lib/nanoc/base/views/mutable_identifiable_collection_view.rb +1 -1
  29. data/lib/nanoc/base/views/mutable_item_collection_view.rb +1 -1
  30. data/lib/nanoc/base/views/mutable_layout_collection_view.rb +1 -1
  31. data/lib/nanoc/checking/checks/html.rb +1 -1
  32. data/lib/nanoc/checking/checks/stale.rb +2 -1
  33. data/lib/nanoc/checking/checks/w3c_validator.rb +1 -0
  34. data/lib/nanoc/cli/commands/compile.rb +3 -2
  35. data/lib/nanoc/cli/commands/show-data.rb +4 -2
  36. data/lib/nanoc/data_sources/filesystem.rb +1 -1
  37. data/lib/nanoc/helpers/filtering.rb +1 -2
  38. data/lib/nanoc/helpers/rendering.rb +1 -2
  39. data/lib/nanoc/helpers/xml_sitemap.rb +2 -2
  40. data/lib/nanoc/rule_dsl/action_provider.rb +7 -0
  41. data/lib/nanoc/rule_dsl/rule_context.rb +4 -1
  42. data/lib/nanoc/rule_dsl/rule_memory_calculator.rb +33 -13
  43. data/lib/nanoc/spec.rb +5 -6
  44. data/lib/nanoc/version.rb +1 -1
  45. data/spec/nanoc/base/checksummer_spec.rb +19 -9
  46. data/spec/nanoc/base/compiler_spec.rb +4 -8
  47. data/spec/nanoc/base/entities/document_spec.rb +20 -0
  48. data/spec/nanoc/base/entities/identifiable_collection_spec.rb +12 -0
  49. data/spec/nanoc/base/entities/item_rep_spec.rb +1 -1
  50. data/spec/nanoc/base/entities/processing_actions/snapshot_spec.rb +19 -13
  51. data/spec/nanoc/base/entities/rule_memory_spec.rb +39 -3
  52. data/spec/nanoc/base/entities/site_spec.rb +15 -10
  53. data/spec/nanoc/base/filter_spec.rb +28 -1
  54. data/spec/nanoc/base/item_rep_writer_spec.rb +4 -2
  55. data/spec/nanoc/base/repos/outdatedness_store_spec.rb +1 -2
  56. data/spec/nanoc/base/repos/snapshot_repo_spec.rb +4 -4
  57. data/spec/nanoc/base/repos/store_spec.rb +5 -1
  58. data/spec/nanoc/base/services/compiler/stages/compile_reps_spec.rb +9 -10
  59. data/spec/nanoc/base/services/executor_spec.rb +2 -2
  60. data/spec/nanoc/base/services/item_rep_router_spec.rb +83 -39
  61. data/spec/nanoc/base/services/outdatedness_checker_spec.rb +1 -2
  62. data/spec/nanoc/base/services/outdatedness_rules_spec.rb +2 -3
  63. data/spec/nanoc/base/services/pruner_spec.rb +2 -2
  64. data/spec/nanoc/base/views/identifiable_collection_view_spec.rb +46 -28
  65. data/spec/nanoc/base/views/item_rep_view_spec.rb +72 -15
  66. data/spec/nanoc/base/views/item_view_spec.rb +20 -14
  67. data/spec/nanoc/base/views/mutable_identifiable_collection_view_spec.rb +10 -4
  68. data/spec/nanoc/base/views/mutable_item_collection_view_spec.rb +10 -5
  69. data/spec/nanoc/base/views/mutable_layout_collection_view_spec.rb +10 -5
  70. data/spec/nanoc/cli/commands/compile/file_action_printer_spec.rb +1 -1
  71. data/spec/nanoc/cli/commands/compile/timing_recorder_spec.rb +1 -1
  72. data/spec/nanoc/cli/commands/show_data_spec.rb +9 -7
  73. data/spec/nanoc/cli/commands/show_rules_spec.rb +16 -10
  74. data/spec/nanoc/regressions/gh_1037a_spec.rb +29 -0
  75. data/spec/nanoc/regressions/gh_1037b_spec.rb +18 -0
  76. data/spec/nanoc/regressions/gh_1082a_spec.rb +18 -0
  77. data/spec/nanoc/regressions/gh_1082b_spec.rb +20 -0
  78. data/spec/nanoc/regressions/gh_1082c_spec.rb +19 -0
  79. data/spec/nanoc/regressions/gh_1082d_spec.rb +17 -0
  80. data/spec/nanoc/regressions/gh_1093_spec.rb +49 -0
  81. data/spec/nanoc/regressions/gh_1097_spec.rb +21 -0
  82. data/spec/nanoc/regressions/gh_1100_spec.rb +20 -0
  83. data/spec/nanoc/regressions/gh_1102_spec.rb +26 -0
  84. data/spec/nanoc/regressions/gh_776_spec.rb +1 -5
  85. data/spec/nanoc/rule_dsl/recording_executor_spec.rb +14 -14
  86. data/spec/nanoc/rule_dsl/rule_context_spec.rb +22 -13
  87. data/spec/nanoc/rule_dsl/rule_memory_calculator_spec.rb +38 -54
  88. data/spec/spec_helper.rb +1 -1
  89. data/test/base/test_compiler.rb +3 -4
  90. data/test/base/test_item_array.rb +4 -15
  91. data/test/checking/checks/test_html.rb +4 -3
  92. data/test/cli/commands/test_compile.rb +2 -2
  93. data/test/filters/test_relativize_paths.rb +28 -28
  94. data/test/fixtures/vcr_cassettes/html_run_error.yml +25 -76
  95. data/test/helpers/test_xml_sitemap.rb +22 -19
  96. metadata +16 -2
@@ -15,7 +15,7 @@ module Nanoc
15
15
  #
16
16
  # @return [self]
17
17
  def create(content, attributes, identifier)
18
- @objects << Nanoc::Int::Layout.new(content, attributes, identifier)
18
+ @objects = @objects.add(Nanoc::Int::Layout.new(content, attributes, identifier))
19
19
  self
20
20
  end
21
21
  end
@@ -8,7 +8,7 @@ module ::Nanoc::Checking::Checks
8
8
  end
9
9
 
10
10
  def validator_class
11
- ::W3CValidators::MarkupValidator
11
+ ::W3CValidators::NuValidator
12
12
  end
13
13
  end
14
14
  end
@@ -26,7 +26,8 @@ module Nanoc::Checking::Checks
26
26
  .flat_map(&:reps)
27
27
  .map(&:unwrap)
28
28
  .flat_map(&:raw_paths)
29
- .flat_map(&:values),
29
+ .flat_map(&:values)
30
+ .flatten,
30
31
  )
31
32
  end
32
33
 
@@ -3,6 +3,7 @@ module ::Nanoc::Checking::Checks
3
3
  class W3CValidator < ::Nanoc::Checking::Check
4
4
  def run
5
5
  require 'w3c_validators'
6
+ require 'resolv-replace'
6
7
 
7
8
  Dir[@config[:output_dir] + '/**/*.' + extension].each do |filename|
8
9
  results = validator_class.new.validate_file(filename)
@@ -355,8 +355,9 @@ module Nanoc::CLI::Commands
355
355
  Nanoc::Int::NotificationCenter.remove(:compilation_suspended, self)
356
356
  Nanoc::Int::NotificationCenter.remove(:rep_written, self)
357
357
 
358
- @reps.select { |r| !r.compiled? }.each do |rep|
359
- rep.raw_paths.each do |_snapshot_name, raw_path|
358
+ @reps.reject(&:compiled?).each do |rep|
359
+ raw_paths = rep.raw_paths.values.flatten.uniq
360
+ raw_paths.each do |raw_path|
360
361
  log(:low, :skip, raw_path, nil)
361
362
  end
362
363
  end
@@ -115,8 +115,10 @@ module Nanoc::CLI::Commands
115
115
  puts ' (not written)'
116
116
  end
117
117
  length = rep.raw_paths.keys.map { |s| s.to_s.length }.max
118
- rep.raw_paths.each do |snapshot_name, raw_path|
119
- puts format(" [ %-#{length}s ] %s", snapshot_name, raw_path)
118
+ rep.raw_paths.each do |snapshot_name, raw_paths|
119
+ raw_paths.each do |raw_path|
120
+ puts format(" [ %-#{length}s ] %s", snapshot_name, raw_path)
121
+ end
120
122
  end
121
123
  end
122
124
  end
@@ -254,7 +254,7 @@ module Nanoc::DataSources
254
254
  by_basename.each_pair do |basename, filenames|
255
255
  # Divide
256
256
  meta_filenames = filenames.select { |fn| ext_of(fn) == '.yaml' }
257
- content_filenames = filenames.select { |fn| ext_of(fn) != '.yaml' }
257
+ content_filenames = filenames.reject { |fn| ext_of(fn) == '.yaml' }
258
258
 
259
259
  # Check number of files per type
260
260
  unless [0, 1].include?(meta_filenames.size)
@@ -13,8 +13,7 @@ module Nanoc::Helpers
13
13
  data = capture(&block)
14
14
 
15
15
  # Find filter
16
- klass = Nanoc::Filter.named(filter_name)
17
- raise Nanoc::Int::Errors::UnknownFilter.new(filter_name) if klass.nil?
16
+ klass = Nanoc::Filter.named!(filter_name)
18
17
 
19
18
  # Create filter
20
19
  assigns = {
@@ -41,8 +41,7 @@ module Nanoc::Helpers
41
41
  raise Nanoc::Int::Errors::CannotDetermineFilter.new(layout.identifier) if filter_name.nil?
42
42
 
43
43
  # Get filter class
44
- filter_class = Nanoc::Filter.named(filter_name)
45
- raise Nanoc::Int::Errors::UnknownFilter.new(filter_name) if filter_class.nil?
44
+ filter_class = Nanoc::Filter.named!(filter_name)
46
45
 
47
46
  # Create filter
48
47
  filter = filter_class.new(assigns)
@@ -26,8 +26,8 @@ module Nanoc::Helpers
26
26
  xml.urlset(xmlns: 'http://www.sitemaps.org/schemas/sitemap/0.9') do
27
27
  # Add item
28
28
  items.sort_by(&:identifier).each do |item|
29
- reps = item.reps.reject { |r| r.raw_path.nil? }
30
- reps.reject! { |r| !select_proc[r] } if select_proc
29
+ reps = item.reps.select(&:path)
30
+ reps.select! { |r| select_proc[r] } if select_proc
31
31
  reps.sort_by { |r| r.name.to_s }.each do |rep|
32
32
  xml.url do
33
33
  xml.loc URI.escape(@config[:base_url] + rep.path)
@@ -40,12 +40,19 @@ module Nanoc::RuleDSL
40
40
  @rule_memory_calculator.snapshots_defs_for(rep)
41
41
  end
42
42
 
43
+ def need_preprocessing?
44
+ @rules_collection.preprocessors.any?
45
+ end
46
+
43
47
  def preprocess(site)
44
48
  ctx = new_preprocessor_context(site)
45
49
 
46
50
  @rules_collection.preprocessors.each_value do |preprocessor|
47
51
  ctx.instance_eval(&preprocessor)
48
52
  end
53
+
54
+ site.data_source =
55
+ Nanoc::Int::InMemDataSource.new(ctx.items.unwrap, ctx.layouts.unwrap)
49
56
  end
50
57
 
51
58
  def postprocess(site, reps)
@@ -74,7 +74,10 @@ module Nanoc::RuleDSL
74
74
  #
75
75
  # @return [void]
76
76
  def write(path)
77
- snapshot(:last, path: path)
77
+ @_write_snapshot_counter ||= 0
78
+ snapshot_name = "_#{@_write_snapshot_counter}".to_sym
79
+ @_write_snapshot_counter += 1
80
+ snapshot(snapshot_name, path: path)
78
81
  end
79
82
  end
80
83
  end
@@ -55,9 +55,21 @@ module Nanoc::RuleDSL
55
55
  end
56
56
 
57
57
  def snapshots_defs_for(rep)
58
- self[rep].snapshot_actions.map do |a|
59
- Nanoc::Int::SnapshotDef.new(a.snapshot_name)
58
+ is_binary = rep.item.content.binary?
59
+ snapshot_defs = []
60
+
61
+ self[rep].each do |action|
62
+ case action
63
+ when Nanoc::Int::ProcessingActions::Snapshot
64
+ action.snapshot_names.each do |snapshot_name|
65
+ snapshot_defs << Nanoc::Int::SnapshotDef.new(snapshot_name, binary: is_binary)
66
+ end
67
+ when Nanoc::Int::ProcessingActions::Filter
68
+ is_binary = Nanoc::Filter.named!(action.filter_name).to_binary?
69
+ end
60
70
  end
71
+
72
+ snapshot_defs
61
73
  end
62
74
 
63
75
  # @param [Nanoc::Int::ItemRep] rep The item representation to get the rule
@@ -81,14 +93,14 @@ module Nanoc::RuleDSL
81
93
  if rule_memory.any_layouts?
82
94
  executor.snapshot(:post)
83
95
  end
84
- unless rule_memory.snapshot_actions.any? { |sa| sa.snapshot_name == :last }
96
+ unless rule_memory.snapshot_actions.any? { |sa| sa.snapshot_names.include?(:last) }
85
97
  executor.snapshot(:last)
86
98
  end
87
- unless rule_memory.snapshot_actions.any? { |sa| sa.snapshot_name == :pre }
99
+ unless rule_memory.snapshot_actions.any? { |sa| sa.snapshot_names.include?(:pre) }
88
100
  executor.snapshot(:pre)
89
101
  end
90
102
 
91
- assign_paths_to_mem(rule_memory, rep: rep)
103
+ copy_paths_from_routing_rules(rule_memory.compact_snapshots, rep: rep)
92
104
  end
93
105
 
94
106
  # @param [Nanoc::Int::Layout] layout
@@ -106,21 +118,29 @@ module Nanoc::RuleDSL
106
118
  end
107
119
  end
108
120
 
109
- def assign_paths_to_mem(mem, rep:)
121
+ def copy_paths_from_routing_rules(mem, rep:)
110
122
  mem.map do |action|
111
- if action.is_a?(Nanoc::Int::ProcessingActions::Snapshot) && action.path.nil?
112
- path_from_rules = basic_path_from_rules_for(rep, action.snapshot_name)
113
- if path_from_rules
114
- action.copy(path: path_from_rules.to_s)
115
- else
116
- action
117
- end
123
+ if action.is_a?(Nanoc::Int::ProcessingActions::Snapshot) && action.paths.empty?
124
+ copy_path_from_routing_rule(action, rep: rep)
118
125
  else
119
126
  action
120
127
  end
121
128
  end
122
129
  end
123
130
 
131
+ def copy_path_from_routing_rule(action, rep:)
132
+ paths_from_rules =
133
+ action.snapshot_names.map do |snapshot_name|
134
+ basic_path_from_rules_for(rep, snapshot_name)
135
+ end.compact
136
+
137
+ if paths_from_rules.any?
138
+ action.update(paths: paths_from_rules.map(&:to_s))
139
+ else
140
+ action
141
+ end
142
+ end
143
+
124
144
  # FIXME: ugly
125
145
  def basic_path_from_rules_for(rep, snapshot_name)
126
146
  routing_rules = @rules_collection.routing_rules_for(rep)
data/lib/nanoc/spec.rb CHANGED
@@ -31,7 +31,7 @@ module Nanoc
31
31
  # @return [Nanoc::ItemWithRepsView] A view for the newly created item
32
32
  def create_item(content, attributes, identifier)
33
33
  item = Nanoc::Int::Item.new(content, attributes, identifier)
34
- @items << item
34
+ @items = @items.add(item)
35
35
  Nanoc::ItemWithRepsView.new(item, view_context)
36
36
  end
37
37
 
@@ -46,7 +46,7 @@ module Nanoc
46
46
  # @return [Nanoc::ItemWithRepsView] A view for the newly created layout
47
47
  def create_layout(content, attributes, identifier)
48
48
  layout = Nanoc::Int::Layout.new(content, attributes, identifier)
49
- @layouts << layout
49
+ @layouts = @layouts.add(layout)
50
50
  Nanoc::LayoutView.new(layout, view_context)
51
51
  end
52
52
 
@@ -58,7 +58,7 @@ module Nanoc
58
58
  # @param [Symbol] rep The rep name to create
59
59
  def create_rep(item, path, rep = :default)
60
60
  rep = Nanoc::Int::ItemRep.new(item.unwrap, rep)
61
- rep.paths[:last] = path
61
+ rep.paths[:last] = [path]
62
62
  @reps << rep
63
63
  Nanoc::ItemRepView.new(rep, view_context)
64
64
  end
@@ -146,7 +146,7 @@ module Nanoc
146
146
  end
147
147
 
148
148
  def snapshots_defs_for(_rep)
149
- [Nanoc::Int::SnapshotDef.new(:last)]
149
+ [Nanoc::Int::SnapshotDef.new(:last, binary: false)]
150
150
  end
151
151
  end.new(self)
152
152
  end
@@ -160,8 +160,7 @@ module Nanoc
160
160
  site = Nanoc::Int::Site.new(
161
161
  config: @config,
162
162
  code_snippets: [],
163
- items: @items,
164
- layouts: @layouts,
163
+ data_source: Nanoc::Int::InMemDataSource.new(@items, @layouts),
165
164
  )
166
165
  site.compiler = new_compiler_for(site)
167
166
  site
data/lib/nanoc/version.rb CHANGED
@@ -1,4 +1,4 @@
1
1
  module Nanoc
2
2
  # The current Nanoc version.
3
- VERSION = '4.6.1'.freeze
3
+ VERSION = '4.6.2'.freeze
4
4
  end
@@ -279,10 +279,13 @@ describe Nanoc::Int::Checksummer do
279
279
  let(:config) { Nanoc::Int::Configuration.new(hash: { 'foo' => 'bar' }) }
280
280
 
281
281
  let(:wrapped) do
282
- Nanoc::Int::IdentifiableCollection.new(config).tap do |arr|
283
- arr << Nanoc::Int::Item.new('foo', {}, '/foo.md')
284
- arr << Nanoc::Int::Item.new('bar', {}, '/foo.md')
285
- end
282
+ Nanoc::Int::IdentifiableCollection.new(
283
+ config,
284
+ [
285
+ Nanoc::Int::Item.new('foo', {}, '/foo.md'),
286
+ Nanoc::Int::Item.new('bar', {}, '/foo.md'),
287
+ ],
288
+ )
286
289
  end
287
290
 
288
291
  it { is_expected.to eql('Nanoc::ItemCollectionWithRepsView<Nanoc::Int::IdentifiableCollection<Nanoc::Int::Item<content=Nanoc::Int::TextualContent<String<foo>>,attributes=Hash<>,identifier=Nanoc::Identifier<String</foo.md>>>,Nanoc::Int::Item<content=Nanoc::Int::TextualContent<String<bar>>,attributes=Hash<>,identifier=Nanoc::Identifier<String</foo.md>>>,>>') }
@@ -294,10 +297,13 @@ describe Nanoc::Int::Checksummer do
294
297
  let(:config) { Nanoc::Int::Configuration.new(hash: { 'foo' => 'bar' }) }
295
298
 
296
299
  let(:wrapped) do
297
- Nanoc::Int::IdentifiableCollection.new(config).tap do |arr|
298
- arr << Nanoc::Int::Item.new('foo', {}, '/foo.md')
299
- arr << Nanoc::Int::Item.new('bar', {}, '/foo.md')
300
- end
300
+ Nanoc::Int::IdentifiableCollection.new(
301
+ config,
302
+ [
303
+ Nanoc::Int::Item.new('foo', {}, '/foo.md'),
304
+ Nanoc::Int::Item.new('bar', {}, '/foo.md'),
305
+ ],
306
+ )
301
307
  end
302
308
 
303
309
  it { is_expected.to eql('Nanoc::ItemCollectionWithoutRepsView<Nanoc::Int::IdentifiableCollection<Nanoc::Int::Item<content=Nanoc::Int::TextualContent<String<foo>>,attributes=Hash<>,identifier=Nanoc::Identifier<String</foo.md>>>,Nanoc::Int::Item<content=Nanoc::Int::TextualContent<String<bar>>,attributes=Hash<>,identifier=Nanoc::Identifier<String</foo.md>>>,>>') }
@@ -310,7 +316,11 @@ describe Nanoc::Int::Checksummer do
310
316
  let(:item) { Nanoc::Int::Item.new('stuff', {}, '/stuff.md') }
311
317
 
312
318
  let(:site) do
313
- Nanoc::Int::Site.new(config: config, code_snippets: code_snippets, items: items, layouts: layouts)
319
+ Nanoc::Int::Site.new(
320
+ config: config,
321
+ code_snippets: code_snippets,
322
+ data_source: Nanoc::Int::InMemDataSource.new(items, layouts),
323
+ )
314
324
  end
315
325
 
316
326
  let(:config) { Nanoc::Int::Configuration.new(hash: { 'foo' => 'bar' }) }
@@ -35,8 +35,7 @@ describe Nanoc::Int::Compiler do
35
35
  Nanoc::Int::Site.new(
36
36
  config: config,
37
37
  code_snippets: code_snippets,
38
- items: items,
39
- layouts: layouts,
38
+ data_source: Nanoc::Int::InMemDataSource.new(items, layouts),
40
39
  )
41
40
  end
42
41
 
@@ -45,17 +44,14 @@ describe Nanoc::Int::Compiler do
45
44
  let(:code_snippets) { [] }
46
45
 
47
46
  let(:items) do
48
- Nanoc::Int::IdentifiableCollection.new(config).tap do |col|
49
- col << item
50
- col << other_item
51
- end
47
+ Nanoc::Int::IdentifiableCollection.new(config, [item, other_item])
52
48
  end
53
49
 
54
50
  let(:memory) do
55
51
  actions =
56
52
  [
57
53
  Nanoc::Int::ProcessingActions::Filter.new(:erb, {}),
58
- Nanoc::Int::ProcessingActions::Snapshot.new(:last, nil),
54
+ Nanoc::Int::ProcessingActions::Snapshot.new([:last], []),
59
55
  ]
60
56
 
61
57
  Nanoc::Int::RuleMemory.new(nil, actions: actions)
@@ -66,7 +62,7 @@ describe Nanoc::Int::Compiler do
66
62
  reps << other_rep
67
63
 
68
64
  reps.each do |rep|
69
- rep.snapshot_defs << Nanoc::Int::SnapshotDef.new(:last)
65
+ rep.snapshot_defs << Nanoc::Int::SnapshotDef.new(:last, binary: false)
70
66
  end
71
67
 
72
68
  allow(outdatedness_checker).to receive(:outdated?).with(rep).and_return(true)
@@ -203,4 +203,24 @@ shared_examples 'a document' do
203
203
  end
204
204
  end
205
205
  end
206
+
207
+ describe '#with_identifier_prefix' do
208
+ let(:document) { described_class.new('kontent', { at: 'ribut' }, '/donkey.md') }
209
+
210
+ subject { document.with_identifier_prefix('/animals') }
211
+
212
+ it 'does not mutate the original' do
213
+ document.freeze
214
+ subject
215
+ end
216
+
217
+ it 'returns a new document with a prefixed identifier' do
218
+ expect(subject.identifier).to eq('/animals/donkey.md')
219
+ end
220
+
221
+ it 'does not change other data' do
222
+ expect(subject.content).to be_some_textual_content('kontent')
223
+ expect(subject.attributes).to eq(at: 'ribut')
224
+ end
225
+ end
206
226
  end
@@ -0,0 +1,12 @@
1
+ describe Nanoc::Int::IdentifiableCollection do
2
+ subject(:identifiable_collection) { described_class.new(config, objects) }
3
+
4
+ let(:config) { Nanoc::Int::Configuration.new }
5
+ let(:objects) { [] }
6
+
7
+ describe '#reject' do
8
+ subject { identifiable_collection.reject { |_| false } }
9
+
10
+ it { is_expected.to be_a(described_class) }
11
+ end
12
+ end
@@ -8,7 +8,7 @@ describe Nanoc::Int::ItemRep do
8
8
  let(:snapshot_name) { raise 'override me' }
9
9
 
10
10
  before do
11
- rep.snapshot_defs = [Nanoc::Int::SnapshotDef.new(:donkey)]
11
+ rep.snapshot_defs = [Nanoc::Int::SnapshotDef.new(:donkey, binary: false)]
12
12
  end
13
13
 
14
14
  context 'snapshot does not exist' do
@@ -1,32 +1,38 @@
1
1
  describe Nanoc::Int::ProcessingActions::Snapshot do
2
- let(:action) { described_class.new(:before_layout, '/foo.md') }
2
+ let(:action) { described_class.new([:before_layout], ['/foo.md']) }
3
3
 
4
4
  describe '#serialize' do
5
5
  subject { action.serialize }
6
- it { is_expected.to eql([:snapshot, :before_layout, true, '/foo.md']) }
6
+ it { is_expected.to eql([:snapshot, [:before_layout], true, ['/foo.md']]) }
7
7
  end
8
8
 
9
9
  describe '#to_s' do
10
10
  subject { action.to_s }
11
- it { is_expected.to eql('snapshot :before_layout, path: "/foo.md"') }
11
+ it { is_expected.to eql('snapshot [:before_layout], paths: ["/foo.md"]') }
12
12
  end
13
13
 
14
14
  describe '#inspect' do
15
15
  subject { action.inspect }
16
- it { is_expected.to eql('<Nanoc::Int::ProcessingActions::Snapshot :before_layout, true, "/foo.md">') }
16
+ it { is_expected.to eql('<Nanoc::Int::ProcessingActions::Snapshot [:before_layout], true, ["/foo.md"]>') }
17
17
  end
18
18
 
19
- describe '#copy' do
20
- context 'without path' do
21
- subject { action.copy }
22
- its(:snapshot_name) { is_expected.to eql(:before_layout) }
23
- its(:path) { is_expected.to eql('/foo.md') }
19
+ describe '#update' do
20
+ context 'with nothing' do
21
+ subject { action.update }
22
+ its(:snapshot_names) { is_expected.to eql([:before_layout]) }
23
+ its(:paths) { is_expected.to eql(['/foo.md']) }
24
24
  end
25
25
 
26
- context 'with path' do
27
- subject { action.copy(path: '/donkey.md') }
28
- its(:snapshot_name) { is_expected.to eql(:before_layout) }
29
- its(:path) { is_expected.to eql('/donkey.md') }
26
+ context 'with snapshot name' do
27
+ subject { action.update(snapshot_names: [:zebra]) }
28
+ its(:snapshot_names) { is_expected.to eql([:before_layout, :zebra]) }
29
+ its(:paths) { is_expected.to eql(['/foo.md']) }
30
+ end
31
+
32
+ context 'with paths' do
33
+ subject { action.update(paths: ['/donkey.md', '/giraffe.md']) }
34
+ its(:snapshot_names) { is_expected.to eql([:before_layout]) }
35
+ its(:paths) { is_expected.to eql(['/foo.md', '/donkey.md', '/giraffe.md']) }
30
36
  end
31
37
  end
32
38
  end