nanoc 4.0.0b1 → 4.0.0b2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (50) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile.lock +1 -1
  3. data/NEWS.md +26 -2
  4. data/README.md +1 -1
  5. data/lib/nanoc/base.rb +3 -1
  6. data/lib/nanoc/base/checksummer.rb +1 -3
  7. data/lib/nanoc/base/compilation/compiler.rb +3 -3
  8. data/lib/nanoc/base/compilation/compiler_dsl.rb +3 -3
  9. data/lib/nanoc/base/compilation/item_rep_proxy.rb +1 -1
  10. data/lib/nanoc/base/core_ext/array.rb +0 -11
  11. data/lib/nanoc/base/core_ext/hash.rb +0 -11
  12. data/lib/nanoc/base/identifiable_collection.rb +81 -0
  13. data/lib/nanoc/base/source_data/identifier.rb +9 -9
  14. data/lib/nanoc/base/source_data/site.rb +7 -5
  15. data/lib/nanoc/base/views/identifiable_collection.rb +78 -0
  16. data/lib/nanoc/base/views/item_collection.rb +1 -86
  17. data/lib/nanoc/base/views/layout_collection.rb +1 -57
  18. data/lib/nanoc/base/views/mutable_identifiable_collection.rb +17 -0
  19. data/lib/nanoc/base/views/mutable_item_collection.rb +2 -14
  20. data/lib/nanoc/base/views/mutable_layout_collection.rb +2 -14
  21. data/lib/nanoc/cli/commands/create-site.rb +44 -40
  22. data/lib/nanoc/data_sources/filesystem.rb +1 -1
  23. data/lib/nanoc/data_sources/filesystem_unified.rb +3 -3
  24. data/lib/nanoc/data_sources/filesystem_verbose.rb +3 -3
  25. data/lib/nanoc/filters/erb.rb +2 -2
  26. data/lib/nanoc/filters/rdiscount.rb +1 -1
  27. data/lib/nanoc/filters/redcarpet.rb +1 -1
  28. data/lib/nanoc/version.rb +1 -1
  29. data/tasks/test.rake +1 -0
  30. data/test/base/core_ext/array_spec.rb +0 -8
  31. data/test/base/core_ext/hash_spec.rb +0 -26
  32. data/test/base/test_compiler.rb +1 -1
  33. data/test/base/test_compiler_dsl.rb +13 -10
  34. data/test/base/test_item.rb +0 -6
  35. data/test/base/test_item_array.rb +8 -276
  36. data/test/base/test_layout.rb +1 -5
  37. data/test/base/test_outdatedness_checker.rb +9 -2
  38. data/test/base/test_site.rb +5 -5
  39. data/test/cli/commands/test_compile.rb +14 -0
  40. data/test/cli/commands/test_create_site.rb +40 -2
  41. data/test/cli/commands/test_prune.rb +19 -4
  42. data/test/data_sources/test_filesystem.rb +1 -1
  43. data/test/data_sources/test_filesystem_unified.rb +6 -6
  44. data/test/extra/checking/checks/test_stale.rb +2 -2
  45. data/test/helper.rb +8 -1
  46. data/test/helpers/test_blogging.rb +0 -235
  47. data/test/helpers/test_breadcrumbs.rb +31 -23
  48. data/test/helpers/test_xml_sitemap.rb +38 -29
  49. metadata +5 -3
  50. data/lib/nanoc/base/source_data/item_array.rb +0 -86
@@ -4,38 +4,46 @@ class Nanoc::Helpers::BreadcrumbsTest < Nanoc::TestCase
4
4
  include Nanoc::Helpers::Breadcrumbs
5
5
 
6
6
  def test_breadcrumbs_trail_at_root
7
- @items = Nanoc::Int::ItemArray.new({})
8
- @items << Nanoc::Int::Item.new('root', {}, '/')
9
- @item = @items.last
7
+ @items = Nanoc::Int::IdentifiableCollection.new({})
8
+ item = Nanoc::Int::Item.new('root', {}, '/')
9
+ @items << item
10
+ @item = item
10
11
 
