nanoc3 3.2.0a3 → 3.2.0a4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (147) hide show
  1. data/.gemtest +0 -0
  2. data/LICENSE +1 -1
  3. data/NEWS.md +23 -4
  4. data/README.md +7 -0
  5. data/lib/nanoc3/base/compilation/checksum_store.rb +17 -90
  6. data/lib/nanoc3/base/compilation/compiled_content_cache.rb +5 -0
  7. data/lib/nanoc3/base/compilation/compiler.rb +112 -175
  8. data/lib/nanoc3/base/compilation/compiler_dsl.rb +54 -11
  9. data/lib/nanoc3/base/compilation/dependency_tracker.rb +32 -65
  10. data/lib/nanoc3/base/compilation/filter.rb +4 -3
  11. data/lib/nanoc3/base/compilation/item_rep_proxy.rb +19 -4
  12. data/lib/nanoc3/base/compilation/item_rep_recorder_proxy.rb +90 -0
  13. data/lib/nanoc3/base/compilation/outdatedness_checker.rb +152 -15
  14. data/lib/nanoc3/base/compilation/outdatedness_reasons.rb +12 -9
  15. data/lib/nanoc3/base/compilation/rule.rb +3 -1
  16. data/lib/nanoc3/base/compilation/rule_memory_calculator.rb +42 -0
  17. data/lib/nanoc3/base/compilation/rule_memory_store.rb +53 -0
  18. data/lib/nanoc3/base/compilation/rules_collection.rb +205 -0
  19. data/lib/nanoc3/base/core_ext/array.rb +20 -0
  20. data/lib/nanoc3/base/core_ext/hash.rb +30 -0
  21. data/lib/nanoc3/base/core_ext/pathname.rb +26 -0
  22. data/lib/nanoc3/base/core_ext/string.rb +12 -0
  23. data/lib/nanoc3/base/core_ext.rb +1 -0
  24. data/lib/nanoc3/base/directed_graph.rb +11 -3
  25. data/lib/nanoc3/base/errors.rb +0 -4
  26. data/lib/nanoc3/base/memoization.rb +72 -0
  27. data/lib/nanoc3/base/result_data/item_rep.rb +64 -25
  28. data/lib/nanoc3/base/source_data/code_snippet.rb +9 -0
  29. data/lib/nanoc3/base/source_data/configuration.rb +20 -0
  30. data/lib/nanoc3/base/source_data/item.rb +29 -4
  31. data/lib/nanoc3/base/source_data/layout.rb +20 -1
  32. data/lib/nanoc3/base/source_data/site.rb +49 -26
  33. data/lib/nanoc3/base/store.rb +10 -1
  34. data/lib/nanoc3/base.rb +6 -1
  35. data/lib/nanoc3/cli/base.rb +20 -7
  36. data/lib/nanoc3/cli/commands/compile.rb +0 -2
  37. data/lib/nanoc3/cli/commands/create_site.rb +16 -7
  38. data/lib/nanoc3/cli/commands/debug.rb +3 -3
  39. data/lib/nanoc3/cli/commands/view.rb +1 -0
  40. data/lib/nanoc3/cli/commands/watch.rb +2 -1
  41. data/lib/nanoc3/data_sources/deprecated/delicious.rb +0 -2
  42. data/lib/nanoc3/data_sources/deprecated/last_fm.rb +0 -2
  43. data/lib/nanoc3/data_sources/deprecated/twitter.rb +0 -2
  44. data/lib/nanoc3/data_sources/filesystem.rb +17 -3
  45. data/lib/nanoc3/data_sources/filesystem_unified.rb +17 -17
  46. data/lib/nanoc3/extra/auto_compiler.rb +5 -1
  47. data/lib/nanoc3/extra/core_ext/time.rb +1 -1
  48. data/lib/nanoc3/extra/file_proxy.rb +11 -1
  49. data/lib/nanoc3/extra/validators/links.rb +1 -1
  50. data/lib/nanoc3/filters/asciidoc.rb +3 -3
  51. data/lib/nanoc3/filters/colorize_syntax.rb +106 -27
  52. data/lib/nanoc3/filters/erb.rb +16 -6
  53. data/lib/nanoc3/filters/erubis.rb +5 -1
  54. data/lib/nanoc3/filters/haml.rb +2 -1
  55. data/lib/nanoc3/filters/less.rb +3 -6
  56. data/lib/nanoc3/filters/mustache.rb +3 -0
  57. data/lib/nanoc3/filters/redcarpet.rb +27 -0
  58. data/lib/nanoc3/filters/sass.rb +1 -5
  59. data/lib/nanoc3/filters/slim.rb +25 -0
  60. data/lib/nanoc3/filters/typogruby.rb +23 -0
  61. data/lib/nanoc3/filters.rb +6 -0
  62. data/lib/nanoc3/helpers/blogging.rb +22 -26
  63. data/lib/nanoc3/helpers/rendering.rb +1 -1
  64. data/lib/nanoc3/helpers/xml_sitemap.rb +11 -2
  65. data/lib/nanoc3.rb +24 -3
  66. data/nanoc3.gemspec +4 -3
  67. data/tasks/clean.rake +11 -0
  68. data/tasks/doc.rake +14 -0
  69. data/tasks/test.rake +38 -0
  70. data/test/base/core_ext/array_spec.rb +55 -0
  71. data/test/base/core_ext/hash_spec.rb +82 -0
  72. data/test/base/core_ext/pathname_spec.rb +29 -0
  73. data/test/base/core_ext/string_spec.rb +39 -0
  74. data/test/base/test_checksum_store.rb +37 -0
  75. data/test/base/test_code_snippet.rb +33 -0
  76. data/test/base/test_compiler.rb +303 -0
  77. data/test/base/test_compiler_dsl.rb +156 -0
  78. data/test/base/test_context.rb +33 -0
  79. data/test/base/test_data_source.rb +48 -0
  80. data/test/base/test_dependency_tracker.rb +264 -0
  81. data/test/base/test_directed_graph.rb +285 -0
  82. data/test/base/test_filter.rb +85 -0
  83. data/test/base/test_item.rb +164 -0
  84. data/test/base/test_item_rep.rb +555 -0
  85. data/test/base/test_layout.rb +44 -0
  86. data/test/base/test_memoization.rb +53 -0
  87. data/test/base/test_notification_center.rb +36 -0
  88. data/test/base/test_outdatedness_checker.rb +365 -0
  89. data/test/base/test_plugin.rb +32 -0
  90. data/test/base/test_rule.rb +21 -0
  91. data/test/base/test_rule_context.rb +67 -0
  92. data/test/base/test_site.rb +144 -0
  93. data/test/cli/commands/test_compile.rb +12 -0
  94. data/test/cli/commands/test_create_item.rb +12 -0
  95. data/test/cli/commands/test_create_layout.rb +28 -0
  96. data/test/cli/commands/test_create_site.rb +24 -0
  97. data/test/cli/commands/test_help.rb +12 -0
  98. data/test/cli/commands/test_info.rb +12 -0
  99. data/test/cli/commands/test_update.rb +12 -0
  100. data/test/cli/test_logger.rb +12 -0
  101. data/test/data_sources/test_filesystem.rb +420 -0
  102. data/test/data_sources/test_filesystem_unified.rb +562 -0
  103. data/test/data_sources/test_filesystem_verbose.rb +359 -0
  104. data/test/extra/core_ext/test_enumerable.rb +32 -0
  105. data/test/extra/core_ext/test_time.rb +17 -0
  106. data/test/extra/deployers/test_rsync.rb +234 -0
  107. data/test/extra/test_auto_compiler.rb +417 -0
  108. data/test/extra/test_file_proxy.rb +21 -0
  109. data/test/extra/test_vcs.rb +24 -0
  110. data/test/extra/validators/test_links.rb +53 -0
  111. data/test/extra/validators/test_w3c.rb +49 -0
  112. data/test/filters/test_asciidoc.rb +22 -0
  113. data/test/filters/test_bluecloth.rb +20 -0
  114. data/test/filters/test_coderay.rb +46 -0
  115. data/test/filters/test_colorize_syntax.rb +149 -0
  116. data/test/filters/test_erb.rb +101 -0
  117. data/test/filters/test_erubis.rb +72 -0
  118. data/test/filters/test_haml.rb +98 -0
  119. data/test/filters/test_kramdown.rb +20 -0
  120. data/test/filters/test_less.rb +59 -0
  121. data/test/filters/test_markaby.rb +26 -0
  122. data/test/filters/test_maruku.rb +20 -0
  123. data/test/filters/test_mustache.rb +27 -0
  124. data/test/filters/test_rainpress.rb +31 -0
  125. data/test/filters/test_rdiscount.rb +33 -0
  126. data/test/filters/test_rdoc.rb +18 -0
  127. data/test/filters/test_redcarpet.rb +63 -0
  128. data/test/filters/test_redcloth.rb +35 -0
  129. data/test/filters/test_relativize_paths.rb +231 -0
  130. data/test/filters/test_rubypants.rb +20 -0
  131. data/test/filters/test_sass.rb +103 -0
  132. data/test/filters/test_slim.rb +37 -0
  133. data/test/filters/test_typogruby.rb +23 -0
  134. data/test/helper.rb +161 -0
  135. data/test/helpers/test_blogging.rb +756 -0
  136. data/test/helpers/test_breadcrumbs.rb +83 -0
  137. data/test/helpers/test_capturing.rb +43 -0
  138. data/test/helpers/test_filtering.rb +108 -0
  139. data/test/helpers/test_html_escape.rb +34 -0
  140. data/test/helpers/test_link_to.rb +251 -0
  141. data/test/helpers/test_rendering.rb +90 -0
  142. data/test/helpers/test_tagging.rb +89 -0
  143. data/test/helpers/test_text.rb +26 -0
  144. data/test/helpers/test_xml_sitemap.rb +105 -0
  145. data/test/tasks/test_clean.rb +69 -0
  146. metadata +96 -27
  147. data/lib/nanoc3/base/compilation/checksummer.rb +0 -68
