nanoc 4.5.2 → 4.5.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (44) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile.lock +7 -7
  3. data/NEWS.md +7 -0
  4. data/lib/nanoc/base/entities/item_rep.rb +0 -46
  5. data/lib/nanoc/base/repos.rb +1 -0
  6. data/lib/nanoc/base/repos/snapshot_repo.rb +60 -0
  7. data/lib/nanoc/base/services/compiler.rb +30 -17
  8. data/lib/nanoc/base/services/executor.rb +17 -8
  9. data/lib/nanoc/base/services/item_rep_writer.rb +3 -3
  10. data/lib/nanoc/base/views/item_rep_collection_view.rb +1 -1
  11. data/lib/nanoc/base/views/item_rep_view.rb +2 -2
  12. data/lib/nanoc/base/views/post_compile_item_rep_view.rb +9 -7
  13. data/lib/nanoc/base/views/view_context.rb +3 -1
  14. data/lib/nanoc/cli/commands/compile.rb +3 -3
  15. data/lib/nanoc/cli/commands/shell.rb +1 -0
  16. data/lib/nanoc/extra/parallel_collection.rb +1 -1
  17. data/lib/nanoc/helpers/capturing.rb +9 -5
  18. data/lib/nanoc/rule_dsl/action_provider.rb +2 -0
  19. data/lib/nanoc/rule_dsl/rule_memory_calculator.rb +4 -1
  20. data/lib/nanoc/spec.rb +17 -18
  21. data/lib/nanoc/version.rb +1 -1
  22. data/spec/nanoc/base/compiler_spec.rb +9 -8
  23. data/spec/nanoc/base/entities/item_rep_spec.rb +0 -222
  24. data/spec/nanoc/base/filter_spec.rb +1 -0
  25. data/spec/nanoc/base/item_rep_writer_spec.rb +9 -4
  26. data/spec/nanoc/base/repos/snapshot_repo_spec.rb +314 -0
  27. data/spec/nanoc/base/services/compiler/phases/cache_spec.rb +107 -0
  28. data/spec/nanoc/base/services/executor_spec.rb +230 -44
  29. data/spec/nanoc/base/views/document_view_spec.rb +1 -0
  30. data/spec/nanoc/base/views/item_rep_view_spec.rb +18 -5
  31. data/spec/nanoc/base/views/item_view_spec.rb +18 -7
  32. data/spec/nanoc/base/views/mutable_document_view_spec.rb +6 -5
  33. data/spec/nanoc/base/views/post_compile_item_rep_view_spec.rb +8 -3
  34. data/spec/nanoc/cli/commands/compile/file_action_printer_spec.rb +3 -3
  35. data/spec/nanoc/helpers/capturing_spec.rb +8 -5
  36. data/spec/nanoc/regressions/gh_1064_spec.rb +18 -0
  37. data/spec/nanoc/rule_dsl/rule_context_spec.rb +2 -1
  38. data/spec/nanoc/rule_dsl/rule_memory_calculator_spec.rb +15 -3
  39. data/spec/spec_helper.rb +43 -0
  40. data/test/cli/commands/test_compile.rb +1 -1
  41. data/test/filters/test_xsl.rb +1 -0
  42. data/test/helpers/test_capturing.rb +9 -2
  43. data/test/helpers/test_xml_sitemap.rb +1 -1
  44. metadata +6 -2
@@ -3,12 +3,22 @@ describe Nanoc::ItemWithRepsView do
3
3
  let(:other_view_class) { Nanoc::LayoutView }
4
4
  it_behaves_like 'a document view'
5
5
 
6
- let(:view_context) { Nanoc::ViewContext.new(reps: reps, items: items, dependency_tracker: dependency_tracker, compilation_context: compilation_context) }
6
+ let(:view_context) do
7
+ Nanoc::ViewContext.new(
8
+ reps: reps,
9
+ items: items,
10
+ dependency_tracker: dependency_tracker,
11
+ compilation_context: compilation_context,
12
+ snapshot_repo: snapshot_repo,
13
+ )
14
+ end
15
+
7
16
  let(:reps) { [] }
8
17
  let(:items) { [] }
