nanoc 4.6.3 → 4.6.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,4 +1,4 @@
1
1
  module Nanoc
2
2
  # The current Nanoc version.
3
- VERSION = '4.6.3'.freeze
3
+ VERSION = '4.6.4'.freeze
4
4
  end
@@ -27,7 +27,7 @@ describe Nanoc::CLI::Commands::Compile::TimingRecorder, stdio: true do
27
27
  Nanoc::Int::NotificationCenter.post(:filtering_ended, rep, :erb)
28
28
 
29
29
  expect { listener.stop }
30
- .to output(/^erb \| 1 1\.00s 1\.00s 1\.00s 1\.00s$/).to_stdout
30
+ .to output(/^erb 1 1\.00s 1\.00s 1\.00s 1\.00s$/).to_stdout
31
31
  end
32
32
 
33
33
  it 'records multiple from filtering_started to filtering_ended' do
@@ -43,7 +43,39 @@ describe Nanoc::CLI::Commands::Compile::TimingRecorder, stdio: true do
43
43
  Nanoc::Int::NotificationCenter.post(:filtering_ended, rep, :erb)
44
44
 
45
45
  expect { listener.stop }
46
- .to output(/^erb \| 2 1\.00s 1\.50s 2\.00s 3\.00s$/).to_stdout
46
+ .to output(/^erb 2 1\.00s 1\.50s 2\.00s 3\.00s$/).to_stdout
47
+ end
48
+
49
+ it 'records inner filters in nested filtering_started/filtering_ended' do
50
+ listener.start
51
+
52
+ Timecop.freeze(Time.local(2008, 9, 1, 10, 5, 0))
53
+ Nanoc::Int::NotificationCenter.post(:filtering_started, rep, :outer)
54
+ Timecop.freeze(Time.local(2008, 9, 1, 10, 5, 1))
55
+ Nanoc::Int::NotificationCenter.post(:filtering_started, rep, :inner)
56
+ Timecop.freeze(Time.local(2008, 9, 1, 10, 5, 3))
57
+ Nanoc::Int::NotificationCenter.post(:filtering_ended, rep, :inner)
58
+ Timecop.freeze(Time.local(2008, 9, 1, 10, 5, 6))
59
+ Nanoc::Int::NotificationCenter.post(:filtering_ended, rep, :outer)
60
+
61
+ expect { listener.stop }
62
+ .to output(/^inner │ 1 2\.00s 2\.00s 2\.00s 2\.00s$/).to_stdout
63
+ end
64
+
65
+ it 'records outer filters in nested filtering_started/filtering_ended' do
66
+ listener.start
67
+
68
+ Timecop.freeze(Time.local(2008, 9, 1, 10, 5, 0))
69
+ Nanoc::Int::NotificationCenter.post(:filtering_started, rep, :outer)
70
+ Timecop.freeze(Time.local(2008, 9, 1, 10, 5, 1))
71
+ Nanoc::Int::NotificationCenter.post(:filtering_started, rep, :inner)
72
+ Timecop.freeze(Time.local(2008, 9, 1, 10, 5, 3))
73
+ Nanoc::Int::NotificationCenter.post(:filtering_ended, rep, :inner)
74
+ Timecop.freeze(Time.local(2008, 9, 1, 10, 5, 6))
75
+ Nanoc::Int::NotificationCenter.post(:filtering_ended, rep, :outer)
76
+
77
+ expect { listener.stop }
78
+ .to output(/^outer │ 1 6\.00s 6\.00s 6\.00s 6\.00s$/).to_stdout
47
79
  end
48
80
 
49
81
  it 'records single from filtering_started over compilation_{suspended,started} to filtering_ended' do
@@ -59,8 +91,7 @@ describe Nanoc::CLI::Commands::Compile::TimingRecorder, stdio: true do
59
91
  Timecop.freeze(Time.local(2008, 9, 1, 10, 5, 7))
60
92
  Nanoc::Int::NotificationCenter.post(:filtering_ended, rep, :erb)
61
93
 
62
- # FIXME: wrong count (should be 1, not 2)
63
94
  expect { listener.stop }
