nanoc3 3.2.0a4 → 3.2.0b1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (141) hide show
  1. data/NEWS.md +20 -2
  2. data/README.md +7 -3
  3. data/bin/nanoc3 +1 -3
  4. data/lib/nanoc3.rb +1 -13
  5. data/lib/nanoc3/base/compilation/filter.rb +21 -0
  6. data/lib/nanoc3/base/compilation/item_rep_recorder_proxy.rb +1 -3
  7. data/lib/nanoc3/base/compilation/outdatedness_checker.rb +1 -1
  8. data/lib/nanoc3/base/compilation/rule_memory_calculator.rb +0 -2
  9. data/lib/nanoc3/base/compilation/rules_collection.rb +37 -13
  10. data/lib/nanoc3/base/directed_graph.rb +3 -3
  11. data/lib/nanoc3/base/memoization.rb +6 -9
  12. data/lib/nanoc3/base/source_data/code_snippet.rb +2 -1
  13. data/lib/nanoc3/base/source_data/configuration.rb +7 -3
  14. data/lib/nanoc3/base/source_data/item.rb +52 -10
  15. data/lib/nanoc3/base/source_data/layout.rb +28 -1
  16. data/lib/nanoc3/base/source_data/site.rb +14 -3
  17. data/lib/nanoc3/cli.rb +98 -6
  18. data/lib/nanoc3/cli/{base.rb → command.rb} +117 -153
  19. data/lib/nanoc3/cli/commands/autocompile.rb +20 -48
  20. data/lib/nanoc3/cli/commands/compile.rb +32 -48
  21. data/lib/nanoc3/cli/commands/create_item.rb +21 -37
  22. data/lib/nanoc3/cli/commands/create_layout.rb +18 -36
  23. data/lib/nanoc3/cli/commands/create_site.rb +15 -34
  24. data/lib/nanoc3/cli/commands/debug.rb +17 -31
  25. data/lib/nanoc3/cli/commands/info.rb +14 -29
  26. data/lib/nanoc3/cli/commands/nanoc.rb +37 -0
  27. data/lib/nanoc3/cli/commands/update.rb +21 -44
  28. data/lib/nanoc3/cli/commands/view.rb +18 -44
  29. data/lib/nanoc3/cli/commands/watch.rb +16 -31
  30. data/lib/nanoc3/data_sources/filesystem.rb +25 -6
  31. data/lib/nanoc3/data_sources/filesystem_unified.rb +5 -5
  32. data/lib/nanoc3/extra/auto_compiler.rb +1 -0
  33. data/lib/nanoc3/extra/file_proxy.rb +0 -1
  34. data/lib/nanoc3/filters.rb +2 -0
  35. data/lib/nanoc3/filters/asciidoc.rb +16 -36
  36. data/lib/nanoc3/filters/bluecloth.rb +2 -2
  37. data/lib/nanoc3/filters/coderay.rb +2 -2
  38. data/lib/nanoc3/filters/colorize_syntax.rb +18 -5
  39. data/lib/nanoc3/filters/erb.rb +2 -2
  40. data/lib/nanoc3/filters/erubis.rb +2 -2
  41. data/lib/nanoc3/filters/haml.rb +2 -2
  42. data/lib/nanoc3/filters/kramdown.rb +2 -2
  43. data/lib/nanoc3/filters/less.rb +32 -1
  44. data/lib/nanoc3/filters/markaby.rb +2 -2
  45. data/lib/nanoc3/filters/maruku.rb +2 -2
  46. data/lib/nanoc3/filters/mustache.rb +2 -2
  47. data/lib/nanoc3/filters/rainpress.rb +2 -2
  48. data/lib/nanoc3/filters/rdiscount.rb +4 -3
  49. data/lib/nanoc3/filters/rdoc.rb +10 -6
  50. data/lib/nanoc3/filters/redcarpet.rb +2 -2
  51. data/lib/nanoc3/filters/redcloth.rb +2 -2
  52. data/lib/nanoc3/filters/rubypants.rb +2 -2
  53. data/lib/nanoc3/filters/sass.rb +44 -52
  54. data/lib/nanoc3/filters/slim.rb +2 -2
  55. data/lib/nanoc3/filters/typogruby.rb +2 -2
  56. data/lib/nanoc3/filters/uglify_js.rb +42 -0
  57. data/nanoc3.gemspec +1 -1
  58. data/tasks/test.rake +6 -0
  59. data/test/base/core_ext/array_spec.rb +0 -2
  60. data/test/base/core_ext/hash_spec.rb +0 -2
  61. data/test/base/core_ext/pathname_spec.rb +0 -2
  62. data/test/base/core_ext/string_spec.rb +0 -2
  63. data/test/base/test_checksum_store.rb +0 -2
  64. data/test/base/test_code_snippet.rb +0 -2
  65. data/test/base/test_compiler.rb +2 -4
  66. data/test/base/test_compiler_dsl.rb +1 -3
  67. data/test/base/test_context.rb +0 -2
  68. data/test/base/test_data_source.rb +0 -2
  69. data/test/base/test_dependency_tracker.rb +0 -2
  70. data/test/base/test_directed_graph.rb +0 -2
  71. data/test/base/test_filter.rb +0 -2
  72. data/test/base/test_item.rb +19 -4
  73. data/test/base/test_item_rep.rb +0 -2
  74. data/test/base/test_layout.rb +19 -4
  75. data/test/base/test_memoization.rb +39 -2
  76. data/test/base/test_notification_center.rb +0 -2
  77. data/test/base/test_outdatedness_checker.rb +31 -2
  78. data/test/base/test_plugin.rb +0 -2
  79. data/test/base/test_rule.rb +0 -2
  80. data/test/base/test_rule_context.rb +0 -2
  81. data/test/base/test_site.rb +30 -3
  82. data/test/cli/commands/test_compile.rb +24 -3
  83. data/test/cli/commands/test_create_item.rb +5 -3
  84. data/test/cli/commands/test_create_layout.rb +4 -4
  85. data/test/cli/commands/test_create_site.rb +5 -5
  86. data/test/cli/commands/test_help.rb +3 -3
  87. data/test/cli/commands/test_info.rb +2 -3
  88. data/test/cli/commands/test_update.rb +0 -2
  89. data/test/cli/test_cli.rb +40 -0
  90. data/test/cli/test_logger.rb +0 -2
  91. data/test/data_sources/test_filesystem.rb +0 -2
  92. data/test/data_sources/test_filesystem_unified.rb +32 -58
  93. data/test/data_sources/test_filesystem_verbose.rb +0 -2
  94. data/test/extra/core_ext/test_enumerable.rb +0 -2
  95. data/test/extra/core_ext/test_time.rb +0 -2
  96. data/test/extra/deployers/test_rsync.rb +0 -2
  97. data/test/extra/test_auto_compiler.rb +5 -7
  98. data/test/extra/test_file_proxy.rb +0 -2
  99. data/test/extra/test_vcs.rb +0 -2
  100. data/test/extra/validators/test_links.rb +0 -2
  101. data/test/extra/validators/test_w3c.rb +0 -2
  102. data/test/filters/test_asciidoc.rb +0 -2
  103. data/test/filters/test_bluecloth.rb +0 -2
  104. data/test/filters/test_coderay.rb +0 -2
  105. data/test/filters/test_colorize_syntax.rb +49 -2
  106. data/test/filters/test_erb.rb +0 -2
  107. data/test/filters/test_erubis.rb +0 -2
  108. data/test/filters/test_haml.rb +0 -2
  109. data/test/filters/test_kramdown.rb +0 -2
  110. data/test/filters/test_less.rb +59 -5
  111. data/test/filters/test_markaby.rb +0 -2
  112. data/test/filters/test_maruku.rb +0 -2
  113. data/test/filters/test_mustache.rb +0 -2
  114. data/test/filters/test_rainpress.rb +0 -2
  115. data/test/filters/test_rdiscount.rb +0 -2
  116. data/test/filters/test_rdoc.rb +0 -2
  117. data/test/filters/test_redcarpet.rb +0 -2
  118. data/test/filters/test_redcloth.rb +0 -2
  119. data/test/filters/test_relativize_paths.rb +77 -24
  120. data/test/filters/test_rubypants.rb +0 -2
  121. data/test/filters/test_sass.rb +136 -10
  122. data/test/filters/test_slim.rb +0 -2
  123. data/test/filters/test_typogruby.rb +0 -2
  124. data/test/filters/test_uglify_js.rb +30 -0
  125. data/test/gem_loader.rb +11 -0
  126. data/test/helper.rb +3 -0
  127. data/test/helpers/test_blogging.rb +0 -2
  128. data/test/helpers/test_breadcrumbs.rb +0 -2
  129. data/test/helpers/test_capturing.rb +0 -2
  130. data/test/helpers/test_filtering.rb +0 -2
  131. data/test/helpers/test_html_escape.rb +0 -2
  132. data/test/helpers/test_link_to.rb +0 -2
  133. data/test/helpers/test_rendering.rb +0 -2
  134. data/test/helpers/test_tagging.rb +0 -2
  135. data/test/helpers/test_text.rb +0 -2
  136. data/test/helpers/test_xml_sitemap.rb +0 -2
  137. data/test/tasks/test_clean.rb +0 -2
  138. metadata +11 -9
  139. data/lib/nanoc3/cli/commands.rb +0 -16
  140. data/lib/nanoc3/cli/commands/help.rb +0 -71
  141. data/tasks/clean.rake +0 -11
