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,144 @@
1
+ # encoding: utf-8
2
+
3
+ require 'test/helper'
4
+
5
+ class Nanoc3::SiteTest < MiniTest::Unit::TestCase
6
+
7
+ include Nanoc3::TestHelpers
8
+
9
+ def test_initialize_with_dir_without_config_yaml
10
+ assert_raises(Errno::ENOENT) do
11
+ site = Nanoc3::Site.new('.')
12
+ end
13
+ end
14
+
15
+ def test_initialize_with_dir_with_config_yaml
16
+ File.open('config.yaml', 'w') { |io| io.write('output_dir: public_html') }
17
+ site = Nanoc3::Site.new('.')
18
+ assert_equal 'public_html', site.config[:output_dir]
19
+ end
20
+
21
+ def test_initialize_with_config_hash
22
+ site = Nanoc3::Site.new(:foo => 'bar')
23
+ assert_equal 'bar', site.config[:foo]
24
+ end
25
+
26
+ def test_initialize_with_incomplete_data_source_config
27
+ site = Nanoc3::Site.new(:data_sources => [ { :type => 'foo', :items_root => '/bar/' } ])
28
+ assert_equal('foo', site.config[:data_sources][0][:type])
29
+ assert_equal('/bar/', site.config[:data_sources][0][:items_root])
30
+ assert_equal('/', site.config[:data_sources][0][:layouts_root])
31
+ assert_equal({}, site.config[:data_sources][0][:config])
32
+ end
33
+
34
+ def test_load_rules_with_existing_rules_file
35
+ # Mock DSL
36
+ dsl = mock
37
+ dsl.expects(:compile).with('*')
38
+
39
+ # Create site
40
+ site = Nanoc3::Site.new({})
41
+ site.compiler.rules_collection.expects(:dsl).returns(dsl)
42
+
43
+ # Create rules file
44
+ File.open('Rules', 'w') do |io|
45
+ io.write <<-EOF
46
+ compile '*' do
47
+ # ... do nothing ...
48
+ end
49
+ EOF
50
+ end
51
+
52
+ # Load rules
53
+ site.compiler.rules_collection.load
54
+ end
55
+
56
+ def test_load_data_sources_first
57
+ # Create site
58
+ Nanoc3::CLI::Base.new.run([ 'create_site', 'bar' ])
59
+
60
+ FileUtils.cd('bar') do
61
+ # Create data source code
62
+ File.open('lib/some_data_source.rb', 'w') do |io|
63
+ io.write "class FooDataSource < Nanoc3::DataSource\n"
64
+ io.write " identifier :site_test_foo\n"
65
+ io.write " def items ; [ Nanoc3::Item.new('content', {}, '/foo/') ] ; end\n"
66
+ io.write "end\n"
67
+ end
68
+
69
+ # Update configuration
70
+ File.open('config.yaml', 'w') do |io|
71
+ io.write "data_sources:\n"
72
+ io.write " - type: site_test_foo"
73
+ end
74
+
75
+ # Create site
76
+ site = Nanoc3::Site.new('.')
77
+ site.load_data
78
+
79
+ # Check
80
+ assert_equal 1, site.data_sources.size
81
+ assert_equal '/foo/', site.items[0].identifier
82
+ end
83
+ end
84
+
85
+ end
86
+
87
+ describe 'Nanoc3::Site#initialize' do
88
+
89
+ include Nanoc3::TestHelpers
90
+
91
+ it 'should merge default config' do
92
+ site = Nanoc3::Site.new(:foo => 'bar')
93
+ site.config[:foo].must_equal 'bar'
94
+ site.config[:output_dir].must_equal 'output'
95
+ end
96
+
97
+ it 'should not raise under normal circumstances' do
98
+ Nanoc3::Site.new({})
99
+ end
100
+
101
+ it 'should not raise for non-existant output directory' do
102
+ Nanoc3::Site.new(:output_dir => 'fklsdhailfdjalghlkasdflhagjskajdf')
103
+ end
104
+
105
+ it 'should not raise for unknown data sources' do
106
+ proc do
107
+ Nanoc3::Site.new(:data_source => 'fklsdhailfdjalghlkasdflhagjskajdf')
108
+ end
109
+ end
110
+
111
+ end
112
+
113
+ describe 'Nanoc3::Site#compiler' do
114
+
115
+ include Nanoc3::TestHelpers
116
+
117
+ it 'should not raise under normal circumstances' do
118
+ site = Nanoc3::Site.new({})
119
+ site.compiler
120
+ end
121
+
122
+ end
123
+
124
+ describe 'Nanoc3::Site#data_sources' do
125
+
126
+ include Nanoc3::TestHelpers
127
+
128
+ it 'should not raise for known data sources' do
129
+ site = Nanoc3::Site.new({})
130
+ site.data_sources
131
+ end
132
+
133
+ it 'should raise for unknown data sources' do
134
+ proc do
135
+ site = Nanoc3::Site.new(
136
+ :data_sources => [
137
+ { :type => 'fklsdhailfdjalghlkasdflhagjskajdf' }
138
+ ]
139
+ )
140
+ site.data_sources
141
+ end.must_raise Nanoc3::Errors::UnknownDataSource
142
+ end
143
+
144
+ end
@@ -0,0 +1,12 @@
1
+ # encoding: utf-8
2
+
3
+ require 'test/helper'
4
+
5
+ class Nanoc3::CLI::Commands::CompileTest < MiniTest::Unit::TestCase
6
+
7
+ include Nanoc3::TestHelpers
8
+
9
+ def test_stub
10
+ end
11
+
12
+ end
@@ -0,0 +1,12 @@
1
+ # encoding: utf-8
2
+
3
+ require 'test/helper'
4
+
5
+ class Nanoc3::CLI::Commands::CreateItemTest < MiniTest::Unit::TestCase
6
+
7
+ include Nanoc3::TestHelpers
8
+
9
+ def test_stub
10
+ end
11
+
12
+ end
@@ -0,0 +1,28 @@
1
+ # encoding: utf-8
2
+
3
+ require 'test/helper'
4
+
5
+ class Nanoc3::CLI::Commands::CreateLayoutTest < MiniTest::Unit::TestCase
6
+
7
+ include Nanoc3::TestHelpers
8
+
9
+ def test_can_compile_new_layout
10
+ Nanoc3::CLI::Base.new.run([ 'create_site', 'foo' ])
11
+
12
+ FileUtils.cd('foo') do
13
+ # Create new layout
14
+ Nanoc3::CLI::Base.new.run([ 'create_layout', 'moo' ])
15
+
16
+ # Makes rules use new layout
17
+ rules_raw = File.read('Rules')
18
+ File.open('Rules', 'w') do |io|
19
+ io.write rules_raw.sub("layout 'default'", "layout 'moo'")
20
+ end
21
+
22
+ site = Nanoc3::Site.new('.')
23
+ site.load_data
24
+ site.compile
25
+ end
26
+ end
27
+
28
+ end
@@ -0,0 +1,24 @@
1
+ # encoding: utf-8
2
+
3
+ require 'test/helper'
4
+
5
+ class Nanoc3::CLI::Commands::CreateSiteTest < MiniTest::Unit::TestCase
6
+
7
+ include Nanoc3::TestHelpers
8
+
9
+ def test_create_site_with_existing_name
10
+ Nanoc3::CLI::Base.new.run([ 'create_site', 'foo' ])
11
+ assert_raises(SystemExit) { Nanoc3::CLI::Base.new.run([ 'create_site', 'foo' ]) }
12
+ end
13
+
14
+ def test_can_compile_new_site
15
+ Nanoc3::CLI::Base.new.run([ 'create_site', 'foo' ])
16
+
17
+ FileUtils.cd('foo') do
18
+ site = Nanoc3::Site.new('.')
19
+ site.load_data
20
+ site.compile
21
+ end
22
+ end
23
+
24
+ end
@@ -0,0 +1,12 @@
1
+ # encoding: utf-8
2
+
3
+ require 'test/helper'
4
+
5
+ class Nanoc3::CLI::Commands::HelpTest < MiniTest::Unit::TestCase
6
+
7
+ include Nanoc3::TestHelpers
8
+
9
+ def test_stub
10
+ end
11
+
12
+ end
@@ -0,0 +1,12 @@
1
+ # encoding: utf-8
2
+
3
+ require 'test/helper'
4
+
5
+ class Nanoc3::CLI::Commands::InfoTest < MiniTest::Unit::TestCase
6
+
7
+ include Nanoc3::TestHelpers
8
+
9
+ def test_stub
10
+ end
11
+
12
+ end
@@ -0,0 +1,12 @@
1
+ # encoding: utf-8
2
+
3
+ require 'test/helper'
4
+
5
+ class Nanoc3::CLI::Commands::UpdateTest < MiniTest::Unit::TestCase
6
+
7
+ include Nanoc3::TestHelpers
8
+
9
+ def test_stub
10
+ end
11
+
12
+ end
@@ -0,0 +1,12 @@
1
+ # encoding: utf-8
2
+
3
+ require 'test/helper'
4
+
5
+ class Nanoc3::CLI::LoggerTest < MiniTest::Unit::TestCase
6
+
7
+ include Nanoc3::TestHelpers
8
+
9
+ def test_stub
10
+ end
11
+
12
+ end
@@ -0,0 +1,420 @@
1
+ # encoding: utf-8
2
+
3
+ require 'test/helper'
4
+
5
+ class Nanoc3::DataSources::FilesystemTest < MiniTest::Unit::TestCase
6
+
7
+ include Nanoc3::TestHelpers
8
+
9
+ class SampleFilesystemDataSource < Nanoc3::DataSource
10
+ include Nanoc3::DataSources::Filesystem
11
+ end
12
+
13
+ def test_setup
14
+ # Create data source
15
+ data_source = SampleFilesystemDataSource.new(nil, nil, nil, nil)
16
+
17
+ # Remove files to make sure they are recreated
18
+ FileUtils.rm_rf('content')
19
+ FileUtils.rm_rf('layouts/default')
20
+ FileUtils.rm_rf('lib/default.rb')
21
+
22
+ # Mock VCS
23
+ vcs = mock
24
+ vcs.expects(:add).times(3) # One time for each directory
25
+ data_source.vcs = vcs
26
+
27
+ # Recreate files
28
+ data_source.setup
29
+
30
+ # Ensure essential files have been recreated
31
+ assert(File.directory?('content/'))
32
+ assert(File.directory?('layouts/'))
33
+ assert(File.directory?('lib/'))
34
+
35
+ # Ensure no non-essential files have been recreated
36
+ assert(!File.file?('content/index.html'))
37
+ assert(!File.file?('layouts/default.html'))
38
+ assert(!File.file?('lib/default.rb'))
39
+ end
40
+
41
+ def test_items
42
+ # Create data source
43
+ data_source = SampleFilesystemDataSource.new(nil, nil, nil, nil)
44
+
45
+ # Check
46
+ data_source.expects(:load_objects).with('content', 'item', Nanoc3::Item)
47
+ data_source.items
48
+ end
49
+
50
+ def test_layouts
51
+ # Create data source
52
+ data_source = SampleFilesystemDataSource.new(nil, nil, nil, nil)
53
+
54
+ # Check
55
+ data_source.expects(:load_objects).with('layouts', 'layout', Nanoc3::Layout)
56
+ data_source.layouts
57
+ end
58
+
59
+ def test_create_item
60
+ # Create data source
61
+ data_source = SampleFilesystemDataSource.new(nil, nil, nil, nil)
62
+
63
+ # Check
64
+ data_source.expects(:create_object).with('content', 'the content', 'the attributes', 'the identifier', {})
65
+ data_source.create_item('the content', 'the attributes', 'the identifier')
66
+ end
67
+
68
+ def test_create_layout
69
+ # Create data source
70
+ data_source = SampleFilesystemDataSource.new(nil, nil, nil, nil)
71
+
72
+ # Check
73
+ data_source.expects(:create_object).with('layouts', 'the content', 'the attributes', 'the identifier', {})
74
+ data_source.create_layout('the content', 'the attributes', 'the identifier')
75
+ end
76
+
77
+ def test_all_split_files_in_allowing_periods_in_identifiers
78
+ # Create data source
79
+ data_source = Nanoc3::DataSources::FilesystemCompact.new(nil, nil, nil, { :allow_periods_in_identifiers => true })
80
+
81
+ # Write sample files
82
+ FileUtils.mkdir_p('foo')
83
+ %w( foo.html foo.yaml bar.entry.html foo/qux.yaml ).each do |filename|
84
+ File.open(filename, 'w') { |io| io.write('test') }
85
+ end
86
+
87
+ # Write stray files
88
+ %w( foo.html~ foo.yaml.orig bar.entry.html.bak ).each do |filename|
89
+ File.open(filename, 'w') { |io| io.write('test') }
90
+ end
91
+
92
+ # Get all files
93
+ output_expected = {
94
+ './foo' => [ 'yaml', 'html' ],
95
+ './bar.entry' => [ nil, 'html' ],
96
+ './foo/qux' => [ 'yaml', nil ]
97
+ }
98
+ output_actual = data_source.send :all_split_files_in, '.'
99
+
100
+ # Check
101
+ assert_equal output_expected, output_actual
102
+ end
103
+
104
+ def test_all_split_files_in_disallowing_periods_in_identifiers
105
+ # Create data source
106
+ data_source = Nanoc3::DataSources::FilesystemCompact.new(nil, nil, nil, nil)
107
+
108
+ # Write sample files
109
+ FileUtils.mkdir_p('foo')
110
+ %w( foo.html foo.yaml bar.html.erb foo/qux.yaml ).each do |filename|
111
+ File.open(filename, 'w') { |io| io.write('test') }
112
+ end
113
+
114
+ # Write stray files
115
+ %w( foo.html~ foo.yaml.orig bar.entry.html.bak ).each do |filename|
116
+ File.open(filename, 'w') { |io| io.write('test') }
117
+ end
118
+
119
+ # Get all files
120
+ output_expected = {
121
+ './foo' => [ 'yaml', 'html' ],
122
+ './bar' => [ nil, 'html.erb' ],
123
+ './foo/qux' => [ 'yaml', nil ]
124
+ }
125
+ output_actual = data_source.send :all_split_files_in, '.'
126
+
127
+ # Check
128
+ assert_equal output_expected, output_actual
129
+ end
130
+
131
+ def test_all_split_files_in_with_multiple_dirs
132
+ # Create data source
133
+ data_source = Nanoc3::DataSources::FilesystemCompact.new(nil, nil, nil, nil)
134
+
135
+ # Write sample files
136
+ %w( aaa/foo.html bbb/foo.html ccc/foo.html ).each do |filename|
137
+ FileUtils.mkdir_p(File.dirname(filename))
138
+ File.open(filename, 'w') { |io| io.write('test') }
139
+ end
140
+
141
+ # Check
142
+ expected = {
143
+ './aaa/foo' => [ nil, 'html' ],
144
+ './bbb/foo' => [ nil, 'html' ],
145
+ './ccc/foo' => [ nil, 'html' ]
146
+ }
147
+ assert_equal expected, data_source.send(:all_split_files_in, '.')
148
+ end
149
+
150
+ def test_all_split_files_in_with_multiple_content_files
151
+ # Create data source
152
+ data_source = Nanoc3::DataSources::FilesystemCompact.new(nil, nil, nil, nil)
153
+
154
+ # Write sample files
155
+ %w( foo.html foo.xhtml foo.txt foo.yaml bar.html qux.yaml ).each do |filename|
156
+ File.open(filename, 'w') { |io| io.write('test') }
157
+ end
158
+
159
+ # Check
160
+ assert_raises RuntimeError do
161
+ data_source.send(:all_split_files_in, '.')
162
+ end
163
+ end
164
+
165
+ def test_basename_of_allowing_periods_in_identifiers
166
+ # Create data source
167
+ data_source = Nanoc3::DataSources::FilesystemCompact.new(nil, nil, nil, { :allow_periods_in_identifiers => true })
168
+
169
+ # Get input and expected output
170
+ expected = {
171
+ '/' => '/',
172
+ '/foo' => '/foo',
173
+ '/foo.html' => '/foo',
174
+ '/foo.xyz.html' => '/foo.xyz',
175
+ '/foo/' => '/foo/',
176
+ '/foo.xyz/' => '/foo.xyz/',
177
+ '/foo/bar' => '/foo/bar',
178
+ '/foo/bar.html' => '/foo/bar',
179
+ '/foo/bar.xyz.html' => '/foo/bar.xyz',
180
+ '/foo/bar/' => '/foo/bar/',
181
+ '/foo/bar.xyz/' => '/foo/bar.xyz/',
182
+ '/foo.xyz/bar.xyz/' => '/foo.xyz/bar.xyz/'
183
+ }
184
+
185
+ # Check
186
+ expected.each_pair do |input, expected_output|
187
+ actual_output = data_source.send(:basename_of, input)
188
+ assert_equal(
189
+ expected_output, actual_output,
190
+ "basename_of(#{input.inspect}) should equal #{expected_output.inspect}, not #{actual_output.inspect}"
191
+ )
192
+ end
193
+ end
194
+
195
+ def test_basename_of_disallowing_periods_in_identifiers
196
+ # Create data source
197
+ data_source = Nanoc3::DataSources::FilesystemCompact.new(nil, nil, nil, nil)
198
+
199
+ # Get input and expected output
200
+ expected = {
201
+ '/' => '/',
202
+ '/foo' => '/foo',
203
+ '/foo.html' => '/foo',
204
+ '/foo.xyz.html' => '/foo',
205
+ '/foo/' => '/foo/',
206
+ '/foo.xyz/' => '/foo.xyz/',
207
+ '/foo/bar' => '/foo/bar',
208
+ '/foo/bar.html' => '/foo/bar',
209
+ '/foo/bar.xyz.html' => '/foo/bar',
210
+ '/foo/bar/' => '/foo/bar/',
211
+ '/foo/bar.xyz/' => '/foo/bar.xyz/',
212
+ '/foo.xyz/bar.xyz/' => '/foo.xyz/bar.xyz/'
213
+ }
214
+
215
+ # Check
216
+ expected.each_pair do |input, expected_output|
217
+ actual_output = data_source.send(:basename_of, input)
218
+ assert_equal(
219
+ expected_output, actual_output,
220
+ "basename_of(#{input.inspect}) should equal #{expected_output.inspect}, not #{actual_output.inspect}"
221
+ )
222
+ end
223
+ end
224
+
225
+ def test_ext_of_allowing_periods_in_identifiers
226
+ # Create data source
227
+ data_source = Nanoc3::DataSources::FilesystemCompact.new(nil, nil, nil, { :allow_periods_in_identifiers => true })
228
+
229
+ # Get input and expected output
230
+ expected = {
231
+ '/' => '',
232
+ '/foo' => '',
233
+ '/foo.html' => '.html',
234
+ '/foo.xyz.html' => '.html',
235
+ '/foo/' => '',
236
+ '/foo.xyz/' => '',
237
+ '/foo/bar' => '',
238
+ '/foo/bar.html' => '.html',
239
+ '/foo/bar.xyz.html' => '.html',
240
+ '/foo/bar/' => '',
241
+ '/foo/bar.xyz/' => '',
242
+ '/foo.xyz/bar.xyz/' => ''
243
+ }
244
+
245
+ # Check
246
+ expected.each_pair do |input, expected_output|
247
+ actual_output = data_source.send(:ext_of, input)
248
+ assert_equal(
249
+ expected_output, actual_output,
250
+ "basename_of(#{input.inspect}) should equal #{expected_output.inspect}, not #{actual_output.inspect}"
251
+ )
252
+ end
253
+ end
254
+
255
+ def test_ext_of_disallowing_periods_in_identifiers
256
+ # Create data source
257
+ data_source = Nanoc3::DataSources::FilesystemCompact.new(nil, nil, nil, nil)
258
+
259
+ # Get input and expected output
260
+ expected = {
261
+ '/' => '',
262
+ '/foo' => '',
263
+ '/foo.html' => '.html',
264
+ '/foo.xyz.html' => '.xyz.html',
265
+ '/foo/' => '',
266
+ '/foo.xyz/' => '',
267
+ '/foo/bar' => '',
268
+ '/foo/bar.html' => '.html',
269
+ '/foo/bar.xyz.html' => '.xyz.html',
270
+ '/foo/bar/' => '',
271
+ '/foo/bar.xyz/' => '',
272
+ '/foo.xyz/bar.xyz/' => ''
273
+ }
274
+
275
+ # Check
276
+ expected.each_pair do |input, expected_output|
277
+ actual_output = data_source.send(:ext_of, input)
278
+ assert_equal(
279
+ expected_output, actual_output,
280
+ "basename_of(#{input.inspect}) should equal #{expected_output.inspect}, not #{actual_output.inspect}"
281
+ )
282
+ end
283
+ end
284
+
285
+ def test_parse_embedded_invalid_2
286
+ # Create a file
287
+ File.open('test.html', 'w') do |io|
288
+ io.write "-----\n"
289
+ io.write "blah blah\n"
290
+ end
291
+
292
+ # Create data source
293
+ data_source = Nanoc3::DataSources::FilesystemCombined.new(nil, nil, nil, nil)
294
+
295
+ # Parse it
296
+ assert_raises(RuntimeError) do
297
+ data_source.instance_eval { parse('test.html', nil, 'foobar') }
298
+ end
299
+ end
300
+
301
+ def test_parse_embedded_separators_but_not_metadata
302
+ # Create a file
303
+ File.open('test.html', 'w') do |io|
304
+ io.write "blah blah\n"
305
+ io.write "-----\n"
306
+ io.write "blah blah\n"
307
+ end
308
+
309
+ # Create data source
310
+ data_source = Nanoc3::DataSources::FilesystemCombined.new(nil, nil, nil, nil)
311
+
312
+ # Parse it
313
+ result = data_source.instance_eval { parse('test.html', nil, 'foobar') }
314
+ assert_equal(File.read('test.html'), result[1])
315
+ assert_equal({}, result[0])
316
+ end
317
+
318
+ def test_parse_embedded_full_meta
319
+ # Create a file
320
+ File.open('test.html', 'w') do |io|
321
+ io.write "-----\n"
322
+ io.write "foo: bar\n"
323
+ io.write "-----\n"
324
+ io.write "blah blah\n"
325
+ end
326
+
327
+ # Create data source
328
+ data_source = Nanoc3::DataSources::FilesystemCombined.new(nil, nil, nil, nil)
329
+
330
+ # Parse it
331
+ result = data_source.instance_eval { parse('test.html', nil, 'foobar') }
332
+ assert_equal({ 'foo' => 'bar' }, result[0])
333
+ assert_equal('blah blah', result[1])
334
+ end
335
+
336
+ def test_parse_embedded_with_extra_spaces
337
+ # Create a file
338
+ File.open('test.html', 'w') do |io|
339
+ io.write "----- \n"
340
+ io.write "foo: bar\n"
341
+ io.write "-----\t\t\t\t\t\n"
342
+ io.write "blah blah\n"
343
+ end
344
+
345
+ # Create data source
346
+ data_source = Nanoc3::DataSources::FilesystemCombined.new(nil, nil, nil, nil)
347
+
348
+ # Parse it
349
+ result = data_source.instance_eval { parse('test.html', nil, 'foobar') }
350
+ assert_equal({ 'foo' => 'bar' }, result[0])
351
+ assert_equal('blah blah', result[1])
352
+ end
353
+
354
+ def test_parse_embedded_empty_meta
355
+ # Create a file
356
+ File.open('test.html', 'w') do |io|
357
+ io.write "-----\n"
358
+ io.write "-----\n"
359
+ io.write "blah blah\n"
360
+ end
361
+
362
+ # Create data source
363
+ data_source = Nanoc3::DataSources::FilesystemCombined.new(nil, nil, nil, nil)
364
+
365
+ # Parse it
366
+ result = data_source.instance_eval { parse('test.html', nil, 'foobar') }
367
+ assert_equal({}, result[0])
368
+ assert_equal('blah blah', result[1])
369
+ end
370
+
371
+ def test_parse_embedded_no_meta
372
+ content = "blah\n" \
373
+ "blah blah blah\n" \
374
+ "blah blah\n"
375
+
376
+ # Create a file
377
+ File.open('test.html', 'w') { |io| io.write(content) }
378
+
379
+ # Create data source
380
+ data_source = Nanoc3::DataSources::FilesystemCombined.new(nil, nil, nil, nil)
381
+
382
+ # Parse it
383
+ result = data_source.instance_eval { parse('test.html', nil, 'foobar') }
384
+ assert_equal({}, result[0])
385
+ assert_equal(content, result[1])
386
+ end
387
+
388
+ def test_parse_embedded_diff
389
+ content = \
390
+ "--- a/foo\n" \
391
+ "+++ b/foo\n" \
392
+ "blah blah\n"
393
+
394
+ # Create a file
395
+ File.open('test.html', 'w') { |io| io.write(content) }
396
+
397
+ # Create data source
398
+ data_source = Nanoc3::DataSources::FilesystemCombined.new(nil, nil, nil, nil)
399
+
400
+ # Parse it
401
+ result = data_source.instance_eval { parse('test.html', nil, 'foobar') }
402
+ assert_equal({}, result[0])
403
+ assert_equal(content, result[1])
404
+ end
405
+
406
+ def test_parse_external
407
+ # Create a file
408
+ File.open('test.html', 'w') { |io| io.write("blah blah") }
409
+ File.open('test.yaml', 'w') { |io| io.write("foo: bar") }
410
+
411
+ # Create data source
412
+ data_source = Nanoc3::DataSources::FilesystemCombined.new(nil, nil, nil, nil)
413
+
414
+ # Parse it
415
+ result = data_source.instance_eval { parse('test.html', 'test.yaml', 'foobar') }
416
+ assert_equal({ "foo" => "bar"}, result[0])
417
+ assert_equal("blah blah", result[1])
418
+ end
419
+
420
+ end