64
- .to output(/^erb \| 2 1\.00s 2\.50s 4\.00s 5\.00s$/).to_stdout
95
+ .to output(/^erb 1 5\.00s 5\.00s 5\.00s 5\.00s$/).to_stdout
65
96
  end
66
97
  end
@@ -0,0 +1,7 @@
1
+ describe Nanoc::CLI::StreamCleaners::UTF8 do
2
+ subject { described_class.new }
3
+
4
+ it 'handles all cases' do
5
+ expect(subject.clean('┼─ “© Denis” ‘and others…’ ─┼')).to eq('+- "(c) Denis" \'and others...\' -+')
6
+ end
7
+ end
@@ -43,8 +43,8 @@ describe Nanoc::Helpers::Blogging, helper: true do
43
43
  let(:item_attributes) { {} }
44
44
 
45
45
  before do
46
- item = ctx.create_item('Stuff', item_attributes, '/stuff/')
47
- ctx.create_rep(item, '/rep/path/stuff.html')
46
+ ctx.create_item('Stuff', item_attributes, '/stuff/')
47
+ ctx.create_rep(ctx.items['/stuff/'], '/rep/path/stuff.html')
48
48
 
49
49
  ctx.config[:base_url] = base_url
50
50
  end
@@ -96,9 +96,10 @@ describe Nanoc::Helpers::Blogging, helper: true do
96
96
  let(:item_attributes) { {} }
97
97
 
98
98
  before do
99
- ctx.item = ctx.create_item('Feed', item_attributes, '/feed/')
100
- ctx.create_rep(ctx.item, '/feed.xml')
99
+ ctx.create_item('Feed', item_attributes, '/feed/')
100
+ ctx.create_rep(ctx.items['/feed/'], '/feed.xml')
101
101
 
102
+ ctx.item = ctx.items['/feed/']
102
103
  ctx.config[:base_url] = base_url
103
104
  end
104
105
 
@@ -170,8 +171,8 @@ describe Nanoc::Helpers::Blogging, helper: true do
170
171
  let(:base_url) { 'http://url.base' }
171
172
 
172
173
  before do
173
- item = ctx.create_item('Stuff', item_attributes, '/stuff/')
174
- ctx.create_rep(item, item_rep_path)
174
+ ctx.create_item('Stuff', item_attributes, '/stuff/')
175
+ ctx.create_rep(ctx.items['/stuff/'], item_rep_path)
175
176
 
176
177
  ctx.config[:base_url] = base_url
177
178
  end
@@ -1,8 +1,9 @@
1
1
  describe Nanoc::Helpers::Capturing, helper: true do
2
2
  describe '#content_for' do
3
3
  before do
4
- ctx.item = ctx.create_item('some content', {}, '/about.md')
5
- ctx.create_rep(ctx.item, '/about.html')
4
+ ctx.create_item('some content', {}, '/about.md')
5
+ ctx.create_rep(ctx.items['/about.md'], '/about.html')
6
+ ctx.item = ctx.items['/about.md']
6
7
  end
7
8
 
8
9
  describe 'setting content' do
@@ -148,8 +149,8 @@ describe Nanoc::Helpers::Capturing, helper: true do
148
149
  let(:item) { ctx.items['/other.md'] }
149
150
 
150
151
  before do
151
- item = ctx.create_item('other content', {}, '/other.md')
152
- ctx.create_rep(item, '/other.html')
152
+ ctx.create_item('other content', {}, '/other.md')
153
+ ctx.create_rep(ctx.items['/other.md'], '/other.html')
153
154
  end
154
155
 
155
156
  context 'other item is not yet compiled' do
@@ -2,49 +2,35 @@ describe Nanoc::Helpers::ChildParent, helper: true do
2
2
  describe '#children_of' do
3
3
  subject { helper.children_of(item) }
4
4
 
5
- let(:item) { ctx.create_item('some content', {}, identifier) }
5
+ before { ctx.create_item('some content', {}, identifier) }
6
+ let(:item) { ctx.items[identifier] }
6
7
 
7
8
  context 'legacy identifier' do