@@ -1,7 +1,5 @@
1
1
  # encoding: utf-8
2
2
 
3
- require 'test/helper'
4
-
5
3
  class Nanoc3::LayoutTest < MiniTest::Unit::TestCase
6
4
 
7
5
  include Nanoc3::TestHelpers
@@ -19,10 +17,14 @@ class Nanoc3::LayoutTest < MiniTest::Unit::TestCase
19
17
  def test_frozen_identifier
20
18
  layout = Nanoc3::Layout.new("foo", {}, '/foo')
21
19
 
22
- error = assert_raises(RuntimeError) do
20
+ raised = false
21
+ begin
23
22
  layout.identifier.chop!
23
+ rescue => error
24
+ raised = true
25
+ assert_equal "can't modify frozen string", error.message
24
26
  end
25
- assert_equal "can't modify frozen string", error.message
27
+ assert raised, 'Should have raised when trying to modify a frozen string'
26
28
  end
27
29
 
28
30
  def test_lookup_with_known_attribute
@@ -41,4 +43,17 @@ class Nanoc3::LayoutTest < MiniTest::Unit::TestCase
41
43
  assert_equal(nil, layout[:filter])
42
44
  end
43
45
 
46
+ def test_dump_and_load
47
+ layout = Nanoc3::Layout.new(
48
+ "foobar",
49
+ { :a => { :b => 123 }},
50
+ '/foo/')
51
+
52
+ layout = Marshal.load(Marshal.dump(layout))
53
+
54
+ assert_equal '/foo/', layout.identifier
55
+ assert_equal 'foobar', layout.raw_content
56
+ assert_equal({ :a => { :b => 123 }}, layout.attributes)
57
+ end
58
+
44
59
  end
