nanoc 4.0.0a1 → 4.0.0a2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (52) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile.lock +9 -4
  3. data/NEWS.md +13 -0
  4. data/lib/nanoc/base.rb +2 -0
  5. data/lib/nanoc/base/compilation/compiler.rb +0 -1
  6. data/lib/nanoc/base/compilation/compiler_dsl.rb +21 -7
  7. data/lib/nanoc/base/compilation/item_rep_proxy.rb +10 -1
  8. data/lib/nanoc/base/compilation/rule.rb +10 -12
  9. data/lib/nanoc/base/compilation/rules_collection.rb +2 -2
  10. data/lib/nanoc/base/pattern.rb +63 -0
  11. data/lib/nanoc/base/source_data/data_source.rb +33 -18
  12. data/lib/nanoc/base/source_data/identifier.rb +65 -3
  13. data/lib/nanoc/base/source_data/item.rb +1 -1
  14. data/lib/nanoc/base/source_data/item_array.rb +17 -2
  15. data/lib/nanoc/base/source_data/layout.rb +1 -1
  16. data/lib/nanoc/base/source_data/site.rb +4 -3
  17. data/lib/nanoc/base/views/config.rb +22 -0
  18. data/lib/nanoc/base/views/item.rb +76 -0
  19. data/lib/nanoc/base/views/item_collection.rb +46 -4
  20. data/lib/nanoc/base/views/item_rep.rb +23 -0
  21. data/lib/nanoc/base/views/layout.rb +4 -0
  22. data/lib/nanoc/base/views/layout_collection.rb +7 -1
  23. data/lib/nanoc/base/views/mutable_config.rb +5 -0
  24. data/lib/nanoc/base/views/mutable_item.rb +15 -0
  25. data/lib/nanoc/base/views/mutable_item_collection.rb +25 -0
  26. data/lib/nanoc/base/views/mutable_layout.rb +5 -0
  27. data/lib/nanoc/base/views/mutable_layout_collection.rb +20 -2
  28. data/lib/nanoc/cli/cleaning_stream.rb +15 -0
  29. data/lib/nanoc/cli/commands/create-site.rb +17 -35
  30. data/lib/nanoc/cli/commands/shell.rb +7 -4
  31. data/lib/nanoc/data_sources.rb +0 -1
  32. data/lib/nanoc/data_sources/filesystem.rb +75 -76
  33. data/lib/nanoc/data_sources/filesystem_unified.rb +4 -27
  34. data/lib/nanoc/data_sources/filesystem_verbose.rb +4 -21
  35. data/lib/nanoc/version.rb +1 -1
  36. data/nanoc.gemspec +1 -1
  37. data/test/base/test_compiler.rb +35 -15
  38. data/test/base/test_compiler_dsl.rb +32 -30
  39. data/test/base/test_data_source.rb +2 -2
  40. data/test/base/test_item_array.rb +10 -1
  41. data/test/base/test_rule.rb +2 -2
  42. data/test/base/test_site.rb +32 -0
  43. data/test/cli/commands/test_create_site.rb +7 -1
  44. data/test/cli/commands/test_prune.rb +2 -2
  45. data/test/data_sources/test_filesystem.rb +29 -9
  46. data/test/data_sources/test_filesystem_unified.rb +48 -68
  47. data/test/helper.rb +1 -0
  48. data/test/helpers/test_breadcrumbs.rb +4 -4
  49. data/test/test_gem.rb +0 -1
  50. metadata +4 -5
  51. data/lib/nanoc/data_sources/static.rb +0 -62
  52. data/test/data_sources/test_static.rb +0 -93
@@ -45,27 +45,6 @@ module Nanoc::DataSources
45
45
 
46
46
  private
47
47
 