8
9
  let(:identifier) { Nanoc::Identifier.new('/foo/', type: :legacy) }
9
10
 
10
- let!(:child_item) do
11
+ before do
11
12
  ctx.create_item('abc', {}, Nanoc::Identifier.new('/foo/a/', type: :legacy))
12
- end
13
-
14
- let!(:grandchild_item) do
15
13
  ctx.create_item('def', {}, Nanoc::Identifier.new('/foo/a/b/', type: :legacy))
16
- end
17
-
18
- let!(:sibling_item) do
19
14
  ctx.create_item('xyz', {}, Nanoc::Identifier.new('/bar/', type: :legacy))
20
15
  end
21
16
 
22
17
  it 'returns only direct children' do
23
- expect(subject).to eql([child_item])
18
+ expect(subject).to eql([ctx.items['/foo/a/']])
24
19
  end
25
20
  end
26
21
 
27
22
  context 'full identifier' do
28
23
  let(:identifier) { Nanoc::Identifier.new('/foo.md', type: :full) }
29
24
 
30
- let!(:child_item) do
25
+ before do
31
26
  ctx.create_item('abc', {}, Nanoc::Identifier.new('/foo/a.md', type: :full))
32
- end
33
-
34
- let!(:grandchild_item) do
35
27
  ctx.create_item('def', {}, Nanoc::Identifier.new('/foo/a/b.md', type: :full))
36
- end
37
-
38
- let!(:sibling_item) do
39
28
  ctx.create_item('xyz', {}, Nanoc::Identifier.new('/bar.md', type: :full))
40
- end
41
-
42
- let!(:index_child_item) do
43
29
  ctx.create_item('xyz', {}, Nanoc::Identifier.new('/foo/a/index.md', type: :full))
44
30
  end
45
31
 
46
32
  it 'returns only direct children' do
47
- expect(subject).to eql([child_item])
33
+ expect(subject).to eql([ctx.items['/foo/a.md']])
48
34
  end
49
35
  end
50
36
  end
@@ -52,53 +38,36 @@ describe Nanoc::Helpers::ChildParent, helper: true do
52
38
  describe '#parent_of' do
53
39
  subject { helper.parent_of(item) }
54
40
 
55
- let(:item) { ctx.create_item('some content', {}, identifier) }
41
+ before { ctx.create_item('some content', {}, identifier) }
42
+ let(:item) { ctx.items[identifier] }
56
43
 
57
44
  context 'legacy identifier' do
58
45
  let(:identifier) { Nanoc::Identifier.new('/foo/bar/', type: :legacy) }
59
46
 
60
- let!(:parent_item) do
47
+ before do
61
48
  ctx.create_item('abc', {}, Nanoc::Identifier.new('/foo/', type: :legacy))
62
- end
63
-
64
- let!(:sibling_item) do
65
49
  ctx.create_item('def', {}, Nanoc::Identifier.new('/foo/qux/', type: :legacy))
66
- end
67
-
68
- let!(:child_item) do
69
50
  ctx.create_item('xyz', {}, Nanoc::Identifier.new('/foo/bar/asdf/', type: :legacy))
70
- end
71
-
72
- let!(:grandparent_item) do
73
51
  ctx.create_item('opq', {}, Nanoc::Identifier.new('/', type: :legacy))
74
52
  end
75
53
 
76
54
  it 'returns parent' do
77
- expect(subject).to eql(parent_item)
55
+ expect(subject).to eql(ctx.items['/foo/'])
78
56
  end
79
57
  end
80
58
 
81
59
  context 'full identifier' do
82
60
  let(:identifier) { Nanoc::Identifier.new('/foo/bar.md', type: :full) }
83
61
 
84
- let!(:parent_item) do
62
+ before do
85
63
  ctx.create_item('abc', {}, Nanoc::Identifier.new('/foo.md', type: :full))
86
- end
87
-
88
- let!(:sibling_item) do
89
64
  ctx.create_item('def', {}, Nanoc::Identifier.new('/foo/qux.md', type: :full))