9
18
  let(:dependency_tracker) { Nanoc::Int::DependencyTracker.new(dependency_store) }
10
19
  let(:dependency_store) { Nanoc::Int::DependencyStore.new([]) }
11
20
  let(:compilation_context) { double(:compilation_context) }
21
+ let(:snapshot_repo) { Nanoc::Int::SnapshotRepo.new }
12
22
 
13
23
  let(:base_item) { Nanoc::Int::Item.new('base', {}, '/base.md') }
14
24
 
@@ -203,15 +213,16 @@ describe Nanoc::ItemWithRepsView do
203
213
  Nanoc::Int::SnapshotDef.new(:post),
204
214
  Nanoc::Int::SnapshotDef.new(:specific),
205
215
  ]
206
- ir.snapshot_contents = {
207
- last: Nanoc::Int::TextualContent.new('Last Hallo'),
208
- pre: Nanoc::Int::TextualContent.new('Pre Hallo'),
209
- post: Nanoc::Int::TextualContent.new('Post Hallo'),
210
- specific: Nanoc::Int::TextualContent.new('Specific Hallo'),
211
- }
212
216
  end
213
217
  end
214
218
 
219
+ before do
220
+ snapshot_repo.set(rep, :last, Nanoc::Int::TextualContent.new('Last Hallo'))
221
+ snapshot_repo.set(rep, :pre, Nanoc::Int::TextualContent.new('Pre Hallo'))
222
+ snapshot_repo.set(rep, :post, Nanoc::Int::TextualContent.new('Post Hallo'))
223
+ snapshot_repo.set(rep, :specific, Nanoc::Int::TextualContent.new('Specific Hallo'))
224
+ end
225
+
215
226
  context 'requesting implicit default rep' do
216
227
  let(:params) { {} }
217
228
 
@@ -1,5 +1,5 @@
1
1
  shared_examples 'a mutable document view' do
2
- let(:view) { described_class.new(item, view_context) }
2
+ let(:view) { described_class.new(document, view_context) }
3
3
 
4
4
  let(:view_context) do
5
5
  Nanoc::ViewContext.new(
@@ -7,14 +7,15 @@ shared_examples 'a mutable document view' do
7
7
  items: double(:items),
8
8
  dependency_tracker: dependency_tracker,
9
9
  compilation_context: double(:compilation_context),
10
+ snapshot_repo: snapshot_repo,
10
11
  )
11
12
  end
12
13
 
13
14
  let(:dependency_tracker) { Nanoc::Int::DependencyTracker.new(double(:dependency_store)) }
15
+ let(:snapshot_repo) { double(:snapshot_repo) }
14
16
 
15
17
  describe '#[]=' do
16
- # FIXME: rename :item to :document
17
- let(:item) { entity_class.new('content', {}, '/asdf/') }
18
+ let(:document) { entity_class.new('content', {}, '/asdf/') }
18
19
 
19
20
  it 'sets attributes' do
20
21
  view[:title] = 'Donkey'
@@ -43,7 +44,7 @@ shared_examples 'a mutable document view' do
43
44
  end
44
45
 
45
46
  describe '#identifier=' do
46
- let(:item) { entity_class.new('content', {}, '/about.md') }
47
+ let(:document) { entity_class.new('content', {}, '/about.md') }
47
48
 
48
49
  subject { view.identifier = arg }
49
50
 
@@ -75,7 +76,7 @@ shared_examples 'a mutable document view' do
75
76
  end
76
77
 
77
78
  describe '#update_attributes' do
78
- let(:item) { entity_class.new('content', {}, '/asdf/') }
79
+ let(:document) { entity_class.new('content', {}, '/asdf/') }
79
80
 
80
81
  let(:update) { { friend: 'Giraffe' } }
81
82
 
@@ -9,6 +9,7 @@ describe Nanoc::PostCompileItemRepView do
9
9
  items: items,
10
10
  dependency_tracker: dependency_tracker,
11
11
  compilation_context: compilation_context,
12
+ snapshot_repo: snapshot_repo,
12
13
  )
13
14
  end
14
15
 
@@ -17,6 +18,7 @@ describe Nanoc::PostCompileItemRepView do
17
18
  let(:config) { Nanoc::Int::Configuration.new }
