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,149 @@
1
+ # encoding: utf-8
2
+
3
+ require 'test/helper'
4
+
5
+ class Nanoc3::Filters::ColorizeSyntaxTest < MiniTest::Unit::TestCase
6
+
7
+ include Nanoc3::TestHelpers
8
+
9
+ def test_coderay_simple
10
+ if_have 'coderay', 'nokogiri' do
11
+ # Create filter
12
+ filter = ::Nanoc3::Filters::ColorizeSyntax.new
13
+
14
+ # Get input and expected output
15
+ input = '<pre title="moo"><code class="language-ruby"># comment</code></pre>'
16
+ expected_output = '<pre title="moo"><code class="language-ruby"><span class="c"># comment</span></code></pre>'
17
+
18
+ # Run filter
19
+ actual_output = filter.run(input)
20
+ assert_equal(expected_output, actual_output)
21
+ end
22
+ end
23
+
24
+ def test_coderay_with_comment
25
+ if_have 'coderay', 'nokogiri' do
26
+ # Create filter
27
+ filter = ::Nanoc3::Filters::ColorizeSyntax.new
28
+
29
+ # Get input and expected output
30
+ input = %[<pre title="moo"><code>#!ruby\n# comment</code></pre>]
31
+ expected_output = '<pre title="moo"><code class="language-ruby"><span class="c"># comment</span></code></pre>'
32
+
33
+ # Run filter
34
+ actual_output = filter.run(input)
35
+ assert_equal(expected_output, actual_output)
36
+ end
37
+ end
38
+
39
+ def test_coderay_with_comment_and_class
40
+ if_have 'coderay', 'nokogiri' do
41
+ # Create filter
42
+ filter = ::Nanoc3::Filters::ColorizeSyntax.new
43
+
44
+ # Get input and expected output
45
+ input = %[<pre title="moo"><code class="language-ruby">#!ruby\n# comment</code></pre>]
46
+ expected_output = %[<pre title="moo"><code class="language-ruby"><span class="dt">#!ruby</span>\n<span class="c"># comment</span></code></pre>]
47
+
48
+ # Run filter
49
+ actual_output = filter.run(input)
50
+ assert_equal(expected_output, actual_output)
51
+ end
52
+ end
53
+
54
+ def test_coderay_with_more_classes
55
+ if_have 'coderay', 'nokogiri' do
56
+ # Create filter
57
+ filter = ::Nanoc3::Filters::ColorizeSyntax.new
58
+
59
+ # Get input and expected output
60
+ input = '<pre title="moo"><code class="abc language-ruby xyz"># comment</code></pre>'
61
+ expected_output = '<pre title="moo"><code class="abc language-ruby xyz"><span class="c"># comment</span></code></pre>'
62
+
63
+ # Run filter
64
+ actual_output = filter.run(input)
65
+ assert_equal(expected_output, actual_output)
66
+ end
67
+ end
68
+
69
+ def test_pygmentize
70
+ if_have 'nokogiri' do
71
+ if `which pygmentize`.strip.empty?
72
+ skip "could not find pygmentize"
73
+ end
74
+
75
+ # Create filter
76
+ filter = ::Nanoc3::Filters::ColorizeSyntax.new
77
+
78
+ # Get input and expected output
79
+ input = '<pre title="moo"><code class="language-ruby"># comment</code></pre>'
80
+ expected_output = '<pre title="moo"><code class="language-ruby"><span class="c1"># comment</span></code></pre>'
81
+
82
+ # Run filter
83
+ actual_output = filter.run(input, :colorizers => { :ruby => :pygmentize })
84
+ assert_equal(expected_output, actual_output)
85
+ end
86
+ end
87
+
88
+ def test_simon_highlight
89
+ if_have 'nokogiri' do
90
+ if `which highlight`.strip.empty?
91
+ skip "could not find `highlight`"
92
+ end
93
+
94
+ # Create filter
95
+ filter = ::Nanoc3::Filters::ColorizeSyntax.new
96
+
97
+ # Get input and expected output
98
+ input = %Q[<pre title="moo"><code class="language-ruby">\n# comment\n</code></pre>]
99
+ expected_output = '<pre title="moo"><code class="language-ruby"><span class="hl slc"># comment</span></code></pre>'
100
+
101
+ # Run filter
102
+ actual_output = filter.run(input, :default_colorizer => :simon_highlight)
103
+ assert_equal(expected_output, actual_output)
104
+ end
105
+ end
106
+
107
+ def test_colorize_syntax_with_unknown_syntax
108
+ if_have 'coderay', 'nokogiri' do
109
+ # Create filter
110
+ filter = ::Nanoc3::Filters::ColorizeSyntax.new
111
+
112
+ # Run filter
113
+ assert_raises RuntimeError do
114
+ filter.run('<p>whatever</p>', :syntax => :kasflwafhaweoineurl)
115
+ end
116
+ end
117
+ end
118
+
119
+ def test_colorize_syntax_with_xml
120
+ if_have 'coderay', 'nokogiri' do
121
+ # Create filter
122
+ filter = ::Nanoc3::Filters::ColorizeSyntax.new
123
+
124
+ # Get input and expected output
125
+ input = '<p>foo<br/>bar</p>'
126
+ expected_output = '<p>foo<br/>bar</p>'
127
+
128
+ # Run filter
129
+ actual_output = filter.run(input, :syntax => :xml)
130
+ assert_equal(expected_output, actual_output)
131
+ end
132
+ end
133
+
134
+ def test_colorize_syntax_with_xhtml
135
+ if_have 'coderay', 'nokogiri' do
136
+ # Create filter
137
+ filter = ::Nanoc3::Filters::ColorizeSyntax.new
138
+
139
+ # Get input and expected output
140
+ input = '<p>foo<br/>bar</p>'
141
+ expected_output = '<p>foo<br />bar</p>'
142
+
143
+ # Run filter
144
+ actual_output = filter.run(input, :syntax => :xhtml)
145
+ assert_equal(expected_output, actual_output)
146
+ end
147
+ end
148
+
149
+ end
@@ -0,0 +1,101 @@
1
+ # encoding: utf-8
2
+
3
+ require 'test/helper'
4
+
5
+ class Nanoc3::Filters::ERBTest < MiniTest::Unit::TestCase
6
+
7
+ include Nanoc3::TestHelpers
8
+
9
+ def test_filter_with_instance_variable
10
+ # Create filter
11
+ filter = ::Nanoc3::Filters::ERB.new({ :location => 'a cheap motel' })
12
+
13
+ # Run filter
14
+ result = filter.run('<%= "I was hiding in #{@location}." %>')
15
+ assert_equal('I was hiding in a cheap motel.', result)
16
+ end
17
+
18
+ def test_filter_with_instance_method
19
+ # Create filter
20
+ filter = ::Nanoc3::Filters::ERB.new({ :location => 'a cheap motel' })
21
+
22
+ # Run filter
23
+ result = filter.run('<%= "I was hiding in #{location}." %>')
24
+ assert_equal('I was hiding in a cheap motel.', result)
25
+ end
26
+
27
+ def test_filter_error_item
28
+ # Create item and item rep
29
+ item = MiniTest::Mock.new
30
+ item.expect(:identifier, '/foo/bar/baz/')
31
+ item_rep = MiniTest::Mock.new
32
+ item_rep.expect(:name, :quux)
33
+
34
+ # Create filter
35
+ filter = ::Nanoc3::Filters::ERB.new({
36
+ :item => item,
37
+ :item_rep => item_rep,
38
+ :location => 'a cheap motel'
39
+ })
40
+
41
+ # Run filter
42
+ raised = false
43
+ begin
44
+ filter.run('<%= this isn\'t really ruby so it\'ll break, muahaha %>')
45
+ rescue SyntaxError => e
46
+ e.message =~ /(.+?):\d+: /
47
+ assert_match 'item /foo/bar/baz/ (rep quux)', $1
48
+ raised = true
49
+ end
50
+ assert raised
51
+ end
52
+
53
+ def test_filter_with_yield
54
+ # Create filter
55
+ filter = ::Nanoc3::Filters::ERB.new({ :content => 'a cheap motel' })
56
+
57
+ # Run filter
58
+ result = filter.run('<%= "I was hiding in #{yield}." %>')
59
+ assert_equal('I was hiding in a cheap motel.', result)
60
+ end
61
+
62
+ def test_filter_with_yield_without_content
63
+ # Create filter
64
+ filter = ::Nanoc3::Filters::ERB.new({ :location => 'a cheap motel' })
65
+
66
+ # Run filter
67
+ assert_raises LocalJumpError do
68
+ filter.run('<%= "I was hiding in #{yield}." %>')
69
+ end
70
+ end
71
+
72
+ def test_safe_level
73
+ # Set up
74
+ filter = ::Nanoc3::Filters::ERB.new
75
+ File.open('moo', 'w') { |io| io.write("one miiillion dollars") }
76
+
77
+ # Without
78
+ res = filter.run('<%= File.read("moo") %>', :safe_level => nil)
79
+ assert_equal 'one miiillion dollars', res
80
+
81
+ # With
82
+ assert_raises(SecurityError) do
83
+ res = filter.run('<%= File.read("moo") %>', :safe_level => 4)
84
+ end
85
+ end
86
+
87
+ def test_trim_mode
88
+ # Set up
89
+ filter = ::Nanoc3::Filters::ERB.new({ :location => 'a cheap motel' })
90
+ $trim_mode_works = false
91
+
92
+ # Without
93
+ filter.run('% $trim_mode_works = true')
94
+ refute $trim_mode_works
95
+
96
+ # With
97
+ filter.run('% $trim_mode_works = true', :trim_mode => '%')
98
+ assert $trim_mode_works
99
+ end
100
+
101
+ end
@@ -0,0 +1,72 @@
1
+ # encoding: utf-8
2
+
3
+ require 'test/helper'
4
+
5
+ class Nanoc3::Filters::ErubisTest < MiniTest::Unit::TestCase
6
+
7
+ include Nanoc3::TestHelpers
8
+
9
+ def test_filter_with_instance_variable
10
+ if_have 'erubis' do
11
+ # Create filter
12
+ filter = ::Nanoc3::Filters::Erubis.new({ :location => 'a cheap motel' })
13
+
14
+ # Run filter
15
+ result = filter.run('<%= "I was hiding in #{@location}." %>')
16
+ assert_equal('I was hiding in a cheap motel.', result)
17
+ end
18
+ end
19
+
20
+ def test_filter_with_instance_method
21
+ if_have 'erubis' do
22
+ # Create filter
23
+ filter = ::Nanoc3::Filters::Erubis.new({ :location => 'a cheap motel' })
24
+
25
+ # Run filter
26
+ result = filter.run('<%= "I was hiding in #{location}." %>')
27
+ assert_equal('I was hiding in a cheap motel.', result)
28
+ end
29
+ end
30
+
31
+ def test_filter_error
32
+ if_have 'erubis' do
33
+ # Create filter
34
+ filter = ::Nanoc3::Filters::Erubis.new
35
+
36
+ # Run filter
37
+ raised = false
38
+ begin
39
+ filter.run('<%= this isn\'t really ruby so it\'ll break, muahaha %>')
40
+ rescue SyntaxError => e
41
+ e.message =~ /(.+?):\d+: /
42
+ assert_match '?', $1
43
+ raised = true
44
+ end
45
+ assert raised
46
+ end
47
+ end
48
+
49
+ def test_filter_with_yield
50
+ if_have 'erubis' do
51
+ # Create filter
52
+ filter = ::Nanoc3::Filters::Erubis.new({ :content => 'a cheap motel' })
53
+
54
+ # Run filter
55
+ result = filter.run('<%= "I was hiding in #{yield}." %>')
56
+ assert_equal('I was hiding in a cheap motel.', result)
57
+ end
58
+ end
59
+
60
+ def test_filter_with_yield_without_content
61
+ if_have 'erubis' do
62
+ # Create filter
63
+ filter = ::Nanoc3::Filters::Erubis.new({ :location => 'a cheap motel' })
64
+
65
+ # Run filter
66
+ assert_raises LocalJumpError do
67
+ filter.run('<%= "I was hiding in #{yield}." %>')
68
+ end
69
+ end
70
+ end
71
+
72
+ end
@@ -0,0 +1,98 @@
1
+ # encoding: utf-8
2
+
3
+ require 'test/helper'
4
+
5
+ class Nanoc3::Filters::HamlTest < MiniTest::Unit::TestCase
6
+
7
+ include Nanoc3::TestHelpers
8
+
9
+ def test_filter
10
+ if_have 'haml' do
11
+ # Create filter
12
+ filter = ::Nanoc3::Filters::Haml.new({ :question => 'Is this the Payne residence?' })
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= question')
20
+ assert_equal("<p>Is this the Payne residence?</p>\n", result)
21
+
22
+ # Run filter (assigns with @)
23
+ result = filter.run('%p= @question')
24
+ assert_equal("<p>Is this the Payne residence?</p>\n", result)
25
+ end
26
+ end
27
+
28
+ def test_filter_with_params
29
+ if_have 'haml' do
30
+ # Create filter
31
+ filter = ::Nanoc3::Filters::Haml.new({ :foo => 'bar' })
32
+
33
+ # Check with HTML5
34
+ result = filter.run('%img', :format => :html5)
35
+ assert_match(/<img>/, result)
36
+
37
+ # Check with XHTML
38
+ result = filter.run('%img', :format => :xhtml)
39
+ assert_match(/<img\s*\/>/, result)
40
+ end
41
+ end
42
+
43
+ def test_filter_error
44
+ if_have 'haml' do
45
+ # Create filter
46
+ filter = ::Nanoc3::Filters::Haml.new({ :foo => 'bar' })
47
+
48
+ # Run filter
49
+ raised = false
50
+ begin
51
+ filter.run('%p= this isn\'t really ruby so it\'ll break, muahaha')
52
+ rescue SyntaxError => e
53
+ e.message =~ /(.+?):\d+: /
54
+ assert_match '?', $1
55
+ raised = true
56
+ end
57
+ assert raised
58
+ end
59
+ end
60
+
61
+ def test_filter_with_yield
62
+ if_have 'haml' do
63
+ # Create filter
64
+ filter = ::Nanoc3::Filters::Haml.new({ :content => 'Is this the Payne residence?' })
65
+
66
+ # Run filter
67
+ result = filter.run('%p= yield')
68
+ assert_equal("<p>Is this the Payne residence?</p>\n", result)
69
+ end
70
+ end
71
+
72
+ def test_filter_with_yield_without_content
73
+ if_have 'haml' do
74
+ # Create filter
75
+ filter = ::Nanoc3::Filters::Haml.new({ :location => 'Is this the Payne residence?' })
76
+
77
+ # Run filter
78
+ assert_raises LocalJumpError do
79
+ filter.run('%p= yield')
80
+ end
81
+ end
82
+ end
83
+
84
+ def test_filter_with_proper_indentation
85
+ if_have 'haml' do
86
+ # Create file to include
87
+ File.open('stuff', 'w') do |io|
88
+ io.write("<pre>Max Payne\nMona Sax</pre>")
89
+ end
90
+
91
+ # Run filter
92
+ filter = ::Nanoc3::Filters::Haml.new
93
+ result = filter.run("%body\n ~ File.read('stuff')")
94
+ assert_match(/Max Payne&#x000A;Mona Sax/, result)
95
+ end
96
+ end
97
+
98
+ end
@@ -0,0 +1,20 @@
1
+ # encoding: utf-8
2
+
3
+ require 'test/helper'
4
+
5
+ class Nanoc3::Filters::KramdownTest < MiniTest::Unit::TestCase
6
+
7
+ include Nanoc3::TestHelpers
8
+
9
+ def test_filter
10
+ if_have 'kramdown' do
11
+ # Create filter
12
+ filter = ::Nanoc3::Filters::Kramdown.new
13
+
14
+ # Run filter
15
+ result = filter.run("This is _so_ **cool**!")
16
+ assert_equal("<p>This is <em>so</em> <strong>cool</strong>!</p>\n", result)
17
+ end
18
+ end
19
+
20
+ end
@@ -0,0 +1,59 @@
1
+ # encoding: utf-8
2
+
3
+ require 'test/helper'
4
+
5
+ class Nanoc3::Filters::LessTest < MiniTest::Unit::TestCase
6
+
7
+ include Nanoc3::TestHelpers
8
+
9
+ def test_filter
10
+ if_have 'less' do
11
+ # Create item
12
+ @item = Nanoc3::Item.new("blah", { :content_filename => 'content/foo/bar.txt' }, '/foo/bar/')
13
+
14
+ # Create filter
15
+ filter = ::Nanoc3::Filters::Less.new(:item => @item)
16
+
17
+ # Run filter
18
+ result = filter.run('.foo { bar: 1 + 1 }')
19
+ assert_match /\.foo\s*\{\s*bar:\s*2;?\s*\}/, result
20
+ end
21
+ end
22
+
23
+ def test_filter_with_paths_relative_to_site_directory
24
+ if_have 'less' do
25
+ # Create file to import
26
+ FileUtils.mkdir_p('content/foo/bar')
27
+ File.open('content/foo/bar/imported_file.less', 'w') { |io| io.write('p { color: red; }') }
28
+
29
+ # Create item
30
+ @item = Nanoc3::Item.new("blah", { :content_filename => 'content/foo/bar.txt' }, '/foo/bar/')
31
+
32
+ # Create filter
33
+ filter = ::Nanoc3::Filters::Less.new(:item => @item)
34
+
35
+ # Run filter
36
+ result = filter.run('@import "content/foo/bar/imported_file.less";')
37
+ assert_match /p\s*\{\s*color:\s*red;?\s*\}/, result
38
+ end
39
+ end
40
+
41
+ def test_filter_with_paths_relative_to_current_file
42
+ if_have 'less' do
43
+ # Create file to import
44
+ FileUtils.mkdir_p('content/foo/bar')
45
+ File.open('content/foo/bar/imported_file.less', 'w') { |io| io.write('p { color: red; }') }
46
+
47
+ # Create item
48
+ @item = Nanoc3::Item.new("blah", { :content_filename => 'content/foo/bar.txt' }, '/foo/bar/')
49
+
50
+ # Create filter
51
+ filter = ::Nanoc3::Filters::Less.new(:item => @item)
52
+
53
+ # Run filter
54
+ result = filter.run('@import "bar/imported_file.less";')
55
+ assert_match /p\s*\{\s*color:\s*red;?\s*\}/, result
56
+ end
57
+ end
58
+
59
+ end
@@ -0,0 +1,26 @@
1
+ # encoding: utf-8
2
+
3
+ require 'test/helper'
4
+
5
+ class Nanoc3::Filters::MarkabyTest < MiniTest::Unit::TestCase
6
+
7
+ include Nanoc3::TestHelpers
8
+
9
+ def test_filter
10
+ # Don’t run this test on 1.9.x, because it breaks and it annoys me
11
+ if RUBY_VERSION >= '1.9'
12
+ skip "Markaby is not compatible with 1.9.x"
13
+ return
14
+ end
15
+
16
+ if_have 'markaby' do
17
+ # Create filter
18
+ filter = ::Nanoc3::Filters::Markaby.new
19
+
20
+ # Run filter
21
+ result = filter.run("html do\nend")
22
+ assert_equal("<html></html>", result)
23
+ end
24
+ end
25
+
26
+ end
@@ -0,0 +1,20 @@
1
+ # encoding: utf-8
2
+
3
+ require 'test/helper'
4
+
5
+ class Nanoc3::Filters::MarukuTest < MiniTest::Unit::TestCase
6
+
7
+ include Nanoc3::TestHelpers
8
+
9
+ def test_filter
10
+ if_have 'maruku' do
11
+ # Create filter
12
+ filter = ::Nanoc3::Filters::Maruku.new
13
+
14
+ # Run filter
15
+ result = filter.run("This is _so_ *cool*!")
16
+ assert_equal("<p>This is <em>so</em> <em>cool</em>!</p>", result)
17
+ end
18
+ end
19
+
20
+ end
@@ -0,0 +1,27 @@
1
+ # encoding: utf-8
2
+
3
+ require 'test/helper'
4
+
5
+ class Nanoc3::Filters::MustacheTest < MiniTest::Unit::TestCase
6
+
7
+ include Nanoc3::TestHelpers
8
+
9
+ def test_filter
10
+ if_have 'mustache' do
11
+ # Create item
12
+ item = Nanoc3::Item.new(
13
+ 'content',
14
+ { :title => 'Max Payne', :protagonist => 'Max Payne' },
15
+ '/games/max-payne/'
16
+ )
17
+
18
+ # Create filter
19
+ filter = ::Nanoc3::Filters::Mustache.new({ :item => item })
20
+
21
+ # Run filter
22
+ result = filter.run('The protagonist of {{title}} is {{protagonist}}.')
23
+ assert_equal('The protagonist of Max Payne is Max Payne.', result)
24
+ end
25
+ end
26
+
27
+ end
@@ -0,0 +1,31 @@
1
+ # encoding: utf-8
2
+
3
+ require 'test/helper'
4
+
5
+ class Nanoc3::Filters::RainpressTest < MiniTest::Unit::TestCase
6
+
7
+ include Nanoc3::TestHelpers
8
+
9
+ def test_filter
10
+ if_have 'rainpress' do
11
+ # Create filter
12
+ filter = ::Nanoc3::Filters::Rainpress.new
13
+
14
+ # Run filter
15
+ result = filter.run("body { color: black; }")
16
+ assert_equal("body{color:#000}", result)
17
+ end
18
+ end
19
+
20
+ def test_filter_with_options
21
+ if_have 'rainpress' do
22
+ # Create filter
23
+ filter = ::Nanoc3::Filters::Rainpress.new
24
+
25
+ # Run filter
26
+ result = filter.run("body { color: #aabbcc; }", :colors => false)
27
+ assert_equal("body{color:#aabbcc}", result)
28
+ end
29
+ end
30
+
31
+ end
@@ -0,0 +1,33 @@
1
+ # encoding: utf-8
2
+
3
+ require 'test/helper'
4
+
5
+ class Nanoc3::Filters::RDiscountTest < MiniTest::Unit::TestCase
6
+
7
+ include Nanoc3::TestHelpers
8
+
9
+ def test_filter
10
+ if_have 'rdiscount' do
11
+ # Create filter
12
+ filter = ::Nanoc3::Filters::RDiscount.new
13
+
14
+ # Run filter
15
+ result = filter.run("> Quote")
16
+ assert_match(/<blockquote>\s*<p>Quote<\/p>\s*<\/blockquote>/, result)
17
+ end
18
+ end
19
+
20
+ def test_with_extensions
21
+ if_have 'rdiscount' do
22
+ # Create filter
23
+ filter = ::Nanoc3::Filters::RDiscount.new
24
+
25
+ # Run filter
26
+ input = "The quotation 'marks' sure make this look sarcastic!"
27
+ output_expected = /The quotation &lsquo;marks&rsquo; sure make this look sarcastic!/
28
+ output_actual = filter.run(input, :extensions => [ :smart ])
29
+ assert_match(output_expected, output_actual)
30
+ end
31
+ end
32
+
33
+ end
@@ -0,0 +1,18 @@
1
+ # encoding: utf-8
2
+
3
+ require 'test/helper'
4
+
5
+ class Nanoc3::Filters::RDocTest < MiniTest::Unit::TestCase
6
+
7
+ include Nanoc3::TestHelpers
8
+
9
+ def test_filter
10
+ # Get filter
11
+ filter = ::Nanoc3::Filters::RDoc.new
12
+
13
+ # Run filter
14
+ result = filter.run("= Foo")
15
+ assert_match(%r{<h1>Foo</h1>\Z}, result)
16
+ end
17
+
18
+ end