90
- end
91
-
92
- let!(:child_item) do
93
65
  ctx.create_item('xyz', {}, Nanoc::Identifier.new('/foo/bar/asdf.md', type: :full))
94
- end
95
-
96
- let!(:grandparent_item) do
97
66
  ctx.create_item('opq', {}, Nanoc::Identifier.new('/index.md', type: :full))
98
67
  end
99
68
 
100
69
  it 'returns parent' do
101
- expect(subject).to eql(parent_item)
70
+ expect(subject).to eql(ctx.items['/foo.md'])
102
71
  end
103
72
  end
104
73
  end
@@ -1,8 +1,11 @@
1
1
  describe Nanoc::Helpers::Filtering, helper: true do
2
2
  describe '#filter' do
3
3
  before do
4
- ctx.item = ctx.create_item('some content', { title: 'Hello!' }, '/about.md')
5
- ctx.item_rep = ctx.create_rep(ctx.item, '/about.html')
4
+ ctx.create_item('some content', { title: 'Hello!' }, '/about.md')
5
+ ctx.create_rep(ctx.items['/about.md'], '/about.html')
6
+
7
+ ctx.item = ctx.items['/about.md']
8
+ ctx.item_rep = ctx.item.reps[:default]
6
9
  end
7
10
 
8
11
  let(:content) do
@@ -33,14 +33,22 @@ describe Nanoc::Helpers::LinkTo, helper: true do
33
33
  end
34
34
 
35
35
  context 'with rep' do
36
- let(:item) { ctx.create_item('content', {}, '/target/') }
37
- let(:target) { ctx.create_rep(item, '/target.html') }
36
+ before do
37
+ ctx.create_item('content', {}, '/target/')
38
+ ctx.create_rep(ctx.items['/target/'], '/target.html')
39
+ end
40
+
41
+ let(:target) { ctx.items['/target/'].reps[:default] }
38
42
 
39
43
  it { is_expected.to eql('<a href="/target.html">Text</a>') }
40
44
  end
41
45
 
42
46
  context 'with item' do
43
- let(:target) { ctx.create_item('content', {}, '/target/') }
47
+ before do
48
+ ctx.create_item('content', {}, '/target/')
49
+ end
50
+
51
+ let(:target) { ctx.items['/target/'] }
44
52
 
45
53
  before do
46
54
  ctx.create_rep(target, '/target.html')
@@ -66,8 +74,12 @@ describe Nanoc::Helpers::LinkTo, helper: true do
66
74
  end
67
75
 
68
76
  context 'with nil path' do
69
- let(:item) { ctx.create_item('content', {}, '/target/') }
70
- let(:target) { ctx.create_rep(item, nil) }
77
+ before do
78
+ ctx.create_item('content', {}, '/target/')
79
+ ctx.create_rep(ctx.items['/target/'], nil)
80
+ end
81
+
82
+ let(:target) { ctx.items['/target/'].reps[:default] }
71
83
 
72
84
  it 'raises' do
73
85
  expect { subject }.to raise_error(RuntimeError)
@@ -87,8 +99,11 @@ describe Nanoc::Helpers::LinkTo, helper: true do
87
99
 
88
100
  context 'current' do
89
101
  before do
90
- ctx.item = ctx.create_item('content', {}, '/target.md')
91
- ctx.item_rep = ctx.create_rep(ctx.item, '/target.html')
102
+ ctx.create_item('content', {}, '/target.md')
103
+ ctx.create_rep(ctx.items['/target.md'], '/target.html')
104
+
105
+ ctx.item = ctx.items['/target.md']
106
+ ctx.item_rep = ctx.item.reps[:default]
92
107
  end
93
108
 
94
109
  it { is_expected.to eql('<span class="active">Text</span>') }
@@ -100,8 +115,11 @@ describe Nanoc::Helpers::LinkTo, helper: true do
100
115
 
101
116
  context 'item rep present, but not current' do
102
117
  before do