48
- # See {Nanoc::DataSources::Filesystem#create_object}.
49
- def create_object(dir_name, content, attributes, identifier, params = {})
50
- # Determine base path
51
- last_component = identifier.split('/')[-1] || dir_name
52
-
53
- # Get filenames
54
- ext = params[:extension] || '.html'
55
- dir_path = dir_name + identifier
56
- meta_filename = dir_name + identifier + last_component + '.yaml'
57
- content_filename = dir_name + identifier + last_component + ext
58
-
59
- # Notify
60
- Nanoc::Int::NotificationCenter.post(:file_created, meta_filename)
61
- Nanoc::Int::NotificationCenter.post(:file_created, content_filename)
62
-
63
- # Create files
64
- FileUtils.mkdir_p(dir_path)
65
- File.open(meta_filename, 'w') { |io| io.write(YAML.dump(attributes.__nanoc_stringify_keys_recursively)) }
66
- File.open(content_filename, 'w') { |io| io.write(content) }
67
- end
68
-
69
48
  # See {Nanoc::DataSources::Filesystem#filename_for}.
70
49
  def filename_for(base_filename, ext)
71
50
  return nil if ext.nil?
@@ -82,6 +61,10 @@ module Nanoc::DataSources
82
61
 
83
62
  # See {Nanoc::DataSources::Filesystem#identifier_for_filename}.
84
63
  def identifier_for_filename(filename)
64
+ if config[:identifier_style] == 'full'
65
+ return Nanoc::Identifier.new(filename, style: :full)
66
+ end
67
+
85
68
  filename.sub(/[^\/]+\.yaml$/, '')
86
69
  end
87
70
  end
@@ -2,5 +2,5 @@
2
2
 
3
3
  module Nanoc
4
4
  # The current nanoc version.
5
- VERSION = '4.0.0a1'
5
+ VERSION = '4.0.0a2'
6
6
  end
@@ -25,7 +25,7 @@ Gem::Specification.new do |s|
25
25
  s.rdoc_options = ['--main', 'README.md']
26
26
  s.extra_rdoc_files = ['ChangeLog', 'LICENSE', 'README.md', 'NEWS.md']
27
27
 
28
- s.required_ruby_version = '>= 1.9.3'
28
+ s.required_ruby_version = '>= 2.0.0'
29
29
 
30
30
  s.add_runtime_dependency('cri', '~> 2.3')
31
31
 
@@ -53,7 +53,7 @@ class Nanoc::Int::CompilerTest < Nanoc::TestCase
53
53
 
54
54
  # Create compiler
55
55
  compiler = Nanoc::Int::Compiler.new(site)
56
- compiler.rules_collection.layout_filter_mapping[/.*/] = [:erb, { foo: 'bar' }]
56
+ compiler.rules_collection.layout_filter_mapping[Nanoc::Int::Pattern.from(/.*/)] = [:erb, { foo: 'bar' }]
57
57
 
58
58
  # Mock layout
59
59
  layout = MiniTest::Mock.new
@@ -69,7 +69,7 @@ class Nanoc::Int::CompilerTest < Nanoc::TestCase
69
69
 
70
70
  # Create compiler
71
71
  compiler = Nanoc::Int::Compiler.new(site)
72
- compiler.rules_collection.layout_filter_mapping[/.*/] = [:some_unknown_filter, { foo: 'bar' }]
72
+ compiler.rules_collection.layout_filter_mapping[Nanoc::Int::Pattern.from(/.*/)] = [:some_unknown_filter, { foo: 'bar' }]
73
73
 
74
74
  # Mock layout
75
75
  layout = MiniTest::Mock.new
@@ -85,7 +85,7 @@ class Nanoc::Int::CompilerTest < Nanoc::TestCase
85
85
 
86
86
  # Create compiler
87
87
  compiler = Nanoc::Int::Compiler.new(site)
88
- compiler.rules_collection.layout_filter_mapping[%r{^/foo/$}] = [:erb, { foo: 'bar' }]
88
+ compiler.rules_collection.layout_filter_mapping[Nanoc::Int::Pattern.from(%r{^/foo/$})] = [:erb, { foo: 'bar' }]
89
89
 
90
90
  # Mock layout
91
91
  layout = MiniTest::Mock.new