11
- assert_equal [@items[0]], breadcrumbs_trail
12
+ assert_equal [item], breadcrumbs_trail
12
13
  end
13
14
 
14
15
  def test_breadcrumbs_trail_with_1_parent
15
- @items = Nanoc::Int::ItemArray.new({})
16
- @items << Nanoc::Int::Item.new('parent', {}, '/')
17
- @items << Nanoc::Int::Item.new('child', {}, '/foo/')
18
- @item = @items.last
19
-
20
- assert_equal [@items[0], @items[1]], breadcrumbs_trail
16
+ @items = Nanoc::Int::IdentifiableCollection.new({})
17
+ parent_item = Nanoc::Int::Item.new('parent', {}, '/')
18
+ child_item = Nanoc::Int::Item.new('child', {}, '/foo/')
19
+ @items << parent_item
20
+ @items << child_item
21
+ @item = child_item
22
+
23
+ assert_equal [parent_item, child_item], breadcrumbs_trail
21
24
  end
22
25
 
23
26
  def test_breadcrumbs_trail_with_many_parents
24
- @items = Nanoc::Int::ItemArray.new({})
25
- @items << Nanoc::Int::Item.new('grandparent', {}, '/')
26
- @items << Nanoc::Int::Item.new('parent', {}, '/foo/')
27
- @items << Nanoc::Int::Item.new('child', {}, '/foo/bar/')
28
- @item = @items.last
29
-
30
- assert_equal [@items[0], @items[1], @items[2]], breadcrumbs_trail
27
+ @items = Nanoc::Int::IdentifiableCollection.new({})
28
+ grandparent_item = Nanoc::Int::Item.new('grandparent', {}, '/')
29
+ parent_item = Nanoc::Int::Item.new('parent', {}, '/foo/')
30
+ child_item = Nanoc::Int::Item.new('child', {}, '/foo/bar/')
31
+ @items << grandparent_item
32
+ @items << parent_item
33
+ @items << child_item
34
+ @item = child_item
35
+
36
+ assert_equal [grandparent_item, parent_item, child_item], breadcrumbs_trail
31
37
  end
32
38
 
33
39
  def test_breadcrumbs_trail_with_nils
34
- @items = Nanoc::Int::ItemArray.new({})
35
- @items << Nanoc::Int::Item.new('grandparent', {}, '/')
36
- @items << Nanoc::Int::Item.new('child', {}, '/foo/bar/')
37
- @item = @items.last
38
-
39
- assert_equal [@items[0], nil, @items[1]], breadcrumbs_trail
40
+ @items = Nanoc::Int::IdentifiableCollection.new({})
41
+ grandparent_item = Nanoc::Int::Item.new('grandparent', {}, '/')
42
+ child_item = Nanoc::Int::Item.new('child', {}, '/foo/bar/')
43
+ @items << grandparent_item
44
+ @items << child_item
45
+ @item = child_item
46
+
47
+ assert_equal [grandparent_item, nil, child_item], breadcrumbs_trail
40
48
  end
41
49
  end
@@ -14,25 +14,29 @@ class Nanoc::Helpers::XMLSitemapTest < Nanoc::TestCase
14
14
  def test_xml_sitemap
15
15
  if_have 'builder', 'nokogiri' do
16
16
  # Create items
17
- @items = []
17
+ @items = Nanoc::Int::IdentifiableCollection.new({})
18
18
 
19
19
  # Create item 1
20
- @items << Nanoc::ItemView.new(Nanoc::Int::Item.new('some content 1', {}, '/item-one/'))
21
- create_item_rep(@items.last.unwrap, :one_a, '/item-one/a/')
22
- create_item_rep(@items.last.unwrap, :one_b, '/item-one/b/')
20
+ item = Nanoc::ItemView.new(Nanoc::Int::Item.new('some content 1', {}, '/item-one/'))
21
+ @items << item
22
+ create_item_rep(item.unwrap, :one_a, '/item-one/a/')
23
+ create_item_rep(item.unwrap, :one_b, '/item-one/b/')
23
24
 