@@ -1,7 +1,5 @@
1
1
  # encoding: utf-8
2
2
 
3
- require 'test/helper'
4
-
5
3
  class Nanoc3::MemoizationTest < MiniTest::Unit::TestCase
6
4
 
7
5
  include Nanoc3::TestHelpers
@@ -36,6 +34,33 @@ class Nanoc3::MemoizationTest < MiniTest::Unit::TestCase
36
34
 
37
35
  end
38
36
 
37
+ class EqualSample
38
+
39
+ extend Nanoc3::Memoization
40
+
41
+ def initialize(value)
42
+ @value = value
43
+ end
44
+
45
+ def hash
46
+ 4
47
+ end
48
+
49
+ def eql?(other)
50
+ true
51
+ end
52
+
53
+ def ==(other)
54
+ true
55
+ end
56
+
57
+ def run(n)
58
+ @value*10 + n
59
+ end
60
+ memoize :run
61
+
62
+ end
63
+
39
64
  def test
40
65
  sample1a = Sample1.new(10)
41
66
  sample1b = Sample1.new(15)
@@ -50,4 +75,16 @@ class Nanoc3::MemoizationTest < MiniTest::Unit::TestCase
50
75
  end
51
76
  end
52
77
 
78
+ def test_equal
79
+ sample1 = EqualSample.new(2)
80
+ sample2 = EqualSample.new(3)
81
+
82
+ 3.times do
83
+ assert_equal (2*10+5), sample1.run(5)
84
+ assert_equal (2*10+3), sample1.run(3)
85
+ assert_equal (3*10+5), sample2.run(5)
86
+ assert_equal (3*10+3), sample2.run(3)
87
+ end
88
+ end
89
+
53
90
  end