18
19
  let(:dependency_tracker) { Nanoc::Int::DependencyTracker.new(double(:dependency_store)) }
19
20
  let(:compilation_context) { double(:compilation_context, compiled_content_cache: compiled_content_cache) }
21
+ let(:snapshot_repo) { double(:snapshot_repo) }
20
22
 
21
23
  let(:snapshot_contents) do
22
24
  {
@@ -36,9 +38,12 @@ describe Nanoc::PostCompileItemRepView do
36
38
  subject { view.compiled_content }
37
39
 
38
40
  context 'binary' do
39
- let(:item) do
40
- content = Nanoc::Int::Content.create('/foo.dat', binary: true)
41
- Nanoc::Int::Item.new(content, {}, '/foo.dat')
41
+ let(:snapshot_contents) do
42
+ {
43
+ last: Nanoc::Int::TextualContent.new('content-last'),
44
+ pre: Nanoc::Int::BinaryContent.new('/content/pre'),
45
+ donkey: Nanoc::Int::TextualContent.new('content-donkey'),
46
+ }
42
47
  end
43
48
 
44
49
  it 'raises error' do
@@ -25,7 +25,7 @@ describe Nanoc::CLI::Commands::Compile::FileActionPrinter, stdio: true do
25
25
  Nanoc::Int::NotificationCenter.post(:compilation_started, rep)
26
26
  Timecop.freeze(Time.local(2008, 9, 1, 10, 5, 1))
27
27
 
28
- expect { Nanoc::Int::NotificationCenter.post(:rep_written, rep, '/foo.html', true, true) }
28
+ expect { Nanoc::Int::NotificationCenter.post(:rep_written, rep, false, '/foo.html', true, true) }
29
29
  .to output(/create.*\[1\.00s\]/).to_stdout
30
30
  end
31
31
 
@@ -35,7 +35,7 @@ describe Nanoc::CLI::Commands::Compile::FileActionPrinter, stdio: true do
35
35
 
36
36
  Nanoc::Int::NotificationCenter.post(:compilation_started, rep)
37
37
 
38
- expect { Nanoc::Int::NotificationCenter.post(:rep_written, rep, '/foo.html', true, true) }
38
+ expect { Nanoc::Int::NotificationCenter.post(:rep_written, rep, false, '/foo.html', true, true) }
39
39
  .not_to output(/create/).to_stdout
40
40
  end
41
41
 
@@ -50,7 +50,7 @@ describe Nanoc::CLI::Commands::Compile::FileActionPrinter, stdio: true do
50
50
  Nanoc::Int::NotificationCenter.post(:compilation_started, rep)
51
51
  Timecop.freeze(Time.local(2008, 9, 1, 10, 5, 6))
52
52
 
53
- expect { Nanoc::Int::NotificationCenter.post(:rep_written, rep, '/foo.html', true, true) }
53
+ expect { Nanoc::Int::NotificationCenter.post(:rep_written, rep, false, '/foo.html', true, true) }
54
54
  .to output(/create.*\[4\.00s\]/).to_stdout
55
55
  end
56
56
 
@@ -13,7 +13,7 @@ describe Nanoc::Helpers::Capturing, helper: true do
13
13
 
14
14
  it 'stores snapshot content' do
15
15
  subject
16
- expect(ctx.item.reps[:default].unwrap.snapshot_contents[:__capture_foo].string).to eql('foo')
16
+ expect(ctx.snapshot_repo.get(ctx.item.reps[:default].unwrap, :__capture_foo).string).to eql('foo')
17
17
  end
18
18
  end
19
19
 
@@ -36,7 +36,7 @@ describe Nanoc::Helpers::Capturing, helper: true do
36
36
  it 'overwrites' do
37
37
  helper.content_for(:foo, params) { _erbout << 'foo' }
38
38
  helper.content_for(:foo, params) { _erbout << 'bar' }
39
- expect(ctx.item.reps[:default].unwrap.snapshot_contents[:__capture_foo].string).to eql('bar')
39
+ expect(ctx.snapshot_repo.get(ctx.item.reps[:default].unwrap, :__capture_foo).string).to eql('bar')
40
40
  end
41
41
  end
42
42
 
@@ -46,7 +46,7 @@ describe Nanoc::Helpers::Capturing, helper: true do
46
46
  it 'appends' do
47
47
  helper.content_for(:foo, params) { _erbout << 'foo' }
48
48
  helper.content_for(:foo, params) { _erbout << 'bar' }
49
- expect(ctx.item.reps[:default].unwrap.snapshot_contents[:__capture_foo].string).to eql('foobar')
49
+ expect(ctx.snapshot_repo.get(ctx.item.reps[:default].unwrap, :__capture_foo).string).to eql('foobar')
50
50
  end
51
51
  end
52
52
 
@@ -108,8 +108,11 @@ describe Nanoc::Helpers::Capturing, helper: true do
108
108
  context 'other item is compiled' do
109
109
  before do
110
110
  item.reps[:default].unwrap.compiled = true
111
- item.reps[:default].unwrap.snapshot_contents[:__capture_foo] =
112
- Nanoc::Int::TextualContent.new('other captured foo')
111
+ ctx.snapshot_repo.set(
112
+ item.reps[:default].unwrap,
113
+ :__capture_foo,
114
+ Nanoc::Int::TextualContent.new('other captured foo'),
115
+ )
113
116
  end
114
117
 
115
118
  it 'returns the captured content' do
@@ -0,0 +1,18 @@
1
+ describe 'GH-1064', site: true, stdio: true do
2
+ before do
3
+ File.write('content/foo.erb', '*<%= @items["/bar.*"].compiled_content(snapshot: :pre) %>*')
4
+ File.write('content/bar.erb', 'Bar!')
5
+
6
+ File.write('Rules', <<EOS)
7
+ compile '/*' do
8
+ filter :erb
9
+ write item.identifier
10
+ end
11
+ EOS
12
+ end
13
+
14
+ it 'does not reuse old content' do
15
+ Nanoc::CLI.run(%w(compile))
16
+ expect(File.read('output/foo.erb')).to eql('*Bar!*')
17
+ end
18
+ end
@@ -14,8 +14,9 @@ describe(Nanoc::RuleDSL::RuleContext) do
14
14
  let(:executor) { double(:executor) }
15
15
  let(:reps) { double(:reps) }
16
16
  let(:compilation_context) { double(:compilation_context) }
17
- let(:view_context) { Nanoc::ViewContext.new(reps: reps, items: items, dependency_tracker: dependency_tracker, compilation_context: compilation_context) }
17
+ let(:view_context) { Nanoc::ViewContext.new(reps: reps, items: items, dependency_tracker: dependency_tracker, compilation_context: compilation_context, snapshot_repo: snapshot_repo) }
18
18
  let(:dependency_tracker) { double(:dependency_tracker) }
19
+ let(:snapshot_repo) { double(:snapshot_repo) }
19
20
 
20
21
  describe '#initialize' do
21
22
  it 'wraps objects in view classes' do
@@ -96,7 +96,11 @@ describe(Nanoc::RuleDSL::RuleMemoryCalculator) do
96
96
  expect(subject[1].snapshot_name).to eql(:last)
97
97
  expect(subject[1].path).to be_nil
98
98
 
99
- expect(subject.size).to eql(2)
99
+ expect(subject[2]).to be_a(Nanoc::Int::ProcessingActions::Snapshot)
100
+ expect(subject[2].snapshot_name).to eql(:pre)
101
+ expect(subject[2].path).to be_nil
102
+
103
+ expect(subject.size).to eql(3)
100
104
  end
101
105
  end
102
106
 
@@ -122,7 +126,11 @@ describe(Nanoc::RuleDSL::RuleMemoryCalculator) do
122
126
  expect(subject[1].snapshot_name).to eql(:last)
123
127
  expect(subject[1].path).to eq('/foo.md')
124
128
 
125
- expect(subject.size).to eql(2)
129
+ expect(subject[2]).to be_a(Nanoc::Int::ProcessingActions::Snapshot)
130
+ expect(subject[2].snapshot_name).to eql(:pre)
131
+ expect(subject[2].path).to be_nil
132
+
133
+ expect(subject.size).to eql(3)
126
134
  end
127
135
  end
128
136
 
@@ -148,7 +156,11 @@ describe(Nanoc::RuleDSL::RuleMemoryCalculator) do
148
156
  expect(subject[1].snapshot_name).to eql(:last)
149
157
  expect(subject[1].path).to be_nil
150
158
 
151
- expect(subject.size).to eql(2)
159
+ expect(subject[2]).to be_a(Nanoc::Int::ProcessingActions::Snapshot)
160
+ expect(subject[2].snapshot_name).to eql(:pre)
161
+ expect(subject[2].path).to be_nil
162
+
163
+ expect(subject.size).to eql(3)
152
164
  end
153
165
  end
154
166
  end
data/spec/spec_helper.rb CHANGED
@@ -173,3 +173,46 @@ RSpec::Matchers.define :yield_from_fiber do |expected|
173
173
  "expected that proc would not yield #{expected.inspect} from fiber, but was #{@res.inspect}"
174
174
  end
175
175
  end
176
+
177
+ RSpec::Matchers.define :be_some_textual_content do |expected|
178
+ include RSpec::Matchers::Composable
179
+
180
+ match do |actual|
181
+ actual.is_a?(Nanoc::Int::TextualContent) && values_match?(expected, actual.string)
182
+ end
183
+
184
+ description do
185
+ "textual content matching #{expected.inspect}"
186
+ end
187
+
188
+ failure_message do |actual|
189
+ "expected #{actual.inspect} to be textual content matching #{expected.inspect}"
190
+ end
191
+
192
+ failure_message_when_negated do |actual|
193
+ "expected #{actual.inspect} not to be textual content matching #{expected.inspect}"
194
+ end
195
+ end
196
+
197
+ RSpec::Matchers.define :be_some_binary_content do |expected|
198
+ include RSpec::Matchers::Composable
199
+
200
+ match do |actual|
201
+ actual.is_a?(Nanoc::Int::BinaryContent) && values_match?(expected, File.read(actual.filename))
202
+ end
203
+
204
+ description do
205
+ "binary content matching #{expected.inspect}"
206
+ end
207
+
208
+ failure_message do |actual|
209
+ "expected #{actual.inspect} to be binary content matching #{expected.inspect}"
210
+ end
211
+
212
+ failure_message_when_negated do |actual|
213
+ "expected #{actual.inspect} not to be binary content matching #{expected.inspect}"
214
+ end
215
+ end
216
+
217
+ RSpec::Matchers.alias_matcher :some_textual_content, :be_some_textual_content
218
+ RSpec::Matchers.alias_matcher :some_binary_content, :be_some_binary_content
@@ -173,7 +173,7 @@ class Nanoc::CLI::Commands::CompileTest < Nanoc::TestCase
173
173
  listener = new_file_action_printer([rep])
174
174
  listener.start
175
175
  Nanoc::Int::NotificationCenter.post(:compilation_started, rep)
176
- Nanoc::Int::NotificationCenter.post(:rep_written, rep, rep.raw_path, false, true)
176
+ Nanoc::Int::NotificationCenter.post(:rep_written, rep, false, rep.raw_path, false, true)
177
177
  listener.stop
178
178
 
179
179
  # Check
@@ -100,6 +100,7 @@ EOS
100
100
  items: :__irrelevat_items,
101
101
  dependency_tracker: @dependency_tracker,
102
102
  compilation_context: :__irrelevat_compiler,
103
+ snapshot_repo: :__irrelevant_snapshot_repo,
103
104
  )
