nanoc3 3.2.0a3 → 3.2.0a4
Sign up to get free protection for your applications and to get access to all the features.
- data/.gemtest +0 -0
- data/LICENSE +1 -1
- data/NEWS.md +23 -4
- data/README.md +7 -0
- data/lib/nanoc3/base/compilation/checksum_store.rb +17 -90
- data/lib/nanoc3/base/compilation/compiled_content_cache.rb +5 -0
- data/lib/nanoc3/base/compilation/compiler.rb +112 -175
- data/lib/nanoc3/base/compilation/compiler_dsl.rb +54 -11
- data/lib/nanoc3/base/compilation/dependency_tracker.rb +32 -65
- data/lib/nanoc3/base/compilation/filter.rb +4 -3
- data/lib/nanoc3/base/compilation/item_rep_proxy.rb +19 -4
- data/lib/nanoc3/base/compilation/item_rep_recorder_proxy.rb +90 -0
- data/lib/nanoc3/base/compilation/outdatedness_checker.rb +152 -15
- data/lib/nanoc3/base/compilation/outdatedness_reasons.rb +12 -9
- data/lib/nanoc3/base/compilation/rule.rb +3 -1
- data/lib/nanoc3/base/compilation/rule_memory_calculator.rb +42 -0
- data/lib/nanoc3/base/compilation/rule_memory_store.rb +53 -0
- data/lib/nanoc3/base/compilation/rules_collection.rb +205 -0
- data/lib/nanoc3/base/core_ext/array.rb +20 -0
- data/lib/nanoc3/base/core_ext/hash.rb +30 -0
- data/lib/nanoc3/base/core_ext/pathname.rb +26 -0
- data/lib/nanoc3/base/core_ext/string.rb +12 -0
- data/lib/nanoc3/base/core_ext.rb +1 -0
- data/lib/nanoc3/base/directed_graph.rb +11 -3
- data/lib/nanoc3/base/errors.rb +0 -4
- data/lib/nanoc3/base/memoization.rb +72 -0
- data/lib/nanoc3/base/result_data/item_rep.rb +64 -25
- data/lib/nanoc3/base/source_data/code_snippet.rb +9 -0
- data/lib/nanoc3/base/source_data/configuration.rb +20 -0
- data/lib/nanoc3/base/source_data/item.rb +29 -4
- data/lib/nanoc3/base/source_data/layout.rb +20 -1
- data/lib/nanoc3/base/source_data/site.rb +49 -26
- data/lib/nanoc3/base/store.rb +10 -1
- data/lib/nanoc3/base.rb +6 -1
- data/lib/nanoc3/cli/base.rb +20 -7
- data/lib/nanoc3/cli/commands/compile.rb +0 -2
- data/lib/nanoc3/cli/commands/create_site.rb +16 -7
- data/lib/nanoc3/cli/commands/debug.rb +3 -3
- data/lib/nanoc3/cli/commands/view.rb +1 -0
- data/lib/nanoc3/cli/commands/watch.rb +2 -1
- data/lib/nanoc3/data_sources/deprecated/delicious.rb +0 -2
- data/lib/nanoc3/data_sources/deprecated/last_fm.rb +0 -2
- data/lib/nanoc3/data_sources/deprecated/twitter.rb +0 -2
- data/lib/nanoc3/data_sources/filesystem.rb +17 -3
- data/lib/nanoc3/data_sources/filesystem_unified.rb +17 -17
- data/lib/nanoc3/extra/auto_compiler.rb +5 -1
- data/lib/nanoc3/extra/core_ext/time.rb +1 -1
- data/lib/nanoc3/extra/file_proxy.rb +11 -1
- data/lib/nanoc3/extra/validators/links.rb +1 -1
- data/lib/nanoc3/filters/asciidoc.rb +3 -3
- data/lib/nanoc3/filters/colorize_syntax.rb +106 -27
- data/lib/nanoc3/filters/erb.rb +16 -6
- data/lib/nanoc3/filters/erubis.rb +5 -1
- data/lib/nanoc3/filters/haml.rb +2 -1
- data/lib/nanoc3/filters/less.rb +3 -6
- data/lib/nanoc3/filters/mustache.rb +3 -0
- data/lib/nanoc3/filters/redcarpet.rb +27 -0
- data/lib/nanoc3/filters/sass.rb +1 -5
- data/lib/nanoc3/filters/slim.rb +25 -0
- data/lib/nanoc3/filters/typogruby.rb +23 -0
- data/lib/nanoc3/filters.rb +6 -0
- data/lib/nanoc3/helpers/blogging.rb +22 -26
- data/lib/nanoc3/helpers/rendering.rb +1 -1
- data/lib/nanoc3/helpers/xml_sitemap.rb +11 -2
- data/lib/nanoc3.rb +24 -3
- data/nanoc3.gemspec +4 -3
- data/tasks/clean.rake +11 -0
- data/tasks/doc.rake +14 -0
- data/tasks/test.rake +38 -0
- data/test/base/core_ext/array_spec.rb +55 -0
- data/test/base/core_ext/hash_spec.rb +82 -0
- data/test/base/core_ext/pathname_spec.rb +29 -0
- data/test/base/core_ext/string_spec.rb +39 -0
- data/test/base/test_checksum_store.rb +37 -0
- data/test/base/test_code_snippet.rb +33 -0
- data/test/base/test_compiler.rb +303 -0
- data/test/base/test_compiler_dsl.rb +156 -0
- data/test/base/test_context.rb +33 -0
- data/test/base/test_data_source.rb +48 -0
- data/test/base/test_dependency_tracker.rb +264 -0
- data/test/base/test_directed_graph.rb +285 -0
- data/test/base/test_filter.rb +85 -0
- data/test/base/test_item.rb +164 -0
- data/test/base/test_item_rep.rb +555 -0
- data/test/base/test_layout.rb +44 -0
- data/test/base/test_memoization.rb +53 -0
- data/test/base/test_notification_center.rb +36 -0
- data/test/base/test_outdatedness_checker.rb +365 -0
- data/test/base/test_plugin.rb +32 -0
- data/test/base/test_rule.rb +21 -0
- data/test/base/test_rule_context.rb +67 -0
- data/test/base/test_site.rb +144 -0
- data/test/cli/commands/test_compile.rb +12 -0
- data/test/cli/commands/test_create_item.rb +12 -0
- data/test/cli/commands/test_create_layout.rb +28 -0
- data/test/cli/commands/test_create_site.rb +24 -0
- data/test/cli/commands/test_help.rb +12 -0
- data/test/cli/commands/test_info.rb +12 -0
- data/test/cli/commands/test_update.rb +12 -0
- data/test/cli/test_logger.rb +12 -0
- data/test/data_sources/test_filesystem.rb +420 -0
- data/test/data_sources/test_filesystem_unified.rb +562 -0
- data/test/data_sources/test_filesystem_verbose.rb +359 -0
- data/test/extra/core_ext/test_enumerable.rb +32 -0
- data/test/extra/core_ext/test_time.rb +17 -0
- data/test/extra/deployers/test_rsync.rb +234 -0
- data/test/extra/test_auto_compiler.rb +417 -0
- data/test/extra/test_file_proxy.rb +21 -0
- data/test/extra/test_vcs.rb +24 -0
- data/test/extra/validators/test_links.rb +53 -0
- data/test/extra/validators/test_w3c.rb +49 -0
- data/test/filters/test_asciidoc.rb +22 -0
- data/test/filters/test_bluecloth.rb +20 -0
- data/test/filters/test_coderay.rb +46 -0
- data/test/filters/test_colorize_syntax.rb +149 -0
- data/test/filters/test_erb.rb +101 -0
- data/test/filters/test_erubis.rb +72 -0
- data/test/filters/test_haml.rb +98 -0
- data/test/filters/test_kramdown.rb +20 -0
- data/test/filters/test_less.rb +59 -0
- data/test/filters/test_markaby.rb +26 -0
- data/test/filters/test_maruku.rb +20 -0
- data/test/filters/test_mustache.rb +27 -0
- data/test/filters/test_rainpress.rb +31 -0
- data/test/filters/test_rdiscount.rb +33 -0
- data/test/filters/test_rdoc.rb +18 -0
- data/test/filters/test_redcarpet.rb +63 -0
- data/test/filters/test_redcloth.rb +35 -0
- data/test/filters/test_relativize_paths.rb +231 -0
- data/test/filters/test_rubypants.rb +20 -0
- data/test/filters/test_sass.rb +103 -0
- data/test/filters/test_slim.rb +37 -0
- data/test/filters/test_typogruby.rb +23 -0
- data/test/helper.rb +161 -0
- data/test/helpers/test_blogging.rb +756 -0
- data/test/helpers/test_breadcrumbs.rb +83 -0
- data/test/helpers/test_capturing.rb +43 -0
- data/test/helpers/test_filtering.rb +108 -0
- data/test/helpers/test_html_escape.rb +34 -0
- data/test/helpers/test_link_to.rb +251 -0
- data/test/helpers/test_rendering.rb +90 -0
- data/test/helpers/test_tagging.rb +89 -0
- data/test/helpers/test_text.rb +26 -0
- data/test/helpers/test_xml_sitemap.rb +105 -0
- data/test/tasks/test_clean.rb +69 -0
- metadata +96 -27
- data/lib/nanoc3/base/compilation/checksummer.rb +0 -68
@@ -0,0 +1,756 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'test/helper'
|
4
|
+
|
5
|
+
class Nanoc3::Helpers::BloggingTest < MiniTest::Unit::TestCase
|
6
|
+
|
7
|
+
include Nanoc3::TestHelpers
|
8
|
+
|
9
|
+
include Nanoc3::Helpers::Blogging
|
10
|
+
include Nanoc3::Helpers::Text
|
11
|
+
|
12
|
+
def mock_article
|
13
|
+
item = mock
|
14
|
+
item.stubs(:[]).with(:updated_at).returns(Time.now - 500)
|
15
|
+
item.stubs(:[]).with(:kind).returns('article')
|
16
|
+
item.stubs(:[]).with(:created_at).returns(Time.now - 1000)
|
17
|
+
item.stubs(:[]).with(:title).returns('An Item')
|
18
|
+
item.stubs(:[]).with(:custom_path_in_feed).returns(nil)
|
19
|
+
item.stubs(:[]).with(:custom_url_in_feed).returns(nil)
|
20
|
+
item.stubs(:[]).with(:excerpt).returns(nil)
|
21
|
+
item.stubs(:path).returns("/item/")
|
22
|
+
item.stubs(:[]).with(:author_name).returns(nil)
|
23
|
+
item.stubs(:[]).with(:author_uri).returns(nil)
|
24
|
+
item.stubs(:compiled_content).returns('item content')
|
25
|
+
item
|
26
|
+
end
|
27
|
+
|
28
|
+
def mock_item
|
29
|
+
item = mock
|
30
|
+
item.stubs(:[]).with(:kind).returns('item')
|
31
|
+
item
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_articles
|
35
|
+
# Create items
|
36
|
+
@items = [
|
37
|
+
Nanoc3::Item.new(
|
38
|
+
'blah',
|
39
|
+
{ :kind => 'item' },
|
40
|
+
'/0/'
|
41
|
+
),
|
42
|
+
Nanoc3::Item.new(
|
43
|
+
'blah blah',
|
44
|
+
{ :kind => 'article' },
|
45
|
+
'/1/'
|
46
|
+
),
|
47
|
+
Nanoc3::Item.new(
|
48
|
+
'blah blah blah',
|
49
|
+
{ :kind => 'article' },
|
50
|
+
'/2/'
|
51
|
+
)
|
52
|
+
]
|
53
|
+
|
54
|
+
# Check
|
55
|
+
assert_equal(2, articles.size)
|
56
|
+
assert articles.include?(@items[1])
|
57
|
+
assert articles.include?(@items[2])
|
58
|
+
ensure
|
59
|
+
# Cleanup
|
60
|
+
@items = nil
|
61
|
+
end
|
62
|
+
|
63
|
+
def test_sorted_articles
|
64
|
+
# Create items
|
65
|
+
@items = [
|
66
|
+
Nanoc3::Item.new(
|
67
|
+
'blah',
|
68
|
+
{ :kind => 'item' },
|
69
|
+
'/0/'
|
70
|
+
),
|
71
|
+
Nanoc3::Item.new(
|
72
|
+
'blah',
|
73
|
+
{ :kind => 'article', :created_at => (Date.today - 1).to_s },
|
74
|
+
'/1/'
|
75
|
+
),
|
76
|
+
Nanoc3::Item.new(
|
77
|
+
'blah',
|
78
|
+
{ :kind => 'article', :created_at => (Time.now - 500).to_s },
|
79
|
+
'/2/'
|
80
|
+
)
|
81
|
+
]
|
82
|
+
|
83
|
+
# Check
|
84
|
+
assert_equal(2, sorted_articles.size)
|
85
|
+
assert_equal(@items[2], sorted_articles[0])
|
86
|
+
assert_equal(@items[1], sorted_articles[1])
|
87
|
+
ensure
|
88
|
+
# Cleanup
|
89
|
+
@items = nil
|
90
|
+
end
|
91
|
+
|
92
|
+
def test_atom_feed
|
93
|
+
if_have 'builder' do
|
94
|
+
# Create items
|
95
|
+
@items = [ mock, mock_article, mock_article ]
|
96
|
+
|
97
|
+
# Create item 0
|
98
|
+
@items[0].stubs(:[]).with(:kind).returns('item')
|
99
|
+
|
100
|
+
# Create item 1
|
101
|
+
@items[1].stubs(:[]).with(:updated_at).returns(Date.today - 1)
|
102
|
+
@items[1].stubs(:[]).with(:kind).returns('article')
|
103
|
+
@items[1].stubs(:[]).with(:created_at).returns((Date.today - 2).to_s)
|
104
|
+
@items[1].stubs(:[]).with(:title).returns('Item One')
|
105
|
+
@items[1].stubs(:[]).with(:custom_path_in_feed).returns(nil)
|
106
|
+
@items[1].stubs(:[]).with(:custom_url_in_feed).returns(nil)
|
107
|
+
@items[1].stubs(:[]).with(:excerpt).returns(nil)
|
108
|
+
@items[1].stubs(:path).returns("/item1/")
|
109
|
+
@items[1].expects(:compiled_content).with(:snapshot => :pre).returns('item 1 content')
|
110
|
+
|
111
|
+
# Create item 2
|
112
|
+
@items[2].expects(:compiled_content).with(:snapshot => :pre).returns('item 2 content')
|
113
|
+
|
114
|
+
# Mock site
|
115
|
+
@site = mock
|
116
|
+
@site.stubs(:config).returns({ :base_url => 'http://example.com' })
|
117
|
+
|
118
|
+
# Create feed item
|
119
|
+
@item = mock
|
120
|
+
@item.stubs(:[]).with(:title).returns('My Cool Blog')
|
121
|
+
@item.stubs(:[]).with(:author_name).returns('Denis Defreyne')
|
122
|
+
@item.stubs(:[]).with(:author_uri).returns('http://stoneship.org/')
|
123
|
+
@item.stubs(:[]).with(:feed_url).returns(nil)
|
124
|
+
@item.stubs(:path).returns("/journal/feed/")
|
125
|
+
|
126
|
+
# Check
|
127
|
+
atom_feed
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
def test_atom_feed_with_times
|
132
|
+
if_have 'builder' do
|
133
|
+
# Create items
|
134
|
+
@items = [ mock_item, mock_article, mock_article ]
|
135
|
+
|
136
|
+
# Create item 1
|
137
|
+
@items[1].stubs(:[]).with(:updated_at).returns(Time.now - 500)
|
138
|
+
@items[1].stubs(:[]).with(:created_at).returns(Time.now - 1000)
|
139
|
+
@items[1].expects(:compiled_content).returns('item 1 content')
|
140
|
+
|
141
|
+
# Create item 2
|
142
|
+
@items[2].stubs(:[]).with(:updated_at).returns(Time.now - 250)
|
143
|
+
@items[2].stubs(:[]).with(:created_at).returns(Time.now - 1200)
|
144
|
+
@items[2].expects(:compiled_content).returns('item 2 content')
|
145
|
+
|
146
|
+
# Mock site
|
147
|
+
@site = mock
|
148
|
+
@site.stubs(:config).returns({ :base_url => 'http://example.com' })
|
149
|
+
|
150
|
+
# Create feed item
|
151
|
+
@item = mock
|
152
|
+
@item.stubs(:[]).with(:title).returns('My Cool Blog')
|
153
|
+
@item.stubs(:[]).with(:author_name).returns('Denis Defreyne')
|
154
|
+
@item.stubs(:[]).with(:author_uri).returns('http://stoneship.org/')
|
155
|
+
@item.stubs(:[]).with(:feed_url).returns(nil)
|
156
|
+
@item.stubs(:path).returns("/journal/feed/")
|
157
|
+
|
158
|
+
# Check
|
159
|
+
atom_feed
|
160
|
+
end
|
161
|
+
end
|
162
|
+
|
163
|
+
def test_atom_feed_without_articles
|
164
|
+
if_have 'builder' do
|
165
|
+
# Mock items
|
166
|
+
@items = [ mock_item, mock_item ]
|
167
|
+
|
168
|
+
# Mock site
|
169
|
+
@site = mock
|
170
|
+
@site.stubs(:config).returns({ :base_url => 'http://example.com' })
|
171
|
+
|
172
|
+
# Create feed item
|
173
|
+
@item = mock
|
174
|
+
@item.stubs(:[]).with(:title).returns('My Blog Or Something')
|
175
|
+
@item.stubs(:[]).with(:author_name).returns('J. Doe')
|
176
|
+
@item.stubs(:[]).with(:author_uri).returns('http://example.com/~jdoe')
|
177
|
+
|
178
|
+
# Check
|
179
|
+
error = assert_raises(RuntimeError) do
|
180
|
+
atom_feed
|
181
|
+
end
|
182
|
+
assert_equal(
|
183
|
+
'Cannot build Atom feed: no articles',
|
184
|
+
error.message
|
185
|
+
)
|
186
|
+
end
|
187
|
+
end
|
188
|
+
|
189
|
+
def test_atom_feed_without_base_url
|
190
|
+
if_have 'builder' do
|
191
|
+
# Create items
|
192
|
+
@items = [ mock_item, mock_article ]
|
193
|
+
|
194
|
+
# Mock site
|
195
|
+
@site = mock
|
196
|
+
@site.stubs(:config).returns({:base_url => nil})
|
197
|
+
|
198
|
+
# Create feed item
|
199
|
+
@item = mock
|
200
|
+
@item.stubs(:[]).with(:title).returns('My Blog Or Something')
|
201
|
+
@item.stubs(:[]).with(:author_name).returns('J. Doe')
|
202
|
+
@item.stubs(:[]).with(:author_uri).returns('http://example.com/~jdoe')
|
203
|
+
|
204
|
+
# Check
|
205
|
+
error = assert_raises(RuntimeError) do
|
206
|
+
atom_feed
|
207
|
+
end
|
208
|
+
assert_equal(
|
209
|
+
'Cannot build Atom feed: site configuration has no base_url',
|
210
|
+
error.message
|
211
|
+
)
|
212
|
+
end
|
213
|
+
end
|
214
|
+
|
215
|
+
def test_atom_feed_without_title
|
216
|
+
if_have 'builder' do
|
217
|
+
# Create items
|
218
|
+
@items = [ mock_item, mock_article ]
|
219
|
+
|
220
|
+
# Mock site
|
221
|
+
@site = mock
|
222
|
+
@site.stubs(:config).returns({ :base_url => 'http://example.com' })
|
223
|
+
|
224
|
+
# Create feed item
|
225
|
+
@item = mock
|
226
|
+
@item.stubs(:[]).with(:title).returns(nil)
|
227
|
+
@item.stubs(:[]).with(:author_name).returns('J. Doe')
|
228
|
+
@item.stubs(:[]).with(:author_uri).returns('http://example.com/~jdoe')
|
229
|
+
|
230
|
+
# Check
|
231
|
+
error = assert_raises(RuntimeError) do
|
232
|
+
atom_feed
|
233
|
+
end
|
234
|
+
assert_equal(
|
235
|
+
'Cannot build Atom feed: no title in params, item or site config',
|
236
|
+
error.message
|
237
|
+
)
|
238
|
+
end
|
239
|
+
end
|
240
|
+
|
241
|
+
def test_atom_feed_without_author_name
|
242
|
+
if_have 'builder' do
|
243
|
+
# Create items
|
244
|
+
@items = [ mock_item, mock_article ]
|
245
|
+
|
246
|
+
# Mock site
|
247
|
+
@site = mock
|
248
|
+
@site.stubs(:config).returns({ :base_url => 'http://example.com' })
|
249
|
+
|
250
|
+
# Create feed item
|
251
|
+
@item = mock
|
252
|
+
@item.stubs(:[]).with(:title).returns('My Blog Or Something')
|
253
|
+
@item.stubs(:[]).with(:author_name).returns(nil)
|
254
|
+
@item.stubs(:[]).with(:author_uri).returns('http://example.com/~jdoe')
|
255
|
+
|
256
|
+
# Check
|
257
|
+
error = assert_raises(RuntimeError) do
|
258
|
+
atom_feed
|
259
|
+
end
|
260
|
+
assert_equal(
|
261
|
+
'Cannot build Atom feed: no author_name in params, item or site config',
|
262
|
+
error.message
|
263
|
+
)
|
264
|
+
end
|
265
|
+
end
|
266
|
+
|
267
|
+
def test_atom_feed_with_author_name_and_uri_from_content_item
|
268
|
+
if_have 'builder' do
|
269
|
+
# Create items
|
270
|
+
@items = [ mock_article ]
|
271
|
+
|
272
|
+
# Create item 1
|
273
|
+
@items[0].stubs(:[]).with(:author_name).returns("Don Alias")
|
274
|
+
@items[0].stubs(:[]).with(:author_uri).returns("http://don.example.com/")
|
275
|
+
@items[0].expects(:compiled_content).returns('item 1 content')
|
276
|
+
|
277
|
+
# Mock site
|
278
|
+
@site = mock
|
279
|
+
@site.stubs(:config).returns({ :base_url => 'http://example.com/' })
|
280
|
+
|
281
|
+
# Create feed item
|
282
|
+
@item = mock
|
283
|
+
@item.stubs(:[]).with(:kind).returns(nil)
|
284
|
+
@item.stubs(:[]).with(:title).returns('My Cool Blog')
|
285
|
+
@item.stubs(:[]).with(:author_name).returns('Denis Defreyne')
|
286
|
+
@item.stubs(:[]).with(:author_uri).returns('http://stoneship.org/')
|
287
|
+
@item.stubs(:[]).with(:feed_url).returns(nil)
|
288
|
+
@item.stubs(:path).returns("/journal/feed/")
|
289
|
+
|
290
|
+
# Check
|
291
|
+
# TODO: Use xpath matchers for more specific test
|
292
|
+
result = atom_feed
|
293
|
+
# Still should keep feed level author
|
294
|
+
assert_match(
|
295
|
+
/#{Regexp.escape('<name>Denis Defreyne</name>')}/, #'
|
296
|
+
result
|
297
|
+
)
|
298
|
+
assert_match(
|
299
|
+
/#{Regexp.escape('<uri>http://stoneship.org/</uri>')}/, #'
|
300
|
+
result
|
301
|
+
)
|
302
|
+
|
303
|
+
# Overrides on specific items
|
304
|
+
assert_match(
|
305
|
+
/#{Regexp.escape('<name>Don Alias</name>')}/, #'
|
306
|
+
result
|
307
|
+
)
|
308
|
+
assert_match(
|
309
|
+
/#{Regexp.escape('<uri>http://don.example.com/</uri>')}/, #'
|
310
|
+
result
|
311
|
+
)
|
312
|
+
end
|
313
|
+
end
|
314
|
+
|
315
|
+
def test_atom_feed_without_author_uri
|
316
|
+
if_have 'builder' do
|
317
|
+
# Create items
|
318
|
+
@items = [ mock_item, mock_article ]
|
319
|
+
|
320
|
+
# Mock site
|
321
|
+
@site = mock
|
322
|
+
@site.stubs(:config).returns({ :base_url => 'http://example.com' })
|
323
|
+
|
324
|
+
# Create feed item
|
325
|
+
@item = mock
|
326
|
+
@item.stubs(:[]).with(:title).returns('My Blog Or Something')
|
327
|
+
@item.stubs(:[]).with(:author_name).returns('J. Doe')
|
328
|
+
@item.stubs(:[]).with(:author_uri).returns(nil)
|
329
|
+
|
330
|
+
# Check
|
331
|
+
error = assert_raises(RuntimeError) do
|
332
|
+
atom_feed
|
333
|
+
end
|
334
|
+
assert_equal(
|
335
|
+
'Cannot build Atom feed: no author_uri in params, item or site config',
|
336
|
+
error.message
|
337
|
+
)
|
338
|
+
end
|
339
|
+
end
|
340
|
+
|
341
|
+
def test_atom_feed_without_articles_created_at
|
342
|
+
if_have 'builder' do
|
343
|
+
# Create items
|
344
|
+
@items = [ mock_item, mock_article, mock_article ]
|
345
|
+
@items[1].stubs(:[]).with(:created_at).returns(Time.now.to_s)
|
346
|
+
@items[2].stubs(:[]).with(:created_at).returns(nil)
|
347
|
+
|
348
|
+
# Mock site
|
349
|
+
@site = mock
|
350
|
+
@site.stubs(:config).returns({ :base_url => 'http://example.com' })
|
351
|
+
|
352
|
+
# Create feed item
|
353
|
+
@item = mock
|
354
|
+
@item.stubs(:[]).with(:title).returns('My Blog Or Something')
|
355
|
+
@item.stubs(:[]).with(:author_name).returns('J. Doe')
|
356
|
+
@item.stubs(:[]).with(:author_uri).returns('http://example.com/~jdoe')
|
357
|
+
|
358
|
+
# Check
|
359
|
+
error = assert_raises(RuntimeError) do
|
360
|
+
atom_feed
|
361
|
+
end
|
362
|
+
assert_equal(
|
363
|
+
'Cannot build Atom feed: one or more articles lack created_at',
|
364
|
+
error.message
|
365
|
+
)
|
366
|
+
end
|
367
|
+
end
|
368
|
+
|
369
|
+
def test_atom_feed_with_title_author_name_and_uri_as_params
|
370
|
+
if_have 'builder' do
|
371
|
+
# Create items
|
372
|
+
@items = [ mock_item, mock_article ]
|
373
|
+
@items[1].expects(:compiled_content).with(:snapshot => :pre).returns('asdf')
|
374
|
+
|
375
|
+
# Mock site
|
376
|
+
@site = mock
|
377
|
+
@site.stubs(:config).returns({ :base_url => 'http://example.com' })
|
378
|
+
|
379
|
+
# Create feed item
|
380
|
+
@item = mock
|
381
|
+
@item.stubs(:[]).with(:title).returns(nil)
|
382
|
+
@item.stubs(:[]).with(:author_name).returns(nil)
|
383
|
+
@item.stubs(:[]).with(:author_uri).returns(nil)
|
384
|
+
@item.stubs(:[]).with(:[]).with(:feed_url).returns('http://example.com/feed')
|
385
|
+
|
386
|
+
# Check
|
387
|
+
atom_feed(
|
388
|
+
:author_name => 'Bob',
|
389
|
+
:author_uri => 'http://example.com/~bob/',
|
390
|
+
:title => 'My Blog Or Something'
|
391
|
+
)
|
392
|
+
end
|
393
|
+
end
|
394
|
+
|
395
|
+
def test_atom_feed_with_title_author_name_and_uri_from_config
|
396
|
+
if_have 'builder' do
|
397
|
+
# Create items
|
398
|
+
@items = [ mock_item, mock_article ]
|
399
|
+
@items[1].expects(:compiled_content).with(:snapshot => :pre).returns('asdf')
|
400
|
+
|
401
|
+
# Mock site
|
402
|
+
@config = {
|
403
|
+
:author_name => 'Bob',
|
404
|
+
:author_uri => 'http://example.com/~bob/',
|
405
|
+
:title => 'My Blog Or Something',
|
406
|
+
:base_url => 'http://example.com'
|
407
|
+
}
|
408
|
+
@site = mock
|
409
|
+
@site.stubs(:config).returns(@config)
|
410
|
+
|
411
|
+
# Create feed item
|
412
|
+
@item = mock
|
413
|
+
@item.stubs(:[]).with(:title).returns(nil)
|
414
|
+
@item.stubs(:[]).with(:author_name).returns(nil)
|
415
|
+
@item.stubs(:[]).with(:author_uri).returns(nil)
|
416
|
+
@item.stubs(:[]).with(:[]).with(:feed_url).returns('http://example.com/feed')
|
417
|
+
|
418
|
+
# Check
|
419
|
+
atom_feed
|
420
|
+
end
|
421
|
+
end
|
422
|
+
|
423
|
+
def test_atom_feed_with_articles_param
|
424
|
+
if_have 'builder' do
|
425
|
+
# Mock items
|
426
|
+
@items = [ mock_article, mock_article ]
|
427
|
+
|
428
|
+
@items[0].expects(:compiled_content).never
|
429
|
+
@items[1].stubs(:[]).with(:title).returns('Item One')
|
430
|
+
@items[1].expects(:compiled_content).with(:snapshot => :pre).returns('asdf')
|
431
|
+
|
432
|
+
# Mock site
|
433
|
+
@site = mock
|
434
|
+
@site.stubs(:config).returns({ :base_url => 'http://example.com' })
|
435
|
+
|
436
|
+
# Create feed item
|
437
|
+
@item = mock
|
438
|
+
@item.stubs(:[]).with(:title).returns('My Blog Or Something')
|
439
|
+
@item.stubs(:[]).with(:author_name).returns('J. Doe')
|
440
|
+
@item.stubs(:[]).with(:author_uri).returns('http://example.com/~jdoe')
|
441
|
+
@item.stubs(:[]).with(:[]).with(:feed_url).returns('http://example.com/feed')
|
442
|
+
|
443
|
+
# Check
|
444
|
+
atom_feed :articles => [ @items[1] ]
|
445
|
+
end
|
446
|
+
end
|
447
|
+
|
448
|
+
def test_atom_feed_with_limit_param
|
449
|
+
if_have 'builder' do
|
450
|
+
# Mock articles
|
451
|
+
@items = [ mock_article, mock_article ]
|
452
|
+
@items.each_with_index do |article, i|
|
453
|
+
article.stubs(:[]).with(:title).returns("Article #{i}")
|
454
|
+
article.stubs(:[]).with(:created_at).returns(Time.now - i)
|
455
|
+
end
|
456
|
+
|
457
|
+
# Mock site
|
458
|
+
@site = mock
|
459
|
+
@site.stubs(:config).returns({ :base_url => 'http://example.com' })
|
460
|
+
|
461
|
+
# Create feed item
|
462
|
+
@item = mock
|
463
|
+
@item.stubs(:[]).with(:title).returns('My Blog Or Something')
|
464
|
+
@item.stubs(:[]).with(:author_name).returns('J. Doe')
|
465
|
+
@item.stubs(:[]).with(:author_uri).returns('http://example.com/~jdoe')
|
466
|
+
@item.stubs(:[]).with(:feed_url).returns('http://example.com/feed')
|
467
|
+
|
468
|
+
# Check
|
469
|
+
result = atom_feed :limit => 1, :articles => @items
|
470
|
+
assert_match(
|
471
|
+
Regexp.new('Article 0', Regexp::MULTILINE),
|
472
|
+
result
|
473
|
+
)
|
474
|
+
refute_match(
|
475
|
+
Regexp.new('Article 1', Regexp::MULTILINE),
|
476
|
+
result
|
477
|
+
)
|
478
|
+
end
|
479
|
+
end
|
480
|
+
|
481
|
+
def test_atom_feed_sorting
|
482
|
+
if_have 'builder' do
|
483
|
+
# Mock articles
|
484
|
+
@items = [ mock_article, mock_article ]
|
485
|
+
@items.each_with_index do |article, i|
|
486
|
+
article.stubs(:[]).with(:title).returns("Article #{i}")
|
487
|
+
end
|
488
|
+
@items[0].stubs(:[]).with(:created_at).returns('23-02-2009')
|
489
|
+
@items[1].stubs(:[]).with(:created_at).returns('22-03-2009')
|
490
|
+
|
491
|
+
# Mock site
|
492
|
+
@site = mock
|
493
|
+
@site.stubs(:config).returns({ :base_url => 'http://example.com' })
|
494
|
+
|
495
|
+
# Create feed item
|
496
|
+
@item = mock
|
497
|
+
@item.stubs(:[]).with(:title).returns('My Blog Or Something')
|
498
|
+
@item.stubs(:[]).with(:author_name).returns('J. Doe')
|
499
|
+
@item.stubs(:[]).with(:author_uri).returns('http://example.com/~jdoe')
|
500
|
+
@item.stubs(:[]).with(:feed_url).returns('http://example.com/feed')
|
501
|
+
|
502
|
+
# Check
|
503
|
+
result = atom_feed
|
504
|
+
assert_match(
|
505
|
+
Regexp.new('Article 1.*Article 0', Regexp::MULTILINE),
|
506
|
+
result
|
507
|
+
)
|
508
|
+
end
|
509
|
+
end
|
510
|
+
|
511
|
+
def test_atom_feed_with_content_proc_param
|
512
|
+
if_have 'builder' do
|
513
|
+
# Mock article
|
514
|
+
@items = [ mock_article ]
|
515
|
+
|
516
|
+
# Mock site
|
517
|
+
@site = mock
|
518
|
+
@site.stubs(:config).returns({ :base_url => 'http://example.com' })
|
519
|
+
|
520
|
+
# Create feed item
|
521
|
+
@item = mock
|
522
|
+
@item.stubs(:[]).with(:title).returns('My Blog Or Something')
|
523
|
+
@item.stubs(:[]).with(:author_name).returns('J. Doe')
|
524
|
+
@item.stubs(:[]).with(:author_uri).returns('http://example.com/~jdoe')
|
525
|
+
@item.stubs(:[]).with(:feed_url).returns('http://example.com/feed')
|
526
|
+
|
527
|
+
# Check
|
528
|
+
result = atom_feed :content_proc => lambda { |a| 'foobar!' }
|
529
|
+
assert_match 'foobar!</content>', result
|
530
|
+
end
|
531
|
+
end
|
532
|
+
|
533
|
+
def test_atom_feed_with_excerpt_proc_param
|
534
|
+
if_have 'builder' do
|
535
|
+
# Mock article
|
536
|
+
@items = [ mock_article ]
|
537
|
+
|
538
|
+
# Mock site
|
539
|
+
@site = mock
|
540
|
+
@site.stubs(:config).returns({ :base_url => 'http://example.com' })
|
541
|
+
|
542
|
+
# Create feed item
|
543
|
+
@item = mock
|
544
|
+
@item.stubs(:[]).with(:title).returns('My Blog Or Something')
|
545
|
+
@item.stubs(:[]).with(:author_name).returns('J. Doe')
|
546
|
+
@item.stubs(:[]).with(:author_uri).returns('http://example.com/~jdoe')
|
547
|
+
@item.stubs(:[]).with(:[]).with(:feed_url).returns('http://example.com/feed')
|
548
|
+
|
549
|
+
# Check
|
550
|
+
result = atom_feed :excerpt_proc => lambda { |a| 'foobar!' }
|
551
|
+
assert_match 'foobar!</summary>', result
|
552
|
+
end
|
553
|
+
end
|
554
|
+
|
555
|
+
def test_atom_feed_with_item_without_path
|
556
|
+
if_have 'builder' do
|
557
|
+
# Create items
|
558
|
+
@items = [ mock_article ]
|
559
|
+
@items[0].stubs(:path).returns(nil)
|
560
|
+
|
561
|
+
# Mock site
|
562
|
+
@site = mock
|
563
|
+
@site.stubs(:config).returns({ :base_url => 'http://example.com' })
|
564
|
+
|
565
|
+
# Create feed item
|
566
|
+
@item = mock
|
567
|
+
@item.stubs(:identifier).returns('/feed/')
|
568
|
+
@item.stubs(:[]).with(:title).returns('My Cool Blog')
|
569
|
+
@item.stubs(:[]).with(:author_name).returns('Denis Defreyne')
|
570
|
+
@item.stubs(:[]).with(:author_uri).returns('http://stoneship.org/')
|
571
|
+
@item.stubs(:[]).with(:feed_url).returns(nil)
|
572
|
+
@item.stubs(:path).returns("/journal/feed/")
|
573
|
+
|
574
|
+
# Check
|
575
|
+
atom_feed
|
576
|
+
end
|
577
|
+
end
|
578
|
+
|
579
|
+
def test_url_for_without_custom_path_in_feed
|
580
|
+
# Create site
|
581
|
+
@site = Nanoc3::Site.new({ :base_url => 'http://example.com' })
|
582
|
+
|
583
|
+
# Create article
|
584
|
+
item = Nanoc3::Item.new('content', {}, '/foo/')
|
585
|
+
item.reps << Nanoc3::ItemRep.new(item, :default)
|
586
|
+
item.reps[0].path = '/foo/bar/'
|
587
|
+
|
588
|
+
# Check
|
589
|
+
assert_equal('http://example.com/foo/bar/', url_for(item))
|
590
|
+
ensure
|
591
|
+
# Cleanup
|
592
|
+
@item = nil
|
593
|
+
end
|
594
|
+
|
595
|
+
def test_url_for_with_custom_path_in_feed
|
596
|
+
# Create site
|
597
|
+
@site = Nanoc3::Site.new({ :base_url => 'http://example.com' })
|
598
|
+
|
599
|
+
# Create article
|
600
|
+
item = Nanoc3::Item.new(
|
601
|
+
'content', { :custom_path_in_feed => '/meow/woof/' }, '/foo/')
|
602
|
+
item.reps << Nanoc3::ItemRep.new(item, :default)
|
603
|
+
|
604
|
+
# Check
|
605
|
+
assert_equal('http://example.com/meow/woof/', url_for(item))
|
606
|
+
ensure
|
607
|
+
# Cleanup
|
608
|
+
@item = nil
|
609
|
+
end
|
610
|
+
|
611
|
+
def test_url_for_with_custom_url_in_feed
|
612
|
+
# Create site
|
613
|
+
@site = Nanoc3::Site.new({ :base_url => 'http://example.com' })
|
614
|
+
|
615
|
+
# Create article
|
616
|
+
item = Nanoc3::Item.new(
|
617
|
+
'content', { :custom_url_in_feed => 'http://example.org/x' }, '/foo/')
|
618
|
+
item.reps << Nanoc3::ItemRep.new(item, :default)
|
619
|
+
|
620
|
+
# Check
|
621
|
+
assert_equal('http://example.org/x', url_for(item))
|
622
|
+
ensure
|
623
|
+
# Cleanup
|
624
|
+
@item = nil
|
625
|
+
end
|
626
|
+
|
627
|
+
def test_url_for_without_base_url
|
628
|
+
# Create site
|
629
|
+
@site = Nanoc3::Site.new({})
|
630
|
+
|
631
|
+
# Check
|
632
|
+
assert_raises(RuntimeError) do
|
633
|
+
url_for(nil)
|
634
|
+
end
|
635
|
+
end
|
636
|
+
|
637
|
+
def test_url_for_without_path
|
638
|
+
# Create site
|
639
|
+
@site = Nanoc3::Site.new({ :base_url => 'http://example.com' })
|
640
|
+
|
641
|
+
# Create article
|
642
|
+
item = Nanoc3::Item.new('content', {}, '/foo/')
|
643
|
+
item.reps << Nanoc3::ItemRep.new(item, :default)
|
644
|
+
item.reps[0].path = nil
|
645
|
+
|
646
|
+
# Check
|
647
|
+
assert_equal(nil, url_for(item))
|
648
|
+
end
|
649
|
+
|
650
|
+
def test_feed_url_without_custom_feed_url
|
651
|
+
# Create site
|
652
|
+
@site = Nanoc3::Site.new({ :base_url => 'http://example.com' })
|
653
|
+
|
654
|
+
# Create article
|
655
|
+
@item = Nanoc3::Item.new('content', {}, '/foo/')
|
656
|
+
@item.reps << Nanoc3::ItemRep.new(@item, :default)
|
657
|
+
@item.reps[0].path = '/foo/bar/'
|
658
|
+
|
659
|
+
# Check
|
660
|
+
assert_equal('http://example.com/foo/bar/', feed_url)
|
661
|
+
ensure
|
662
|
+
# Cleanup
|
663
|
+
@item = nil
|
664
|
+
end
|
665
|
+
|
666
|
+
def test_feed_url_with_custom_feed_url
|
667
|
+
# Create site
|
668
|
+
@site = Nanoc3::Site.new({ :base_url => 'http://example.com' })
|
669
|
+
|
670
|
+
# Create feed item
|
671
|
+
@item = Nanoc3::Item.new('content', { :feed_url => 'http://example.com/feed/' }, '/foo/')
|
672
|
+
@item.reps << Nanoc3::ItemRep.new(@item, :default)
|
673
|
+
@item.reps[0].path = '/foo/bar/'
|
674
|
+
|
675
|
+
# Check
|
676
|
+
assert_equal('http://example.com/feed/', feed_url)
|
677
|
+
ensure
|
678
|
+
# Cleanup
|
679
|
+
@item = nil
|
680
|
+
end
|
681
|
+
|
682
|
+
def test_feed_url_without_base_url
|
683
|
+
# Create site
|
684
|
+
@site = Nanoc3::Site.new({})
|
685
|
+
|
686
|
+
# Check
|
687
|
+
assert_raises(RuntimeError) do
|
688
|
+
feed_url
|
689
|
+
end
|
690
|
+
end
|
691
|
+
|
692
|
+
def test_atom_tag_for_with_path
|
693
|
+
# Create site
|
694
|
+
@site = Nanoc3::Site.new({ :base_url => 'http://example.com' })
|
695
|
+
|
696
|
+
# Create article
|
697
|
+
item = Nanoc3::Item.new('content', { :created_at => '2008-05-19' }, '/foo/')
|
698
|
+
item.reps << Nanoc3::ItemRep.new(item, :default)
|
699
|
+
item.reps[0].path = '/foo/bar/'
|
700
|
+
|
701
|
+
# Check
|
702
|
+
assert_equal('tag:example.com,2008-05-19:/foo/bar/', atom_tag_for(item))
|
703
|
+
end
|
704
|
+
|
705
|
+
def test_atom_tag_for_without_path
|
706
|
+
# Create site
|
707
|
+
@site = Nanoc3::Site.new({ :base_url => 'http://example.com' })
|
708
|
+
|
709
|
+
# Create article
|
710
|
+
item = Nanoc3::Item.new('content', { :created_at => '2008-05-19' }, '/baz/qux/')
|
711
|
+
item.reps << Nanoc3::ItemRep.new(item, :default)
|
712
|
+
|
713
|
+
# Check
|
714
|
+
assert_equal('tag:example.com,2008-05-19:/baz/qux/', atom_tag_for(item))
|
715
|
+
end
|
716
|
+
|
717
|
+
def test_atom_tag_for_with_base_url_in_dir
|
718
|
+
# Create site
|
719
|
+
@site = Nanoc3::Site.new({ :base_url => 'http://example.com/somedir' })
|
720
|
+
|
721
|
+
# Create article
|
722
|
+
item = Nanoc3::Item.new('content', { :created_at => '2008-05-19' }, '/foo/')
|
723
|
+
item.reps << Nanoc3::ItemRep.new(item, :default)
|
724
|
+
item.reps[0].path = '/foo/bar/'
|
725
|
+
|
726
|
+
# Check
|
727
|
+
assert_equal('tag:example.com,2008-05-19:/somedir/foo/bar/', atom_tag_for(item))
|
728
|
+
end
|
729
|
+
|
730
|
+
def test_atom_tag_for_with_time
|
731
|
+
# Create site
|
732
|
+
@site = Nanoc3::Site.new({ :base_url => 'http://example.com' })
|
733
|
+
|
734
|
+
# Create article
|
735
|
+
item = Nanoc3::Item.new('content', { :created_at => Time.parse('2008-05-19') }, '/foo/')
|
736
|
+
item.reps << Nanoc3::ItemRep.new(item, :default)
|
737
|
+
item.reps[0].path = '/foo/bar/'
|
738
|
+
|
739
|
+
# Check
|
740
|
+
assert_equal('tag:example.com,2008-05-19:/foo/bar/', atom_tag_for(item))
|
741
|
+
end
|
742
|
+
|
743
|
+
def test_atom_tag_for_with_date
|
744
|
+
# Create site
|
745
|
+
@site = Nanoc3::Site.new({ :base_url => 'http://example.com' })
|
746
|
+
|
747
|
+
# Create article
|
748
|
+
item = Nanoc3::Item.new('content', { :created_at => Date.parse('2008-05-19') }, '/foo/')
|
749
|
+
item.reps << Nanoc3::ItemRep.new(item, :default)
|
750
|
+
item.reps[0].path = '/foo/bar/'
|
751
|
+
|
752
|
+
# Check
|
753
|
+
assert_equal('tag:example.com,2008-05-19:/foo/bar/', atom_tag_for(item))
|
754
|
+
end
|
755
|
+
|
756
|
+
end
|