nanoc 4.0.0b1 → 4.0.0b2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/NEWS.md +26 -2
- data/README.md +1 -1
- data/lib/nanoc/base.rb +3 -1
- data/lib/nanoc/base/checksummer.rb +1 -3
- data/lib/nanoc/base/compilation/compiler.rb +3 -3
- data/lib/nanoc/base/compilation/compiler_dsl.rb +3 -3
- data/lib/nanoc/base/compilation/item_rep_proxy.rb +1 -1
- data/lib/nanoc/base/core_ext/array.rb +0 -11
- data/lib/nanoc/base/core_ext/hash.rb +0 -11
- data/lib/nanoc/base/identifiable_collection.rb +81 -0
- data/lib/nanoc/base/source_data/identifier.rb +9 -9
- data/lib/nanoc/base/source_data/site.rb +7 -5
- data/lib/nanoc/base/views/identifiable_collection.rb +78 -0
- data/lib/nanoc/base/views/item_collection.rb +1 -86
- data/lib/nanoc/base/views/layout_collection.rb +1 -57
- data/lib/nanoc/base/views/mutable_identifiable_collection.rb +17 -0
- data/lib/nanoc/base/views/mutable_item_collection.rb +2 -14
- data/lib/nanoc/base/views/mutable_layout_collection.rb +2 -14
- data/lib/nanoc/cli/commands/create-site.rb +44 -40
- data/lib/nanoc/data_sources/filesystem.rb +1 -1
- data/lib/nanoc/data_sources/filesystem_unified.rb +3 -3
- data/lib/nanoc/data_sources/filesystem_verbose.rb +3 -3
- data/lib/nanoc/filters/erb.rb +2 -2
- data/lib/nanoc/filters/rdiscount.rb +1 -1
- data/lib/nanoc/filters/redcarpet.rb +1 -1
- data/lib/nanoc/version.rb +1 -1
- data/tasks/test.rake +1 -0
- data/test/base/core_ext/array_spec.rb +0 -8
- data/test/base/core_ext/hash_spec.rb +0 -26
- data/test/base/test_compiler.rb +1 -1
- data/test/base/test_compiler_dsl.rb +13 -10
- data/test/base/test_item.rb +0 -6
- data/test/base/test_item_array.rb +8 -276
- data/test/base/test_layout.rb +1 -5
- data/test/base/test_outdatedness_checker.rb +9 -2
- data/test/base/test_site.rb +5 -5
- data/test/cli/commands/test_compile.rb +14 -0
- data/test/cli/commands/test_create_site.rb +40 -2
- data/test/cli/commands/test_prune.rb +19 -4
- data/test/data_sources/test_filesystem.rb +1 -1
- data/test/data_sources/test_filesystem_unified.rb +6 -6
- data/test/extra/checking/checks/test_stale.rb +2 -2
- data/test/helper.rb +8 -1
- data/test/helpers/test_blogging.rb +0 -235
- data/test/helpers/test_breadcrumbs.rb +31 -23
- data/test/helpers/test_xml_sitemap.rb +38 -29
- metadata +5 -3
- data/lib/nanoc/base/source_data/item_array.rb +0 -86
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 399486061f80fd3acaf7058ec221d0b401fb6590
|
4
|
+
data.tar.gz: 1f1969bd69c51571a7a66bfd6451b6528f1923ae
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f0c41f17f9fc07ad11b41b1ce6541c9be206a737d99d663f19eae58f68de91cfdce4f392848ac54d8835055784415bd33916003f3463cd14581fecd6005a8036
|
7
|
+
data.tar.gz: 13d7891f10c7014e22b731f2b4efc8982cc8dce52c47eb8ec037183cca0637cfb7661580a24dead39cf05085a668a1448257754f0fbce8f29271fe71eb5b3c1e
|
data/Gemfile.lock
CHANGED
data/NEWS.md
CHANGED
@@ -1,6 +1,30 @@
|
|
1
1
|
# nanoc news
|
2
2
|
|
3
|
-
## 4.0.
|
3
|
+
## 4.0.0b2 (2015-05-23)
|
4
|
+
|
5
|
+
Changes:
|
6
|
+
|
7
|
+
* Removed `ItemCollectionView#at` (#582)
|
8
|
+
* Removed support for calling `ItemCollectionView#[]` with an integer (#582)
|
9
|
+
* Renamed `identifier_style` to `identifier_type`, and made its values be `"full"` or `"legacy"` (#593)
|
10
|
+
* Renamed `pattern_syntax` to `string_pattern_type`, and made its values be `"glob"` or `"legacy"` (#593)
|
11
|
+
* Made `"full"` the default for `identifier_type` (#592, #594)
|
12
|
+
* Made `"glob"` the default for `string_pattern_type` (#592)
|
13
|
+
* Enabled auto-pruning by default for new sites (#590)
|
14
|
+
|
15
|
+
Enhancements:
|
16
|
+
|
17
|
+
* Added `--force` to `create-site` command (#580) [David Alexander]
|
18
|
+
* Made default Rules file more future-proof (#591)
|
19
|
+
|
20
|
+
Fixes:
|
21
|
+
|
22
|
+
* Fixed `LayoutCollectionView#[]` documentation (it mentioned items)
|
23
|
+
* Fixed `ItemCollectionView#[]` returning an array when passed a regex
|
24
|
+
* Fixed an issue with mutable collection views’ `#delete_if` not yielding mutable views
|
25
|
+
* Fixed an issue with collection views’ `#find_all` returning entities instead of views
|
26
|
+
|
27
|
+
## 4.0.0b1 (2015-05-14)
|
4
28
|
|
5
29
|
Changes:
|
6
30
|
|
@@ -14,7 +38,7 @@ Enhancements:
|
|
14
38
|
* Added `Nanoc::Identifier#without_ext`
|
15
39
|
* Made `Nanoc::Identifier#=~` work with a glob
|
16
40
|
* Added `Nanoc::LayoutCollectionView#[]`
|
17
|
-
*
|
41
|
+
* Allowed creation of site in current directory (#549) [David Alexander]
|
18
42
|
|
19
43
|
Fixes:
|
20
44
|
|
data/README.md
CHANGED
@@ -20,4 +20,4 @@ Contributions are greatly appreciated! Consult the [Development guidelines](http
|
|
20
20
|
|
21
21
|
Many thanks to everyone who has contributed to nanoc in one way or another:
|
22
22
|
|
23
|
-
Ale Muñoz, Alexander Mankuta, Arnau Siches, Ben Armston, Bil Bas, Brian Candler, Bruno Dufour, Chris Eppstein, Christian Plessl, Colin Barrett, Damien Pollet, Dan Callahan, Daniel Hofstetter, Daniel Mendler, Daniel Wollschlaeger, David Everitt, Dennis Sutch, Devon Luke Buchanan, Dmitry Bilunov, Eric Sunshine, Erik Hollensbe, Fabian Buch, Felix Hanley, Go Maeda, Gregory Pakosz, Grégory Karékinian, Guilherme Garnier, Jack Chu, Jake Benilov, Jasper Van der Jeugt, Jeff Forcier, John Nishinaga, Justin Clift, Justin Hileman, Kevin Lynagh, Louis T., Mathias Bynens, Matt Keveney, Matthew Frazier, Matthias Beyer, Matthias Reitinger, Matthias Vallentin, Michal Cichra, Nelson Chen, Nicky Peeters, Nikhil Marathe, Oliver Byford, Peter Aronoff, Raphael von der Grün, Remko Tronçon, Riley Goodside, Ruben Verborgh, Scott Vokes, Simon South, Spencer Whitt, Stanley Rost, Starr Horne, Stefan Bühler, Stuart Montgomery, Takashi Uchibe, Toon Willems, Tuomas Kareinen, Ursula Kallio, Vincent Driessen, Xavier Shay, Zaiste de Grengolada, Šime Ramov
|
23
|
+
Ale Muñoz, Alexander Mankuta, Arnau Siches, Ben Armston, Bil Bas, Brian Candler, Bruno Dufour, Chris Eppstein, Christian Plessl, Colin Barrett, Damien Pollet, Dan Callahan, Daniel Hofstetter, Daniel Mendler, Daniel Wollschlaeger, David Alexander, David Everitt, Dennis Sutch, Devon Luke Buchanan, Dmitry Bilunov, Eric Sunshine, Erik Hollensbe, Fabian Buch, Felix Hanley, Go Maeda, Gregory Pakosz, Grégory Karékinian, Guilherme Garnier, Jack Chu, Jake Benilov, Jasper Van der Jeugt, Jeff Forcier, John Nishinaga, Justin Clift, Justin Hileman, Kevin Lynagh, Louis T., Mathias Bynens, Matt Keveney, Matthew Frazier, Matthias Beyer, Matthias Reitinger, Matthias Vallentin, Michal Cichra, Nelson Chen, Nicky Peeters, Nikhil Marathe, Oliver Byford, Peter Aronoff, Raphael von der Grün, Remko Tronçon, Riley Goodside, Ruben Verborgh, Scott Vokes, Simon South, Spencer Whitt, Stanley Rost, Starr Horne, Stefan Bühler, Stuart Montgomery, Takashi Uchibe, Toon Willems, Tuomas Kareinen, Ursula Kallio, Vincent Driessen, Xavier Shay, Zaiste de Grengolada, Šime Ramov
|
data/lib/nanoc/base.rb
CHANGED
@@ -9,6 +9,7 @@ module Nanoc
|
|
9
9
|
autoload 'Identifier', 'nanoc/base/source_data/identifier'
|
10
10
|
|
11
11
|
autoload 'ConfigView', 'nanoc/base/views/config'
|
12
|
+
autoload 'IdentifiableCollectionView', 'nanoc/base/views/identifiable_collection'
|
12
13
|
autoload 'ItemView', 'nanoc/base/views/item'
|
13
14
|
autoload 'ItemRepView', 'nanoc/base/views/item_rep'
|
14
15
|
autoload 'ItemCollectionView', 'nanoc/base/views/item_collection'
|
@@ -16,6 +17,7 @@ module Nanoc
|
|
16
17
|
autoload 'LayoutCollectionView', 'nanoc/base/views/layout_collection'
|
17
18
|
autoload 'SiteView', 'nanoc/base/views/site'
|
18
19
|
|
20
|
+
autoload 'MutableIdentifiableCollectionView', 'nanoc/base/views/mutable_identifiable_collection'
|
19
21
|
autoload 'MutableConfigView', 'nanoc/base/views/mutable_config'
|
20
22
|
autoload 'MutableItemView', 'nanoc/base/views/mutable_item'
|
21
23
|
autoload 'MutableItemCollectionView', 'nanoc/base/views/mutable_item_collection'
|
@@ -39,12 +41,12 @@ module Nanoc::Int
|
|
39
41
|
autoload 'PluginRegistry', 'nanoc/base/plugin_registry'
|
40
42
|
autoload 'Store', 'nanoc/base/store'
|
41
43
|
autoload 'TempFilenameFactory', 'nanoc/base/temp_filename_factory'
|
44
|
+
autoload 'IdentifiableCollection', 'nanoc/base/identifiable_collection'
|
42
45
|
|
43
46
|
# Load source data classes
|
44
47
|
autoload 'CodeSnippet', 'nanoc/base/source_data/code_snippet'
|
45
48
|
autoload 'Configuration', 'nanoc/base/source_data/configuration'
|
46
49
|
autoload 'Item', 'nanoc/base/source_data/item'
|
47
|
-
autoload 'ItemArray', 'nanoc/base/source_data/item_array'
|
48
50
|
autoload 'Layout', 'nanoc/base/source_data/layout'
|
49
51
|
autoload 'Site', 'nanoc/base/source_data/site'
|
50
52
|
|
@@ -64,9 +64,7 @@ module Nanoc::Int
|
|
64
64
|
end
|
65
65
|
|
66
66
|
digest.update('attributes')
|
67
|
-
attributes
|
68
|
-
attributes.delete(:file)
|
69
|
-
update(attributes, digest, visited + [obj])
|
67
|
+
update(obj.attributes, digest, visited + [obj])
|
70
68
|
else
|
71
69
|
data = begin
|
72
70
|
Marshal.dump(obj)
|
@@ -159,7 +159,7 @@ module Nanoc::Int
|
|
159
159
|
# @return [void]
|
160
160
|
def store
|
161
161
|
# Calculate rule memory
|
162
|
-
(reps + layouts).each do |obj|
|
162
|
+
(reps + layouts.to_a).each do |obj|
|
163
163
|
rule_memory_store[obj] = rule_memory_calculator[obj]
|
164
164
|
end
|
165
165
|
|
@@ -177,7 +177,7 @@ module Nanoc::Int
|
|
177
177
|
#
|
178
178
|
# @return [Nanoc::Int::DependencyTracker] The dependency tracker for this site
|
179
179
|
def dependency_tracker
|
180
|
-
dt = Nanoc::Int::DependencyTracker.new(@site.items + @site.layouts)
|
180
|
+
dt = Nanoc::Int::DependencyTracker.new(@site.items.to_a + @site.layouts.to_a)
|
181
181
|
dt.compiler = self
|
182
182
|
dt
|
183
183
|
end
|
@@ -197,7 +197,7 @@ module Nanoc::Int
|
|
197
197
|
#
|
198
198
|
# @api private
|
199
199
|
def objects
|
200
|
-
site.items + site.layouts + site.code_snippets +
|
200
|
+
site.items.to_a + site.layouts.to_a + site.code_snippets +
|
201
201
|
[site.config, rules_collection]
|
202
202
|
end
|
203
203
|
|
@@ -260,14 +260,14 @@ module Nanoc::Int
|
|
260
260
|
|
261
261
|
# @api private
|
262
262
|
def create_pattern(arg)
|
263
|
-
case @config[:
|
263
|
+
case @config[:string_pattern_type]
|
264
264
|
when 'glob'
|
265
265
|
Nanoc::Int::Pattern.from(arg)
|
266
|
-
when
|
266
|
+
when 'legacy'
|
267
267
|
Nanoc::Int::Pattern.from(identifier_to_regex(arg))
|
268
268
|
else
|
269
269
|
raise Nanoc::Int::Errors::GenericTrivial,
|
270
|
-
"Invalid
|
270
|
+
"Invalid string_pattern_type: #{@config[:string_pattern_type]}"
|
271
271
|
end
|
272
272
|
end
|
273
273
|
|
@@ -15,17 +15,6 @@ module Nanoc::ArrayExtensions
|
|
15
15
|
array
|
16
16
|
end
|
17
17
|
|
18
|
-
# Returns a new array where all items' keys are recursively converted to
|
19
|
-
# strings by calling {Nanoc::ArrayExtensions#__nanoc_stringify_keys_recursively} or
|
20
|
-
# {Nanoc::HashExtensions#__nanoc_stringify_keys_recursively}.
|
21
|
-
#
|
22
|
-
# @return [Array] The converted array
|
23
|
-
def __nanoc_stringify_keys_recursively
|
24
|
-
reduce([]) do |array, element|
|
25
|
-
array + [element.respond_to?(:__nanoc_stringify_keys_recursively) ? element.__nanoc_stringify_keys_recursively : element]
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
18
|
# Freezes the contents of the array, as well as all array elements. The
|
30
19
|
# array elements will be frozen using {#__nanoc_freeze_recursively} if they respond
|
31
20
|
# to that message, or #freeze if they do not.
|
@@ -17,17 +17,6 @@ module Nanoc::HashExtensions
|
|
17
17
|
hash
|
18
18
|
end
|
19
19
|
|
20
|
-
# Returns a new hash where all keys are recursively converted to strings by
|
21
|
-
# calling {Nanoc::ArrayExtensions#__nanoc_stringify_keys_recursively} or
|
22
|
-
# {Nanoc::HashExtensions#__nanoc_stringify_keys_recursively}.
|
23
|
-
#
|
24
|
-
# @return [Hash] The converted hash
|
25
|
-
def __nanoc_stringify_keys_recursively
|
26
|
-
reduce({}) do |hash, (key, value)|
|
27
|
-
hash.merge(key.to_s => value.respond_to?(:__nanoc_stringify_keys_recursively) ? value.__nanoc_stringify_keys_recursively : value)
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
20
|
# Freezes the contents of the hash, as well as all hash values. The hash
|
32
21
|
# values will be frozen using {#__nanoc_freeze_recursively} if they respond to
|
33
22
|
# that message, or #freeze if they do not.
|
@@ -0,0 +1,81 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module Nanoc::Int
|
4
|
+
# @api private
|
5
|
+
class IdentifiableCollection
|
6
|
+
include Enumerable
|
7
|
+
|
8
|
+
extend Forwardable
|
9
|
+
|
10
|
+
def_delegator :@objects, :each
|
11
|
+
def_delegator :@objects, :size
|
12
|
+
def_delegator :@objects, :<<
|
13
|
+
def_delegator :@objects, :concat
|
14
|
+
|
15
|
+
def initialize(config)
|
16
|
+
@config = config
|
17
|
+
|
18
|
+
@objects = []
|
19
|
+
end
|
20
|
+
|
21
|
+
def freeze
|
22
|
+
@objects.freeze
|
23
|
+
build_mapping
|
24
|
+
super
|
25
|
+
end
|
26
|
+
|
27
|
+
def [](arg)
|
28
|
+
case arg
|
29
|
+
when String
|
30
|
+
object_with_identifier(arg) || object_matching_glob(arg)
|
31
|
+
when Regexp
|
32
|
+
@objects.find { |i| i.identifier.to_s =~ arg }
|
33
|
+
else
|
34
|
+
raise ArgumentError, "don’t know how to fetch objects by #{arg.inspect}"
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def to_a
|
39
|
+
@objects
|
40
|
+
end
|
41
|
+
|
42
|
+
def empty?
|
43
|
+
@objects.empty?
|
44
|
+
end
|
45
|
+
|
46
|
+
def delete_if(&block)
|
47
|
+
@objects.delete_if(&block)
|
48
|
+
end
|
49
|
+
|
50
|
+
protected
|
51
|
+
|
52
|
+
def object_with_identifier(identifier)
|
53
|
+
if self.frozen?
|
54
|
+
@mapping[identifier.to_s]
|
55
|
+
else
|
56
|
+
@objects.find { |i| i.identifier == identifier }
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def object_matching_glob(glob)
|
61
|
+
if use_globs?
|
62
|
+
pat = Nanoc::Int::Pattern.from(glob)
|
63
|
+
@objects.find { |i| pat.match?(i.identifier) }
|
64
|
+
else
|
65
|
+
nil
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
def build_mapping
|
70
|
+
@mapping = {}
|
71
|
+
@objects.each do |object|
|
72
|
+
@mapping[object.identifier.to_s] = object
|
73
|
+
end
|
74
|
+
@mapping.freeze
|
75
|
+
end
|
76
|
+
|
77
|
+
def use_globs?
|
78
|
+
@config[:string_pattern_type] == 'glob'
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
@@ -16,10 +16,10 @@ module Nanoc
|
|
16
16
|
end
|
17
17
|
|
18
18
|
def initialize(string, params = {})
|
19
|
-
@
|
19
|
+
@type = params.fetch(:type, :full)
|
20
20
|
|
21
|
-
case @
|
22
|
-
when :
|
21
|
+
case @type
|
22
|
+
when :legacy
|
23
23
|
@string = "/#{string}/".gsub(/^\/+|\/+$/, '/').freeze
|
24
24
|
when :full
|
25
25
|
if string !~ /\A\//
|
@@ -29,7 +29,7 @@ module Nanoc
|
|
29
29
|
@string = string.dup.freeze
|
30
30
|
else
|
31
31
|
raise Nanoc::Int::Errors::Generic,
|
32
|
-
"Invalid :
|
32
|
+
"Invalid :type param for identifier: #{@type.inspect}"
|
33
33
|
end
|
34
34
|
end
|
35
35
|
|
@@ -50,10 +50,10 @@ module Nanoc
|
|
50
50
|
to_s <=> other.to_s
|
51
51
|
end
|
52
52
|
|
53
|
-
# @return [Boolean] True if this is a full-
|
53
|
+
# @return [Boolean] True if this is a full-type identifier (i.e. includes
|
54
54
|
# the extension), false otherwise
|
55
55
|
def full?
|
56
|
-
@
|
56
|
+
@type == :full
|
57
57
|
end
|
58
58
|
|
59
59
|
# @return [String]
|
@@ -72,12 +72,12 @@ module Nanoc
|
|
72
72
|
raise Nanoc::Int::Errors::Generic,
|
73
73
|
"Invalid prefix (does not start with a slash): #{@string.inspect}"
|
74
74
|
end
|
75
|
-
Nanoc::Identifier.new(string.sub(/\/+\z/, '') + @string,
|
75
|
+
Nanoc::Identifier.new(string.sub(/\/+\z/, '') + @string, type: @type)
|
76
76
|
end
|
77
77
|
|
78
78
|
# @return [String]
|
79
79
|
def with_ext(ext)
|
80
|
-
|
80
|
+
unless full?
|
81
81
|
raise Nanoc::Int::Errors::Generic,
|
82
82
|
'Cannot use #with_ext on identifier that does not include the file extension'
|
83
83
|
end
|
@@ -117,7 +117,7 @@ module Nanoc
|
|
117
117
|
end
|
118
118
|
|
119
119
|
def inspect
|
120
|
-
"<Nanoc::Identifier
|
120
|
+
"<Nanoc::Identifier type=#{@type} #{to_s.inspect}>"
|
121
121
|
end
|
122
122
|
end
|
123
123
|
end
|
@@ -24,7 +24,8 @@ module Nanoc::Int
|
|
24
24
|
type: 'filesystem_unified',
|
25
25
|
items_root: '/',
|
26
26
|
layouts_root: '/',
|
27
|
-
config: {}
|
27
|
+
config: {},
|
28
|
+
identifier_type: 'full',
|
28
29
|
}
|
29
30
|
|
30
31
|
# The default configuration for a site. A site's configuration overrides
|
@@ -32,14 +33,15 @@ module Nanoc::Int
|
|
32
33
|
# that lacks some options, the default value will be taken from
|
33
34
|
# `DEFAULT_CONFIG`.
|
34
35
|
DEFAULT_CONFIG = {
|
35
|
-
text_extensions: %w( css erb haml htm html js less markdown md php rb sass scss txt xhtml xml coffee hb handlebars mustache ms slim ).sort,
|
36
|
+
text_extensions: %w( css erb haml htm html js less markdown md php rb sass scss txt xhtml xml coffee hb handlebars mustache ms slim rdoc ).sort,
|
36
37
|
lib_dirs: %w( lib ),
|
37
38
|
commands_dirs: %w( commands ),
|
38
39
|
output_dir: 'output',
|
39
40
|
data_sources: [{}],
|
40
41
|
index_filenames: ['index.html'],
|
41
42
|
enable_output_diff: false,
|
42
|
-
prune: { auto_prune: false, exclude: ['.git', '.hg', '.svn', 'CVS'] }
|
43
|
+
prune: { auto_prune: false, exclude: ['.git', '.hg', '.svn', 'CVS'] },
|
44
|
+
string_pattern_type: 'glob',
|
43
45
|
}
|
44
46
|
|
45
47
|
# Creates a site object for the site specified by the given
|
@@ -325,7 +327,7 @@ module Nanoc::Int
|
|
325
327
|
@items_loaded = true
|
326
328
|
|
327
329
|
# Get items
|
328
|
-
@items = Nanoc::Int::
|
330
|
+
@items = Nanoc::Int::IdentifiableCollection.new(@config)
|
329
331
|
data_sources.each do |ds|
|
330
332
|
items_in_ds = ds.items
|
331
333
|
items_in_ds.each do |i|
|
@@ -343,7 +345,7 @@ module Nanoc::Int
|
|
343
345
|
@layouts_loaded = true
|
344
346
|
|
345
347
|
# Get layouts
|
346
|
-
@layouts =
|
348
|
+
@layouts = Nanoc::Int::IdentifiableCollection.new(@config)
|
347
349
|
data_sources.each do |ds|
|
348
350
|
layouts_in_ds = ds.layouts
|
349
351
|
layouts_in_ds.each do |l|
|
@@ -0,0 +1,78 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module Nanoc
|
4
|
+
class IdentifiableCollectionView
|
5
|
+
include Enumerable
|
6
|
+
|
7
|
+
# @api private
|
8
|
+
def initialize(objects)
|
9
|
+
@objects = objects
|
10
|
+
end
|
11
|
+
|
12
|
+
# @api private
|
13
|
+
def unwrap
|
14
|
+
@objects
|
15
|
+
end
|
16
|
+
|
17
|
+
# @abstract
|
18
|
+
#
|
19
|
+
# @api private
|
20
|
+
def view_class
|
21
|
+
raise NotImplementedError
|
22
|
+
end
|
23
|
+
|
24
|
+
# Calls the given block once for each object, passing that object as a parameter.
|
25
|
+
#
|
26
|
+
# @yieldparam [#identifier] object
|
27
|
+
#
|
28
|
+
# @yieldreturn [void]
|
29
|
+
#
|
30
|
+
# @return [self]
|
31
|
+
def each
|
32
|
+
@objects.each { |i| yield view_class.new(i) }
|
33
|
+
self
|
34
|
+
end
|
35
|
+
|
36
|
+
# @return [Integer]
|
37
|
+
def size
|
38
|
+
@objects.size
|
39
|
+
end
|
40
|
+
|
41
|
+
# Finds all objects whose identifier matches the given argument.
|
42
|
+
#
|
43
|
+
# @param [String, Regex] arg
|
44
|
+
#
|
45
|
+
# @return [Enumerable]
|
46
|
+
def find_all(arg)
|
47
|
+
pat = Nanoc::Int::Pattern.from(arg)
|
48
|
+
select { |i| pat.match?(i.identifier) }
|
49
|
+
end
|
50
|
+
|
51
|
+
# @overload [](string)
|
52
|
+
#
|
53
|
+
# Finds the object whose identifier matches the given string.
|
54
|
+
#
|
55
|
+
# If the glob syntax is enabled, the string can be a glob, in which case
|
56
|
+
# this method finds the first object that matches the given glob.
|
57
|
+
#
|
58
|
+
# @param [String] string
|
59
|
+
#
|
60
|
+
# @return [nil] if no object matches the string
|
61
|
+
#
|
62
|
+
# @return [#identifier] if an object was found
|
63
|
+
#
|
64
|
+
# @overload [](regex)
|
65
|
+
#
|
66
|
+
# Finds the object whose identifier matches the given regular expression.
|
67
|
+
#
|
68
|
+
# @param [Regex] regex
|
69
|
+
#
|
70
|
+
# @return [nil] if no object matches the regex
|
71
|
+
#
|
72
|
+
# @return [#identifier] if an object was found
|
73
|
+
def [](arg)
|
74
|
+
res = @objects[arg]
|
75
|
+
res && view_class.new(res)
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|