104
105
  end
105
106
 
@@ -15,9 +15,14 @@ class Nanoc::Helpers::CapturingTest < Nanoc::TestCase
15
15
  items: :__irrelevant__,
16
16
  dependency_tracker: :__irrelevant__,
17
17
  compilation_context: :__irrelevant__,
18
+ snapshot_repo: snapshot_repo,
18
19
  )
19
20
  end
20
21
 
22
+ def snapshot_repo
23
+ @_snapshot_repo ||= Nanoc::Int::SnapshotRepo.new
24
+ end
25
+
21
26
  def before
22
27
  super
23
28
  Nanoc::CLI::ErrorHandler.enable
@@ -74,7 +79,9 @@ foot
74
79
  EOS
75
80
 
76
81
  item = Nanoc::Int::Item.new('content', {}, '/')
82
+ view_context = view_context_for(item)
77
83
  @item = Nanoc::ItemWithRepsView.new(item, view_context_for(item))
84
+ @config = Nanoc::ConfigView.new(Nanoc::Int::Configuration.new, view_context)
78
85
 
79
86
  result = ::ERB.new(content).result(binding)
80
87
 
@@ -155,7 +162,7 @@ EOS
155
162
 
156
163
  # Compile once
157
164
  File.open('content/includer.erb', 'w') do |io|