@@ -101,10 +101,10 @@ class Nanoc::Int::CompilerTest < Nanoc::TestCase
101
101
 
102
102
  # Create compiler
103
103
  compiler = Nanoc::Int::Compiler.new(site)
104
- compiler.rules_collection.layout_filter_mapping[%r{^/a/b/c/.*/$}] = [:erb, { char: 'd' }]
105
- compiler.rules_collection.layout_filter_mapping[%r{^/a/.*/$}] = [:erb, { char: 'b' }]
106
- compiler.rules_collection.layout_filter_mapping[%r{^/a/b/.*/$}] = [:erb, { char: 'c' }] # never used!
107
- compiler.rules_collection.layout_filter_mapping[%r{^/.*/$}] = [:erb, { char: 'a' }]
104
+ compiler.rules_collection.layout_filter_mapping[Nanoc::Int::Pattern.from(%r{^/a/b/c/.*/$})] = [:erb, { char: 'd' }]
105
+ compiler.rules_collection.layout_filter_mapping[Nanoc::Int::Pattern.from(%r{^/a/.*/$})] = [:erb, { char: 'b' }]
106
+ compiler.rules_collection.layout_filter_mapping[Nanoc::Int::Pattern.from(%r{^/a/b/.*/$})] = [:erb, { char: 'c' }] # never used!
107
+ compiler.rules_collection.layout_filter_mapping[Nanoc::Int::Pattern.from(%r{^/.*/$})] = [:erb, { char: 'a' }]
108
108
 
109
109
  # Mock layout
110
110
  layouts = [mock, mock, mock, mock]
@@ -149,7 +149,7 @@ class Nanoc::Int::CompilerTest < Nanoc::TestCase
149
149
  layout '/blah/'
150
150
  filter :erb
151
151
  end
152
- rule = Nanoc::Int::Rule.new(/blah/, :meh, rule_block)
152
+ rule = Nanoc::Int::Rule.new(Nanoc::Int::Pattern.from(/blah/), :meh, rule_block)
153
153
 
154
154
  # Create layout
155
155
  layout = Nanoc::Int::Layout.new('head <%= yield %> foot', {}, '/blah/')
@@ -163,7 +163,7 @@ class Nanoc::Int::CompilerTest < Nanoc::TestCase
163
163
  # Create compiler
164
164
  compiler = Nanoc::Int::Compiler.new(site)
165
165
  compiler.rules_collection.expects(:compilation_rule_for).times(2).with(rep).returns(rule)
166
- compiler.rules_collection.layout_filter_mapping[%r{^/blah/$}] = [:erb, {}]
166
+ compiler.rules_collection.layout_filter_mapping[Nanoc::Int::Pattern.from(%r{^/blah/$})] = [:erb, {}]
167
167
  site.stubs(:compiler).returns(compiler)
168
168
 
169
169
  # Compile
@@ -256,15 +256,15 @@ class Nanoc::Int::CompilerTest < Nanoc::TestCase
256
256
  FileUtils.cd('bar') do
257
257
  # Create routes
258
258
  File.open('Rules', 'w') do |io|
259
- io.write "compile '*' do\n"
259
+ io.write "compile '/**/*' do\n"
260
260
  io.write " layout 'default'\n"
261
261
  io.write "end\n"
262
262
  io.write "\n"
263
- io.write "route '*' do\n"
263
+ io.write "route '/**/*' do\n"
264
264
  io.write " 'index.html'\n"
265
265
  io.write "end\n"
266
266
  io.write "\n"
267
- io.write "layout '*', :erb\n"
267
+ io.write "layout '/**/*', :erb\n"
268
268
  end
269
269
 
270
270
  # Create site
@@ -317,16 +317,16 @@ class Nanoc::Int::CompilerTest < Nanoc::TestCase
317
317
  FileUtils.cd('bar') do
318
318
  # Create routes
319
319
  File.open('Rules', 'w') do |io|
320
- io.write "compile '*' do\n"
320
+ io.write "compile '/**/*' do\n"
321
321
  io.write " snapshot :aaa\n"