@@ -1,7 +1,5 @@
1
1
  # encoding: utf-8
2
2
 
3
- require 'test/helper'
4
-
5
3
  class Nanoc3::NotificationCenterTest < MiniTest::Unit::TestCase
6
4
 
7
5
  include Nanoc3::TestHelpers
@@ -1,7 +1,5 @@
1
1
  # encoding: utf-8
2
2
 
3
- require 'test/helper'
4
-
5
3
  class Nanoc3::OutdatednessCheckerTest < MiniTest::Unit::TestCase
6
4
 
7
5
  include Nanoc3::TestHelpers
@@ -362,4 +360,35 @@ class Nanoc3::OutdatednessCheckerTest < MiniTest::Unit::TestCase
362
360
  end
363
361
  end
364
362
 
363
+ def test_items_in_rules_should_not_cause_outdatedness
364
+ # Create site
365
+ with_site(:name => 'foo') do |site|
366
+ File.open('content/index.html', 'w') { |io| io.write('o hello') }
367
+ File.open('Rules', 'w') do |io|
368
+ io.write("compile '/' do\n")
369
+ io.write(" filter :erb, :stuff => @items\n")
370
+ io.write("end\n")
371
+ io.write("\n")
372
+ io.write("route '/' do\n")
373
+ io.write(" '/index.html'\n")
374
+ io.write("end\n")
375
+ end
376
+ end
377
+
378
+ # Compile
379
+ FileUtils.cd('foo') do
380
+ site = Nanoc3::Site.new('.')
381
+ site.compile
382
+ end
383
+
384
+ # Assert not outdated
385
+ FileUtils.cd('foo') do
386
+ site = Nanoc3::Site.new('.')
387
+ outdatedness_checker = site.compiler.outdatedness_checker
388
+ site.items.each do |item|
389
+ refute outdatedness_checker.outdated?(item), "item should not be outdated"
390
+ end
391
+ end
392
+ end
393
+
365
394
  end
@@ -1,7 +1,5 @@
1
1
  # encoding: utf-8
2
2
 
3
- require 'test/helper'
4
-
5
3
  class Nanoc3::PluginTest < MiniTest::Unit::TestCase
6
4
 
7
5
  include Nanoc3::TestHelpers
@@ -1,7 +1,5 @@
1
1
  # encoding: utf-8
2
2
 
3
- require 'test/helper'
4
-
5
3
  class Nanoc3::RuleTest < MiniTest::Unit::TestCase
6
4
 
7
5
  include Nanoc3::TestHelpers
@@ -1,7 +1,5 @@
1
1
  # encoding: utf-8
2
2
 
3
- require 'test/helper'
4
-
5
3
  class Nanoc3::RuleContextTest < MiniTest::Unit::TestCase
6
4
 
7
5
  include Nanoc3::TestHelpers
@@ -1,7 +1,5 @@
1
1
  # encoding: utf-8
2
2
 