158
- io.write 'Old-<%= content_for(@items.find { |i| i.identifier == \'/includee/\' }, :blah) %>'
165
+ io.write 'Old-<%= content_for(@items["/includee/"], :blah) %>'
159
166
  end
160
167
  Nanoc::CLI.run(%w(compile))
161
168
  assert_equal '{}', File.read('output/includee/index.html')
@@ -163,7 +170,7 @@ EOS
163
170
 
164
171
  # Compile again
165
172
  File.open('content/includer.erb', 'w') do |io|
166
- io.write 'New-<%= content_for(@items.find { |i| i.identifier == \'/includee/\' }, :blah) %>'
173
+ io.write 'New-<%= content_for(@items["/includee/"], :blah) %>'
167
174
  end
168
175
  Nanoc::CLI.run(%w(compile))
169
176
  assert_equal '{}', File.read('output/includee/index.html')
@@ -8,7 +8,7 @@ class Nanoc::Helpers::XMLSitemapTest < Nanoc::TestCase
8
8
 
9
9
  @reps = Nanoc::Int::ItemRepRepo.new
10
10
  dependency_tracker = Nanoc::Int::DependencyTracker.new(nil)
11
- @view_context = Nanoc::ViewContext.new(reps: @reps, items: nil, dependency_tracker: dependency_tracker, compilation_context: :__irrelevant__)
11
+ @view_context = Nanoc::ViewContext.new(reps: @reps, items: nil, dependency_tracker: dependency_tracker, compilation_context: :__irrelevant__, snapshot_repo: :__irrelevant_snapshot_repo)
12
12
 