322
322
  io.write " snapshot :aaa\n"
323
323
  io.write "end\n"
324
324
  io.write "\n"
325
- io.write "route '*' do\n"
325
+ io.write "route '/**/*' do\n"
326
326
  io.write " '/index.html'\n"
327
327
  io.write "end\n"
328
328
  io.write "\n"
329
- io.write "layout '*', :erb\n"
329
+ io.write "layout '/**/*', :erb\n"
330
330
  end
331
331
 
332
332
  # Compile
@@ -588,4 +588,24 @@ class Nanoc::Int::CompilerTest < Nanoc::TestCase
588
588
  assert_empty stack
589
589
  end
590
590
  end
591
+
592
+ def test_find_layouts_by_glob
593
+ Nanoc::CLI.run %w( create_site bar )
594
+ FileUtils.cd('bar') do
595
+ File.open('Rules', 'w') do |io|
596
+ io.write "compile '/**/*' do\n"
597
+ io.write " layout '/default.*'\n"
598
+ io.write "end\n"
599
+ io.write "\n"
600
+ io.write "route '/**/*' do\n"
601
+ io.write " '/index.html'\n"
602
+ io.write "end\n"
603
+ io.write "\n"
604
+ io.write "layout '/**/*', :erb\n"
605
+ end
606
+
607
+ site = Nanoc::Int::Site.new('.')
608
+ site.compile
609
+ end
610
+ end
591
611
  end
@@ -141,36 +141,6 @@ EOS
141
141
  end
142
142
  end
143
143
 
144
- def test_passthrough_with_ext_from_static_data_source
145
- with_site do
146
- # Create config
147
- File.open('nanoc.yaml', 'w') do |io|
148
- io.write "data_sources:\n"
149
- io.write " - type: static\n"
150
- end
151
-
152
- # Create rules
153
- File.open('Rules', 'w') do |io|
154
- io.write <<EOS
155
- passthrough "/foo.txt/"
156
- EOS
157
- end
158
-
159
- # Create items
160
- FileUtils.mkdir_p('static')
161
- File.open('static/foo.txt', 'w') do |io|
162
- io.write 'Hello I am foo'
163
- end
164
-
165
- # Compile
166
- site = Nanoc::Int::Site.new('.')
167
- site.compile
168
-
169
- # Check paths
170
- assert_equal ['output/foo.txt'], Dir['output/*']
171
- end
172
- end
173
-
174
144
  def test_passthrough_priority
175
145
  with_site do
176
146
  # Create rules
@@ -267,6 +237,38 @@ EOS
267
237
  end
268
238
  end
269
239
 
240
+ def test_create_pattern_with_string
241
+ compiler_dsl = Nanoc::Int::CompilerDSL.new(nil, {})
242
+
243
+ pattern = compiler_dsl.create_pattern('/foo/*')
244
+ assert pattern.match?('/foo/a/a/a/a')
245
+ end
246
+
247
+ def test_create_pattern_with_string_with_glob_pattern_syntax
248
+ compiler_dsl = Nanoc::Int::CompilerDSL.new(nil, { pattern_syntax: 'glob' })
249
+
250
+ pattern = compiler_dsl.create_pattern('/foo/*')
251
+ assert pattern.match?('/foo/aaaa')
252
+ refute pattern.match?('/foo/aaaa/')
253
+ refute pattern.match?('/foo/a/a/a/a')
254
+ end
255
+
256
+ def test_create_pattern_with_regex
257
+ compiler_dsl = Nanoc::Int::CompilerDSL.new(nil, {})
258
+
259
+ pattern = compiler_dsl.create_pattern(%r<\A/foo/a*/>)
260
+ assert pattern.match?('/foo/aaaa/')
261
+ end
262
+
263
+ def test_create_pattern_with_string_with_unknown_pattern_syntax
264
+ compiler_dsl = Nanoc::Int::CompilerDSL.new(nil, { pattern_syntax: 'donkey' })
265
+
266
+ err = assert_raises(Nanoc::Int::Errors::GenericTrivial) do
267
+ compiler_dsl.create_pattern('/foo/*')
268
+ end
269
+ assert_equal 'Invalid pattern_syntax: donkey', err.message
270
+ end
271
+
270
272
  def test_identifier_to_regex_without_wildcards