3
- require 'test/helper'
4
-
5
3
  class Nanoc3::SiteTest < MiniTest::Unit::TestCase
6
4
 
7
5
  include Nanoc3::TestHelpers
@@ -55,7 +53,7 @@ EOF
55
53
 
56
54
  def test_load_data_sources_first
57
55
  # Create site
58
- Nanoc3::CLI::Base.new.run([ 'create_site', 'bar' ])
56
+ Nanoc3::CLI.run %w( create_site bar)
59
57
 
60
58
  FileUtils.cd('bar') do
61
59
  # Create data source code
@@ -82,6 +80,35 @@ EOF
82
80
  end
83
81
  end
84
82
 
83
+ def test_setup_child_parent_links
84
+ Nanoc3::CLI.run %w( create_site bar)
85
+ FileUtils.cd('bar') do
86
+ Nanoc3::CLI.run %w( create_item /parent/ )
87
+ Nanoc3::CLI.run %w( create_item /parent/foo/ )
88
+ Nanoc3::CLI.run %w( create_item /parent/bar/ )
89
+ Nanoc3::CLI.run %w( create_item /parent/bar/qux/ )
90
+
91
+ site = Nanoc3::Site.new('.')
92
+
93
+ root = site.items.find { |i| i.identifier == '/' }
94
+ style = site.items.find { |i| i.identifier == '/stylesheet/' }
95
+ parent = site.items.find { |i| i.identifier == '/parent/' }
96
+ foo = site.items.find { |i| i.identifier == '/parent/foo/' }
97
+ bar = site.items.find { |i| i.identifier == '/parent/bar/' }
98
+ qux = site.items.find { |i| i.identifier == '/parent/bar/qux/' }
99
+
100
+ assert_equal Set.new([ parent, style ]), Set.new(root.children)
101
+ assert_equal Set.new([ foo, bar ]), Set.new(parent.children)
102
+ assert_equal Set.new([ qux ]), Set.new(bar.children)
103
+
104
+ assert_equal nil, root.parent
105
+ assert_equal root, parent.parent
106
+ assert_equal parent, foo.parent
107
+ assert_equal parent, bar.parent
108
+ assert_equal bar, qux.parent
109
+ end
110
+ end
111
+
85
112
  end
86
113
 
87
114
  describe 'Nanoc3::Site#initialize' do
@@ -1,12 +1,33 @@
1
1
  # encoding: utf-8
2
2
 
3
- require 'test/helper'
4
-
5
3
  class Nanoc3::CLI::Commands::CompileTest < MiniTest::Unit::TestCase
6
4
 
7
5
  include Nanoc3::TestHelpers
8
6
 
9
- def test_stub
7
+ def test_profiling_information
8
+ with_site do |site|
9
+ Nanoc3::CLI.run %w( create_item foo )
10
+ Nanoc3::CLI.run %w( create_item bar )
11
+ Nanoc3::CLI.run %w( create_item baz )
12
+
13
+ File.open('Rules', 'w') do |io|
14
+ io.write "compile '*' do\n"
15
+ io.write " filter :erb\n"
16
+ io.write "end\n"
17
+ io.write "\n"
18
+ io.write "route '*' do\n"
19
+ io.write " if item.binary?\n"
20
+ io.write " item.identifier.chop + '.' + item[:extension]\n"
21
+ io.write " else\n"
22
+ io.write " item.identifier + 'index.html'\n"
23
+ io.write " end\n"
24
+ io.write "end\n"
25
+ io.write "\n"
26
+ io.write "layout '*', :erb\n"
27
+ end
28
+
29
+ Nanoc3::CLI.run %w( compile --verbose )
30
+ end
10
31
  end
11
32
 
12
33
  end
@@ -1,12 +1,14 @@
1
1
  # encoding: utf-8
2
2
 
3
- require 'test/helper'
4
-
5
3
  class Nanoc3::CLI::Commands::CreateItemTest < MiniTest::Unit::TestCase
6
4
 
7
5
  include Nanoc3::TestHelpers
8
6
 
