nanoc 3.2.4 → 3.3.0

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