271
273
  # Create compiler DSL
272
274
  compiler_dsl = Nanoc::Int::CompilerDSL.new(nil, {})
@@ -28,8 +28,8 @@ class Nanoc::DataSourceTest < Nanoc::TestCase
28
28
  data_source.down
29
29
 
30
30
  # Test methods - loading data
31
- assert_equal [], data_source.items
32
- assert_equal [], data_source.layouts
31
+ assert_equal [], data_source.items
32
+ assert_equal [], data_source.layouts
33
33
  end
34
34
 
35
35
  def test_new_item
@@ -7,7 +7,7 @@ class Nanoc::Int::ItemArrayTest < Nanoc::TestCase
7
7
  @one = Nanoc::Int::Item.new('Item One', {}, '/one/')
8
8
  @two = Nanoc::Int::Item.new('Item Two', {}, '/two/')
9
9
 
10
- @items = Nanoc::Int::ItemArray.new
10
+ @items = Nanoc::Int::ItemArray.new({})
11
11
  @items << @one
12
12
  @items << @two
13
13
  end
@@ -44,6 +44,15 @@ class Nanoc::Int::ItemArrayTest < Nanoc::TestCase
44
44
  assert_equal @two, @items.at(-1)
45
45
  end
46
46
 
47
+ def test_brackets_with_glob
48
+ @items = Nanoc::Int::ItemArray.new({ pattern_syntax: 'glob' })
49
+ @items << @one
50
+ @items << @two
51
+
52
+ assert_equal @one, @items['/on*/']
53
+ assert_equal @two, @items['/*wo/']
54
+ end
55
+
47
56
  def test_brackets_and_slice_with_range
48
57
  assert_equal [@one, @two], @items[0..1]
49
58
  assert_equal [@one, @two], @items[0, 2]
@@ -14,11 +14,11 @@ class Nanoc::Int::RuleTest < Nanoc::TestCase
14
14
  end
15
15
 
16
16
  def test_matches
17
- regexp = %r</(.*)/(.*)/>
17
+ pattern = Nanoc::Int::Pattern.from(%r</(.*)/(.*)/>)
18
18
  identifier = '/anything/else/'
19
19
  expected = ['anything', 'else']
20
20
 
21
- rule = Nanoc::Int::Rule.new(regexp, :string, Proc.new {})
21
+ rule = Nanoc::Int::Rule.new(pattern, :string, Proc.new {})
22
22
 
23
23
  assert_equal expected, rule.send(:matches, identifier)
24
24
  end
@@ -185,6 +185,9 @@ EOF
185
185
  FileUtils.mkdir_p('content/parent')
186
186
  FileUtils.mkdir_p('content/parent/bar')
187
187
 
188
+ data = File.read('nanoc.yaml').sub('identifier_style: full', 'identifier_style: stripped')
189
+ File.open('nanoc.yaml', 'w') { |io| io << data }
190
+
188
191
  File.open('content/parent.md', 'w') { |io| io << 'asdf' }
189
192
  File.open('content/parent/foo.md', 'w') { |io| io << 'asdf' }
190
193
  File.open('content/parent/bar.md', 'w') { |io| io << 'asdf' }
@@ -211,6 +214,35 @@ EOF
211
214
  end
212
215
  end
213
216
 