9
- def test_stub
7
+ def test_run
8
+ with_site do |site|
9
+ Nanoc3::CLI.run %w( create_item /blah/ )
10
+ assert File.file?('content/blah.html')
11
+ end
10
12
  end
11
13
 
12
14
  end
@@ -1,17 +1,17 @@
1
1
  # encoding: utf-8
2
2
 
3
- require 'test/helper'
4
-
5
3
  class Nanoc3::CLI::Commands::CreateLayoutTest < MiniTest::Unit::TestCase
6
4
 
7
5
  include Nanoc3::TestHelpers
8
6
 
9
7
  def test_can_compile_new_layout
10
- Nanoc3::CLI::Base.new.run([ 'create_site', 'foo' ])
8
+ require 'nanoc3/cli'
9
+
10
+ Nanoc3::CLI.run %w( create_site foo )
11
11
 
12
12
  FileUtils.cd('foo') do
13
13
  # Create new layout
14
- Nanoc3::CLI::Base.new.run([ 'create_layout', 'moo' ])
14
+ Nanoc3::CLI.run %w( create_layout moo )
15
15
 
16
16
  # Makes rules use new layout
17
17
  rules_raw = File.read('Rules')
@@ -1,18 +1,18 @@
1
1
  # encoding: utf-8
2
2
 
3
- require 'test/helper'
4
-
5
3
  class Nanoc3::CLI::Commands::CreateSiteTest < MiniTest::Unit::TestCase
6
4
 
7
5
  include Nanoc3::TestHelpers
8
6
 
9
7
  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' ]) }
8
+ Nanoc3::CLI.run %w( create_site foo )
9
+ assert_raises(SystemExit) do
10
+ Nanoc3::CLI.run %w( create_site foo )
11
+ end
12
12
  end
13
13
 
14
14
  def test_can_compile_new_site
15
- Nanoc3::CLI::Base.new.run([ 'create_site', 'foo' ])
15
+ Nanoc3::CLI.run %w( create_site foo )
16
16
 
17
17
  FileUtils.cd('foo') do
18
18
  site = Nanoc3::Site.new('.')
@@ -1,12 +1,12 @@
1
1
  # encoding: utf-8
2
2
 
3
- require 'test/helper'
4
-
5
3
  class Nanoc3::CLI::Commands::HelpTest < MiniTest::Unit::TestCase
6
4
 
7
5
  include Nanoc3::TestHelpers
8
6
 
9
- def test_stub
7
+ def test_run
8
+ Nanoc3::CLI.run %w( help )
9
+ Nanoc3::CLI.run %w( help co )
10
10
  end
11
11
 
12
12
  end
@@ -1,12 +1,11 @@
1
1
  # encoding: utf-8
2
2
 
3
- require 'test/helper'
4
-
5
3
  class Nanoc3::CLI::Commands::InfoTest < MiniTest::Unit::TestCase
6
4
 
7
5
  include Nanoc3::TestHelpers
8
6
 
9
- def test_stub
7
+ def test_run
8
+ Nanoc3::CLI.run %w( info )
10
9
  end
11
10
 
12
11
  end
@@ -1,7 +1,5 @@
1
1
  # encoding: utf-8
2
2
 
3
- require 'test/helper'
4
-
5
3
  class Nanoc3::CLI::Commands::UpdateTest < MiniTest::Unit::TestCase
6
4
 
7
5
  include Nanoc3::TestHelpers
