nanoc 3.2.4 → 3.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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,19 @@
1
+ # encoding: utf-8
2
+
3
+ class Nanoc::Extra::FileProxyTest < MiniTest::Unit::TestCase
4
+
5
+ include Nanoc::TestHelpers
6
+
7
+ def test_create_many
8
+ if_implemented do
9
+ # Create test file
10
+ File.open('test.txt', 'w') { |io| }
11
+
12
+ # Create lots of file proxies
13
+ count = Process.getrlimit(Process::RLIMIT_NOFILE)[0] + 5
14
+ file_proxies = []
15
+ count.times { file_proxies << Nanoc::Extra::FileProxy.new('test.txt') }
16
+ end
17
+ end
18
+
19
+ end
@@ -0,0 +1,22 @@
1
+ # encoding: utf-8
2
+
3
+ class Nanoc::Extra::VCSTest < MiniTest::Unit::TestCase
4
+
5
+ include Nanoc::TestHelpers
6
+
7
+ def test_named
8
+ assert_nil(Nanoc::Extra::VCS.named(:lkasjdlkfjlkasdfkj))
9
+
10
+ refute_nil(Nanoc::Extra::VCS.named(:svn))
11
+ refute_nil(Nanoc::Extra::VCS.named(:subversion))
12
+ end
13
+
14
+ def test_not_implemented
15
+ vcs = Nanoc::Extra::VCS.new
16
+
17
+ assert_raises(NotImplementedError) { vcs.add('x') }
18
+ assert_raises(NotImplementedError) { vcs.remove('x') }
19
+ assert_raises(NotImplementedError) { vcs.move('x', 'y') }
20
+ end
21
+
22
+ end
@@ -0,0 +1,62 @@
1
+ # encoding: utf-8
2
+
3
+ class Nanoc::Extra::Validators::LinksTest < MiniTest::Unit::TestCase
4
+
5
+ include Nanoc::TestHelpers
6
+
7
+ def test_is_external_href?
8
+ # Create validator
9
+ validator = Nanoc::Extra::Validators::Links.new(nil, nil)
10
+
11
+ # Test
12
+ assert validator.send(:is_external_href?, 'http://example.com/')
13
+ assert validator.send(:is_external_href?, 'https://example.com/')
14
+ assert validator.send(:is_external_href?, 'mailto:bob@example.com')
15
+ assert !validator.send(:is_external_href?, '../stuff')
16
+ assert !validator.send(:is_external_href?, '/stuff')
17
+ end
18
+
19
+ def test_is_valid_internal_href?
20
+ # Create files
21
+ FileUtils.mkdir_p('output')
22
+ FileUtils.mkdir_p('output/stuff')
23
+ File.open('output/origin', 'w') { |io| io.write('hi') }
24
+ File.open('output/foo', 'w') { |io| io.write('hi') }
25
+ File.open('output/stuff/blah', 'w') { |io| io.write('hi') }
26
+
27
+ # Create validator
28
+ validator = Nanoc::Extra::Validators::Links.new('output', [ 'index.html' ])
29
+
30
+ # Test
31
+ assert validator.send(:is_valid_internal_href?, 'foo', 'output/origin')
32
+ assert validator.send(:is_valid_internal_href?, 'origin', 'output/origin')
33
+ assert validator.send(:is_valid_internal_href?, 'stuff/blah', 'output/origin')
34
+ assert validator.send(:is_valid_internal_href?, '/foo', 'output/origin')
35
+ assert validator.send(:is_valid_internal_href?, '/origin', 'output/origin')
36
+ assert validator.send(:is_valid_internal_href?, '/stuff/blah', 'output/origin')
37
+ end
38
+
39
+ def test_is_valid_external_href?
40
+ # Create validator
41
+ validator = Nanoc::Extra::Validators::Links.new('output', [ 'index.html' ])
42
+ validator.stubs(:fetch_http_status_for).returns(200)
43
+
44
+ # Test
45
+ assert validator.send(:is_valid_external_href?, 'http://example.com/')
46
+ assert validator.send(:is_valid_external_href?, 'https://example.com/')
47
+ assert validator.send(:is_valid_external_href?, 'foo://example.com/')
48
+ refute validator.send(:is_valid_external_href?, 'http://example.com/">')
49
+ end
50
+
51
+ def test_fetch_http_status_for
52
+ # Create validator
53
+ validator = Nanoc::Extra::Validators::Links.new('output', [ 'index.html' ])
54
+
55
+ # Test
56
+ assert validator.send(:fetch_http_status_for, URI.parse('http://heise.de/'), 200)
57
+ assert validator.send(:fetch_http_status_for, URI.parse('https://www.google.com/'), 200)
58
+ assert validator.send(:fetch_http_status_for, URI.parse('https://google.com/'), 200)
59
+ assert validator.send(:fetch_http_status_for, URI.parse('http://google.com/foo/bar'), 404)
60
+ end
61
+
62
+ end
@@ -0,0 +1,47 @@
1
+ # encoding: utf-8
2
+
3
+ class Nanoc::Extra::Validators::W3CTest < MiniTest::Unit::TestCase
4
+
5
+ include Nanoc::TestHelpers
6
+
7
+ def test_simple
8
+ if_have 'w3c_validators' do
9
+ # Create some sample files
10
+ %w{ foo bar baz }.each do |filename|
11
+ %w{ xxx yyy }.each do |extension|
12
+ File.open("#{filename}.#{extension}", 'w') { |io| io.write("hello") }
13
+ end
14
+ end
15
+
16
+ # Create validator
17
+ w3c = Nanoc::Extra::Validators::W3C.new('.', [ :xxx ])
18
+
19
+ # Configure expectations
20
+ validator_result = mock
21
+ validator_result.expects(:errors).times(3)
22
+ validator = mock
23
+ validator.expects(:validate_file).times(3).returns(validator_result)
24
+ w3c.expects(:types_to_extensions).with([ :xxx ]).returns([ 'xxx' ])
25
+ w3c.expects(:validator_for).with('xxx').times(3).returns(validator)
26
+ w3c.expects(:validation_started).times(3)
27
+ w3c.expects(:validation_ended).times(3)
28
+
29
+ # Run
30
+ w3c.run
31
+ end
32
+ end
33
+
34
+ def test_with_unknown_types
35
+ if_have 'w3c_validators' do
36
+ # Create validator
37
+ w3c = Nanoc::Extra::Validators::W3C.new('.', [ :foo ])
38
+
39
+ # Test
40
+ exception = assert_raises RuntimeError do
41
+ w3c.run
42
+ end
43
+ assert_equal 'unknown type: foo', exception.message
44
+ end
45
+ end
46
+
47
+ end
@@ -0,0 +1,22 @@
1
+ # encoding: utf-8
2
+
3
+ class Nanoc::Filters::AsciiDocTest < MiniTest::Unit::TestCase
4
+
5
+ include Nanoc::TestHelpers
6
+
7
+ def test_filter
8
+ if_have 'systemu' do
9
+ if `which asciidoc`.strip.empty?
10
+ skip "could not find asciidoc"
11
+ end
12
+
13
+ # Create filter
14
+ filter = ::Nanoc::Filters::AsciiDoc.new
15
+
16
+ # Run filter
17
+ result = filter.run("== Blah blah")
18
+ assert_match %r{<h2 id="_blah_blah">Blah blah</h2>}, result
19
+ end
20
+ end
21
+
22
+ end
@@ -0,0 +1,18 @@
1
+ # encoding: utf-8
2
+
3
+ class Nanoc::Filters::BlueClothTest < MiniTest::Unit::TestCase
4
+
5
+ include Nanoc::TestHelpers
6
+
7
+ def test_filter
8
+ if_have 'bluecloth' do
9
+ # Create filter
10
+ filter = ::Nanoc::Filters::BlueCloth.new
11
+
12
+ # Run filter
13
+ result = filter.run("> Quote")
14
+ assert_match %r{<blockquote>\s*<p>Quote</p>\s*</blockquote>}, result
15
+ end
16
+ end
17
+
18
+ end
@@ -0,0 +1,44 @@
1
+ # encoding: utf-8
2
+
3
+ class Nanoc::Filters::CodeRayTest < MiniTest::Unit::TestCase
4
+
5
+ include Nanoc::TestHelpers
6
+
7
+ def test_filter_without_language
8
+ if_have 'coderay' do
9
+ # Get filter
10
+ filter = ::Nanoc::Filters::CodeRay.new
11
+
12
+ # Run filter
13
+ code = "def some_function ; x = blah.foo ; x.bar 'xyzzy' ; end"
14
+ assert_raises(ArgumentError) do
15
+ filter.run(code)
16
+ end
17
+ end
18
+ end
19
+
20
+ def test_filter_with_known_language
21
+ if_have 'coderay' do
22
+ # Get filter
23
+ filter = ::Nanoc::Filters::CodeRay.new
24
+
25
+ # Run filter
26
+ code = "def some_function ; x = blah.foo ; x.bar 'xyzzy' ; end"
27
+ result = filter.run(code, :language => 'ruby')
28
+ assert_match %r{^<span class="keyword">def</span> <span class="function">some_function</span>}, result
29
+ end
30
+ end
31
+
32
+ def test_filter_with_unknown_language
33
+ if_have 'coderay' do
34
+ # Get filter
35
+ filter = ::Nanoc::Filters::CodeRay.new
36
+
37
+ # Run filter
38
+ code = "def some_function ; x = blah.foo ; x.bar 'xyzzy' ; end"
39
+ result = filter.run(code, :language => 'skldfhjsdhfjszfnocmluhfixfmersumulh')
40
+ assert_equal code, result
41
+ end
42
+ end
43
+
44
+ end
@@ -0,0 +1,18 @@
1
+ # encoding: utf-8
2
+
3
+ class Nanoc::Filters::CoffeeScriptTest < MiniTest::Unit::TestCase
4
+
5
+ include Nanoc::TestHelpers
6
+
7
+ def test_filter
8
+ if_have 'coffee-script' do
9
+ # Create filter
10
+ filter = ::Nanoc::Filters::CoffeeScript.new
11
+
12
+ # Run filter (no assigns)
13
+ result = filter.run('alert 42')
14
+ assert_equal("(function() { alert(42); }).call(this); ", result.gsub(/\s+/, ' '))
15
+ end
16
+ end
17
+
18
+ end
@@ -0,0 +1,379 @@
1
+ # encoding: utf-8
2
+
3
+ class Nanoc::Filters::ColorizeSyntaxTest < MiniTest::Unit::TestCase
4
+
5
+ include Nanoc::TestHelpers
6
+
7
+ def test_coderay_simple
8
+ if_have 'coderay', 'nokogiri' do
9
+ # Create filter
10
+ filter = ::Nanoc::Filters::ColorizeSyntax.new
11
+
12
+ # Get input and expected output
13
+ input = '<pre title="moo"><code class="language-ruby"># comment</code></pre>'
14
+ expected_output = '<pre title="moo"><code class="language-ruby"><span class="comment"># comment</span></code></pre>'
15
+
16
+ # Run filter
17
+ actual_output = filter.run(input)
18
+ assert_equal(expected_output, actual_output)
19
+ end
20
+ end
21
+
22
+ def test_dummy
23
+ if_have 'nokogiri' do
24
+ # Create filter
25
+ filter = ::Nanoc::Filters::ColorizeSyntax.new
26
+
27
+ # Get input and expected output
28
+ input = '<pre title="moo"><code class="language-ruby"># comment</code></pre>'
29
+ expected_output = input # because we are using a dummy
30
+
31
+ # Run filter
32
+ actual_output = filter.run(input, :default_colorizer => :dummy)
33
+ assert_equal(expected_output, actual_output)
34
+ end
35
+ end
36
+
37
+ def test_full_page
38
+ if_have 'nokogiri' do
39
+ # Create filter
40
+ filter = ::Nanoc::Filters::ColorizeSyntax.new
41
+
42
+ # Get input and expected output
43
+ input = <<EOS
44
+ <!DOCTYPE html>
45
+ <html>
46
+ <head>
47
+ <title>Foo</title>
48
+ </head>
49
+ <body>
50
+ <pre title="moo"><code class="language-ruby"># comment</code></pre>
51
+ </body>
52
+ </html>
53
+ EOS
54
+ expected_output = <<EOS
55
+ <!DOCTYPE html>
56
+ <html>
57
+ <head>
58
+ <meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\">
59
+ <title>Foo</title>
60
+ </head>
61
+ <body>
62
+ <pre title="moo"><code class="language-ruby"># comment</code></pre>
63
+ </body>
64
+ </html>
65
+ EOS
66
+
67
+ # Run filter
68
+ actual_output = filter.run(input, :default_colorizer => :dummy, :is_fullpage => true)
69
+ assert_equal(expected_output, actual_output)
70
+ end
71
+ end
72
+
73
+ def test_coderay_with_comment
74
+ if_have 'coderay', 'nokogiri' do
75
+ # Create filter
76
+ filter = ::Nanoc::Filters::ColorizeSyntax.new
77
+
78
+ # Get input and expected output
79
+ input = %[<pre title="moo"><code>#!ruby\n# comment</code></pre>]
80
+ expected_output = '<pre title="moo"><code class="language-ruby"><span class="comment"># comment</span></code></pre>'
81
+
82
+ # Run filter
83
+ actual_output = filter.run(input)
84
+ assert_equal(expected_output, actual_output)
85
+ end
86
+ end
87
+
88
+ def test_coderay_with_comment_and_class
89
+ if_have 'coderay', 'nokogiri' do
90
+ # Create filter
91
+ filter = ::Nanoc::Filters::ColorizeSyntax.new
92
+
93
+ # Get input and expected output
94
+ input = %[<pre title="moo"><code class="language-ruby">#!ruby\n# comment</code></pre>]
95
+ expected_output = %[<pre title="moo"><code class="language-ruby"><span class="doctype">#!ruby</span>\n<span class="comment"># comment</span></code></pre>]
96
+
97
+ # Run filter
98
+ actual_output = filter.run(input)
99
+ assert_equal(expected_output, actual_output)
100
+ end
101
+ end
102
+
103
+ def test_coderay_with_more_classes
104
+ if_have 'coderay', 'nokogiri' do
105
+ # Create filter
106
+ filter = ::Nanoc::Filters::ColorizeSyntax.new
107
+
108
+ # Get input and expected output
109
+ input = '<pre title="moo"><code class="abc language-ruby xyz"># comment</code></pre>'
110
+ expected_output = '<pre title="moo"><code class="abc language-ruby xyz"><span class="comment"># comment</span></code></pre>'
111
+
112
+ # Run filter
113
+ actual_output = filter.run(input)
114
+ assert_equal(expected_output, actual_output)
115
+ end
116
+ end
117
+
118
+ def test_pygmentize
119
+ if_have 'nokogiri', 'systemu' do
120
+ if `which pygmentize`.strip.empty?
121
+ skip "could not find pygmentize"
122
+ end
123
+
124
+ # Create filter
125
+ filter = ::Nanoc::Filters::ColorizeSyntax.new
126
+
127
+ # Get input and expected output
128
+ input = '<pre title="moo"><code class="language-ruby"># comment</code></pre>'
129
+ expected_output = '<pre title="moo"><code class="language-ruby"><span class="c1"># comment</span></code></pre>'
130
+
131
+ # Run filter
132
+ actual_output = filter.run(input, :colorizers => { :ruby => :pygmentize })
133
+ assert_equal(expected_output, actual_output)
134
+ end
135
+ end
136
+
137
+ def test_pygmentsrb
138
+ if_have 'pygments', 'nokogiri' do
139
+ # Create filter
140
+ filter = ::Nanoc::Filters::ColorizeSyntax.new
141
+
142
+ # Get input and expected output
143
+ input = '<pre title="moo"><code class="language-ruby"># comment…</code></pre>'
144
+ expected_output = '<pre title="moo"><code class="language-ruby"><span class="c1"># comment…</span></code></pre>'
145
+
146
+ # Run filter
147
+ actual_output = filter.run(input, :colorizers => { :ruby => :pygmentsrb })
148
+ assert_equal(expected_output, actual_output)
149
+ end
150
+ end
151
+
152
+ def test_simon_highlight
153
+ if_have 'nokogiri', 'systemu' do
154
+ if `which highlight`.strip.empty?
155
+ skip "could not find `highlight`"
156
+ end
157
+
158
+ # Create filter
159
+ filter = ::Nanoc::Filters::ColorizeSyntax.new
160
+
161
+ # Get input and expected output
162
+ input = %Q[<pre title="moo"><code class="language-ruby">\n# comment\n</code></pre>]
163
+ expected_output = '<pre title="moo"><code class="language-ruby"><span class="hl slc"># comment</span></code></pre>'
164
+
165
+ # Run filter
166
+ actual_output = filter.run(input, :default_colorizer => :simon_highlight)
167
+ assert_equal(expected_output, actual_output)
168
+ end
169
+ end
170
+
171
+ def test_colorize_syntax_with_unknown_syntax
172
+ if_have 'coderay', 'nokogiri' do
173
+ # Create filter
174
+ filter = ::Nanoc::Filters::ColorizeSyntax.new
175
+
176
+ # Run filter
177
+ assert_raises RuntimeError do
178
+ filter.run('<p>whatever</p>', :syntax => :kasflwafhaweoineurl)
179
+ end
180
+ end
181
+ end
182
+
183
+ def test_colorize_syntax_with_xml
184
+ if_have 'coderay', 'nokogiri' do
185
+ # Create filter
186
+ filter = ::Nanoc::Filters::ColorizeSyntax.new
187
+
188
+ # Get input and expected output
189
+ input = '<p>foo<br/>bar</p>'
190
+ expected_output = '<p>foo<br/>bar</p>'
191
+
192
+ # Run filter
193
+ actual_output = filter.run(input, :syntax => :xml)
194
+ assert_equal(expected_output, actual_output)
195
+ end
196
+ end
197
+
198
+ def test_colorize_syntax_with_xhtml
199
+ if_have 'coderay', 'nokogiri' do
200
+ # Create filter
201
+ filter = ::Nanoc::Filters::ColorizeSyntax.new
202
+
203
+ # Get input and expected output
204
+ input = '<p>foo<br/>bar</p>'
205
+ expected_output = '<p>foo<br />bar</p>'
206
+
207
+ # Run filter
208
+ actual_output = filter.run(input, :syntax => :xhtml)
209
+ assert_equal(expected_output, actual_output)
210
+ end
211
+ end
212
+
213
+ def test_colorize_syntax_with_default_colorizer
214
+ if `which pygmentize`.strip.empty?
215
+ skip 'no pygmentize found, which is required for this test'
216
+ return
217
+ end
218
+
219
+ if_have 'nokogiri', 'systemu' do
220
+ # Create filter
221
+ filter = ::Nanoc::Filters::ColorizeSyntax.new
222
+
223
+ # Get input and expected output
224
+ input = '<pre><code class="language-ruby">puts "foo"</code></pre>'
225
+ expected_output = '<pre><code class="language-ruby"><span class="nb">puts</span> <span class="s2">"foo"</span></code></pre>'
226
+
227
+ # Run filter
228
+ actual_output = filter.run(input, :default_colorizer => :pygmentize)
229
+ assert_equal(expected_output, actual_output)
230
+ end
231
+ end
232
+
233
+ def test_colorize_syntax_with_missing_executables
234
+ if_have 'nokogiri', 'systemu' do
235
+ begin
236
+ original_path = ENV['PATH']
237
+ ENV['PATH'] = './blooblooblah'
238
+
239
+ # Create filter
240
+ filter = ::Nanoc::Filters::ColorizeSyntax.new
241
+
242
+ # Get input and expected output
243
+ input = '<pre><code class="language-ruby">puts "foo"</code></pre>'
244
+
245
+ # Run filter
246
+ [ :albino, :pygmentize, :simon_highlight ].each do |colorizer|
247
+ begin
248
+ input = '<pre><code class="language-ruby">puts "foo"</code></pre>'
249
+ actual_output = filter.run(
250
+ input,
251
+ :colorizers => { :ruby => colorizer })
252
+ flunk "expected colorizer to raise if no executable is available"
253
+ rescue => e
254
+ end
255
+ end
256
+ ensure
257
+ ENV['PATH'] = original_path
258
+ end
259
+ end
260
+ end
261
+
262
+ def test_colorize_syntax_with_non_language_shebang_line
263
+ if_have 'coderay', 'nokogiri' do
264
+ # Create filter
265
+ filter = ::Nanoc::Filters::ColorizeSyntax.new
266
+
267
+ # Get input and expected output
268
+ input = <<EOS
269
+ before
270
+ <pre><code>
271
+ #!/usr/bin/env ruby
272
+ puts 'hi!'
273
+ </code></pre>
274
+ after
275
+ EOS
276
+ expected_output = <<EOS
277
+ before
278
+ <pre><code>
279
+ #!/usr/bin/env ruby
280
+ puts 'hi!'
281
+ </code></pre>
282
+ after
283
+ EOS
284
+
285
+ # Run filter
286
+ actual_output = filter.run(input)
287
+ assert_equal(expected_output, actual_output)
288
+ end
289
+ end
290
+
291
+ def test_colorize_syntax_with_non_language_shebang_line_and_language_line
292
+ if_have 'coderay', 'nokogiri' do
293
+ # Create filter
294
+ filter = ::Nanoc::Filters::ColorizeSyntax.new
295
+
296
+ # Get input and expected output
297
+ input = <<EOS
298
+ before
299
+ <pre><code>
300
+ #!ruby
301
+ #!/usr/bin/env ruby
302
+ puts 'hi!'
303
+ </code></pre>
304
+ after
305
+ EOS
306
+ expected_output = <<EOS
307
+ before
308
+ <pre><code class=\"language-ruby\"><span class=\"doctype\">#!/usr/bin/env ruby</span>
309
+ puts <span class=\"string\"><span class=\"delimiter\">'</span><span class=\"content\">hi!</span><span class=\"delimiter\">'</span></span></code></pre>
310
+ after
311
+ EOS
312
+
313
+ # Run filter
314
+ actual_output = filter.run(input)
315
+ assert_equal(expected_output, actual_output)
316
+ end
317
+ end
318
+
319
+ def test_not_outside_pre
320
+ if_have 'coderay', 'nokogiri' do
321
+ # Create filter
322
+ filter = ::Nanoc::Filters::ColorizeSyntax.new
323
+
324
+ # Get input and expected output
325
+ input = '<code class="language-ruby"># comment</code>'
326
+ expected_output = '<code class="language-ruby"># comment</code>'
327
+
328
+ # Run filter
329
+ actual_output = filter.run(input, :outside_pre => false)
330
+ assert_equal(expected_output, actual_output)
331
+ end
332
+ end
333
+
334
+ def test_outside_pre
335
+ if_have 'coderay', 'nokogiri' do
336
+ # Create filter
337
+ filter = ::Nanoc::Filters::ColorizeSyntax.new
338
+
339
+ # Get input and expected output
340
+ input = '<code class="language-ruby"># comment</code>'
341
+ expected_output = '<code class="language-ruby"><span class="comment"># comment</span></code>'
342
+
343
+ # Run filter
344
+ actual_output = filter.run(input, :outside_pre => true)
345
+ assert_equal(expected_output, actual_output)
346
+ end
347
+ end
348
+
349
+ def test_strip
350
+ if_have 'coderay', 'nokogiri' do
351
+ # Create filter
352
+ filter = ::Nanoc::Filters::ColorizeSyntax.new
353
+
354
+ # Simple test
355
+ assert_equal " bar", filter.send(:strip, "\n bar")
356
+
357
+ # Get input and expected output
358
+ input = <<EOS
359
+ before
360
+ <pre><code class="language-ruby">
361
+ def foo
362
+ end
363
+ </code></pre>
364
+ after
365
+ EOS
366
+ expected_output = <<EOS
367
+ before
368
+ <pre><code class="language-ruby"> <span class=\"keyword\">def</span> <span class=\"function\">foo</span>
369
+ <span class=\"keyword\">end</span></code></pre>
370
+ after
371
+ EOS
372
+
373
+ # Run filter
374
+ actual_output = filter.run(input)
375
+ assert_equal(expected_output, actual_output)
376
+ end
377
+ end
378
+
379
+ end