103
- ctx.item = ctx.create_item('content', {}, '/other.md')
104
- ctx.item_rep = ctx.create_rep(ctx.item, '/other.html')
118
+ ctx.create_item('content', {}, '/other.md')
119
+ ctx.create_rep(ctx.items['/other.md'], '/other.html')
120
+
121
+ ctx.item = ctx.items['/other.md']
122
+ ctx.item_rep = ctx.item.reps[:default]
105
123
  end
106
124
 
107
125
  it { is_expected.to eql('<a href="/target.html">Text</a>') }
@@ -110,12 +128,18 @@ describe Nanoc::Helpers::LinkTo, helper: true do
110
128
 
111
129
  context 'with rep' do
112
130
  before do
113
- ctx.item = ctx.create_item('content', {}, '/target.md')
114
- ctx.item_rep = ctx.create_rep(ctx.item, '/target.html')
131
+ ctx.create_item('content', {}, '/target.md')
132
+ ctx.create_rep(ctx.items['/target.md'], '/target.html')
133
+
134
+ ctx.create_item('content', {}, '/other.md')
135
+ ctx.create_rep(ctx.items['/other.md'], '/other.html')
136
+
137
+ ctx.item = ctx.items['/target.md']
138
+ ctx.item_rep = ctx.item.reps[:default]
115
139
  end
116
140
 
117
- let(:some_item) { ctx.create_item('content', {}, '/other.md') }
118
- let(:some_item_rep) { ctx.create_rep(some_item, '/other.html') }
141
+ let(:some_item) { ctx.items['/other.md'] }
142
+ let(:some_item_rep) { some_item.reps[:default] }
119
143
 
120
144
  context 'current' do
121
145
  let(:target) { ctx.item_rep }
@@ -141,12 +165,18 @@ describe Nanoc::Helpers::LinkTo, helper: true do
141
165
 
142
166
  context 'with item' do
143
167
  before do
144
- ctx.item = ctx.create_item('content', {}, '/target.md')
145
- ctx.item_rep = ctx.create_rep(ctx.item, '/target.html')
168
+ ctx.create_item('content', {}, '/target.md')
169
+ ctx.create_rep(ctx.items['/target.md'], '/target.html')
170
+
171
+ ctx.create_item('content', {}, '/other.md')
172
+ ctx.create_rep(ctx.items['/other.md'], '/other.html')
173
+
174
+ ctx.item = ctx.items['/target.md']
175
+ ctx.item_rep = ctx.item.reps[:default]
146
176
  end
147
177
 
148
- let!(:some_item) { ctx.create_item('content', {}, '/other.md') }
149
- let!(:some_item_rep) { ctx.create_rep(some_item, '/other.html') }
178
+ let(:some_item) { ctx.items['/other.md'] }
179
+ let(:some_item_rep) { some_item.reps[:default] }
150
180
 
151
181
  context 'current' do
152
182
  let(:target) { ctx.item }
@@ -175,8 +205,11 @@ describe Nanoc::Helpers::LinkTo, helper: true do
175
205
  subject { helper.relative_path_to(target) }
176
206
 
177
207
  before do
178
- ctx.item = ctx.create_item('content', {}, '/foo/self.md')
179
- ctx.item_rep = ctx.create_rep(ctx.item, self_path)
208
+ ctx.create_item('content', {}, '/foo/self.md')
209
+ ctx.create_rep(ctx.items['/foo/self.md'], self_path)
210
+
211
+ ctx.item = ctx.items['/foo/self.md']
212
+ ctx.item_rep = ctx.item.reps[:default]
180
213
  end
181
214
 
182
215
  context 'current item rep has non-nil path' do
@@ -214,7 +247,12 @@ describe Nanoc::Helpers::LinkTo, helper: true do
214
247
  end
215
248
 
216
249
  context 'to rep' do
217
- let(:target) { ctx.create_rep(ctx.item, '/bar/target.html') }
250
+ before do
251
+ ctx.create_rep(ctx.item, '/bar/target.html', :special)
252
+ end
253
+
254
+ let(:target) { ctx.item.reps[:special] }
255
+
218
256
  it { is_expected.to eql('../bar/target.html') }
219
257
 
220
258
  context 'to self' do