24
25
  # Create item 2
25
- @items << Nanoc::ItemView.new(Nanoc::Int::Item.new('some content 2', { is_hidden: true }, '/item-two/'))
26
+ item = Nanoc::ItemView.new(Nanoc::Int::Item.new('some content 2', { is_hidden: true }, '/item-two/'))
27
+ @items << item
26
28
 
27
29
  # Create item 3
28
30
  attrs = { mtime: Time.parse('2004-07-12'), changefreq: 'daily', priority: 0.5 }
29
- @items << Nanoc::ItemView.new(Nanoc::Int::Item.new('some content 3', attrs, '/item-three/'))
30
- create_item_rep(@items.last.unwrap, :three_a, '/item-three/a/')
31
- create_item_rep(@items.last.unwrap, :three_b, '/item-three/b/')
31
+ item = Nanoc::ItemView.new(Nanoc::Int::Item.new('some content 3', attrs, '/item-three/'))
32
+ @items << item
33
+ create_item_rep(item.unwrap, :three_a, '/item-three/a/')
34
+ create_item_rep(item.unwrap, :three_b, '/item-three/b/')
32
35
 
33
36
  # Create item 4
34
- @items << Nanoc::ItemView.new(Nanoc::Int::Item.new('some content 4', {}, '/item-four/'))
35
- create_item_rep(@items.last.unwrap, :four_a, nil)
37
+ item = Nanoc::ItemView.new(Nanoc::Int::Item.new('some content 4', {}, '/item-four/'))
38
+ @items << item
39
+ create_item_rep(item.unwrap, :four_a, nil)
36
40
 
37
41
  # Create sitemap item
38
42
  @item = Nanoc::ItemView.new(Nanoc::Int::Item.new('sitemap content', {}, '/sitemap/'))
@@ -71,11 +75,12 @@ class Nanoc::Helpers::XMLSitemapTest < Nanoc::TestCase
71
75
  def test_sitemap_with_items_as_param
72
76
  if_have 'builder', 'nokogiri' do
73
77
  # Create items
74
- @items = []
78
+ @items = Nanoc::Int::IdentifiableCollection.new({})
75
79
  @items << nil
76
- @items << Nanoc::ItemView.new(Nanoc::Int::Item.new('some content 1', {}, '/item-one/'))
77
- create_item_rep(@items.last.unwrap, :one_a, '/item-one/a/')
78
- create_item_rep(@items.last.unwrap, :one_b, '/item-one/b/')
80
+ item = Nanoc::ItemView.new(Nanoc::Int::Item.new('some content 1', {}, '/item-one/'))
81
+ @items << item
82
+ create_item_rep(item.unwrap, :one_a, '/item-one/a/')
83
+ create_item_rep(item.unwrap, :one_b, '/item-one/b/')
79
84
  @items << nil
80
85
 
81
86
  # Create sitemap item
@@ -85,7 +90,7 @@ class Nanoc::Helpers::XMLSitemapTest < Nanoc::TestCase
85
90
  @config = Nanoc::ConfigView.new({ base_url: 'http://example.com' })
86
91
 
87
92
  # Build sitemap
88
- res = xml_sitemap(items: [@items[1]])
93
+ res = xml_sitemap(items: [item])
89
94
 
90
95
  # Check
91
96
  doc = Nokogiri::XML(res)
@@ -107,10 +112,11 @@ class Nanoc::Helpers::XMLSitemapTest < Nanoc::TestCase
107
112
  def test_filter
108
113
  if_have 'builder', 'nokogiri' do
109
114
  # Create items