@@ -0,0 +1,40 @@
1
+ # encoding: utf-8
2
+
3
+ class Nanoc3::CLITest < MiniTest::Unit::TestCase
4
+
5
+ include Nanoc3::TestHelpers
6
+
7
+ COMMAND_CODE = <<EOS
8
+ # encoding: utf-8
9
+
10
+ usage '_test [options]'
11
+ summary 'meh'
12
+ description 'longer meh'
13
+
14
+ run do |opts, args, cmd|
15
+ File.open('_test.out', 'w') { |io| io.write('It works!') }
16
+ end
17
+ EOS
18
+
19
+ def test_load_custom_commands
20
+ Nanoc3::CLI.run %w( create_site foo )
21
+
22
+ FileUtils.cd('foo') do
23
+ # Create command
24
+ FileUtils.mkdir_p('commands')
25
+ File.open('commands/_test.rb', 'w') { |io| io.write(COMMAND_CODE) }
26
+
27
+ # Run command
28
+ begin
29
+ Nanoc3::CLI.run %w( _test )
30
+ rescue SystemExit
31
+ assert false, 'Running _test should not cause system exit'
32
+ end
33
+
34
+ # Check
35
+ assert File.file?('_test.out')
36
+ assert_equal 'It works!', File.read('_test.out')
37
+ end
38
+ end
39
+
40
+ end
@@ -1,7 +1,5 @@
1
1
  # encoding: utf-8
2
2
 
3
- require 'test/helper'
4
-
5
3
  class Nanoc3::CLI::LoggerTest < MiniTest::Unit::TestCase
6
4
 
7
5
  include Nanoc3::TestHelpers
@@ -1,7 +1,5 @@
1
1
  # encoding: utf-8
2
2
 
3
- require 'test/helper'
4
-
5
3
  class Nanoc3::DataSources::FilesystemTest < MiniTest::Unit::TestCase
6
4
 
7
5
  include Nanoc3::TestHelpers
@@ -1,7 +1,5 @@
1
1
  # encoding: utf-8
2
2
 
3
- require 'test/helper'
4
-
5
3
  class Nanoc3::DataSources::FilesystemUnifiedTest < MiniTest::Unit::TestCase
6
4
 
7
5
  include Nanoc3::TestHelpers
@@ -191,78 +189,54 @@ class Nanoc3::DataSources::FilesystemUnifiedTest < MiniTest::Unit::TestCase
191
189
  end
192
190
 
193
191
  def test_identifier_for_filename_with_subfilename_allowing_periods_in_identifiers
194
- # Create data source
195
- data_source = new_data_source(:allow_periods_in_identifiers => true)
196
-
197
- # Build directory
198
- FileUtils.mkdir_p('foo')
199
- File.open('foo/bar.yaml', 'w') { |io| io.write('test') }
200
- File.open('foo/bar.html', 'w') { |io| io.write('test') }
201
- File.open('foo/quxbar.yaml', 'w') { |io| io.write('test') }
202
- File.open('foo/quxbar.html', 'w') { |io| io.write('test') }
203
- File.open('foo/barqux.yaml', 'w') { |io| io.write('test') }
204
- File.open('foo/barqux.html', 'w') { |io| io.write('test') }
205
- File.open('foo/quxbarqux.yaml', 'w') { |io| io.write('test') }
206
- File.open('foo/quxbarqux.html', 'w') { |io| io.write('test') }
207
- File.open('foo/qux.bar.yaml', 'w') { |io| io.write('test') }
208
- File.open('foo/qux.bar.html', 'w') { |io| io.write('test') }
209
- File.open('foo/bar.qux.yaml', 'w') { |io| io.write('test') }
210
- File.open('foo/bar.qux.html', 'w') { |io| io.write('test') }
211
- File.open('foo/qux.bar.qux.yaml', 'w') { |io| io.write('test') }
212
- File.open('foo/qux.bar.qux.html', 'w') { |io| io.write('test') }
213
-
214
- # Check content filename
215
- {
192
+ expectations = {
216
193
  'foo/bar.yaml' => '/foo/bar/',
217
194
  'foo/quxbar.yaml' => '/foo/quxbar/',
218
195
  'foo/barqux.yaml' => '/foo/barqux/',
219
196
  'foo/quxbarqux.yaml' => '/foo/quxbarqux/',
220
197
  'foo/qux.bar.yaml' => '/foo/qux.bar/',
221
198
  'foo/bar.qux.yaml' => '/foo/bar.qux/',
222
- 'foo/qux.bar.qux.yaml' => '/foo/qux.bar.qux/'
223
- }.each_pair do |meta_filename, expected_identifier|
224
- assert_equal(
225
- expected_identifier,
226
- data_source.instance_eval { identifier_for_filename(meta_filename) }
227
- )
199
+ 'foo/qux.bar.qux.yaml' => '/foo/qux.bar.qux/',
200
+ 'foo/index.yaml' => '/foo/',
201
+ 'index.yaml' => '/',
202
+ 'foo/blah_index.yaml' => '/foo/blah_index/'
203
+ }
204
+
205
+ data_source = new_data_source(:allow_periods_in_identifiers => true)
206
+ expectations.each_pair do |meta_filename, expected_identifier|
207
+ content_filename = meta_filename.sub(/yaml$/, 'html')
208
+ [ meta_filename, content_filename ].each do |filename|
209
+ assert_equal(
210
+ expected_identifier,
211
+ data_source.instance_eval { identifier_for_filename(filename) }
212
+ )
213
+ end
228
214
  end