@@ -0,0 +1,63 @@
1
+ # encoding: utf-8
2
+
3
+ require 'test/helper'
4
+
5
+ class Nanoc3::Filters::RedcarpetTest < MiniTest::Unit::TestCase
6
+
7
+ include Nanoc3::TestHelpers
8
+
9
+ def test_find
10
+ refute Nanoc3::Filter.named(:redcarpet).nil?
11
+ end
12
+
13
+ def test_filter
14
+ if_have 'redcarpet' do
15
+ # Create filter
16
+ filter = ::Nanoc3::Filters::Redcarpet.new
17
+
18
+ # Run filter
19
+ result = filter.run("> Quote")
20
+ assert_match(/<blockquote>\s*<p>Quote<\/p>\s*<\/blockquote>/, result)
21
+ end
22
+ end
23
+
24
+ def test_with_extensions
25
+ if_have 'redcarpet' do
26
+ # Create filter
27
+ filter = ::Nanoc3::Filters::Redcarpet.new
28
+
29
+ # Run filter
30
+ input = "The quotation 'marks' sure make this look sarcastic!"
31
+ output_expected = /The quotation &lsquo;marks&rsquo; sure make this look sarcastic!/
32
+ output_actual = filter.run(input, :options => [ :smart ])
33
+ assert_match(output_expected, output_actual)
34
+ end
35
+ end
36
+
37
+ def test_html_by_default
38
+ if_have 'redcarpet' do
39
+ # Create filter
40
+ filter = ::Nanoc3::Filters::Redcarpet.new
41
+
42
+ # Run filter
43
+ input = "![Alt](/path/to/img 'Title')"
44
+ output_expected = %r{<img src="/path/to/img" alt="Alt" title="Title">}
45
+ output_actual = filter.run(input)
46
+ assert_match(output_expected, output_actual)
47
+ end
48
+ end
49
+
50
+ def test_xhtml_if_requested
51
+ if_have 'redcarpet' do
52
+ # Create filter
53
+ filter = ::Nanoc3::Filters::Redcarpet.new
54
+
55
+ # Run filter
56
+ input = "![Alt](/path/to/img 'Title')"
57
+ output_expected = %r{<img src="/path/to/img" alt="Alt" title="Title"/>}
58
+ output_actual = filter.run(input, :options => [ :xhtml ])
59
+ assert_match(output_expected, output_actual)
60
+ end
61
+ end
62
+
63
+ end
@@ -0,0 +1,35 @@
1
+ # encoding: utf-8
2
+
3
+ require 'test/helper'
4
+
5
+ class Nanoc3::Filters::RedClothTest < MiniTest::Unit::TestCase
6
+
7
+ include Nanoc3::TestHelpers
8
+
9
+ def test_filter
10
+ if_have 'redcloth' do
11
+ # Get filter
12
+ filter = ::Nanoc3::Filters::RedCloth.new
13
+
14
+ # Run filter
15
+ result = filter.run("h1. Foo")
16
+ assert_equal("<h1>Foo</h1>", result)
17
+ end
18
+ end
19
+
20
+ def test_filter_with_options
21
+ if_have 'redcloth' do
22
+ # Get filter
23
+ filter = ::Nanoc3::Filters::RedCloth.new
24
+
25
+ # Run filter without options
26
+ result = filter.run("I am a member of SPECTRE.")
27
+ assert_equal("<p>I am a member of <span class=\"caps\">SPECTRE</span>.</p>", result)
28
+
29
+ # Run filter with options
30
+ result = filter.run("I am a member of SPECTRE.", :no_span_caps => true)
31
+ assert_equal("<p>I am a member of SPECTRE.</p>", result)
32
+ end
33
+ end
34
+
35
+ end
@@ -0,0 +1,231 @@
1
+ # encoding: utf-8
2
+
3
+ require 'test/helper'
4
+
5
+ class Nanoc3::Filters::RelativizePathsTest < MiniTest::Unit::TestCase
6
+
7
+ include Nanoc3::TestHelpers
8
+
9
+ def test_filter_html_with_double_quotes
10
+ # Create filter with mock item
11
+ filter = Nanoc3::Filters::RelativizePaths.new
12
+
13
+ # Mock item
14
+ filter.instance_eval do
15
+ @item_rep = MiniTest::Mock.new
16
+ @item_rep.expect(:path, '/foo/bar/baz/')
17
+ end
18
+
19
+ # Set content
20
+ raw_content = %[<a href="/foo">foo</a>]
21
+ expected_content = %[<a href="../..">foo</a>]
22
+
23
+ # Test
24
+ actual_content = filter.run(raw_content, :type => :html)
25
+ assert_equal(expected_content, actual_content)
26
+ end
27
+
28
+ def test_filter_html_with_single_quotes
29
+ # Create filter with mock item
30
+ filter = Nanoc3::Filters::RelativizePaths.new
31
+
32
+ # Mock item
33
+ filter.instance_eval do
34
+ @item_rep = MiniTest::Mock.new
35
+ @item_rep.expect(:path, '/foo/bar/baz/')
36
+ end
37
+
38
+ # Set content
39
+ raw_content = %[<a href='/foo'>foo</a>]
40
+ expected_content = %[<a href='../..'>foo</a>]
41
+
42
+ # Test
43
+ actual_content = filter.run(raw_content, :type => :html)
44
+ assert_equal(expected_content, actual_content)
45
+ end
46
+
47
+ def test_filter_html_without_quotes
48
+ # Create filter with mock item
49
+ filter = Nanoc3::Filters::RelativizePaths.new
50
+
51
+ # Mock item
52
+ filter.instance_eval do
53
+ @item_rep = MiniTest::Mock.new
54
+ @item_rep.expect(:path, '/foo/bar/baz/')
55
+ end
56
+
57
+ # Set content
58
+ raw_content = %[<a href=/foo>foo</a>]
59
+ expected_content = %[<a href=../..>foo</a>]
60
+
61
+ # Test
62
+ actual_content = filter.run(raw_content, :type => :html)
63
+ assert_equal(expected_content, actual_content)
64
+ end
65
+
66
+ def test_filter_html_multiple
67
+ # Create filter with mock item
68
+ filter = Nanoc3::Filters::RelativizePaths.new
69
+
70
+ # Mock item
71
+ filter.instance_eval do
72
+ @item_rep = MiniTest::Mock.new
73
+ @item_rep.expect(:path, '/foo/bar/baz/')
74
+ end
75
+
76
+ # Set content
77
+ raw_content = %[<a href="/foo">foo</a> <a href="/bar">bar</a>]
78
+ expected_content = %[<a href="../..">foo</a> <a href="../../../bar">bar</a>]
79
+
80
+ # Test
81
+ actual_content = filter.run(raw_content, :type => :html)
82
+ assert_equal(expected_content, actual_content)
83
+ end
84
+
85
+ def test_filter_html_outside_tag
86
+ # Create filter with mock item
87
+ filter = Nanoc3::Filters::RelativizePaths.new
88
+
89
+ # Mock item
90
+ filter.instance_eval do
91
+ @item_rep = MiniTest::Mock.new
92
+ @item_rep.expect(:path, '/foo/bar/baz/')
93
+ end
94
+
95
+ # Set content
96
+ raw_content = %[stuff href="/foo" more stuff]
97
+ expected_content = %[stuff href="/foo" more stuff]
98
+
99
+ # Test
100
+ actual_content = filter.run(raw_content, :type => :html)
101
+ assert_equal(expected_content, actual_content)
102
+ end
103
+
104
+ def test_filter_html_root
105
+ # Create filter with mock item
106
+ filter = Nanoc3::Filters::RelativizePaths.new
107
+
108
+ # Mock item
109
+ filter.instance_eval do
110
+ @item_rep = MiniTest::Mock.new
111
+ @item_rep.expect(:path, '/woof/meow/')
112
+ end
113
+
114
+ # Set content
115
+ raw_content = %[<a href="/">foo</a>]
116
+ expected_content = %[<a href="../../">foo</a>]
117
+
118
+ # Test
119
+ actual_content = filter.run(raw_content, :type => :html)
120
+ assert_equal(expected_content, actual_content)
121
+ end
122
+
123
+ def test_filter_implicit
124
+ # Create filter with mock item
125
+ filter = Nanoc3::Filters::RelativizePaths.new
126
+
127
+ # Test
128
+ assert_raises(RuntimeError) do
129
+ filter.run("moo")
130
+ end
131
+ end
132
+
133
+ def test_filter_css_with_double_quotes
134
+ # Create filter with mock item
135
+ filter = Nanoc3::Filters::RelativizePaths.new
136
+
137
+ # Mock item
138
+ filter.instance_eval do
139
+ @item_rep = MiniTest::Mock.new
140
+ @item_rep.expect(:path, '/foo/bar/baz/')
141
+ end
142
+
143
+ # Set content
144
+ raw_content = %[background: url("/foo/bar/background.png");]
145
+ expected_content = %[background: url("../background.png");]
146
+
147
+ # Test
148
+ actual_content = filter.run(raw_content, :type => :css)
149
+ assert_equal(expected_content, actual_content)
150
+ end
151
+
152
+ def test_filter_css_with_single_quotes
153
+ # Create filter with mock item
154
+ filter = Nanoc3::Filters::RelativizePaths.new
155
+
156
+ # Mock item
157
+ filter.instance_eval do
158
+ @item_rep = MiniTest::Mock.new
159
+ @item_rep.expect(:path, '/foo/bar/baz/')
160
+ end
161
+
162
+ # Set content
163
+ raw_content = %[background: url('/foo/bar/background.png');]
164
+ expected_content = %[background: url('../background.png');]
165
+
166
+ # Test
167
+ actual_content = filter.run(raw_content, :type => :css)
168
+ assert_equal(expected_content, actual_content)
169
+ end
170
+
171
+ def test_filter_css_without_quotes
172
+ # Create filter with mock item
173
+ filter = Nanoc3::Filters::RelativizePaths.new
174
+
175
+ # Mock item
176
+ filter.instance_eval do
177
+ @item_rep = MiniTest::Mock.new
178
+ @item_rep.expect(:path, '/foo/bar/baz/')
179
+ end
180
+
181
+ # Set content
182
+ raw_content = %[background: url(/foo/bar/background.png);]
183
+ expected_content = %[background: url(../background.png);]
184
+
185
+ # Test
186
+ actual_content = filter.run(raw_content, :type => :css)
187
+ assert_equal(expected_content, actual_content)
188
+ end
189
+
190
+ def test_filter_css_multiple
191
+ # Create filter with mock item
192
+ filter = Nanoc3::Filters::RelativizePaths.new
193
+
194
+ # Mock item
195
+ filter.instance_eval do
196
+ @item_rep = MiniTest::Mock.new
197
+ @item_rep.expect(:path, '/foo/bar/baz/')
198
+ end
199
+
200
+ # Set content
201
+ raw_content = %[background: url(/foo/bar/a.png) url(/foo/bar/b.png);]
202
+ expected_content = %[background: url(../a.png) url(../b.png);]
203
+
204
+ # Test
205
+ actual_content = filter.run(raw_content, :type => :css)
206
+ assert_equal(expected_content, actual_content)
207
+ end
208
+
209
+ def test_filter_css_root
210
+ # It is probably a bit weird to have “url(/)” in CSS, but I’ve made a
211
+ # test case for this situation anyway. Can’t hurt…
212
+
213
+ # Create filter with mock item
214
+ filter = Nanoc3::Filters::RelativizePaths.new
215
+
216
+ # Mock item
217
+ filter.instance_eval do
218
+ @item_rep = MiniTest::Mock.new
219
+ @item_rep.expect(:path, '/woof/meow/')
220
+ end
221
+
222
+ # Set content
223
+ raw_content = %[background: url(/);]
224
+ expected_content = %[background: url(../../);]
225
+
226
+ # Test
227
+ actual_content = filter.run(raw_content, :type => :css)
228
+ assert_equal(expected_content, actual_content)
229
+ end
230
+
231
+ end
@@ -0,0 +1,20 @@
1
+ # encoding: utf-8
2
+
3
+ require 'test/helper'
4
+
5
+ class Nanoc3::Filters::RubyPantsTest < MiniTest::Unit::TestCase
6
+
7
+ include Nanoc3::TestHelpers
8
+
9
+ def test_filter
10
+ if_have 'rubypants' do
11
+ # Get filter
12
+ filter = ::Nanoc3::Filters::RubyPants.new
13
+
14
+ # Run filter
15
+ result = filter.run("Wait---what?")
16
+ assert_equal("Wait&#8212;what?", result)
17
+ end
18
+ end
19
+
20
+ end
@@ -0,0 +1,103 @@
1
+ # encoding: utf-8
2
+
3
+ require 'test/helper'
4
+
5
+ class Nanoc3::Filters::SassTest < MiniTest::Unit::TestCase
6
+
7
+ include Nanoc3::TestHelpers
8
+
9
+ def test_filter
10
+ if_have 'sass' do
11
+ # Get filter
12
+ filter = ::Nanoc3::Filters::Sass.new({ :foo => 'bar' })
13
+
14
+ # Run filter
15
+ result = filter.run(".foo #bar\n color: #f00")
16
+ assert_match(/.foo\s+#bar\s*\{\s*color:\s+(red|#f00);?\s*\}/, result)
17
+ end
18
+ end
19
+
20
+ def test_filter_with_params
21
+ if_have 'sass' do
22
+ # Create filter
23
+ filter = ::Nanoc3::Filters::Sass.new({ :foo => 'bar' })
24
+
25
+ # Check with compact
26
+ result = filter.run(".foo #bar\n color: #f00", :style => 'compact')
27
+ assert_match(/^\.foo #bar[\s\n]*\{[\s\n]*color:\s*(red|#f00);?[\s\n]*\}/m, result)
28
+
29
+ # Check with compressed
30
+ result = filter.run(".foo #bar\n color: #f00", :style => 'compressed')
31
+ assert_match(/^\.foo #bar[\s\n]*\{[\s\n]*color:\s*(red|#f00);?[\s\n]*\}/m, result)
32
+ end
33
+ end
34
+
35
+ def test_filter_error
36
+ if_have 'sass' do
37
+ # Create filter
38
+ filter = ::Nanoc3::Filters::Sass.new({ :foo => 'bar' })
39
+
40
+ # Run filter
41
+ raised = false
42
+ begin
43
+ filter.run('$*#&!@($')
44
+ rescue Sass::SyntaxError => e
45
+ assert_match ':1', e.backtrace[0]
46
+ raised = true
47
+ end
48
+ assert raised
49
+ end
50
+ end
51
+
52
+ def test_filter_can_import_external_files
53
+ if_have 'sass' do
54
+ # Create filter
55
+ filter = ::Nanoc3::Filters::Sass.new(:items => [])
56
+
57
+ # Create sample file
58
+ File.open('moo.sass', 'w') { |io| io.write "body\n color: red" }
59
+
60
+ # Run filter
61
+ filter.run('@import moo')
62
+ end
63
+ end
64
+
65
+ def test_filter_can_import_relative_files
66
+ if_have 'sass' do
67
+ # Create filter
68
+ filter = ::Nanoc3::Filters::Sass.new(:items => [])
69
+
70
+ # Create sample file
71
+ File.open('moo.sass', 'w') { |io| io.write %Q{@import subdir/relative} }
72
+ FileUtils.mkdir_p("subdir")
73
+ File.open('subdir/relative.sass', 'w') { |io| io.write "body\n color: red" }
74
+
75
+ # Run filter
76
+ filter.run('@import moo')
77
+ end
78
+ end
79
+
80
+ def test_filter_will_skip_items_without_filename
81
+ if_have 'sass' do
82
+ # Create filter
83
+ filter = ::Nanoc3::Filters::Sass.new(:items => [ Nanoc3::Item.new('blah', {}, '/blah/') ])
84
+
85
+ # Create sample file
86
+ File.open('moo.sass', 'w') { |io| io.write "body\n color: red" }
87
+
88
+ # Run filter
89
+ filter.run('@import moo')
90
+ end
91
+ end
92
+
93
+ def test_css_imports_work
94
+ if_have 'sass' do
95
+ # Create filter
96
+ filter = ::Nanoc3::Filters::Sass.new(:items => [ Nanoc3::Item.new('blah', {}, '/blah/') ])
97
+
98
+ # Run filter
99
+ filter.run('@import moo.css')
100
+ end
101
+ end
102
+
103
+ end
@@ -0,0 +1,37 @@
1
+ # encoding: utf-8
2
+
3
+ require 'test/helper'
4
+
5
+ class Nanoc3::Filters::SlimTest < MiniTest::Unit::TestCase
6
+
7
+ include Nanoc3::TestHelpers
8
+
9
+ def test_filter
10
+ if_have 'slim' do
11
+ # Create filter
12
+ filter = ::Nanoc3::Filters::Slim.new({ :rabbit => 'The rabbit is on the branch.' })
13
+
14
+ # Run filter (no assigns)
15
+ result = filter.run('html')
16
+ assert_match(/<html>.*<\/html>/, result)
17
+
18
+ # Run filter (assigns without @)
19
+ result = filter.run('p = rabbit')
20
+ assert_equal("<p>The rabbit is on the branch.</p>", result)
21
+
22
+ # Run filter (assigns with @)
23
+ result = filter.run('p = @rabbit')
24
+ assert_equal("<p>The rabbit is on the branch.</p>", result)
25
+ end
26
+ end
27
+
28
+ def test_filter_with_yield
29
+ if_have 'slim' do
30
+ filter = ::Nanoc3::Filters::Slim.new({ :content => 'The rabbit is on the branch.' })
31
+
32
+ result = filter.run('p = yield')
33
+ assert_equal("<p>The rabbit is on the branch.</p>", result)
34
+ end
35
+ end
36
+
37
+ end
@@ -0,0 +1,23 @@
1
+ # encoding: utf-8
2
+
3
+ require 'test/helper'
4
+
5
+ class Nanoc3::Filters::TypogrubyTest < MiniTest::Unit::TestCase
6
+
7
+ include Nanoc3::TestHelpers
8
+
9
+ def test_filter
10
+ if_have 'typogruby' do
11
+ # Get filter
12
+ filter = ::Nanoc3::Filters::Typogruby.new
13
+
14
+ # Run filter
15
+ a = '"Typogruby makes HTML look smarter &amp; better, don\'t you think?"'
16
+ b = '<span class="dquo">&#8220;</span>Typogruby makes <span class="caps">HTML</span> look smarter <span class="amp">&amp;</span> better, don&#8217;t you&nbsp;think?&#8221;'
17
+ result = filter.run(a)
18
+ assert_equal(b, result)
19
+ end
20
+ end
21
+
22
+ end
23
+
data/test/helper.rb ADDED
@@ -0,0 +1,161 @@
1
+ # encoding: utf-8
2
+
3
+ # Load unit testing stuff
4
+ begin
5
+ require 'minitest/unit'
6
+ require 'minitest/spec'
7
+ require 'minitest/mock'
8
+ require 'mocha'
9
+ rescue => e
10
+ $stderr.puts "To run the nanoc unit tests, you need minitest and mocha."
11
+ raise e
12
+ end
13
+
14
+ # Load nanoc
15
+ $LOAD_PATH.unshift(File.expand_path(File.dirname(__FILE__) + '/../lib'))
16
+ require 'nanoc3'
17
+ require 'nanoc3/cli'
18
+ require 'nanoc3/tasks'
19
+
20
+ # Load miscellaneous requirements
21
+ require 'stringio'
22
+
23
+ module Nanoc3::TestHelpers
24
+
25
+ def if_have(*libs)
26
+ libs.each do |lib|
27
+ begin
28
+ require lib
29
+ rescue LoadError
30
+ skip "requiring #{lib} failed"
31
+ return
32
+ end
33
+ end
34
+
35
+ yield
36
+ end
37
+
38
+ def if_implemented
39
+ begin
40
+ yield
41
+ rescue NotImplementedError, NameError
42
+ skip $!
43
+ return
44
+ end
45
+ end
46
+
47
+ def with_site(params={})
48
+ # Build site name
49
+ site_name = params[:name]
50
+ if site_name.nil?
51
+ @site_num ||= 0
52
+ site_name = "site-#{@site_num}"
53
+ @site_num += 1
54
+ end
55
+
56
+ # Build rules
57
+ rules_content = <<EOS
58
+ compile '*' do
59
+ {{compilation_rule_content}}
60
+ end
61
+
62
+ route '*' do
63
+ if item.binary?
64
+ item.identifier.chop + '.' + item[:extension]
65
+ else
66
+ item.identifier + 'index.html'
67
+ end
68
+ end
69
+
70
+ layout '*', :erb
71
+ EOS
72
+ rules_content.gsub!('{{compilation_rule_content}}', params[:compilation_rule_content] || '')
73
+
74
+ # Create site
75
+ unless File.directory?(site_name)
76
+ FileUtils.mkdir_p(site_name)
77
+ FileUtils.cd(site_name) do
78
+ FileUtils.mkdir_p('content')
79
+ FileUtils.mkdir_p('layouts')
80
+ FileUtils.mkdir_p('lib')
81
+ FileUtils.mkdir_p('output')
82
+
83
+ if params[:has_layout]
84
+ File.open('layouts/default.html', 'w') do |io|
85
+ io.write('... <%= @yield %> ...')
86
+ end
87
+ end
88
+
89
+ File.open('config.yaml', 'w') { |io| io.write('stuff: 12345') }
90
+ File.open('Rules', 'w') { |io| io.write(rules_content) }
91
+ end
92
+ end
93
+
94
+ # Yield site
95
+ FileUtils.cd(site_name) do
96
+ yield Nanoc3::Site.new('.')
97
+ end
98
+ end
99
+
100
+ def setup
101
+ # Clean up
102
+ GC.start
103
+
104
+ # Go quiet
105
+ unless ENV['QUIET'] == 'false'
106
+ $stdout = StringIO.new
107
+ $stderr = StringIO.new
108
+ end
109
+
110
+ # Enter tmp
111
+ FileUtils.mkdir_p('tmp')
112
+ FileUtils.cd('tmp')
113
+ end
114
+
115
+ def teardown
116
+ # Exit tmp
117
+ FileUtils.cd('..')
118
+ FileUtils.rm_rf('tmp')
119
+
120
+ # Go unquiet
121
+ unless ENV['QUIET'] == 'false'
122
+ $stdout = STDOUT
123
+ $stderr = STDERR
124
+ end
125
+ end
126
+
127
+ # Adapted from http://github.com/lsegal/yard-examples/tree/master/doctest
128
+ def assert_examples_correct(object)
129
+ P(object).tags(:example).each do |example|
130
+ begin
131
+ # Get input and output
132
+ parts = example.text.split(/# ?=>/).map { |s| s.strip }
133
+ code = parts[0].strip
134
+ expected_out_raw = parts[1].strip
135
+
136
+ # Evaluate
137
+ expected_out = eval(parts[1])
138
+ actual_out = instance_eval("#{code}")
139
+ rescue Exception => e
140
+ e.message << " (code: #{code}; expected output: #{expected_out_raw})"
141
+ raise e
142
+ end
143
+
144
+ assert_equal expected_out, actual_out,
145
+ "Incorrect example: #{code}"
146
+ end
147
+ end
148
+
149
+ def assert_contains_exactly(expected, actual)
150
+ assert_equal expected.size, actual.size,
151
+ 'Expected %s to be of same size as %s' % [actual.inspect, expected.inspect]
152
+ remaining = actual.dup.to_a
153
+ expected.each do |e|
154
+ index = remaining.index(e)
155
+ remaining.delete_at(index) if index
156
+ end
157
+ assert remaining.empty?,
158
+ 'Expected %s to contain all the elements of %s' % [actual.inspect, expected.inspect]
159
+ end
160
+
161
+ end