217
+ def test_setup_child_parent_links_for_full_style_identifiers
218
+ Nanoc::CLI.run %w( create_site bar)
219
+ FileUtils.cd('bar') do
220
+ FileUtils.mkdir_p('content/parent')
221
+ FileUtils.mkdir_p('content/parent/bar')
222
+
223
+ File.open('content/parent.md', 'w') { |io| io << 'asdf' }
224
+ File.open('content/parent/foo.md', 'w') { |io| io << 'asdf' }
225
+ File.open('content/parent/bar/qux.md', 'w') { |io| io << 'asdf' }
226
+
227
+ site = Nanoc::Int::Site.new('.')
228
+
229
+ root = site.items.find { |i| i.identifier == '/index.html' }
230
+ parent = site.items.find { |i| i.identifier == '/parent.md' }
231
+ foo = site.items.find { |i| i.identifier == '/parent/foo.md' }
232
+ qux = site.items.find { |i| i.identifier == '/parent/bar/qux.md' }
233
+
234
+ assert_equal Set.new([]), Set.new(root.children)
235
+ assert_equal Set.new([]), Set.new(parent.children)
236
+ assert_equal Set.new([]), Set.new(foo.children)
237
+ assert_equal Set.new([]), Set.new(qux.children)
238
+
239
+ assert_equal nil, root.parent
240
+ assert_equal nil, parent.parent
241
+ assert_equal nil, foo.parent
242
+ assert_equal nil, qux.parent
243
+ end
244
+ end
245
+
214
246
  def test_multiple_items_with_same_identifier
215
247
  with_site do
216
248
  File.open('content/sam.html', 'w') { |io| io.write('I am Sam!') }
@@ -50,7 +50,13 @@ class Nanoc::CLI::Commands::CreateSiteTest < Nanoc::TestCase
50
50
  assert_equal 'Could not read content/index.html because the file is not valid UTF-8.', exception.message
51
51
 
52
52
  # Try with encoding = specific
53
- File.open('nanoc.yaml', 'w') { |io| io.write("meh: true\n") }
53
+ File.open('nanoc.yaml', 'w') do |io|
54
+ io.write("pattern_syntax: glob\n")
55
+ io.write("data_sources:\n")
56
+ io.write(" -\n")
57
+ io.write(" type: filesystem_unified\n")
58
+ io.write(" identifier_style: full\n")
59
+ end
54
60
  site = Nanoc::Int::Site.new('.')
55
61
  site.compile
56
62
  end
@@ -93,8 +93,8 @@ class Nanoc::CLI::Commands::PruneTest < Nanoc::TestCase
93
93
 
94
94
  def test_run_with_symlink_to_output_dir
95
95
  skip_unless_symlinks_supported
96
- if defined?(JRUBY_VERSION) && JRUBY_VERSION == '1.7.11'
97
- skip 'JRuby 1.7.11 has buggy File.find behavior (see https://github.com/jruby/jruby/issues/1647)'
96
+ if defined?(JRUBY_VERSION)
97
+ skip 'JRuby has buggy File.find behavior (see https://github.com/jruby/jruby/issues/1647)'
98
98
  end
99
99
 
100
100
  with_site do |_site|
@@ -40,9 +40,9 @@ class Nanoc::DataSources::FilesystemTest < Nanoc::TestCase
40
40
 
41
41
  # Get all files
42
42
  output_expected = {
43
- './foo' => %w(yaml html),
44
- './bar.entry' => [nil, 'html'],
45
- './foo/qux' => ['yaml', nil]
43
+ './foo' => ['yaml', ['html']],
44
+ './bar.entry' => [nil, ['html']],
45
+ './foo/qux' => ['yaml', [nil]]
46
46
  }
47
47
  output_actual = data_source.send :all_split_files_in, '.'
48
48
 
@@ -67,9 +67,9 @@ class Nanoc::DataSources::FilesystemTest < Nanoc::TestCase
67
67
 
68
68
  # Get all files
69
69
  output_expected = {
70
- './foo' => %w(yaml html),
71
- './bar' => [nil, 'html.erb'],
72
- './foo/qux' => ['yaml', nil]
70
+ './foo' => ['yaml', ['html']],
71
+ './bar' => [nil, ['html.erb']],
72
+ './foo/qux' => ['yaml', [nil]]
73
73
  }
74
74
  output_actual = data_source.send :all_split_files_in, '.'
75
75
 