229
215
  end
230
216
 
231
217
  def test_identifier_for_filename_with_subfilename_disallowing_periods_in_identifiers
232
- # Create data source
233
- data_source = new_data_source
234
-
235
- # Build directory
236
- FileUtils.mkdir_p('foo')
237
- File.open('foo/bar.yaml', 'w') { |io| io.write('test') }
238
- File.open('foo/bar.html', 'w') { |io| io.write('test') }
239
- File.open('foo/quxbar.yaml', 'w') { |io| io.write('test') }
240
- File.open('foo/quxbar.html', 'w') { |io| io.write('test') }
241
- File.open('foo/barqux.yaml', 'w') { |io| io.write('test') }
242
- File.open('foo/barqux.html', 'w') { |io| io.write('test') }
243
- File.open('foo/quxbarqux.yaml', 'w') { |io| io.write('test') }
244
- File.open('foo/quxbarqux.html', 'w') { |io| io.write('test') }
245
- File.open('foo/qux.bar.yaml', 'w') { |io| io.write('test') }
246
- File.open('foo/qux.bar.html', 'w') { |io| io.write('test') }
247
- File.open('foo/bar.qux.yaml', 'w') { |io| io.write('test') }
248
- File.open('foo/bar.qux.html', 'w') { |io| io.write('test') }
249
- File.open('foo/qux.bar.qux.yaml', 'w') { |io| io.write('test') }
250
- File.open('foo/qux.bar.qux.html', 'w') { |io| io.write('test') }
251
-
252
- # Check content filename
253
- {
218
+ expectations = {
254
219
  'foo/bar.yaml' => '/foo/bar/',
255
220
  'foo/quxbar.yaml' => '/foo/quxbar/',
256
221
  'foo/barqux.yaml' => '/foo/barqux/',
257
222
  'foo/quxbarqux.yaml' => '/foo/quxbarqux/',
258
223
  'foo/qux.bar.yaml' => '/foo/qux/',
259
224
  'foo/bar.qux.yaml' => '/foo/bar/',
260
- 'foo/qux.bar.qux.yaml' => '/foo/qux/'
261
- }.each_pair do |meta_filename, expected_identifier|
262
- assert_equal(
263
- expected_identifier,
264
- data_source.instance_eval { identifier_for_filename(meta_filename) }
265
- )
225
+ 'foo/qux.bar.qux.yaml' => '/foo/qux/',
226
+ 'foo/index.yaml' => '/foo/',
227
+ 'index.yaml' => '/',
228
+ 'foo/blah_index.yaml' => '/foo/blah_index/'
229
+ }
230
+
231
+ data_source = new_data_source
232
+ expectations.each_pair do |meta_filename, expected_identifier|
233
+ content_filename = meta_filename.sub(/yaml$/, 'html')
234
+ [ meta_filename, content_filename ].each do |filename|
235
+ assert_equal(
236
+ expected_identifier,
237
+ data_source.instance_eval { identifier_for_filename(filename) }
238
+ )
239
+ end
266
240
  end
267
241
  end
268
242