nanoc3 3.1.7 → 3.1.8
Sign up to get free protection for your applications and to get access to all the features.
- data/.gemtest +0 -0
- data/LICENSE +1 -1
- data/NEWS.md +9 -0
- data/doc/yardoc_templates/default/layout/html/footer.erb +10 -0
- data/lib/nanoc3/base/item.rb +1 -1
- data/lib/nanoc3/base/item_rep.rb +1 -0
- data/lib/nanoc3/base/layout.rb +1 -1
- data/lib/nanoc3/cli/base.rb +4 -2
- data/lib/nanoc3/cli/commands/view.rb +1 -0
- data/lib/nanoc3/data_sources/filesystem.rb +25 -6
- data/lib/nanoc3/data_sources/filesystem_unified.rb +5 -5
- data/lib/nanoc3/extra/validators/links.rb +1 -1
- data/lib/nanoc3/filters/rdiscount.rb +2 -1
- data/lib/nanoc3/filters/sass.rb +20 -8
- data/lib/nanoc3/filters/sass.rb.orig +75 -0
- data/lib/nanoc3.rb +1 -1
- data/nanoc3.gemspec +41 -0
- data/tasks/clean.rake +11 -0
- data/tasks/doc.rake +14 -0
- data/tasks/gem.rake +13 -0
- data/tasks/test.rake +38 -0
- data/test/base/core_ext/array_spec.rb +23 -0
- data/test/base/core_ext/hash_spec.rb +41 -0
- data/test/base/core_ext/string_spec.rb +27 -0
- data/test/base/test_code_snippet.rb +33 -0
- data/test/base/test_compiler.rb +410 -0
- data/test/base/test_compiler_dsl.rb +121 -0
- data/test/base/test_context.rb +33 -0
- data/test/base/test_data_source.rb +48 -0
- data/test/base/test_dependency_tracker.rb +510 -0
- data/test/base/test_directed_graph.rb +91 -0
- data/test/base/test_filter.rb +85 -0
- data/test/base/test_item.rb +141 -0
- data/test/base/test_item_rep.rb +953 -0
- data/test/base/test_layout.rb +44 -0
- data/test/base/test_notification_center.rb +36 -0
- data/test/base/test_plugin.rb +32 -0
- data/test/base/test_rule.rb +21 -0
- data/test/base/test_rule_context.rb +63 -0
- data/test/base/test_site.rb +366 -0
- data/test/cli/commands/test_compile.rb +12 -0
- data/test/cli/commands/test_create_item.rb +12 -0
- data/test/cli/commands/test_create_layout.rb +28 -0
- data/test/cli/commands/test_create_site.rb +24 -0
- data/test/cli/commands/test_help.rb +12 -0
- data/test/cli/commands/test_info.rb +12 -0
- data/test/cli/commands/test_update.rb +12 -0
- data/test/cli/test_logger.rb +12 -0
- data/test/data_sources/test_filesystem.rb +420 -0
- data/test/data_sources/test_filesystem_unified.rb +538 -0
- data/test/data_sources/test_filesystem_verbose.rb +359 -0
- data/test/extra/core_ext/test_enumerable.rb +32 -0
- data/test/extra/core_ext/test_time.rb +17 -0
- data/test/extra/deployers/test_rsync.rb +234 -0
- data/test/extra/test_auto_compiler.rb +482 -0
- data/test/extra/test_file_proxy.rb +21 -0
- data/test/extra/test_vcs.rb +24 -0
- data/test/extra/validators/test_links.rb +53 -0
- data/test/extra/validators/test_w3c.rb +49 -0
- data/test/filters/test_bluecloth.rb +20 -0
- data/test/filters/test_coderay.rb +46 -0
- data/test/filters/test_colorize_syntax.rb +56 -0
- data/test/filters/test_erb.rb +72 -0
- data/test/filters/test_erubis.rb +72 -0
- data/test/filters/test_haml.rb +98 -0
- data/test/filters/test_kramdown.rb +20 -0
- data/test/filters/test_less.rb +59 -0
- data/test/filters/test_markaby.rb +26 -0
- data/test/filters/test_maruku.rb +20 -0
- data/test/filters/test_rainpress.rb +31 -0
- data/test/filters/test_rdiscount.rb +33 -0
- data/test/filters/test_rdoc.rb +18 -0
- data/test/filters/test_redcloth.rb +20 -0
- data/test/filters/test_relativize_paths.rb +231 -0
- data/test/filters/test_rubypants.rb +20 -0
- data/test/filters/test_sass.rb +170 -0
- data/test/filters/test_sass.rb.orig +103 -0
- data/test/gem_loader.rb +11 -0
- data/test/helper.rb +99 -0
- data/test/helpers/test_blogging.rb +808 -0
- data/test/helpers/test_breadcrumbs.rb +83 -0
- data/test/helpers/test_capturing.rb +42 -0
- data/test/helpers/test_filtering.rb +108 -0
- data/test/helpers/test_html_escape.rb +18 -0
- data/test/helpers/test_link_to.rb +251 -0
- data/test/helpers/test_rendering.rb +109 -0
- data/test/helpers/test_tagging.rb +89 -0
- data/test/helpers/test_text.rb +26 -0
- data/test/helpers/test_xml_sitemap.rb +69 -0
- data/test/tasks/test_clean.rb +71 -0
- metadata +83 -8
@@ -0,0 +1,83 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'test/helper'
|
4
|
+
|
5
|
+
class Nanoc3::Helpers::BreadcrumbsTest < MiniTest::Unit::TestCase
|
6
|
+
|
7
|
+
include Nanoc3::TestHelpers
|
8
|
+
|
9
|
+
include Nanoc3::Helpers::Breadcrumbs
|
10
|
+
|
11
|
+
def test_breadcrumbs_trail_at_root
|
12
|
+
# Mock item
|
13
|
+
@item = mock
|
14
|
+
@item.stubs(:identifier).returns('/')
|
15
|
+
@items = [ @item ]
|
16
|
+
|
17
|
+
# Build trail
|
18
|
+
trail = breadcrumbs_trail
|
19
|
+
|
20
|
+
# Check
|
21
|
+
assert_equal(
|
22
|
+
[ @item ],
|
23
|
+
trail
|
24
|
+
)
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_breadcrumbs_trail_with_1_parent
|
28
|
+
# Mock item
|
29
|
+
parent = mock
|
30
|
+
parent.stubs(:identifier).returns('/')
|
31
|
+
@item = mock
|
32
|
+
@item.stubs(:identifier).returns('/foo/')
|
33
|
+
@items = [ parent, @item ]
|
34
|
+
|
35
|
+
# Build trail
|
36
|
+
trail = breadcrumbs_trail
|
37
|
+
|
38
|
+
# Check
|
39
|
+
assert_equal(
|
40
|
+
[ parent, @item ],
|
41
|
+
trail
|
42
|
+
)
|
43
|
+
end
|
44
|
+
|
45
|
+
def test_breadcrumbs_trail_with_many_parents
|
46
|
+
# Mock item
|
47
|
+
grandparent = mock
|
48
|
+
grandparent.stubs(:identifier).returns('/')
|
49
|
+
parent = mock
|
50
|
+
parent.stubs(:identifier).returns('/foo/')
|
51
|
+
@item = mock
|
52
|
+
@item.stubs(:identifier).returns('/foo/bar/')
|
53
|
+
@items = [ grandparent, parent, @item ]
|
54
|
+
|
55
|
+
# Build trail
|
56
|
+
trail = breadcrumbs_trail
|
57
|
+
|
58
|
+
# Check
|
59
|
+
assert_equal(
|
60
|
+
[ grandparent, parent, @item ],
|
61
|
+
trail
|
62
|
+
)
|
63
|
+
end
|
64
|
+
|
65
|
+
def test_breadcrumbs_trail_with_nils
|
66
|
+
# Mock item
|
67
|
+
grandparent = mock
|
68
|
+
grandparent.stubs(:identifier).returns('/')
|
69
|
+
@item = mock
|
70
|
+
@item.stubs(:identifier).returns('/foo/bar/')
|
71
|
+
@items = [ grandparent, @item ]
|
72
|
+
|
73
|
+
# Build trail
|
74
|
+
trail = breadcrumbs_trail
|
75
|
+
|
76
|
+
# Check
|
77
|
+
assert_equal(
|
78
|
+
[ grandparent, nil, @item ],
|
79
|
+
trail
|
80
|
+
)
|
81
|
+
end
|
82
|
+
|
83
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'test/helper'
|
4
|
+
|
5
|
+
class Nanoc3::Helpers::CapturingTest < MiniTest::Unit::TestCase
|
6
|
+
|
7
|
+
include Nanoc3::TestHelpers
|
8
|
+
|
9
|
+
include Nanoc3::Helpers::Capturing
|
10
|
+
|
11
|
+
def test_content_for
|
12
|
+
require 'erb'
|
13
|
+
|
14
|
+
# Build content to be evaluated
|
15
|
+
content = "head <% content_for :sidebar do %>\n" +
|
16
|
+
" <%= 1+2 %>\n" +
|
17
|
+
"<% end %> foot"
|
18
|
+
|
19
|
+
# Evaluate content
|
20
|
+
@item = {}
|
21
|
+
result = ::ERB.new(content).result(binding)
|
22
|
+
|
23
|
+
# Check
|
24
|
+
assert(@item[:content_for_sidebar].strip == '3')
|
25
|
+
assert_match(/^head\s+foot$/, result)
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_capture
|
29
|
+
require 'erb'
|
30
|
+
|
31
|
+
# Capture
|
32
|
+
_erbout = 'foo'
|
33
|
+
captured_content = capture do
|
34
|
+
_erbout << 'bar'
|
35
|
+
end
|
36
|
+
|
37
|
+
# Check
|
38
|
+
assert_equal 'foo', _erbout
|
39
|
+
assert_equal 'bar', captured_content
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
@@ -0,0 +1,108 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'test/helper'
|
4
|
+
|
5
|
+
class Nanoc3::Helpers::FilteringTest < MiniTest::Unit::TestCase
|
6
|
+
|
7
|
+
include Nanoc3::TestHelpers
|
8
|
+
|
9
|
+
include Nanoc3::Helpers::Filtering
|
10
|
+
|
11
|
+
def test_filter_simple
|
12
|
+
if_have 'rubypants' do
|
13
|
+
# Build content to be evaluated
|
14
|
+
content = "<p>Foo...</p>\n" +
|
15
|
+
"<% filter :rubypants do %>\n" +
|
16
|
+
" <p>Bar...</p>\n" +
|
17
|
+
"<% end %>\n"
|
18
|
+
|
19
|
+
# Mock item and rep
|
20
|
+
@item_rep = mock
|
21
|
+
@item_rep.expects(:assigns).returns({})
|
22
|
+
|
23
|
+
# Evaluate content
|
24
|
+
result = ::ERB.new(content).result(binding)
|
25
|
+
|
26
|
+
# Check
|
27
|
+
assert_match('<p>Foo...</p>', result)
|
28
|
+
assert_match('<p>Bar…</p>', result)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_filter_with_assigns
|
33
|
+
if_have 'rubypants' do
|
34
|
+
# Build content to be evaluated
|
35
|
+
content = "<p>Foo...</p>\n" +
|
36
|
+
"<% filter :erb do %>\n" +
|
37
|
+
" <p><%%= @item[:title] %></p>\n" +
|
38
|
+
"<% end %>\n"
|
39
|
+
|
40
|
+
# Mock item and rep
|
41
|
+
@item = mock
|
42
|
+
@item.expects(:[]).with(:title).returns('Bar...')
|
43
|
+
@item.expects(:identifier).returns('/blah/')
|
44
|
+
@item_rep = mock
|
45
|
+
@item_rep.expects(:name).returns('default')
|
46
|
+
@item_rep.expects(:assigns).returns({
|
47
|
+
:item => @item,
|
48
|
+
:item_rep => @item_rep
|
49
|
+
})
|
50
|
+
|
51
|
+
# Evaluate content
|
52
|
+
result = ::ERB.new(content).result(binding)
|
53
|
+
|
54
|
+
# Check
|
55
|
+
assert_match('<p>Foo...</p>', result)
|
56
|
+
assert_match('<p>Bar...</p>', result)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def test_filter_with_unknown_filter_name
|
61
|
+
# Build content to be evaluated
|
62
|
+
content = "<p>Foo...</p>\n" +
|
63
|
+
"<% filter :askjdflkawgjlkwaheflnvz do %>\n" +
|
64
|
+
" <p>Blah blah blah.</p>\n" +
|
65
|
+
"<% end %>\n"
|
66
|
+
|
67
|
+
# Evaluate content
|
68
|
+
error = assert_raises(Nanoc3::Errors::UnknownFilter) do
|
69
|
+
::ERB.new(content).result(binding)
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
def test_filter_with_arguments
|
74
|
+
if_have 'coderay' do
|
75
|
+
# Build content to be evaluated
|
76
|
+
content = "<% filter :coderay, :language => 'ruby' do %>\n" +
|
77
|
+
" def some_function ; x = blah.foo ; x.bar 'xyzzy' ; end\n" +
|
78
|
+
"<% end %>\n"
|
79
|
+
|
80
|
+
# Mock item and rep
|
81
|
+
@item_rep = mock
|
82
|
+
@item_rep.expects(:assigns).returns({})
|
83
|
+
|
84
|
+
# Evaluate content
|
85
|
+
result = ::ERB.new(content).result(binding)
|
86
|
+
assert_match(%r{<span class="r">def</span> <span class="fu">some_function</span>}, result)
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
def test_with_haml
|
91
|
+
if_have 'haml' do
|
92
|
+
# Build content to be evaluated
|
93
|
+
content = "%p Foo.\n" +
|
94
|
+
"- filter(:erb) do\n" +
|
95
|
+
" <%= 'abc' + 'xyz' %>\n" +
|
96
|
+
"%p Bar.\n"
|
97
|
+
|
98
|
+
# Mock item and rep
|
99
|
+
@item_rep = mock
|
100
|
+
@item_rep.expects(:assigns).returns({})
|
101
|
+
|
102
|
+
# Evaluate content
|
103
|
+
result = ::Haml::Engine.new(content).render(binding)
|
104
|
+
assert_match(%r{^<p>Foo.</p>\s*abcxyz\s*<p>Bar.</p>$}, result)
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'test/helper'
|
4
|
+
|
5
|
+
class Nanoc3::Helpers::HTMLEscapeTest < MiniTest::Unit::TestCase
|
6
|
+
|
7
|
+
include Nanoc3::TestHelpers
|
8
|
+
|
9
|
+
include Nanoc3::Helpers::HTMLEscape
|
10
|
+
|
11
|
+
def test_html_escape
|
12
|
+
assert_equal('<', html_escape('<'))
|
13
|
+
assert_equal('>', html_escape('>'))
|
14
|
+
assert_equal('&', html_escape('&'))
|
15
|
+
assert_equal('"', html_escape('"'))
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
@@ -0,0 +1,251 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'test/helper'
|
4
|
+
|
5
|
+
class Nanoc3::Helpers::LinkToTest < MiniTest::Unit::TestCase
|
6
|
+
|
7
|
+
include Nanoc3::TestHelpers
|
8
|
+
|
9
|
+
include Nanoc3::Helpers::LinkTo
|
10
|
+
|
11
|
+
def test_link_to_with_path
|
12
|
+
# Check
|
13
|
+
assert_equal(
|
14
|
+
'<a href="/foo/">Foo</a>',
|
15
|
+
link_to('Foo', '/foo/')
|
16
|
+
)
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_link_to_with_rep
|
20
|
+
# Create rep
|
21
|
+
rep = mock
|
22
|
+
rep.stubs(:path).returns('/bar/')
|
23
|
+
|
24
|
+
# Check
|
25
|
+
assert_equal(
|
26
|
+
'<a href="/bar/">Bar</a>',
|
27
|
+
link_to('Bar', rep)
|
28
|
+
)
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_link_to_with_item
|
32
|
+
# Create rep
|
33
|
+
item = mock
|
34
|
+
item.stubs(:path).returns('/bar/')
|
35
|
+
|
36
|
+
# Check
|
37
|
+
assert_equal(
|
38
|
+
'<a href="/bar/">Bar</a>',
|
39
|
+
link_to('Bar', item)
|
40
|
+
)
|
41
|
+
end
|
42
|
+
|
43
|
+
def test_link_to_with_attributes
|
44
|
+
# Check
|
45
|
+
assert_equal(
|
46
|
+
'<a title="Dis mai foo!" href="/foo/">Foo</a>',
|
47
|
+
link_to('Foo', '/foo/', :title => 'Dis mai foo!')
|
48
|
+
)
|
49
|
+
end
|
50
|
+
|
51
|
+
def test_link_to_escape
|
52
|
+
# Check
|
53
|
+
assert_equal(
|
54
|
+
'<a title="Foo & Bar" href="/foo&bar/">Foo & Bar</a>',
|
55
|
+
link_to('Foo & Bar', '/foo&bar/', :title => 'Foo & Bar')
|
56
|
+
)
|
57
|
+
end
|
58
|
+
|
59
|
+
def test_link_to_to_nil_item_or_item_rep
|
60
|
+
obj = Object.new
|
61
|
+
def obj.path ; nil ; end
|
62
|
+
|
63
|
+
assert_raises RuntimeError do
|
64
|
+
link_to("Some Text", obj)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
def test_link_to_unless_current_current
|
69
|
+
# Create item
|
70
|
+
@item_rep = mock
|
71
|
+
@item_rep.stubs(:path).returns('/foo/')
|
72
|
+
|
73
|
+
# Check
|
74
|
+
assert_equal(
|
75
|
+
'<span class="active" title="You\'re here.">Bar</span>',
|
76
|
+
link_to_unless_current('Bar', @item_rep)
|
77
|
+
)
|
78
|
+
ensure
|
79
|
+
@item = nil
|
80
|
+
end
|
81
|
+
|
82
|
+
def test_link_to_unless_current_not_current
|
83
|
+
# Create item
|
84
|
+
@item_rep = mock
|
85
|
+
@item_rep.stubs(:path).returns('/foo/')
|
86
|
+
|
87
|
+
# Check
|
88
|
+
assert_equal(
|
89
|
+
'<a href="/abc/xyz/">Bar</a>',
|
90
|
+
link_to_unless_current('Bar', '/abc/xyz/')
|
91
|
+
)
|
92
|
+
end
|
93
|
+
|
94
|
+
def test_relative_path_to_with_self
|
95
|
+
# Mock item
|
96
|
+
@item_rep = mock
|
97
|
+
@item_rep.stubs(:path).returns('/foo/bar/baz/')
|
98
|
+
|
99
|
+
# Test
|
100
|
+
assert_equal(
|
101
|
+
'./',
|
102
|
+
relative_path_to('/foo/bar/baz/')
|
103
|
+
)
|
104
|
+
end
|
105
|
+
|
106
|
+
def test_relative_path_to_with_root
|
107
|
+
# Mock item
|
108
|
+
@item_rep = mock
|
109
|
+
@item_rep.stubs(:path).returns('/foo/bar/baz/')
|
110
|
+
|
111
|
+
# Test
|
112
|
+
assert_equal(
|
113
|
+
'../../../',
|
114
|
+
relative_path_to('/')
|
115
|
+
)
|
116
|
+
end
|
117
|
+
|
118
|
+
def test_relative_path_to_file
|
119
|
+
# Mock item
|
120
|
+
@item_rep = mock
|
121
|
+
@item_rep.stubs(:path).returns('/foo/bar/baz/')
|
122
|
+
|
123
|
+
# Test
|
124
|
+
assert_equal(
|
125
|
+
'../../quux',
|
126
|
+
relative_path_to('/foo/quux')
|
127
|
+
)
|
128
|
+
end
|
129
|
+
|
130
|
+
def test_relative_path_to_dir
|
131
|
+
# Mock item
|
132
|
+
@item_rep = mock
|
133
|
+
@item_rep.stubs(:path).returns('/foo/bar/baz/')
|
134
|
+
|
135
|
+
# Test
|
136
|
+
assert_equal(
|
137
|
+
'../../quux/',
|
138
|
+
relative_path_to('/foo/quux/')
|
139
|
+
)
|
140
|
+
end
|
141
|
+
|
142
|
+
def test_relative_path_to_rep
|
143
|
+
# Mock self
|
144
|
+
@item_rep = mock
|
145
|
+
@item_rep.stubs(:path).returns('/foo/bar/baz/')
|
146
|
+
|
147
|
+
# Mock other
|
148
|
+
other_item_rep = mock
|
149
|
+
other_item_rep.stubs(:path).returns('/foo/quux/')
|
150
|
+
|
151
|
+
# Test
|
152
|
+
assert_equal(
|
153
|
+
'../../quux/',
|
154
|
+
relative_path_to(other_item_rep)
|
155
|
+
)
|
156
|
+
end
|
157
|
+
|
158
|
+
|
159
|
+
def test_relative_path_to_item
|
160
|
+
# Mock self
|
161
|
+
@item_rep = mock
|
162
|
+
@item_rep.stubs(:path).returns('/foo/bar/baz/')
|
163
|
+
|
164
|
+
# Mock other
|
165
|
+
other_item = mock
|
166
|
+
other_item.stubs(:path).returns('/foo/quux/')
|
167
|
+
|
168
|
+
# Test
|
169
|
+
assert_equal(
|
170
|
+
'../../quux/',
|
171
|
+
relative_path_to(other_item)
|
172
|
+
)
|
173
|
+
end
|
174
|
+
|
175
|
+
def test_relative_path_to_to_nil
|
176
|
+
# Mock self
|
177
|
+
@item_rep = mock
|
178
|
+
@item_rep.stubs(:path).returns(nil)
|
179
|
+
|
180
|
+
# Mock other
|
181
|
+
other_item_rep = mock
|
182
|
+
other_item_rep.stubs(:path).returns('/foo/quux/')
|
183
|
+
|
184
|
+
# Test
|
185
|
+
assert_raises RuntimeError do
|
186
|
+
relative_path_to(other_item_rep)
|
187
|
+
end
|
188
|
+
end
|
189
|
+
|
190
|
+
def test_relative_path_to_from_nil
|
191
|
+
# Mock self
|
192
|
+
@item_rep = mock
|
193
|
+
@item_rep.stubs(:path).returns('/foo/quux/')
|
194
|
+
|
195
|
+
# Mock other
|
196
|
+
other_item_rep = mock
|
197
|
+
other_item_rep.stubs(:path).returns(nil)
|
198
|
+
|
199
|
+
# Test
|
200
|
+
assert_raises RuntimeError do
|
201
|
+
relative_path_to(other_item_rep)
|
202
|
+
end
|
203
|
+
end
|
204
|
+
|
205
|
+
def test_examples_link_to
|
206
|
+
# Parse
|
207
|
+
YARD.parse('../lib/nanoc3/helpers/link_to.rb')
|
208
|
+
|
209
|
+
# Mock
|
210
|
+
@items = [ mock, mock, mock ]
|
211
|
+
@items[0].stubs(:identifier).returns('/about/')
|
212
|
+
@items[0].stubs(:path).returns('/about.html')
|
213
|
+
@items[1].stubs(:identifier).returns('/software/')
|
214
|
+
@items[1].stubs(:path).returns('/software.html')
|
215
|
+
@items[2].stubs(:identifier).returns('/software/nanoc/')
|
216
|
+
@items[2].stubs(:path).returns('/software/nanoc.html')
|
217
|
+
about_rep_vcard = mock
|
218
|
+
about_rep_vcard.stubs(:path).returns('/about.vcf')
|
219
|
+
@items[0].stubs(:rep).with(:vcard).returns(about_rep_vcard)
|
220
|
+
|
221
|
+
# Run
|
222
|
+
assert_examples_correct 'Nanoc3::Helpers::LinkTo#link_to'
|
223
|
+
end
|
224
|
+
|
225
|
+
def test_examples_link_to_unless_current
|
226
|
+
# Parse
|
227
|
+
YARD.parse('../lib/nanoc3/helpers/link_to.rb')
|
228
|
+
|
229
|
+
# Mock
|
230
|
+
@item_rep = mock
|
231
|
+
@item_rep.stubs(:path).returns('/about/')
|
232
|
+
@item = mock
|
233
|
+
@item.stubs(:path).returns(@item_rep.path)
|
234
|
+
|
235
|
+
# Run
|
236
|
+
assert_examples_correct 'Nanoc3::Helpers::LinkTo#link_to_unless_current'
|
237
|
+
end
|
238
|
+
|
239
|
+
def test_examples_relative_path_to
|
240
|
+
# Parse
|
241
|
+
YARD.parse('../lib/nanoc3/helpers/link_to.rb')
|
242
|
+
|
243
|
+
# Mock
|
244
|
+
@item_rep = mock
|
245
|
+
@item_rep.stubs(:path).returns('/foo/bar/')
|
246
|
+
|
247
|
+
# Run
|
248
|
+
assert_examples_correct 'Nanoc3::Helpers::LinkTo#relative_path_to'
|
249
|
+
end
|
250
|
+
|
251
|
+
end
|
@@ -0,0 +1,109 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'test/helper'
|
4
|
+
|
5
|
+
class Nanoc3::Helpers::RenderingTest < MiniTest::Unit::TestCase
|
6
|
+
|
7
|
+
include Nanoc3::TestHelpers
|
8
|
+
|
9
|
+
include Nanoc3::Helpers::Rendering
|
10
|
+
|
11
|
+
def test_render
|
12
|
+
# Mock layouts
|
13
|
+
layout = MiniTest::Mock.new
|
14
|
+
layout.expect(:identifier, '/foo/')
|
15
|
+
layout.expect(:raw_content, 'This is the <%= @layout.identifier %> layout.')
|
16
|
+
|
17
|
+
# Mock site, compiler and stack
|
18
|
+
stack = []
|
19
|
+
compiler = MiniTest::Mock.new
|
20
|
+
compiler.expect(:stack, stack)
|
21
|
+
compiler.expects(:filter_for_layout).with(layout).returns([ :erb, {} ])
|
22
|
+
@site = MiniTest::Mock.new
|
23
|
+
@site.expect(:compiler, compiler)
|
24
|
+
@site.expect(:layouts, [ layout ])
|
25
|
+
|
26
|
+
# Render
|
27
|
+
assert_equal('This is the /foo/ layout.', render('/foo/'))
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_render_with_unknown_layout
|
31
|
+
# Mock site
|
32
|
+
@site = MiniTest::Mock.new.expect(:layouts, [])
|
33
|
+
|
34
|
+
# Render
|
35
|
+
assert_raises(Nanoc3::Errors::UnknownLayout) do
|
36
|
+
render('/fawgooafwagwfe/')
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_render_without_filter
|
41
|
+
# Mock layouts
|
42
|
+
layout = MiniTest::Mock.new
|
43
|
+
layout.expect(:identifier, '/foo/')
|
44
|
+
layout.expect(:raw_content, 'This is the <%= "foo" %> layout.')
|
45
|
+
|
46
|
+
# Mock compiler
|
47
|
+
compiler = mock
|
48
|
+
compiler.stubs(:filter_for_layout).with(layout).returns(nil)
|
49
|
+
|
50
|
+
# Mock site
|
51
|
+
@site = MiniTest::Mock.new
|
52
|
+
@site.expect(:layouts, [ layout ])
|
53
|
+
@site.expect(:compiler, compiler)
|
54
|
+
|
55
|
+
# Render
|
56
|
+
assert_raises(Nanoc3::Errors::CannotDetermineFilter) do
|
57
|
+
render '/foo/'
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def test_render_with_unknown_filter
|
62
|
+
# Mock layouts
|
63
|
+
layout = MiniTest::Mock.new
|
64
|
+
layout.expect(:identifier, '/foo/')
|
65
|
+
layout.expect(:raw_content, 'This is the <%= "foo" %> layout.')
|
66
|
+
|
67
|
+
# Mock compiler
|
68
|
+
compiler = mock
|
69
|
+
compiler.stubs(:filter_for_layout).with(layout).returns([ :kjsdalfjwagihlawfji, {} ])
|
70
|
+
|
71
|
+
# Mock site
|
72
|
+
@site = MiniTest::Mock.new
|
73
|
+
@site.expect(:layouts, [ layout ])
|
74
|
+
@site.expect(:compiler, compiler)
|
75
|
+
|
76
|
+
# Render
|
77
|
+
assert_raises(Nanoc3::Errors::UnknownFilter) do
|
78
|
+
render '/foo/'
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
def test_render_with_block
|
83
|
+
# Mock layouts
|
84
|
+
layout = MiniTest::Mock.new
|
85
|
+
layout.expect(:identifier, '/foo/')
|
86
|
+
layout.expect(:raw_content, '[partial-before]<%= yield %>[partial-after]')
|
87
|
+
|
88
|
+
# Mock compiler
|
89
|
+
stack = []
|
90
|
+
compiler = mock
|
91
|
+
compiler.stubs(:stack).returns(stack)
|
92
|
+
compiler.expects(:filter_for_layout).with(layout).returns([ :erb, {} ])
|
93
|
+
|
94
|
+
# Mock site
|
95
|
+
@site = MiniTest::Mock.new
|
96
|
+
@site.expect(:compiler, compiler)
|
97
|
+
@site.expect(:layouts, [ layout ])
|
98
|
+
|
99
|
+
# Mock erbout
|
100
|
+
_erbout = '[erbout-before]'
|
101
|
+
|
102
|
+
# Render
|
103
|
+
render '/foo/' do
|
104
|
+
_erbout << "This is some extra content"
|
105
|
+
end
|
106
|
+
assert_equal('[erbout-before][partial-before]This is some extra content[partial-after]', _erbout)
|
107
|
+
end
|
108
|
+
|
109
|
+
end
|
@@ -0,0 +1,89 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'test/helper'
|
4
|
+
|
5
|
+
class Nanoc3::Helpers::TaggingTest < MiniTest::Unit::TestCase
|
6
|
+
|
7
|
+
include Nanoc3::TestHelpers
|
8
|
+
|
9
|
+
include Nanoc3::Helpers::Tagging
|
10
|
+
|
11
|
+
def test_tags_for_without_tags
|
12
|
+
# Create item
|
13
|
+
item = Nanoc3::Item.new('content', {}, '/path/')
|
14
|
+
|
15
|
+
# Check
|
16
|
+
assert_equal(
|
17
|
+
'(none)',
|
18
|
+
tags_for(item)
|
19
|
+
)
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_tags_for_with_custom_base_url
|
23
|
+
# Create item
|
24
|
+
item = Nanoc3::Item.new('content', { :tags => [ 'foo', 'bar' ]}, '/path/')
|
25
|
+
|
26
|
+
# Check
|
27
|
+
assert_equal(
|
28
|
+
"#{link_for_tag('foo', 'http://stoneship.org/tag/')}, " +
|
29
|
+
"#{link_for_tag('bar', 'http://stoneship.org/tag/')}",
|
30
|
+
tags_for(item, :base_url => 'http://stoneship.org/tag/')
|
31
|
+
)
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_tags_for_with_custom_none_text
|
35
|
+
# Create item
|
36
|
+
item = Nanoc3::Item.new('content', { :tags => [ ]}, '/path/')
|
37
|
+
|
38
|
+
# Check
|
39
|
+
assert_equal(
|
40
|
+
'no tags for you, fool',
|
41
|
+
tags_for(item, :none_text => 'no tags for you, fool')
|
42
|
+
)
|
43
|
+
end
|
44
|
+
|
45
|
+
def test_tags_for_with_custom_separator
|
46
|
+
# Create item
|
47
|
+
item = Nanoc3::Item.new('content', { :tags => [ 'foo', 'bar' ]}, '/path/')
|
48
|
+
|
49
|
+
# Check
|
50
|
+
assert_equal(
|
51
|
+
"#{link_for_tag('foo', 'http://technorati.com/tag/')} ++ " +
|
52
|
+
"#{link_for_tag('bar', 'http://technorati.com/tag/')}",
|
53
|
+
tags_for(item, :separator => ' ++ ')
|
54
|
+
)
|
55
|
+
end
|
56
|
+
|
57
|
+
def test_items_with_tag
|
58
|
+
# Create items
|
59
|
+
@items = [
|
60
|
+
Nanoc3::Item.new('item 1', { :tags => [ :foo ] }, '/item1/'),
|
61
|
+
Nanoc3::Item.new('item 2', { :tags => [ :bar ] }, '/item2/'),
|
62
|
+
Nanoc3::Item.new('item 3', { :tags => [ :foo, :bar ] }, '/item3/')
|
63
|
+
]
|
64
|
+
|
65
|
+
# Find items
|
66
|
+
items_with_foo_tag = items_with_tag(:foo)
|
67
|
+
|
68
|
+
# Check
|
69
|
+
assert_equal(
|
70
|
+
[ @items[0], @items[2] ],
|
71
|
+
items_with_foo_tag
|
72
|
+
)
|
73
|
+
end
|
74
|
+
|
75
|
+
def test_link_for_tag
|
76
|
+
assert_equal(
|
77
|
+
%[<a href="http://stoneship.org/tags/foobar" rel="tag">foobar</a>],
|
78
|
+
link_for_tag('foobar', 'http://stoneship.org/tags/')
|
79
|
+
)
|
80
|
+
end
|
81
|
+
|
82
|
+
def test_link_for_tag_escape
|
83
|
+
assert_equal(
|
84
|
+
%[<a href="http://stoneship.org/tags&stuff/foo&bar" rel="tag">foo&bar</a>],
|
85
|
+
link_for_tag('foo&bar', 'http://stoneship.org/tags&stuff/')
|
86
|
+
)
|
87
|
+
end
|
88
|
+
|
89
|
+
end
|