@@ -232,10 +270,11 @@ describe Nanoc::Helpers::LinkTo, helper: true do
232
270
  end
233
271
 
234
272
  context 'to item' do
235
- let(:target) { ctx.create_item('content', {}, '/bar/target.md') }
273
+ let(:target) { ctx.items['/bar/target.md'] }
236
274
 
237
275
  before do
238
- ctx.create_rep(target, '/bar/target.html')
276
+ ctx.create_item('content', {}, '/bar/target.md')
277
+ ctx.create_rep(ctx.items['/bar/target.md'], '/bar/target.html')
239
278
  end
240
279
 
241
280
  it { is_expected.to eql('../bar/target.html') }
@@ -255,7 +294,11 @@ describe Nanoc::Helpers::LinkTo, helper: true do
255
294
  end
256
295
 
257
296
  context 'to nil path' do
258
- let(:target) { ctx.create_rep(ctx.item, nil) }
297
+ let(:target) { ctx.item.reps[:special] }
298
+
299
+ before do
300
+ ctx.create_rep(ctx.item, nil, :special)
301
+ end
259
302
 
260
303
  it 'raises' do
261
304
  expect { subject }.to raise_error(RuntimeError)
@@ -6,15 +6,11 @@ describe Nanoc::Helpers::Rendering, helper: true do
6
6
  [Nanoc::Int::ProcessingActions::Filter.new(:erb, {})]
7
7
  end
8
8
 
9
- let(:layout_view) do
10
- ctx.create_layout(layout_content, {}, layout_identifier)
11
- end
12
-
13
- let(:layout) do
14
- layout_view.unwrap
15
- end
9
+ let(:layout_view) { ctx.layouts[layout_identifier] }
10
+ let(:layout) { layout_view.unwrap }
16
11
 
17
12
  before do
13
+ ctx.create_layout(layout_content, {}, layout_identifier)
18
14
  ctx.update_rule_memory(layout, rule_memory_for_layout)
19
15
  end
20
16
 
@@ -0,0 +1,68 @@
1
+ describe Nanoc::Spec::HelperContext do
2
+ let(:helper) do
3
+ Module.new {}
4
+ end
5
+
6
+ subject(:ctx) { described_class.new(helper) }
7
+
8
+ it 'has no items by default' do
9
+ # TODO: Add #empty? to item collection view
10
+ expect(subject.items.size).to eq(0)
11
+ end
12
+
13
+ it 'has no layouts by default' do
14
+ # TODO: Add #empty? to item collection view
15
+ expect(subject.layouts.size).to eq(0)
16
+ end
17
+
18
+ describe '#create_item' do
19
+ subject { ctx.create_item('foo', {}, '/foo.md') }
20
+
21
+ it 'creates item' do
22
+ expect { subject }
23
+ .to change { ctx.items.size }
24
+ .from(0).to(1)
25
+ end
26
+
27
+ it 'creates item without reps' do
28
+ subject
29
+ expect(ctx.items['/foo.md'].reps.size).to eq(0)
30
+ end
31
+
32
+ it 'returns self' do
33
+ expect(subject).to eq(ctx)
34
+ end
35
+ end
36
+
37
+ describe '#create_layout' do
38
+ subject { ctx.create_layout('foo', {}, '/foo.md') }
39
+
40
+ it 'creates layout' do
41
+ expect { subject }
42
+ .to change { ctx.layouts.size }
43
+ .from(0).to(1)
44
+ end
45
+
46
+ it 'returns self' do
47
+ expect(subject).to eq(ctx)
48
+ end
49
+ end
50
+
51
+ describe '#create_rep' do
52
+ before do
53
+ ctx.create_item('foo', {}, '/foo.md')
54
+ end
55
+
56
+ subject { ctx.create_rep(ctx.items['/foo.md'], '/foo.html') }
57
+
58
+ it 'creates rep' do
59
+ expect { subject }
60
+ .to change { ctx.items['/foo.md'].reps.size }
61
+ .from(0).to(1)
62
+ end
63
+
64
+ it 'returns self' do
65
+ expect(subject).to eq(ctx)
66
+ end
67
+ end
68
+ end