13
13
  @items = nil
14
14
  @item = nil
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nanoc
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.5.2
4
+ version: 4.5.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Denis Defreyne
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-01-11 00:00:00.000000000 Z
11
+ date: 2017-01-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: cri
@@ -170,6 +170,7 @@ files:
170
170
  - lib/nanoc/base/repos/outdatedness_store.rb
171
171
  - lib/nanoc/base/repos/rule_memory_store.rb
172
172
  - lib/nanoc/base/repos/site_loader.rb
173
+ - lib/nanoc/base/repos/snapshot_repo.rb
173
174
  - lib/nanoc/base/repos/store.rb
174
175
  - lib/nanoc/base/services.rb
175
176
  - lib/nanoc/base/services/action_provider.rb
@@ -349,6 +350,8 @@ files:
349
350
  - spec/nanoc/base/repos/dependency_store_spec.rb
350
351
  - spec/nanoc/base/repos/outdatedness_store_spec.rb
351
352
  - spec/nanoc/base/repos/site_loader_spec.rb
353
+ - spec/nanoc/base/repos/snapshot_repo_spec.rb
354
+ - spec/nanoc/base/services/compiler/phases/cache_spec.rb
352
355
  - spec/nanoc/base/services/dependency_tracker_spec.rb
353
356
  - spec/nanoc/base/services/executor_spec.rb
354
357
  - spec/nanoc/base/services/item_rep_router_spec.rb
@@ -411,6 +414,7 @@ files:
411
414
  - spec/nanoc/regressions/gh_1040_spec.rb
412
415
  - spec/nanoc/regressions/gh_1045_spec.rb
413
416
  - spec/nanoc/regressions/gh_1047_spec.rb
417
+ - spec/nanoc/regressions/gh_1064_spec.rb
414
418
  - spec/nanoc/regressions/gh_761_spec.rb
415
419
  - spec/nanoc/regressions/gh_767_spec.rb
416
420
  - spec/nanoc/regressions/gh_769_spec.rb