@@ -89,13 +89,33 @@ class Nanoc::DataSources::FilesystemTest < Nanoc::TestCase
89
89
 
90
90
  # Check
91
91
  expected = {
92
- './aaa/foo' => [nil, 'html'],
93
- './bbb/foo' => [nil, 'html'],
94
- './ccc/foo' => [nil, 'html']
92
+ './aaa/foo' => [nil, ['html']],
93
+ './bbb/foo' => [nil, ['html']],
94
+ './ccc/foo' => [nil, ['html']]
95
95
  }
96
96
  assert_equal expected, data_source.send(:all_split_files_in, '.')
97
97
  end
98
98
 
99
+ def test_all_split_files_in_with_same_extensions
100
+ # Create data source
101
+ config = { identifier_style: 'full' }
102
+ data_source = Nanoc::DataSources::FilesystemUnified.new(nil, nil, nil, config)
103
+
104
+ # Write sample files
105
+ %w( stuff/foo.html stuff/foo.md stuff/foo.yaml ).each do |filename|
106
+ FileUtils.mkdir_p(File.dirname(filename))
107
+ File.open(filename, 'w') { |io| io.write('test') }
108
+ end
109
+
110
+ # Check - { './stuff/foo' => ['yaml', ['html', 'md']] }
111
+ res = data_source.send(:all_split_files_in, '.')
112
+ assert_equal ['./stuff/foo'], res.keys
113
+ assert_equal 2, res.values[0].size
114
+ assert_equal 'yaml', res.values[0][0]
115
+ assert_equal Array, res.values[0][1].class
116
+ assert_equal ['html', 'md'], res.values[0][1].sort
117
+ end
118
+
99
119
  def test_all_split_files_in_with_multiple_content_files
100
120
  # Create data source
101
121
  data_source = Nanoc::DataSources::FilesystemUnified.new(nil, nil, nil, nil)
@@ -12,38 +12,6 @@ class Nanoc::DataSources::FilesystemUnifiedTest < Nanoc::TestCase
12
12
  data_source
13
13
  end
14
14
 
15
- def test_create_object_not_at_root
16
- # Create item
17
- data_source = new_data_source
18
- data_source.send(:create_object, 'foobar', 'content here', { foo: 'bar' }, '/asdf/')
19
-
20
- # Check file existance
21
- assert File.directory?('foobar')
22
- assert !File.directory?('foobar/content')
23
- assert !File.directory?('foobar/asdf')
24
- assert File.file?('foobar/asdf.html')
25
-
26
- # Check file content
27
- expected = /^--- ?\nfoo: bar\n---\ncontent here$/
28
- assert_match expected, File.read('foobar/asdf.html')
29
- end
30
-
31
- def test_create_object_at_root
32
- # Create item
33
- data_source = new_data_source
34
- data_source.send(:create_object, 'foobar', 'content here', { foo: 'bar' }, '/')
35
-
36
- # Check file existance
37
- assert File.directory?('foobar')
38
- assert !File.directory?('foobar/index')
39
- assert !File.directory?('foobar/foobar')
40
- assert File.file?('foobar/index.html')
41
-
42
- # Check file content
43
- expected = /^--- ?\nfoo: bar\n---\ncontent here$/
44
- assert_match expected, File.read('foobar/index.html')
45
- end
46
-
47
15
  def test_load_objects
48
16
  # Create data source
49
17
  data_source = new_data_source
@@ -105,6 +73,32 @@ class Nanoc::DataSources::FilesystemUnifiedTest < Nanoc::TestCase
105
73
  end
106
74
  end
107
75
 