110
- @items = []
111
- @items << Nanoc::ItemView.new(Nanoc::Int::Item.new('some content 1', {}, '/item-one/'))
112
- create_item_rep(@items.last.unwrap, :one_a, '/item-one/a/')
113
- create_item_rep(@items.last.unwrap, :one_b, '/item-one/b/')
115
+ @items = Nanoc::Int::IdentifiableCollection.new({})
116
+ item = Nanoc::ItemView.new(Nanoc::Int::Item.new('some content 1', {}, '/item-one/'))
117
+ @items << item
118
+ create_item_rep(item.unwrap, :one_a, '/item-one/a/')
119
+ create_item_rep(item.unwrap, :one_b, '/item-one/b/')
114
120
 
115
121
  # Create sitemap item
116
122
  @item = Nanoc::ItemView.new(Nanoc::Int::Item.new('sitemap content', {}, '/sitemap/'))
@@ -137,16 +143,19 @@ class Nanoc::Helpers::XMLSitemapTest < Nanoc::TestCase
137
143
  def test_sorted
138
144
  if_have 'builder', 'nokogiri' do
139
145
  # Create items
140
- @items = []
141
- @items << Nanoc::ItemView.new(Nanoc::Int::Item.new('some content 1', {}, '/george/'))
142
- create_item_rep(@items.last.unwrap, :a_alice, '/george/alice/')
143
- create_item_rep(@items.last.unwrap, :b_zoey, '/george/zoey/')
144
- @items << Nanoc::ItemView.new(Nanoc::Int::Item.new('some content 1', {}, '/walton/'))
145
- create_item_rep(@items.last.unwrap, :a_eve, '/walton/eve/')
146
- create_item_rep(@items.last.unwrap, :b_bob, '/walton/bob/')
147
- @items << Nanoc::ItemView.new(Nanoc::Int::Item.new('some content 1', {}, '/lucas/'))
148
- create_item_rep(@items.last.unwrap, :a_trudy, '/lucas/trudy/')
149
- create_item_rep(@items.last.unwrap, :b_mallory, '/lucas/mallory/')
146
+ @items = Nanoc::Int::IdentifiableCollection.new({})
147
+ item = Nanoc::ItemView.new(Nanoc::Int::Item.new('some content 1', {}, '/george/'))
148
+ @items << item
149
+ create_item_rep(item.unwrap, :a_alice, '/george/alice/')
150
+ create_item_rep(item.unwrap, :b_zoey, '/george/zoey/')
151
+ item = Nanoc::ItemView.new(Nanoc::Int::Item.new('some content 1', {}, '/walton/'))
152
+ @items << item
153
+ create_item_rep(item.unwrap, :a_eve, '/walton/eve/')
154
+ create_item_rep(item.unwrap, :b_bob, '/walton/bob/')
155
+ item = Nanoc::ItemView.new(Nanoc::Int::Item.new('some content 1', {}, '/lucas/'))
156
+ @items << item
157
+ create_item_rep(item.unwrap, :a_trudy, '/lucas/trudy/')
158
+ create_item_rep(item.unwrap, :b_mallory, '/lucas/mallory/')
150
159
 
151
160
  # Create sitemap item
152
161
  @item = Nanoc::ItemView.new(Nanoc::Int::Item.new('sitemap content', {}, '/sitemap/'))
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nanoc
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.0.0b1
4
+ version: 4.0.0b2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Denis Defreyne
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-05-14 00:00:00.000000000 Z
11
+ date: 2015-05-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: cri
@@ -96,6 +96,7 @@ files:
96
96
  - lib/nanoc/base/directed_graph.rb
97
97
  - lib/nanoc/base/error.rb
98
98
  - lib/nanoc/base/errors.rb
99
+ - lib/nanoc/base/identifiable_collection.rb
99
100
  - lib/nanoc/base/memoization.rb
100
101
  - lib/nanoc/base/notification_center.rb
101
102
  - lib/nanoc/base/pattern.rb
@@ -106,18 +107,19 @@ files:
106
107
  - lib/nanoc/base/source_data/data_source.rb
107
108
  - lib/nanoc/base/source_data/identifier.rb
108
109
  - lib/nanoc/base/source_data/item.rb
