nanoc 3.2.4 → 3.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gemtest +0 -0
- data/ChangeLog +3 -0
- data/Gemfile +32 -0
- data/LICENSE +19 -0
- data/NEWS.md +470 -0
- data/README.md +114 -0
- data/Rakefile +14 -0
- data/bin/nanoc +7 -27
- data/bin/nanoc3 +3 -0
- data/doc/yardoc_templates/default/layout/html/footer.erb +10 -0
- data/lib/nanoc.rb +41 -0
- data/lib/nanoc/base.rb +49 -0
- data/lib/nanoc/base/compilation/checksum_store.rb +57 -0
- data/lib/nanoc/base/compilation/compiled_content_cache.rb +62 -0
- data/lib/nanoc/base/compilation/compiler.rb +458 -0
- data/lib/nanoc/base/compilation/compiler_dsl.rb +214 -0
- data/lib/nanoc/base/compilation/dependency_tracker.rb +200 -0
- data/lib/nanoc/base/compilation/filter.rb +165 -0
- data/lib/nanoc/base/compilation/item_rep_proxy.rb +103 -0
- data/lib/nanoc/base/compilation/item_rep_recorder_proxy.rb +102 -0
- data/lib/nanoc/base/compilation/outdatedness_checker.rb +223 -0
- data/lib/nanoc/base/compilation/outdatedness_reasons.rb +46 -0
- data/lib/nanoc/base/compilation/rule.rb +73 -0
- data/lib/nanoc/base/compilation/rule_context.rb +84 -0
- data/lib/nanoc/base/compilation/rule_memory_calculator.rb +40 -0
- data/lib/nanoc/base/compilation/rule_memory_store.rb +53 -0
- data/lib/nanoc/base/compilation/rules_collection.rb +243 -0
- data/lib/nanoc/base/context.rb +47 -0
- data/lib/nanoc/base/core_ext.rb +6 -0
- data/lib/nanoc/base/core_ext/array.rb +62 -0
- data/lib/nanoc/base/core_ext/hash.rb +63 -0
- data/lib/nanoc/base/core_ext/pathname.rb +26 -0
- data/lib/nanoc/base/core_ext/string.rb +46 -0
- data/lib/nanoc/base/directed_graph.rb +275 -0
- data/lib/nanoc/base/errors.rb +211 -0
- data/lib/nanoc/base/memoization.rb +67 -0
- data/lib/nanoc/base/notification_center.rb +84 -0
- data/lib/nanoc/base/ordered_hash.rb +200 -0
- data/lib/nanoc/base/plugin_registry.rb +181 -0
- data/lib/nanoc/base/result_data/item_rep.rb +492 -0
- data/lib/nanoc/base/source_data/code_snippet.rb +58 -0
- data/lib/nanoc/base/source_data/configuration.rb +24 -0
- data/lib/nanoc/base/source_data/data_source.rb +234 -0
- data/lib/nanoc/base/source_data/item.rb +301 -0
- data/lib/nanoc/base/source_data/layout.rb +130 -0
- data/lib/nanoc/base/source_data/site.rb +361 -0
- data/lib/nanoc/base/store.rb +135 -0
- data/lib/nanoc/cli.rb +137 -0
- data/lib/nanoc/cli/command_runner.rb +104 -0
- data/lib/nanoc/cli/commands/autocompile.rb +58 -0
- data/lib/nanoc/cli/commands/compile.rb +297 -0
- data/lib/nanoc/cli/commands/create_item.rb +60 -0
- data/lib/nanoc/cli/commands/create_layout.rb +73 -0
- data/lib/nanoc/cli/commands/create_site.rb +411 -0
- data/lib/nanoc/cli/commands/debug.rb +117 -0
- data/lib/nanoc/cli/commands/deploy.rb +79 -0
- data/lib/nanoc/cli/commands/info.rb +98 -0
- data/lib/nanoc/cli/commands/nanoc.rb +38 -0
- data/lib/nanoc/cli/commands/prune.rb +50 -0
- data/lib/nanoc/cli/commands/update.rb +70 -0
- data/lib/nanoc/cli/commands/view.rb +82 -0
- data/lib/nanoc/cli/commands/watch.rb +124 -0
- data/lib/nanoc/cli/error_handler.rb +199 -0
- data/lib/nanoc/cli/logger.rb +92 -0
- data/lib/nanoc/data_sources.rb +29 -0
- data/lib/nanoc/data_sources/deprecated/delicious.rb +42 -0
- data/lib/nanoc/data_sources/deprecated/last_fm.rb +87 -0
- data/lib/nanoc/data_sources/deprecated/twitter.rb +38 -0
- data/lib/nanoc/data_sources/filesystem.rb +299 -0
- data/lib/nanoc/data_sources/filesystem_unified.rb +121 -0
- data/lib/nanoc/data_sources/filesystem_verbose.rb +91 -0
- data/lib/nanoc/extra.rb +24 -0
- data/lib/nanoc/extra/auto_compiler.rb +103 -0
- data/lib/nanoc/extra/chick.rb +125 -0
- data/lib/nanoc/extra/core_ext.rb +6 -0
- data/lib/nanoc/extra/core_ext/enumerable.rb +33 -0
- data/lib/nanoc/extra/core_ext/pathname.rb +30 -0
- data/lib/nanoc/extra/core_ext/time.rb +19 -0
- data/lib/nanoc/extra/deployer.rb +47 -0
- data/lib/nanoc/extra/deployers.rb +15 -0
- data/lib/nanoc/extra/deployers/fog.rb +98 -0
- data/lib/nanoc/extra/deployers/rsync.rb +70 -0
- data/lib/nanoc/extra/file_proxy.rb +40 -0
- data/lib/nanoc/extra/pruner.rb +86 -0
- data/lib/nanoc/extra/validators.rb +12 -0
- data/lib/nanoc/extra/validators/links.rb +268 -0
- data/lib/nanoc/extra/validators/w3c.rb +95 -0
- data/lib/nanoc/extra/vcs.rb +66 -0
- data/lib/nanoc/extra/vcses.rb +17 -0
- data/lib/nanoc/extra/vcses/bazaar.rb +25 -0
- data/lib/nanoc/extra/vcses/dummy.rb +24 -0
- data/lib/nanoc/extra/vcses/git.rb +25 -0
- data/lib/nanoc/extra/vcses/mercurial.rb +25 -0
- data/lib/nanoc/extra/vcses/subversion.rb +25 -0
- data/lib/nanoc/filters.rb +59 -0
- data/lib/nanoc/filters/asciidoc.rb +38 -0
- data/lib/nanoc/filters/bluecloth.rb +19 -0
- data/lib/nanoc/filters/coderay.rb +21 -0
- data/lib/nanoc/filters/coffeescript.rb +20 -0
- data/lib/nanoc/filters/colorize_syntax.rb +298 -0
- data/lib/nanoc/filters/erb.rb +38 -0
- data/lib/nanoc/filters/erubis.rb +34 -0
- data/lib/nanoc/filters/haml.rb +27 -0
- data/lib/nanoc/filters/kramdown.rb +20 -0
- data/lib/nanoc/filters/less.rb +53 -0
- data/lib/nanoc/filters/markaby.rb +20 -0
- data/lib/nanoc/filters/maruku.rb +20 -0
- data/lib/nanoc/filters/mustache.rb +24 -0
- data/lib/nanoc/filters/rainpress.rb +19 -0
- data/lib/nanoc/filters/rdiscount.rb +22 -0
- data/lib/nanoc/filters/rdoc.rb +33 -0
- data/lib/nanoc/filters/redcarpet.rb +62 -0
- data/lib/nanoc/filters/redcloth.rb +47 -0
- data/lib/nanoc/filters/relativize_paths.rb +94 -0
- data/lib/nanoc/filters/rubypants.rb +20 -0
- data/lib/nanoc/filters/sass.rb +74 -0
- data/lib/nanoc/filters/slim.rb +25 -0
- data/lib/nanoc/filters/typogruby.rb +23 -0
- data/lib/nanoc/filters/uglify_js.rb +42 -0
- data/lib/nanoc/filters/xsl.rb +46 -0
- data/lib/nanoc/filters/yui_compressor.rb +23 -0
- data/lib/nanoc/helpers.rb +16 -0
- data/lib/nanoc/helpers/blogging.rb +319 -0
- data/lib/nanoc/helpers/breadcrumbs.rb +40 -0
- data/lib/nanoc/helpers/capturing.rb +138 -0
- data/lib/nanoc/helpers/filtering.rb +50 -0
- data/lib/nanoc/helpers/html_escape.rb +55 -0
- data/lib/nanoc/helpers/link_to.rb +151 -0
- data/lib/nanoc/helpers/rendering.rb +140 -0
- data/lib/nanoc/helpers/tagging.rb +71 -0
- data/lib/nanoc/helpers/text.rb +44 -0
- data/lib/nanoc/helpers/xml_sitemap.rb +76 -0
- data/lib/nanoc/tasks.rb +10 -0
- data/lib/nanoc/tasks/clean.rake +16 -0
- data/lib/nanoc/tasks/clean.rb +29 -0
- data/lib/nanoc/tasks/deploy/rsync.rake +16 -0
- data/lib/nanoc/tasks/validate.rake +92 -0
- data/nanoc.gemspec +49 -0
- data/tasks/doc.rake +16 -0
- data/tasks/test.rake +46 -0
- data/test/base/core_ext/array_spec.rb +73 -0
- data/test/base/core_ext/hash_spec.rb +98 -0
- data/test/base/core_ext/pathname_spec.rb +27 -0
- data/test/base/core_ext/string_spec.rb +37 -0
- data/test/base/test_checksum_store.rb +35 -0
- data/test/base/test_code_snippet.rb +31 -0
- data/test/base/test_compiler.rb +403 -0
- data/test/base/test_compiler_dsl.rb +161 -0
- data/test/base/test_context.rb +31 -0
- data/test/base/test_data_source.rb +46 -0
- data/test/base/test_dependency_tracker.rb +262 -0
- data/test/base/test_directed_graph.rb +288 -0
- data/test/base/test_filter.rb +83 -0
- data/test/base/test_item.rb +179 -0
- data/test/base/test_item_rep.rb +579 -0
- data/test/base/test_layout.rb +59 -0
- data/test/base/test_memoization.rb +90 -0
- data/test/base/test_notification_center.rb +34 -0
- data/test/base/test_outdatedness_checker.rb +394 -0
- data/test/base/test_plugin.rb +30 -0
- data/test/base/test_rule.rb +19 -0
- data/test/base/test_rule_context.rb +65 -0
- data/test/base/test_site.rb +190 -0
- data/test/cli/commands/test_compile.rb +33 -0
- data/test/cli/commands/test_create_item.rb +14 -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_deploy.rb +74 -0
- data/test/cli/commands/test_help.rb +12 -0
- data/test/cli/commands/test_info.rb +11 -0
- data/test/cli/commands/test_prune.rb +98 -0
- data/test/cli/commands/test_update.rb +10 -0
- data/test/cli/test_cli.rb +102 -0
- data/test/cli/test_error_handler.rb +29 -0
- data/test/cli/test_logger.rb +10 -0
- data/test/data_sources/test_filesystem.rb +433 -0
- data/test/data_sources/test_filesystem_unified.rb +536 -0
- data/test/data_sources/test_filesystem_verbose.rb +357 -0
- data/test/extra/core_ext/test_enumerable.rb +30 -0
- data/test/extra/core_ext/test_pathname.rb +17 -0
- data/test/extra/core_ext/test_time.rb +15 -0
- data/test/extra/deployers/test_fog.rb +67 -0
- data/test/extra/deployers/test_rsync.rb +100 -0
- data/test/extra/test_auto_compiler.rb +417 -0
- data/test/extra/test_file_proxy.rb +19 -0
- data/test/extra/test_vcs.rb +22 -0
- data/test/extra/validators/test_links.rb +62 -0
- data/test/extra/validators/test_w3c.rb +47 -0
- data/test/filters/test_asciidoc.rb +22 -0
- data/test/filters/test_bluecloth.rb +18 -0
- data/test/filters/test_coderay.rb +44 -0
- data/test/filters/test_coffeescript.rb +18 -0
- data/test/filters/test_colorize_syntax.rb +379 -0
- data/test/filters/test_erb.rb +105 -0
- data/test/filters/test_erubis.rb +78 -0
- data/test/filters/test_haml.rb +96 -0
- data/test/filters/test_kramdown.rb +18 -0
- data/test/filters/test_less.rb +113 -0
- data/test/filters/test_markaby.rb +24 -0
- data/test/filters/test_maruku.rb +18 -0
- data/test/filters/test_mustache.rb +25 -0
- data/test/filters/test_rainpress.rb +29 -0
- data/test/filters/test_rdiscount.rb +31 -0
- data/test/filters/test_rdoc.rb +18 -0
- data/test/filters/test_redcarpet.rb +73 -0
- data/test/filters/test_redcloth.rb +33 -0
- data/test/filters/test_relativize_paths.rb +533 -0
- data/test/filters/test_rubypants.rb +18 -0
- data/test/filters/test_sass.rb +229 -0
- data/test/filters/test_slim.rb +35 -0
- data/test/filters/test_typogruby.rb +21 -0
- data/test/filters/test_uglify_js.rb +30 -0
- data/test/filters/test_xsl.rb +105 -0
- data/test/filters/test_yui_compressor.rb +44 -0
- data/test/gem_loader.rb +11 -0
- data/test/helper.rb +207 -0
- data/test/helpers/test_blogging.rb +754 -0
- data/test/helpers/test_breadcrumbs.rb +81 -0
- data/test/helpers/test_capturing.rb +41 -0
- data/test/helpers/test_filtering.rb +106 -0
- data/test/helpers/test_html_escape.rb +32 -0
- data/test/helpers/test_link_to.rb +249 -0
- data/test/helpers/test_rendering.rb +89 -0
- data/test/helpers/test_tagging.rb +87 -0
- data/test/helpers/test_text.rb +24 -0
- data/test/helpers/test_xml_sitemap.rb +103 -0
- data/test/tasks/test_clean.rb +67 -0
- metadata +327 -15
- data/bin/nanoc-select +0 -86
- data/lib/nanoc-select.rb +0 -11
@@ -0,0 +1,73 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
describe 'Array#symbolize_keys' do
|
4
|
+
|
5
|
+
it 'should convert keys to symbols' do
|
6
|
+
array_old = [ :abc, 'xyz', { 'foo' => 'bar', :baz => :qux } ]
|
7
|
+
array_new = [ :abc, 'xyz', { :foo => 'bar', :baz => :qux } ]
|
8
|
+
array_old.symbolize_keys.must_equal array_new
|
9
|
+
end
|
10
|
+
|
11
|
+
end
|
12
|
+
|
13
|
+
describe 'Array#stringify_keys' do
|
14
|
+
|
15
|
+
it 'should convert keys to strings' do
|
16
|
+
array_old = [ :abc, 'xyz', { :foo => 'bar', 'baz' => :qux } ]
|
17
|
+
array_new = [ :abc, 'xyz', { 'foo' => 'bar', 'baz' => :qux } ]
|
18
|
+
array_old.stringify_keys.must_equal array_new
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
|
23
|
+
describe 'Array#freeze_recursively' do
|
24
|
+
|
25
|
+
it 'should prevent first-level elements from being modified' do
|
26
|
+
array = [ :a, [ :b, :c ], :d ]
|
27
|
+
array.freeze_recursively
|
28
|
+
|
29
|
+
raised = false
|
30
|
+
begin
|
31
|
+
array[0] = 123
|
32
|
+
rescue => e
|
33
|
+
raised = true
|
34
|
+
assert_match /^can't modify frozen /, e.message
|
35
|
+
end
|
36
|
+
assert raised
|
37
|
+
end
|
38
|
+
|
39
|
+
it 'should prevent second-level elements from being modified' do
|
40
|
+
array = [ :a, [ :b, :c ], :d ]
|
41
|
+
array.freeze_recursively
|
42
|
+
|
43
|
+
raised = false
|
44
|
+
begin
|
45
|
+
array[1][0] = 123
|
46
|
+
rescue => e
|
47
|
+
raised = true
|
48
|
+
assert_match /^can't modify frozen /, e.message
|
49
|
+
end
|
50
|
+
assert raised
|
51
|
+
end
|
52
|
+
|
53
|
+
it 'should not freeze infinitely' do
|
54
|
+
a = []
|
55
|
+
a << a
|
56
|
+
|
57
|
+
a.freeze_recursively
|
58
|
+
|
59
|
+
assert a.frozen?
|
60
|
+
assert a[0].frozen?
|
61
|
+
assert_equal a, a[0]
|
62
|
+
end
|
63
|
+
|
64
|
+
end
|
65
|
+
|
66
|
+
describe 'Array#checksum' do
|
67
|
+
|
68
|
+
it 'should work' do
|
69
|
+
expectation = '78468f950645150238a26f5b8f2dde39a75a7028'
|
70
|
+
[ [ :foo, 123 ]].checksum.must_equal expectation
|
71
|
+
end
|
72
|
+
|
73
|
+
end
|
@@ -0,0 +1,98 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
describe 'Hash#symbolize_keys' do
|
4
|
+
|
5
|
+
it 'should convert keys to symbols' do
|
6
|
+
hash_old = { 'foo' => 'bar' }
|
7
|
+
hash_new = { :foo => 'bar' }
|
8
|
+
hash_old.symbolize_keys.must_equal hash_new
|
9
|
+
end
|
10
|
+
|
11
|
+
end
|
12
|
+
|
13
|
+
describe 'Hash#stringify_keys' do
|
14
|
+
|
15
|
+
it 'should leave strings as strings' do
|
16
|
+
hash_old = { 'foo' => 'bar' }
|
17
|
+
hash_new = { 'foo' => 'bar' }
|
18
|
+
hash_old.stringify_keys.must_equal hash_new
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'should convert symbols to strings' do
|
22
|
+
hash_old = { :foo => 'bar' }
|
23
|
+
hash_new = { 'foo' => 'bar' }
|
24
|
+
hash_old.stringify_keys.must_equal hash_new
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'should convert integers to strings' do
|
28
|
+
hash_old = { 123 => 'bar' }
|
29
|
+
hash_new = { '123' => 'bar' }
|
30
|
+
hash_old.stringify_keys.must_equal hash_new
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'should convert nil to an empty string' do
|
34
|
+
hash_old = { nil => 'bar' }
|
35
|
+
hash_new = { '' => 'bar' }
|
36
|
+
hash_old.stringify_keys.must_equal hash_new
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
|
41
|
+
describe 'Hash#freeze_recursively' do
|
42
|
+
|
43
|
+
it 'should prevent first-level elements from being modified' do
|
44
|
+
hash = { :a => { :b => :c } }
|
45
|
+
hash.freeze_recursively
|
46
|
+
|
47
|
+
raised = false
|
48
|
+
begin
|
49
|
+
hash[:a] = 123
|
50
|
+
rescue => e
|
51
|
+
raised = true
|
52
|
+
assert_match /^can't modify frozen /, e.message
|
53
|
+
end
|
54
|
+
assert raised
|
55
|
+
end
|
56
|
+
|
57
|
+
it 'should prevent second-level elements from being modified' do
|
58
|
+
hash = { :a => { :b => :c } }
|
59
|
+
hash.freeze_recursively
|
60
|
+
|
61
|
+
raised = false
|
62
|
+
begin
|
63
|
+
hash[:a][:b] = 123
|
64
|
+
rescue => e
|
65
|
+
raised = true
|
66
|
+
assert_match /^can't modify frozen /, e.message
|
67
|
+
end
|
68
|
+
assert raised
|
69
|
+
end
|
70
|
+
|
71
|
+
it 'should not freeze infinitely' do
|
72
|
+
a = {}
|
73
|
+
a[:x] = a
|
74
|
+
|
75
|
+
a.freeze_recursively
|
76
|
+
|
77
|
+
assert a.frozen?
|
78
|
+
assert a[:x].frozen?
|
79
|
+
assert_equal a, a[:x]
|
80
|
+
end
|
81
|
+
|
82
|
+
end
|
83
|
+
|
84
|
+
describe 'Hash#checksum' do
|
85
|
+
|
86
|
+
it 'should work' do
|
87
|
+
expectation = '78468f950645150238a26f5b8f2dde39a75a7028'
|
88
|
+
{ :foo => 123 }.checksum.must_equal expectation
|
89
|
+
[ [ :foo, 123 ]].checksum.must_equal expectation
|
90
|
+
end
|
91
|
+
|
92
|
+
it 'should sort keys' do
|
93
|
+
a = { :a => 1, :c => 2, :b => 3 }.checksum
|
94
|
+
b = { :a => 1, :b => 3, :c => 2 }.checksum
|
95
|
+
a.must_equal b
|
96
|
+
end
|
97
|
+
|
98
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
describe 'Pathname#checksum' do
|
4
|
+
|
5
|
+
it 'should work on empty files' do
|
6
|
+
begin
|
7
|
+
FileUtils.mkdir_p('tmp')
|
8
|
+
File.open('tmp/myfile', 'w') { |io| io.write('') }
|
9
|
+
pathname = Pathname.new('tmp/myfile')
|
10
|
+
pathname.checksum.must_equal 'da39a3ee5e6b4b0d3255bfef95601890afd80709'
|
11
|
+
ensure
|
12
|
+
FileUtils.rm_rf('tmp')
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'should work on all files' do
|
17
|
+
begin
|
18
|
+
FileUtils.mkdir_p('tmp')
|
19
|
+
File.open('tmp/myfile', 'w') { |io| io.write('abc') }
|
20
|
+
pathname = Pathname.new('tmp/myfile')
|
21
|
+
pathname.checksum.must_equal 'a9993e364706816aba3e25717850c26c9cd0d89d'
|
22
|
+
ensure
|
23
|
+
FileUtils.rm_rf('tmp')
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
describe 'String#cleaned_identifier' do
|
4
|
+
|
5
|
+
it 'should not convert already clean paths' do
|
6
|
+
'/foo/bar/'.cleaned_identifier.must_equal '/foo/bar/'
|
7
|
+
end
|
8
|
+
|
9
|
+
it 'should prepend slash if necessary' do
|
10
|
+
'foo/bar/'.cleaned_identifier.must_equal '/foo/bar/'
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'should append slash if necessary' do
|
14
|
+
'/foo/bar'.cleaned_identifier.must_equal '/foo/bar/'
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'should remove double slashes at start' do
|
18
|
+
'//foo/bar/'.cleaned_identifier.must_equal '/foo/bar/'
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'should remove double slashes at end' do
|
22
|
+
'/foo/bar//'.cleaned_identifier.must_equal '/foo/bar/'
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
|
27
|
+
describe 'String#checksum' do
|
28
|
+
|
29
|
+
it 'should work on empty strings' do
|
30
|
+
''.checksum.must_equal 'da39a3ee5e6b4b0d3255bfef95601890afd80709'
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'should work on all strings' do
|
34
|
+
'abc'.checksum.must_equal 'a9993e364706816aba3e25717850c26c9cd0d89d'
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
class Nanoc::ChecksumStoreTest < MiniTest::Unit::TestCase
|
4
|
+
|
5
|
+
include Nanoc::TestHelpers
|
6
|
+
|
7
|
+
def test_get_with_existing_object
|
8
|
+
require 'pstore'
|
9
|
+
|
10
|
+
# Create store
|
11
|
+
FileUtils.mkdir_p('tmp')
|
12
|
+
pstore = PStore.new('tmp/checksums')
|
13
|
+
pstore.transaction do
|
14
|
+
pstore[:data] = { [ :item, '/moo/' ] => 'zomg' }
|
15
|
+
pstore[:version] = 1
|
16
|
+
end
|
17
|
+
|
18
|
+
# Check
|
19
|
+
store = Nanoc::ChecksumStore.new
|
20
|
+
store.load
|
21
|
+
obj = Nanoc::Item.new('Moo?', {}, '/moo/')
|
22
|
+
assert_equal 'zomg', store[obj]
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_get_with_nonexistant_object
|
26
|
+
store = Nanoc::ChecksumStore.new
|
27
|
+
store.load
|
28
|
+
|
29
|
+
# Check
|
30
|
+
obj = Nanoc::Item.new('Moo?', {}, '/animals/cow/')
|
31
|
+
new_checksum = 'Moo?'.checksum + '-' + {}.checksum
|
32
|
+
assert_equal nil, store[obj]
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
class Nanoc::CodeSnippetTest < MiniTest::Unit::TestCase
|
4
|
+
|
5
|
+
include Nanoc::TestHelpers
|
6
|
+
|
7
|
+
def test_load
|
8
|
+
# Initialize
|
9
|
+
$complete_insane_parrot = 'meow'
|
10
|
+
|
11
|
+
# Create code and load it
|
12
|
+
code_snippet = Nanoc::CodeSnippet.new("$complete_insane_parrot = 'woof'", 'parrot.rb')
|
13
|
+
code_snippet.load
|
14
|
+
|
15
|
+
# Ensure code is loaded
|
16
|
+
assert_equal('woof', $complete_insane_parrot)
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_load_with_toplevel_binding
|
20
|
+
# Initialize
|
21
|
+
@foo = 'meow'
|
22
|
+
|
23
|
+
# Create code and load it
|
24
|
+
code_snippet = Nanoc::CodeSnippet.new("@foo = 'woof'", 'dog.rb')
|
25
|
+
code_snippet.load
|
26
|
+
|
27
|
+
# Ensure binding is correct
|
28
|
+
assert_equal('meow', @foo)
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
@@ -0,0 +1,403 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
class Nanoc::CompilerTest < MiniTest::Unit::TestCase
|
4
|
+
|
5
|
+
include Nanoc::TestHelpers
|
6
|
+
|
7
|
+
def test_compilation_rule_for
|
8
|
+
# Mock rules
|
9
|
+
rules = [ mock, mock, mock ]
|
10
|
+
rules[0].expects(:applicable_to?).returns(false)
|
11
|
+
rules[1].expects(:applicable_to?).returns(true)
|
12
|
+
rules[1].expects(:rep_name).returns('wrong')
|
13
|
+
rules[2].expects(:applicable_to?).returns(true)
|
14
|
+
rules[2].expects(:rep_name).returns('right')
|
15
|
+
|
16
|
+
# Create compiler
|
17
|
+
compiler = Nanoc::Compiler.new(nil)
|
18
|
+
compiler.rules_collection.instance_eval { @item_compilation_rules = rules }
|
19
|
+
|
20
|
+
# Mock rep
|
21
|
+
rep = mock
|
22
|
+
rep.stubs(:name).returns('right')
|
23
|
+
item = mock
|
24
|
+
rep.stubs(:item).returns(item)
|
25
|
+
|
26
|
+
# Test
|
27
|
+
assert_equal rules[2], compiler.rules_collection.compilation_rule_for(rep)
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_routing_rule_for
|
31
|
+
# Mock rules
|
32
|
+
rules = [ mock, mock, mock ]
|
33
|
+
rules[0].expects(:applicable_to?).returns(false)
|
34
|
+
rules[1].expects(:applicable_to?).returns(true)
|
35
|
+
rules[1].expects(:rep_name).returns('wrong')
|
36
|
+
rules[2].expects(:applicable_to?).returns(true)
|
37
|
+
rules[2].expects(:rep_name).returns('right')
|
38
|
+
|
39
|
+
# Create compiler
|
40
|
+
compiler = Nanoc::Compiler.new(nil)
|
41
|
+
compiler.rules_collection.instance_eval { @item_routing_rules = rules }
|
42
|
+
|
43
|
+
# Mock rep
|
44
|
+
rep = mock
|
45
|
+
rep.stubs(:name).returns('right')
|
46
|
+
item = mock
|
47
|
+
rep.stubs(:item).returns(item)
|
48
|
+
|
49
|
+
# Test
|
50
|
+
assert_equal rules[2], compiler.rules_collection.routing_rule_for(rep)
|
51
|
+
end
|
52
|
+
|
53
|
+
def test_filter_for_layout_with_existant_layout
|
54
|
+
# Mock site
|
55
|
+
site = mock
|
56
|
+
|
57
|
+
# Create compiler
|
58
|
+
compiler = Nanoc::Compiler.new(site)
|
59
|
+
compiler.rules_collection.layout_filter_mapping[/.*/] = [ :erb, { :foo => 'bar' } ]
|
60
|
+
|
61
|
+
# Mock layout
|
62
|
+
layout = MiniTest::Mock.new
|
63
|
+
layout.expect(:identifier, '/some_layout/')
|
64
|
+
|
65
|
+
# Check
|
66
|
+
assert_equal([ :erb, { :foo => 'bar' } ], compiler.rules_collection.filter_for_layout(layout))
|
67
|
+
end
|
68
|
+
|
69
|
+
def test_filter_for_layout_with_existant_layout_and_unknown_filter
|
70
|
+
# Mock site
|
71
|
+
site = mock
|
72
|
+
|
73
|
+
# Create compiler
|
74
|
+
compiler = Nanoc::Compiler.new(site)
|
75
|
+
compiler.rules_collection.layout_filter_mapping[/.*/] = [ :some_unknown_filter, { :foo => 'bar' } ]
|
76
|
+
|
77
|
+
# Mock layout
|
78
|
+
layout = MiniTest::Mock.new
|
79
|
+
layout.expect(:identifier, '/some_layout/')
|
80
|
+
|
81
|
+
# Check
|
82
|
+
assert_equal([ :some_unknown_filter, { :foo => 'bar' } ], compiler.rules_collection.filter_for_layout(layout))
|
83
|
+
end
|
84
|
+
|
85
|
+
def test_filter_for_layout_with_nonexistant_layout
|
86
|
+
# Mock site
|
87
|
+
site = mock
|
88
|
+
|
89
|
+
# Create compiler
|
90
|
+
compiler = Nanoc::Compiler.new(site)
|
91
|
+
compiler.rules_collection.layout_filter_mapping[%r{^/foo/$}] = [ :erb, { :foo => 'bar' } ]
|
92
|
+
|
93
|
+
# Mock layout
|
94
|
+
layout = MiniTest::Mock.new
|
95
|
+
layout.expect(:identifier, '/bar/')
|
96
|
+
|
97
|
+
# Check
|
98
|
+
assert_equal(nil, compiler.rules_collection.filter_for_layout(layout))
|
99
|
+
end
|
100
|
+
|
101
|
+
def test_filter_for_layout_with_many_layouts
|
102
|
+
# Mock site
|
103
|
+
site = mock
|
104
|
+
|
105
|
+
# Create compiler
|
106
|
+
compiler = Nanoc::Compiler.new(site)
|
107
|
+
compiler.rules_collection.layout_filter_mapping[%r{^/a/b/c/.*/$}] = [ :erb, { :char => 'd' } ]
|
108
|
+
compiler.rules_collection.layout_filter_mapping[%r{^/a/.*/$}] = [ :erb, { :char => 'b' } ]
|
109
|
+
compiler.rules_collection.layout_filter_mapping[%r{^/a/b/.*/$}] = [ :erb, { :char => 'c' } ] # never used!
|
110
|
+
compiler.rules_collection.layout_filter_mapping[%r{^/.*/$}] = [ :erb, { :char => 'a' } ]
|
111
|
+
|
112
|
+
# Mock layout
|
113
|
+
layouts = [ mock, mock, mock, mock ]
|
114
|
+
layouts[0].stubs(:identifier).returns('/a/b/c/d/')
|
115
|
+
layouts[1].stubs(:identifier).returns('/a/b/c/')
|
116
|
+
layouts[2].stubs(:identifier).returns('/a/b/')
|
117
|
+
layouts[3].stubs(:identifier).returns('/a/')
|
118
|
+
|
119
|
+
# Get expectations
|
120
|
+
expectations = {
|
121
|
+
0 => 'd',
|
122
|
+
1 => 'b', # never used! not c, because b takes priority
|
123
|
+
2 => 'b',
|
124
|
+
3 => 'a'
|
125
|
+
}
|
126
|
+
|
127
|
+
# Check
|
128
|
+
expectations.each_pair do |num, char|
|
129
|
+
filter_and_args = compiler.rules_collection.filter_for_layout(layouts[num])
|
130
|
+
refute_nil(filter_and_args)
|
131
|
+
assert_equal(char, filter_and_args[1][:char])
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
def test_compile_rep_should_write_proper_snapshots
|
136
|
+
# Mock rep
|
137
|
+
item = Nanoc::Item.new('<%= 1 %> <%%= 2 %> <%%%= 3 %>', {}, '/moo/')
|
138
|
+
rep = Nanoc::ItemRep.new(item, :blah)
|
139
|
+
|
140
|
+
# Set snapshot filenames
|
141
|
+
rep.raw_paths = {
|
142
|
+
:raw => 'raw.txt',
|
143
|
+
:pre => 'pre.txt',
|
144
|
+
:post => 'post.txt',
|
145
|
+
:last => 'last.txt'
|
146
|
+
}
|
147
|
+
|
148
|
+
# Create rule
|
149
|
+
rule_block = proc do
|
150
|
+
filter :erb
|
151
|
+
filter :erb
|
152
|
+
layout '/blah/'
|
153
|
+
filter :erb
|
154
|
+
end
|
155
|
+
rule = Nanoc::Rule.new(/blah/, :meh, rule_block)
|
156
|
+
|
157
|
+
# Create layout
|
158
|
+
layout = Nanoc::Layout.new('head <%= yield %> foot', {}, '/blah/')
|
159
|
+
|
160
|
+
# Create site
|
161
|
+
site = mock
|
162
|
+
site.stubs(:config).returns({})
|
163
|
+
site.stubs(:items).returns([])
|
164
|
+
site.stubs(:layouts).returns([ layout ])
|
165
|
+
|
166
|
+
# Create compiler
|
167
|
+
compiler = Nanoc::Compiler.new(site)
|
168
|
+
compiler.rules_collection.expects(:compilation_rule_for).times(2).with(rep).returns(rule)
|
169
|
+
compiler.rules_collection.layout_filter_mapping[%r{^/blah/$}] = [ :erb, {} ]
|
170
|
+
site.stubs(:compiler).returns(compiler)
|
171
|
+
|
172
|
+
# Compile
|
173
|
+
compiler.send(:compile_rep, rep)
|
174
|
+
|
175
|
+
# Test
|
176
|
+
assert File.file?('raw.txt')
|
177
|
+
assert File.file?('pre.txt')
|
178
|
+
assert File.file?('post.txt')
|
179
|
+
assert File.file?('last.txt')
|
180
|
+
assert_equal '<%= 1 %> <%%= 2 %> <%%%= 3 %>', File.read('raw.txt')
|
181
|
+
assert_equal '1 2 <%= 3 %>', File.read('pre.txt')
|
182
|
+
assert_equal 'head 1 2 3 foot', File.read('post.txt')
|
183
|
+
assert_equal 'head 1 2 3 foot', File.read('last.txt')
|
184
|
+
end
|
185
|
+
|
186
|
+
def test_compile_with_no_reps
|
187
|
+
with_site do |site|
|
188
|
+
site.compile
|
189
|
+
|
190
|
+
assert Dir['output/*'].empty?
|
191
|
+
end
|
192
|
+
end
|
193
|
+
|
194
|
+
def test_compile_with_one_rep
|
195
|
+
with_site do |site|
|
196
|
+
File.open('content/index.html', 'w') { |io| io.write('o hello') }
|
197
|
+
|
198
|
+
site.compile
|
199
|
+
|
200
|
+
assert Dir['output/*'].size == 1
|
201
|
+
assert File.file?('output/index.html')
|
202
|
+
assert File.read('output/index.html') == 'o hello'
|
203
|
+
end
|
204
|
+
end
|
205
|
+
|
206
|
+
def test_compile_with_two_independent_reps
|
207
|
+
with_site do |site|
|
208
|
+
File.open('content/foo.html', 'w') { |io| io.write('o hai') }
|
209
|
+
File.open('content/bar.html', 'w') { |io| io.write('o bai') }
|
210
|
+
|
211
|
+
site.compile
|
212
|
+
|
213
|
+
assert Dir['output/*'].size == 2
|
214
|
+
assert File.file?('output/foo/index.html')
|
215
|
+
assert File.file?('output/bar/index.html')
|
216
|
+
assert File.read('output/foo/index.html') == 'o hai'
|
217
|
+
assert File.read('output/bar/index.html') == 'o bai'
|
218
|
+
end
|
219
|
+
end
|
220
|
+
|
221
|
+
def test_compile_with_two_dependent_reps
|
222
|
+
with_site(:compilation_rule_content => 'filter :erb') do |site|
|
223
|
+
File.open('content/foo.html', 'w') do |io|
|
224
|
+
io.write('<%= @items.find { |i| i.identifier == "/bar/" }.compiled_content %>!!!')
|
225
|
+
end
|
226
|
+
File.open('content/bar.html', 'w') do |io|
|
227
|
+
io.write('manatee')
|
228
|
+
end
|
229
|
+
|
230
|
+
site.compile
|
231
|
+
|
232
|
+
assert Dir['output/*'].size == 2
|
233
|
+
assert File.file?('output/foo/index.html')
|
234
|
+
assert File.file?('output/bar/index.html')
|
235
|
+
assert File.read('output/foo/index.html') == 'manatee!!!'
|
236
|
+
assert File.read('output/bar/index.html') == 'manatee'
|
237
|
+
end
|
238
|
+
end
|
239
|
+
|
240
|
+
def test_compile_with_two_mutually_dependent_reps
|
241
|
+
with_site(:compilation_rule_content => 'filter :erb') do |site|
|
242
|
+
File.open('content/foo.html', 'w') do |io|
|
243
|
+
io.write('<%= @items.find { |i| i.identifier == "/bar/" }.compiled_content %>')
|
244
|
+
end
|
245
|
+
File.open('content/bar.html', 'w') do |io|
|
246
|
+
io.write('<%= @items.find { |i| i.identifier == "/foo/" }.compiled_content %>')
|
247
|
+
end
|
248
|
+
|
249
|
+
assert_raises Nanoc::Errors::RecursiveCompilation do
|
250
|
+
site.compile
|
251
|
+
end
|
252
|
+
end
|
253
|
+
end
|
254
|
+
|
255
|
+
def test_disallow_routes_not_starting_with_slash
|
256
|
+
# Create site
|
257
|
+
Nanoc::CLI.run %w( create_site bar)
|
258
|
+
|
259
|
+
FileUtils.cd('bar') do
|
260
|
+
# Create routes
|
261
|
+
File.open('Rules', 'w') do |io|
|
262
|
+
io.write "compile '*' do\n"
|
263
|
+
io.write " layout 'default'\n"
|
264
|
+
io.write "end\n"
|
265
|
+
io.write "\n"
|
266
|
+
io.write "route '*' do\n"
|
267
|
+
io.write " 'index.html'\n"
|
268
|
+
io.write "end\n"
|
269
|
+
io.write "\n"
|
270
|
+
io.write "layout '*', :erb\n"
|
271
|
+
end
|
272
|
+
|
273
|
+
# Create site
|
274
|
+
site = Nanoc::Site.new('.')
|
275
|
+
error = assert_raises(RuntimeError) do
|
276
|
+
site.compile
|
277
|
+
end
|
278
|
+
assert_match /^The path returned for the.*does not start with a slash. Please ensure that all routing rules return a path that starts with a slash./, error.message
|
279
|
+
end
|
280
|
+
end
|
281
|
+
|
282
|
+
def test_load_should_be_idempotent
|
283
|
+
# Create site
|
284
|
+
Nanoc::CLI.run %w( create_site bar)
|
285
|
+
|
286
|
+
FileUtils.cd('bar') do
|
287
|
+
site = Nanoc::Site.new('.')
|
288
|
+
|
289
|
+
compiler = Nanoc::Compiler.new(site)
|
290
|
+
def compiler.route_reps
|
291
|
+
raise 'oh my gosh it is borken'
|
292
|
+
end
|
293
|
+
|
294
|
+
assert site.instance_eval { !@loaded }
|
295
|
+
assert_raises(RuntimeError) { compiler.load }
|
296
|
+
assert site.instance_eval { !@loaded }
|
297
|
+
assert_raises(RuntimeError) { compiler.load }
|
298
|
+
end
|
299
|
+
end
|
300
|
+
|
301
|
+
def test_compile_should_recompile_all_reps
|
302
|
+
Nanoc::CLI.run %w( create_site bar )
|
303
|
+
|
304
|
+
FileUtils.cd('bar') do
|
305
|
+
Nanoc::CLI.run %w( compile )
|
306
|
+
|
307
|
+
site = Nanoc::Site.new('.')
|
308
|
+
site.compile
|
309
|
+
|
310
|
+
# At this point, even the already compiled items in the previous pass
|
311
|
+
# should have their compiled content assigned, so this should work:
|
312
|
+
site.items[0].reps[0].compiled_content
|
313
|
+
end
|
314
|
+
end
|
315
|
+
|
316
|
+
def test_disallow_multiple_snapshots_with_the_same_name
|
317
|
+
# Create site
|
318
|
+
Nanoc::CLI.run %w( create_site bar )
|
319
|
+
|
320
|
+
FileUtils.cd('bar') do
|
321
|
+
# Create routes
|
322
|
+
File.open('Rules', 'w') do |io|
|
323
|
+
io.write "compile '*' do\n"
|
324
|
+
io.write " snapshot :aaa\n"
|
325
|
+
io.write " snapshot :aaa\n"
|
326
|
+
io.write "end\n"
|
327
|
+
io.write "\n"
|
328
|
+
io.write "route '*' do\n"
|
329
|
+
io.write " '/index.html'\n"
|
330
|
+
io.write "end\n"
|
331
|
+
io.write "\n"
|
332
|
+
io.write "layout '*', :erb\n"
|
333
|
+
end
|
334
|
+
|
335
|
+
# Compile
|
336
|
+
site = Nanoc::Site.new('.')
|
337
|
+
assert_raises Nanoc::Errors::CannotCreateMultipleSnapshotsWithSameName do
|
338
|
+
site.compile
|
339
|
+
end
|
340
|
+
end
|
341
|
+
end
|
342
|
+
|
343
|
+
def test_include_compiled_content_of_active_item_at_previous_snapshot
|
344
|
+
with_site do |site|
|
345
|
+
# Create item
|
346
|
+
File.open('content/index.html', 'w') do |io|
|
347
|
+
io.write('[<%= @item.compiled_content(:snapshot => :aaa) %>]')
|
348
|
+
end
|
349
|
+
|
350
|
+
# Create routes
|
351
|
+
File.open('Rules', 'w') do |io|
|
352
|
+
io.write "compile '*' do\n"
|
353
|
+
io.write " snapshot :aaa\n"
|
354
|
+
io.write " filter :erb\n"
|
355
|
+
io.write " filter :erb\n"
|
356
|
+
io.write "end\n"
|
357
|
+
io.write "\n"
|
358
|
+
io.write "route '*' do\n"
|
359
|
+
io.write " '/index.html'\n"
|
360
|
+
io.write "end\n"
|
361
|
+
io.write "\n"
|
362
|
+
io.write "layout '*', :erb\n"
|
363
|
+
end
|
364
|
+
|
365
|
+
# Compile
|
366
|
+
site = Nanoc::Site.new('.')
|
367
|
+
site.compile
|
368
|
+
|
369
|
+
# Check
|
370
|
+
assert_equal '[[[<%= @item.compiled_content(:snapshot => :aaa) %>]]]', File.read('output/index.html')
|
371
|
+
end
|
372
|
+
end
|
373
|
+
|
374
|
+
def test_layout_with_extra_filter_args
|
375
|
+
with_site do |site|
|
376
|
+
# Create item
|
377
|
+
File.open('content/index.html', 'w') do |io|
|
378
|
+
io.write('This is <%= @foo %>.')
|
379
|
+
end
|
380
|
+
|
381
|
+
# Create routes
|
382
|
+
File.open('Rules', 'w') do |io|
|
383
|
+
io.write "compile '*' do\n"
|
384
|
+
io.write " filter :erb, :locals => { :foo => 123 }\n"
|
385
|
+
io.write "end\n"
|
386
|
+
io.write "\n"
|
387
|
+
io.write "route '*' do\n"
|
388
|
+
io.write " '/index.html'\n"
|
389
|
+
io.write "end\n"
|
390
|
+
io.write "\n"
|
391
|
+
io.write "layout '*', :erb\n"
|
392
|
+
end
|
393
|
+
|
394
|
+
# Compile
|
395
|
+
site = Nanoc::Site.new('.')
|
396
|
+
site.compile
|
397
|
+
|
398
|
+
# Check
|
399
|
+
assert_equal 'This is 123.', File.read('output/index.html')
|
400
|
+
end
|
401
|
+
end
|
402
|
+
|
403
|
+
end
|