76
+ def test_load_objects_with_same_extensions
77
+ # Create data source
78
+ data_source = new_data_source({ identifier_style: 'full' })
79
+
80
+ # Create a fake class
81
+ klass = Class.new do
82
+ attr_reader :stuff
83
+ def initialize(*stuff)
84
+ @stuff = stuff
85
+ end
86
+
87
+ def ==(other)
88
+ @stuff == other.stuff
89
+ end
90
+ end
91
+
92
+ # Create sample files
93
+ FileUtils.mkdir_p('foo')
94
+ File.open('foo/bar.html', 'w') { |io| io.write("---\nnum: 1\n---\ntest 1") }
95
+ File.open('foo/bar.md', 'w') { |io| io.write("---\nnum: 1\n---\ntest 1") }
96
+
97
+ # Check
98
+ actual_out = data_source.send(:load_objects, 'foo', 'The Foo', klass)
99
+ assert_equal 2, actual_out.size
100
+ end
101
+
108
102
  def test_load_binary_objects
109
103
  # Create data source
110
104
  data_source = new_data_source
@@ -137,6 +131,28 @@ class Nanoc::DataSources::FilesystemUnifiedTest < Nanoc::TestCase
137
131
  end
138
132
  end
139
133
 
134
+ def test_identifier_for_filename_with_full_style_identifier
135
+ # Create data source
136
+ data_source = new_data_source({ identifier_style: 'full' })
137
+
138
+ # Get input and expected output
139
+ expected = {
140
+ '/foo' => Nanoc::Identifier.new('/foo', style: :full),
141
+ '/foo.html' => Nanoc::Identifier.new('/foo.html', style: :full),
142
+ '/foo/index.html' => Nanoc::Identifier.new('/foo/index.html', style: :full),
143
+ '/foo.html.erb' => Nanoc::Identifier.new('/foo.html.erb', style: :full),
144
+ }
145
+
146
+ # Check
147
+ expected.each_pair do |input, expected_output|
148
+ actual_output = data_source.send(:identifier_for_filename, input)
149
+ assert_equal(
150
+ expected_output, actual_output,
151
+ "identifier_for_filename(#{input.inspect}) should equal #{expected_output.inspect}, not #{actual_output.inspect}"
152
+ )
153
+ end
154
+ end
155
+
140
156
  def test_identifier_for_filename_allowing_periods_in_identifiers
141
157
  # Create data source
142
158
  data_source = new_data_source(allow_periods_in_identifiers: true)
@@ -439,42 +455,6 @@ class Nanoc::DataSources::FilesystemUnifiedTest < Nanoc::TestCase
439
455
  end
440
456
  end
441
457
 
442
- def test_create_object_allowing_periods_in_identifiers
443
- # Create data source
444
- data_source = new_data_source(allow_periods_in_identifiers: true)
445
-
446
- # Create object without period
447
- data_source.send(:create_object, 'foo', 'some content', { some: 'attributes' }, '/asdf/')
448
- assert File.file?('foo/asdf.html')
449
- data = data_source.send(:parse, 'foo/asdf.html', nil, 'moo')
450
- assert_equal({ 'some' => 'attributes' }, data[0])
451
- assert_equal('some content', data[1])
452
-
453
- # Create object with period
454
- data_source.send(:create_object, 'foo', 'some content', { some: 'attributes' }, '/as.df/')
455
- assert File.file?('foo/as.df.html')
456
- data = data_source.send(:parse, 'foo/as.df.html', nil, 'moo')
457
- assert_equal({ 'some' => 'attributes' }, data[0])
458
- assert_equal('some content', data[1])
459
- end
460
-
461
- def test_create_object_disallowing_periods_in_identifiers
462
- # Create data source
463
- data_source = new_data_source
464
-
465
- # Create object without period
466
- data_source.send(:create_object, 'foo', 'some content', { some: 'attributes' }, '/asdf/')
467
- assert File.file?('foo/asdf.html')
468
- data = data_source.send(:parse, 'foo/asdf.html', nil, 'moo')
469
- assert_equal({ 'some' => 'attributes' }, data[0])
470
- assert_equal('some content', data[1])
471
-
472
- # Create object with period
473
- assert_raises(RuntimeError) do
474
- data_source.send(:create_object, 'foo', 'some content', { some: 'attributes' }, '/as.df/')
475
- end
476
- end
477
-
478
458
  def test_filename_for
479
459
  data_source = new_data_source
480
460