109
- - lib/nanoc/base/source_data/item_array.rb
110
110
  - lib/nanoc/base/source_data/layout.rb
111
111
  - lib/nanoc/base/source_data/site.rb
112
112
  - lib/nanoc/base/store.rb
113
113
  - lib/nanoc/base/temp_filename_factory.rb
114
114
  - lib/nanoc/base/views/config.rb
115
+ - lib/nanoc/base/views/identifiable_collection.rb
115
116
  - lib/nanoc/base/views/item.rb
116
117
  - lib/nanoc/base/views/item_collection.rb
117
118
  - lib/nanoc/base/views/item_rep.rb
118
119
  - lib/nanoc/base/views/layout.rb
119
120
  - lib/nanoc/base/views/layout_collection.rb
120
121
  - lib/nanoc/base/views/mutable_config.rb
122
+ - lib/nanoc/base/views/mutable_identifiable_collection.rb
121
123
  - lib/nanoc/base/views/mutable_item.rb
122
124
  - lib/nanoc/base/views/mutable_item_collection.rb
123
125
  - lib/nanoc/base/views/mutable_layout.rb
@@ -1,86 +0,0 @@
1
- # encoding: utf-8
2
-
3
- module Nanoc::Int
4
- # Acts as an array, but allows fetching items using identifiers, e.g. `@items['/blah/']`.
5
- #
6
- # @api private
7
- class ItemArray
8
- include Enumerable
9
-
10
- extend Forwardable
11
-
12
- EXCLUDED_METHODS = [
13
- :[], :at, :slice, :class, :singleton_class, :clone, :dup, :initialize_dup, :initialize_clone,
14
- :freeze, :methods, :singleton_methods, :protected_methods, :private_methods, :public_methods,
15
- :instance_variables, :instance_variable_get, :instance_variable_set, :instance_variable_defined?,
16
- :instance_of?, :kind_of?, :is_a?, :tap, :send, :public_send, :respond_to?, :respond_to_missing?,
17
- :extend, :display, :method, :public_method, :define_singleton_method, :object_id, :equal?,
18
- :instance_eval, :instance_exec, :__send__, :__id__
19
- ]
20
-
21
- DELEGATED_METHODS = (Array.instance_methods + Enumerable.instance_methods).map(&:to_sym) - EXCLUDED_METHODS
22
- def_delegators :@items, *DELEGATED_METHODS
23
-
24
- def initialize(config)
25
- @config = config
26
-
27
- @items = []
28
- end
29
-
30
- def freeze
31
- @items.freeze
32
- build_mapping
33
- super
34
- end
35
-
36
- def [](*args)
37
- if 1 == args.size && args.first.is_a?(String)
38
- item_with_identifier(args.first) || item_matching_glob(args.first)
39
- elsif 1 == args.size && args.first.is_a?(Regexp)
40
- @items.select { |i| i.identifier.to_s =~ args.first }
41
- else
42
- @items[*args]
43
- end
44
- end
45
- alias_method :slice, :[]
46
-
47
- def at(arg)
48
- if arg.is_a?(String)
49
- item_with_identifier(arg)
50
- else
51
- @items[arg]
52
- end
53
- end
54
-
55
- protected
56
-
57
- def item_with_identifier(identifier)
58
- if self.frozen?
59
- @mapping[identifier.to_s]
60
- else
61
- @items.find { |i| i.identifier == identifier }
62
- end
63
- end
64
-
65
- def item_matching_glob(glob)
66
- if use_globs?
67
- pat = Nanoc::Int::Pattern.from(glob)
68
- @items.find { |i| pat.match?(i.identifier) }
69
- else
70
- nil
71
- end
72
- end
73
-
74
- def build_mapping
75
- @mapping = {}
76
- @items.each do |item|
77
- @mapping[item.identifier.to_s] = item
78
- end
79
- @mapping.freeze
80
- end
81
-
82
- def use_globs?
83
- @config[:pattern_syntax] == 'glob'
84
- end
85
- end
86
- end