nanoc3 3.2.0a3 → 3.2.0a4
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 +23 -4
- data/README.md +7 -0
- data/lib/nanoc3/base/compilation/checksum_store.rb +17 -90
- data/lib/nanoc3/base/compilation/compiled_content_cache.rb +5 -0
- data/lib/nanoc3/base/compilation/compiler.rb +112 -175
- data/lib/nanoc3/base/compilation/compiler_dsl.rb +54 -11
- data/lib/nanoc3/base/compilation/dependency_tracker.rb +32 -65
- data/lib/nanoc3/base/compilation/filter.rb +4 -3
- data/lib/nanoc3/base/compilation/item_rep_proxy.rb +19 -4
- data/lib/nanoc3/base/compilation/item_rep_recorder_proxy.rb +90 -0
- data/lib/nanoc3/base/compilation/outdatedness_checker.rb +152 -15
- data/lib/nanoc3/base/compilation/outdatedness_reasons.rb +12 -9
- data/lib/nanoc3/base/compilation/rule.rb +3 -1
- data/lib/nanoc3/base/compilation/rule_memory_calculator.rb +42 -0
- data/lib/nanoc3/base/compilation/rule_memory_store.rb +53 -0
- data/lib/nanoc3/base/compilation/rules_collection.rb +205 -0
- data/lib/nanoc3/base/core_ext/array.rb +20 -0
- data/lib/nanoc3/base/core_ext/hash.rb +30 -0
- data/lib/nanoc3/base/core_ext/pathname.rb +26 -0
- data/lib/nanoc3/base/core_ext/string.rb +12 -0
- data/lib/nanoc3/base/core_ext.rb +1 -0
- data/lib/nanoc3/base/directed_graph.rb +11 -3
- data/lib/nanoc3/base/errors.rb +0 -4
- data/lib/nanoc3/base/memoization.rb +72 -0
- data/lib/nanoc3/base/result_data/item_rep.rb +64 -25
- data/lib/nanoc3/base/source_data/code_snippet.rb +9 -0
- data/lib/nanoc3/base/source_data/configuration.rb +20 -0
- data/lib/nanoc3/base/source_data/item.rb +29 -4
- data/lib/nanoc3/base/source_data/layout.rb +20 -1
- data/lib/nanoc3/base/source_data/site.rb +49 -26
- data/lib/nanoc3/base/store.rb +10 -1
- data/lib/nanoc3/base.rb +6 -1
- data/lib/nanoc3/cli/base.rb +20 -7
- data/lib/nanoc3/cli/commands/compile.rb +0 -2
- data/lib/nanoc3/cli/commands/create_site.rb +16 -7
- data/lib/nanoc3/cli/commands/debug.rb +3 -3
- data/lib/nanoc3/cli/commands/view.rb +1 -0
- data/lib/nanoc3/cli/commands/watch.rb +2 -1
- data/lib/nanoc3/data_sources/deprecated/delicious.rb +0 -2
- data/lib/nanoc3/data_sources/deprecated/last_fm.rb +0 -2
- data/lib/nanoc3/data_sources/deprecated/twitter.rb +0 -2
- data/lib/nanoc3/data_sources/filesystem.rb +17 -3
- data/lib/nanoc3/data_sources/filesystem_unified.rb +17 -17
- data/lib/nanoc3/extra/auto_compiler.rb +5 -1
- data/lib/nanoc3/extra/core_ext/time.rb +1 -1
- data/lib/nanoc3/extra/file_proxy.rb +11 -1
- data/lib/nanoc3/extra/validators/links.rb +1 -1
- data/lib/nanoc3/filters/asciidoc.rb +3 -3
- data/lib/nanoc3/filters/colorize_syntax.rb +106 -27
- data/lib/nanoc3/filters/erb.rb +16 -6
- data/lib/nanoc3/filters/erubis.rb +5 -1
- data/lib/nanoc3/filters/haml.rb +2 -1
- data/lib/nanoc3/filters/less.rb +3 -6
- data/lib/nanoc3/filters/mustache.rb +3 -0
- data/lib/nanoc3/filters/redcarpet.rb +27 -0
- data/lib/nanoc3/filters/sass.rb +1 -5
- data/lib/nanoc3/filters/slim.rb +25 -0
- data/lib/nanoc3/filters/typogruby.rb +23 -0
- data/lib/nanoc3/filters.rb +6 -0
- data/lib/nanoc3/helpers/blogging.rb +22 -26
- data/lib/nanoc3/helpers/rendering.rb +1 -1
- data/lib/nanoc3/helpers/xml_sitemap.rb +11 -2
- data/lib/nanoc3.rb +24 -3
- data/nanoc3.gemspec +4 -3
- data/tasks/clean.rake +11 -0
- data/tasks/doc.rake +14 -0
- data/tasks/test.rake +38 -0
- data/test/base/core_ext/array_spec.rb +55 -0
- data/test/base/core_ext/hash_spec.rb +82 -0
- data/test/base/core_ext/pathname_spec.rb +29 -0
- data/test/base/core_ext/string_spec.rb +39 -0
- data/test/base/test_checksum_store.rb +37 -0
- data/test/base/test_code_snippet.rb +33 -0
- data/test/base/test_compiler.rb +303 -0
- data/test/base/test_compiler_dsl.rb +156 -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 +264 -0
- data/test/base/test_directed_graph.rb +285 -0
- data/test/base/test_filter.rb +85 -0
- data/test/base/test_item.rb +164 -0
- data/test/base/test_item_rep.rb +555 -0
- data/test/base/test_layout.rb +44 -0
- data/test/base/test_memoization.rb +53 -0
- data/test/base/test_notification_center.rb +36 -0
- data/test/base/test_outdatedness_checker.rb +365 -0
- data/test/base/test_plugin.rb +32 -0
- data/test/base/test_rule.rb +21 -0
- data/test/base/test_rule_context.rb +67 -0
- data/test/base/test_site.rb +144 -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 +562 -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 +417 -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_asciidoc.rb +22 -0
- data/test/filters/test_bluecloth.rb +20 -0
- data/test/filters/test_coderay.rb +46 -0
- data/test/filters/test_colorize_syntax.rb +149 -0
- data/test/filters/test_erb.rb +101 -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_mustache.rb +27 -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_redcarpet.rb +63 -0
- data/test/filters/test_redcloth.rb +35 -0
- data/test/filters/test_relativize_paths.rb +231 -0
- data/test/filters/test_rubypants.rb +20 -0
- data/test/filters/test_sass.rb +103 -0
- data/test/filters/test_slim.rb +37 -0
- data/test/filters/test_typogruby.rb +23 -0
- data/test/helper.rb +161 -0
- data/test/helpers/test_blogging.rb +756 -0
- data/test/helpers/test_breadcrumbs.rb +83 -0
- data/test/helpers/test_capturing.rb +43 -0
- data/test/helpers/test_filtering.rb +108 -0
- data/test/helpers/test_html_escape.rb +34 -0
- data/test/helpers/test_link_to.rb +251 -0
- data/test/helpers/test_rendering.rb +90 -0
- data/test/helpers/test_tagging.rb +89 -0
- data/test/helpers/test_text.rb +26 -0
- data/test/helpers/test_xml_sitemap.rb +105 -0
- data/test/tasks/test_clean.rb +69 -0
- metadata +96 -27
- data/lib/nanoc3/base/compilation/checksummer.rb +0 -68
@@ -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,43 @@
|
|
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 = Nanoc3::Item.new('moo', {}, '/blah/')
|
21
|
+
result = ::ERB.new(content).result(binding)
|
22
|
+
|
23
|
+
# Check
|
24
|
+
assert_equal '3', content_for(@item, :sidebar).strip
|
25
|
+
assert_equal '3', @item[:content_for_sidebar].strip
|
26
|
+
assert_match(/^head\s+foot$/, result)
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_capture
|
30
|
+
require 'erb'
|
31
|
+
|
32
|
+
# Capture
|
33
|
+
_erbout = 'foo'
|
34
|
+
captured_content = capture do
|
35
|
+
_erbout << 'bar'
|
36
|
+
end
|
37
|
+
|
38
|
+
# Check
|
39
|
+
assert_equal 'foo', _erbout
|
40
|
+
assert_equal 'bar', captured_content
|
41
|
+
end
|
42
|
+
|
43
|
+
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,34 @@
|
|
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_with_string
|
12
|
+
assert_equal('<', html_escape('<'))
|
13
|
+
assert_equal('>', html_escape('>'))
|
14
|
+
assert_equal('&', html_escape('&'))
|
15
|
+
assert_equal('"', html_escape('"'))
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_html_escape_with_block
|
19
|
+
_erbout = 'moo'
|
20
|
+
|
21
|
+
html_escape do
|
22
|
+
_erbout << '<h1>Looks like a header</h1>'
|
23
|
+
end
|
24
|
+
|
25
|
+
assert_equal 'moo<h1>Looks like a header</h1>', _erbout
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_html_escape_without_string_or_block
|
29
|
+
assert_raises RuntimeError do
|
30
|
+
h
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
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,90 @@
|
|
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
|
+
with_site do |site|
|
13
|
+
@site = site
|
14
|
+
|
15
|
+
File.open('Rules', 'w') do |io|
|
16
|
+
io.write("layout '/foo/', :erb\n")
|
17
|
+
end
|
18
|
+
|
19
|
+
File.open('layouts/foo.xyz', 'w') do |io|
|
20
|
+
io.write 'This is the <%= @layout.identifier %> layout.'
|
21
|
+
end
|
22
|
+
|
23
|
+
assert_equal('This is the /foo/ layout.', render('/foo/'))
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_render_with_unknown_layout
|
28
|
+
with_site do |site|
|
29
|
+
@site = site
|
30
|
+
|
31
|
+
assert_raises(Nanoc3::Errors::UnknownLayout) do
|
32
|
+
render '/dsfghjkl/'
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_render_without_filter
|
38
|
+
with_site do |site|
|
39
|
+
@site = site
|
40
|
+
|
41
|
+
File.open('Rules', 'w') do |io|
|
42
|
+
io.write("layout '/foo/', nil\n")
|
43
|
+
end
|
44
|
+
|
45
|
+
File.open('layouts/foo.xyz', 'w')
|
46
|
+
|
47
|
+
assert_raises(Nanoc3::Errors::CannotDetermineFilter) do
|
48
|
+
render '/foo/'
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def test_render_with_unknown_filter
|
54
|
+
with_site do |site|
|
55
|
+
@site = site
|
56
|
+
|
57
|
+
File.open('Rules', 'w') do |io|
|
58
|
+
io.write("layout '/foo/', :asdf\n")
|
59
|
+
end
|
60
|
+
|
61
|
+
File.open('layouts/foo.xyz', 'w')
|
62
|
+
|
63
|
+
assert_raises(Nanoc3::Errors::UnknownFilter) do
|
64
|
+
render '/foo/'
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
def test_render_with_block
|
70
|
+
with_site do |site|
|
71
|
+
@site = site
|
72
|
+
|
73
|
+
File.open('Rules', 'w') do |io|
|
74
|
+
io.write("layout '/foo/', :erb\n")
|
75
|
+
end
|
76
|
+
|
77
|
+
File.open('layouts/foo.xyz', 'w') do |io|
|
78
|
+
io.write '[partial-before]<%= yield %>[partial-after]'
|
79
|
+
end
|
80
|
+
|
81
|
+
_erbout = '[erbout-before]'
|
82
|
+
render '/foo/' do
|
83
|
+
_erbout << "This is some extra content"
|
84
|
+
end
|
85
|
+
|
86
|
+
assert_equal('[erbout-before][partial-before]This is some extra content[partial-after]', _erbout)
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
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
|