nanoc 3.4.3 → 3.5.0b1
Sign up to get free protection for your applications and to get access to all the features.
- data/CONTRIBUTING.md +25 -0
- data/Gemfile +3 -1
- data/Gemfile.lock +22 -13
- data/NEWS.md +27 -0
- data/README.md +3 -1
- data/lib/nanoc.rb +2 -2
- data/lib/nanoc/base/compilation/compiler_dsl.rb +19 -0
- data/lib/nanoc/base/core_ext/array.rb +18 -8
- data/lib/nanoc/base/core_ext/hash.rb +18 -8
- data/lib/nanoc/base/core_ext/pathname.rb +2 -8
- data/lib/nanoc/base/plugin_registry.rb +57 -19
- data/lib/nanoc/base/result_data/item_rep.rb +3 -15
- data/lib/nanoc/base/source_data/item.rb +1 -1
- data/lib/nanoc/base/source_data/layout.rb +1 -1
- data/lib/nanoc/base/source_data/site.rb +15 -19
- data/lib/nanoc/cli.rb +28 -23
- data/lib/nanoc/cli/command_runner.rb +4 -0
- data/lib/nanoc/cli/commands/autocompile.rb +15 -6
- data/lib/nanoc/cli/commands/check.rb +47 -0
- data/lib/nanoc/cli/commands/compile.rb +271 -195
- data/lib/nanoc/cli/commands/create-site.rb +5 -5
- data/lib/nanoc/cli/commands/deploy.rb +16 -4
- data/lib/nanoc/cli/commands/prune.rb +3 -3
- data/lib/nanoc/cli/commands/show-data.rb +73 -58
- data/lib/nanoc/cli/commands/show-rules.rb +1 -1
- data/lib/nanoc/cli/commands/validate-css.rb +2 -3
- data/lib/nanoc/cli/commands/validate-html.rb +2 -3
- data/lib/nanoc/cli/commands/validate-links.rb +5 -11
- data/lib/nanoc/cli/commands/view.rb +1 -1
- data/lib/nanoc/cli/commands/watch.rb +38 -20
- data/lib/nanoc/cli/error_handler.rb +122 -122
- data/lib/nanoc/data_sources.rb +2 -0
- data/lib/nanoc/data_sources/filesystem_unified.rb +1 -1
- data/lib/nanoc/data_sources/filesystem_verbose.rb +1 -1
- data/lib/nanoc/data_sources/static.rb +60 -0
- data/lib/nanoc/extra.rb +2 -0
- data/lib/nanoc/extra/checking.rb +16 -0
- data/lib/nanoc/extra/checking/check.rb +33 -0
- data/lib/nanoc/extra/checking/checks.rb +19 -0
- data/lib/nanoc/extra/checking/checks/css.rb +23 -0
- data/lib/nanoc/extra/checking/checks/external_links.rb +149 -0
- data/lib/nanoc/extra/checking/checks/html.rb +24 -0
- data/lib/nanoc/extra/checking/checks/internal_links.rb +57 -0
- data/lib/nanoc/extra/checking/checks/stale.rb +23 -0
- data/lib/nanoc/extra/checking/dsl.rb +31 -0
- data/lib/nanoc/extra/checking/issue.rb +19 -0
- data/lib/nanoc/extra/checking/runner.rb +130 -0
- data/lib/nanoc/extra/link_collector.rb +57 -0
- data/lib/nanoc/extra/pruner.rb +1 -1
- data/lib/nanoc/extra/validators/links.rb +5 -262
- data/lib/nanoc/extra/validators/w3c.rb +8 -76
- data/lib/nanoc/filters/colorize_syntax.rb +1 -1
- data/lib/nanoc/filters/handlebars.rb +2 -2
- data/lib/nanoc/filters/less.rb +1 -1
- data/lib/nanoc/filters/redcarpet.rb +1 -1
- data/lib/nanoc/filters/rubypants.rb +1 -1
- data/lib/nanoc/filters/slim.rb +1 -1
- data/lib/nanoc/helpers/blogging.rb +163 -104
- data/lib/nanoc/helpers/xml_sitemap.rb +9 -3
- data/tasks/doc.rake +2 -1
- data/test/base/core_ext/array_spec.rb +4 -4
- data/test/base/core_ext/hash_spec.rb +7 -7
- data/test/base/core_ext/pathname_spec.rb +12 -2
- data/test/base/test_compiler_dsl.rb +24 -0
- data/test/base/test_item_rep.rb +58 -26
- data/test/cli/commands/test_watch.rb +0 -8
- data/test/data_sources/test_static.rb +66 -0
- data/test/extra/checking/checks/test_css.rb +40 -0
- data/test/extra/checking/checks/test_external_links.rb +76 -0
- data/test/extra/checking/checks/test_html.rb +40 -0
- data/test/extra/checking/checks/test_internal_links.rb +46 -0
- data/test/extra/checking/checks/test_stale.rb +49 -0
- data/test/extra/checking/test_check.rb +16 -0
- data/test/extra/checking/test_dsl.rb +20 -0
- data/test/extra/checking/test_runner.rb +15 -0
- data/test/extra/test_link_collector.rb +93 -0
- data/test/extra/validators/test_links.rb +0 -64
- data/test/extra/validators/test_w3c.rb +20 -26
- data/test/filters/test_colorize_syntax.rb +15 -0
- data/test/filters/test_less.rb +14 -0
- data/test/filters/test_pandoc.rb +5 -1
- data/test/helpers/test_blogging.rb +52 -8
- data/test/helpers/test_xml_sitemap.rb +68 -0
- data/test/test_gem.rb +1 -1
- metadata +31 -6
data/CONTRIBUTING.md
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
Contributing
|
2
|
+
============
|
3
|
+
|
4
|
+
Reporting bugs
|
5
|
+
--------------
|
6
|
+
|
7
|
+
If you find a bug in nanoc, you should report it! But before you do, make sure you have the latest version of nanoc (and dependencies) installed, and see if you can still reproduce the bug there. If you can, report it!
|
8
|
+
|
9
|
+
When reporting a bug, please make sure you include as many details as you can about the bug. Some information that you should include:
|
10
|
+
|
11
|
+
* The nanoc version (`nanoc --version`)
|
12
|
+
* The `crash.log` file, if relevant
|
13
|
+
|
14
|
+
Submitting Patches
|
15
|
+
------------------
|
16
|
+
|
17
|
+
If you want to submit a pull request, please review the following few guidelines:
|
18
|
+
|
19
|
+
* If your pull request is a **bug fix**, submit it on the latest release branch. At the moment of writing, this is `release-3.4.x`. This ensures that the bug fix comes in the next patch release.
|
20
|
+
|
21
|
+
* If your pull request is a new **feature** or extends an existing feature, submit it on the `master` branch.
|
22
|
+
|
23
|
+
In both cases, make sure that your changes have **test cases** that cover the bug fix or the new/changed functionality.
|
24
|
+
|
25
|
+
Also note that **backwards compatibility** must be retained. This means that you cannot simply modify a feature to work in a different way. What you can do, is add an option to make it work in a different way, but do double-check with me (@ddfreyne) first.
|
data/Gemfile
CHANGED
@@ -9,15 +9,17 @@ gem 'coderay'
|
|
9
9
|
gem 'coffee-script'
|
10
10
|
gem 'erubis'
|
11
11
|
gem 'fog'
|
12
|
-
gem 'fssm'
|
13
12
|
gem 'haml'
|
13
|
+
gem 'handlebars'
|
14
14
|
gem 'kramdown'
|
15
15
|
gem 'less', '~> 2.0'
|
16
|
+
gem 'listen'
|
16
17
|
gem 'markaby'
|
17
18
|
gem 'maruku'
|
18
19
|
gem 'mime-types'
|
19
20
|
gem 'mustache'
|
20
21
|
gem 'nokogiri', '~> 1.5.5'
|
22
|
+
gem 'pandoc-ruby'
|
21
23
|
gem 'pygments.rb'
|
22
24
|
gem 'rack'
|
23
25
|
gem 'rake'
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
nanoc (3.
|
4
|
+
nanoc (3.5.0)
|
5
5
|
cri (~> 2.2)
|
6
6
|
|
7
7
|
GEM
|
@@ -25,7 +25,7 @@ GEM
|
|
25
25
|
excon (0.16.10)
|
26
26
|
execjs (1.4.0)
|
27
27
|
multi_json (~> 1.0)
|
28
|
-
fog (1.
|
28
|
+
fog (1.8.0)
|
29
29
|
builder
|
30
30
|
excon (~> 0.14)
|
31
31
|
formatador (~> 0.2.0)
|
@@ -36,47 +36,54 @@ GEM
|
|
36
36
|
nokogiri (~> 1.5.0)
|
37
37
|
ruby-hmac
|
38
38
|
formatador (0.2.4)
|
39
|
-
fssm (0.2.9)
|
40
39
|
haml (3.1.7)
|
40
|
+
handlebars (0.3.1)
|
41
|
+
commonjs (~> 0.2.3)
|
42
|
+
therubyracer (~> 0.10.0)
|
41
43
|
json (1.7.5)
|
42
|
-
kramdown (0.14.
|
44
|
+
kramdown (0.14.1)
|
43
45
|
less (2.2.2)
|
44
46
|
commonjs (~> 0.2.6)
|
47
|
+
libv8 (3.3.10.4)
|
48
|
+
listen (0.6.0)
|
45
49
|
markaby (0.7.2)
|
46
50
|
builder (>= 2.0.0)
|
47
51
|
maruku (0.6.1)
|
48
52
|
syntax (>= 1.0.0)
|
49
53
|
metaclass (0.0.1)
|
50
54
|
mime-types (1.19)
|
51
|
-
minitest (4.3.
|
52
|
-
mocha (0.13.
|
55
|
+
minitest (4.3.3)
|
56
|
+
mocha (0.13.1)
|
53
57
|
metaclass (~> 0.0.1)
|
54
|
-
multi_json (1.
|
58
|
+
multi_json (1.5.0)
|
55
59
|
mustache (0.99.4)
|
56
60
|
net-scp (1.0.4)
|
57
61
|
net-ssh (>= 1.99.1)
|
58
62
|
net-ssh (2.6.2)
|
59
|
-
nokogiri (1.5.
|
63
|
+
nokogiri (1.5.6)
|
64
|
+
pandoc-ruby (0.6.0)
|
60
65
|
posix-spawn (0.3.6)
|
61
|
-
pygments.rb (0.3.
|
66
|
+
pygments.rb (0.3.3)
|
62
67
|
posix-spawn (~> 0.3.6)
|
63
68
|
yajl-ruby (~> 1.1.0)
|
64
69
|
rack (1.4.1)
|
65
70
|
rainpress (1.0)
|
66
|
-
rake (10.0.
|
71
|
+
rake (10.0.3)
|
67
72
|
rdiscount (1.6.8)
|
68
73
|
rdoc (3.12)
|
69
74
|
json (~> 1.4)
|
70
75
|
redcarpet (2.2.2)
|
71
76
|
ruby-hmac (0.4.0)
|
72
77
|
rubypants (0.2.0)
|
73
|
-
sass (3.2.
|
74
|
-
slim (1.3.
|
78
|
+
sass (3.2.4)
|
79
|
+
slim (1.3.5)
|
75
80
|
temple (~> 0.5.5)
|
76
81
|
tilt (~> 1.3.3)
|
77
82
|
syntax (1.0.0)
|
78
83
|
systemu (2.5.2)
|
79
84
|
temple (0.5.5)
|
85
|
+
therubyracer (0.10.2)
|
86
|
+
libv8 (~> 3.3.10)
|
80
87
|
tilt (1.3.3)
|
81
88
|
typogruby (1.0.15)
|
82
89
|
rubypants
|
@@ -102,10 +109,11 @@ DEPENDENCIES
|
|
102
109
|
coffee-script
|
103
110
|
erubis
|
104
111
|
fog
|
105
|
-
fssm
|
106
112
|
haml
|
113
|
+
handlebars
|
107
114
|
kramdown
|
108
115
|
less (~> 2.0)
|
116
|
+
listen
|
109
117
|
markaby
|
110
118
|
maruku
|
111
119
|
mime-types
|
@@ -114,6 +122,7 @@ DEPENDENCIES
|
|
114
122
|
mustache
|
115
123
|
nanoc!
|
116
124
|
nokogiri (~> 1.5.5)
|
125
|
+
pandoc-ruby
|
117
126
|
pygments.rb
|
118
127
|
rack
|
119
128
|
rainpress
|
data/NEWS.md
CHANGED
@@ -1,5 +1,32 @@
|
|
1
1
|
# nanoc news
|
2
2
|
|
3
|
+
## 3.5 (???)
|
4
|
+
|
5
|
+
Major changes:
|
6
|
+
|
7
|
+
* Added checks
|
8
|
+
|
9
|
+
Minor changes:
|
10
|
+
|
11
|
+
* Added `#include_rules` for modularising Rules files [Justin Hileman]
|
12
|
+
* Replaced FSSM with Listen [Takashi Uchibe]
|
13
|
+
* Made USR1 print stack trace
|
14
|
+
* Added ability to configure autocompiler host/port in config.yaml [Stuart Montgomery]
|
15
|
+
* Added static data source
|
16
|
+
* Added `:rep_select` parameter to XML sitemap to allow filtering reps
|
17
|
+
|
18
|
+
Exensions:
|
19
|
+
|
20
|
+
* Added support for parameters in Less filter [Ruben Verborgh]
|
21
|
+
* Added support for icon and logo in Atom feed [Ruben Verborgh]
|
22
|
+
|
23
|
+
## 3.4.4 (???)
|
24
|
+
|
25
|
+
Fixes:
|
26
|
+
|
27
|
+
* Made syntax colorizer only use the first non-empty line when extracting the
|
28
|
+
language comment
|
29
|
+
|
3
30
|
## 3.4.3 (2012-12-09)
|
4
31
|
|
5
32
|
Improvements:
|
data/README.md
CHANGED
@@ -18,7 +18,7 @@ the following places will help you out:
|
|
18
18
|
|
19
19
|
## Versioning
|
20
20
|
|
21
|
-
nanoc uses [Semantic Versioning](semver.org).
|
21
|
+
nanoc uses [Semantic Versioning](http://semver.org/).
|
22
22
|
|
23
23
|
## Source Code Documentation
|
24
24
|
|
@@ -102,6 +102,7 @@ may be interested in the development dependencies:
|
|
102
102
|
* Go Maeda
|
103
103
|
* Nikhil Marathe
|
104
104
|
* Daniel Mendler
|
105
|
+
* Stuart Montgomery
|
105
106
|
* Ale Muñoz
|
106
107
|
* John Nishinaga
|
107
108
|
* Gregory Pakosz
|
@@ -114,6 +115,7 @@ may be interested in the development dependencies:
|
|
114
115
|
* “Soryu”
|
115
116
|
* Eric Sunshine
|
116
117
|
* Dennis Sutch
|
118
|
+
* Takashi Uchibe
|
117
119
|
* Matthias Vallentin
|
118
120
|
* Ruben Verborgh
|
119
121
|
* Scott Vokes
|
data/lib/nanoc.rb
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
module Nanoc
|
4
4
|
|
5
5
|
# The current nanoc version.
|
6
|
-
VERSION = '3.
|
6
|
+
VERSION = '3.5.0b1'
|
7
7
|
|
8
8
|
# @return [String] A string containing information about this nanoc version
|
9
9
|
# and its environment (Ruby engine and version, Rubygems version if any).
|
@@ -11,7 +11,7 @@ module Nanoc
|
|
11
11
|
gem_info = defined?(Gem) ? "with RubyGems #{Gem::VERSION}" : "without RubyGems"
|
12
12
|
engine = defined?(RUBY_ENGINE) ? RUBY_ENGINE : "ruby"
|
13
13
|
res = ''
|
14
|
-
res << "nanoc #{Nanoc::VERSION} © 2007-
|
14
|
+
res << "nanoc #{Nanoc::VERSION} © 2007-2013 Denis Defreyne.\n"
|
15
15
|
res << "Running #{engine} #{RUBY_VERSION} (#{RUBY_RELEASE_DATE}) on #{RUBY_PLATFORM} #{gem_info}.\n"
|
16
16
|
res
|
17
17
|
end
|
@@ -190,6 +190,25 @@ module Nanoc
|
|
190
190
|
@rules_collection.add_item_routing_rule(routing_rule)
|
191
191
|
end
|
192
192
|
|
193
|
+
# Includes an additional rules file in the current rules collection.
|
194
|
+
#
|
195
|
+
# @param [String] name The name of the rules file — an ".rb" extension is
|
196
|
+
# implied if not explicitly given
|
197
|
+
#
|
198
|
+
# @return [void]
|
199
|
+
#
|
200
|
+
# @example Including two additional rules files, 'rules/assets.rb' and
|
201
|
+
# 'rules/content.rb'
|
202
|
+
#
|
203
|
+
# include_rules 'rules/assets'
|
204
|
+
# include_rules 'rules/content'
|
205
|
+
def include_rules(name)
|
206
|
+
filename = [ "#{name}", "#{name}.rb", "./#{name}", "./#{name}.rb" ].find { |f| File.file?(f) }
|
207
|
+
raise Nanoc::Errors::NoRulesFileFound.new if filename.nil?
|
208
|
+
|
209
|
+
self.instance_eval(File.read(filename), filename)
|
210
|
+
end
|
211
|
+
|
193
212
|
private
|
194
213
|
|
195
214
|
# Converts the given identifier, which can contain the '*' or '+'
|
@@ -3,27 +3,37 @@
|
|
3
3
|
module Nanoc::ArrayExtensions
|
4
4
|
|
5
5
|
# Returns a new array where all items' keys are recursively converted to
|
6
|
-
# symbols by calling {Nanoc::ArrayExtensions#
|
7
|
-
# {Nanoc::HashExtensions#
|
6
|
+
# symbols by calling {Nanoc::ArrayExtensions#symbolize_keys_recursively} or
|
7
|
+
# {Nanoc::HashExtensions#symbolize_keys_recursively}.
|
8
8
|
#
|
9
9
|
# @return [Array] The converted array
|
10
|
-
def
|
10
|
+
def symbolize_keys_recursively
|
11
11
|
inject([]) do |array, element|
|
12
|
-
array + [ element.respond_to?(:
|
12
|
+
array + [ element.respond_to?(:symbolize_keys_recursively) ? element.symbolize_keys_recursively : element ]
|
13
13
|
end
|
14
14
|
end
|
15
15
|
|
16
|
+
# @deprecated Renamed to {#symbolize_keys_recursively}
|
17
|
+
def symbolize_keys
|
18
|
+
symbolize_keys_recursively
|
19
|
+
end
|
20
|
+
|
16
21
|
# Returns a new array where all items' keys are recursively converted to
|
17
|
-
# strings by calling {Nanoc::ArrayExtensions#
|
18
|
-
# {Nanoc::HashExtensions#
|
22
|
+
# strings by calling {Nanoc::ArrayExtensions#stringify_keys_recursively} or
|
23
|
+
# {Nanoc::HashExtensions#stringify_keys_recursively}.
|
19
24
|
#
|
20
25
|
# @return [Array] The converted array
|
21
|
-
def
|
26
|
+
def stringify_keys_recursively
|
22
27
|
inject([]) do |array, element|
|
23
|
-
array + [ element.respond_to?(:
|
28
|
+
array + [ element.respond_to?(:stringify_keys_recursively) ? element.stringify_keys_recursively : element ]
|
24
29
|
end
|
25
30
|
end
|
26
31
|
|
32
|
+
# @deprecated Renamed to {#stringify_keys_recursively}
|
33
|
+
def stringify_keys
|
34
|
+
stringify_keys_recursively
|
35
|
+
end
|
36
|
+
|
27
37
|
# Freezes the contents of the array, as well as all array elements. The
|
28
38
|
# array elements will be frozen using {#freeze_recursively} if they respond
|
29
39
|
# to that message, or #freeze if they do not.
|
@@ -3,27 +3,37 @@
|
|
3
3
|
module Nanoc::HashExtensions
|
4
4
|
|
5
5
|
# Returns a new hash where all keys are recursively converted to symbols by
|
6
|
-
# calling {Nanoc::ArrayExtensions#
|
7
|
-
# {Nanoc::HashExtensions#
|
6
|
+
# calling {Nanoc::ArrayExtensions#symbolize_keys_recursively} or
|
7
|
+
# {Nanoc::HashExtensions#symbolize_keys_recursively}.
|
8
8
|
#
|
9
9
|
# @return [Hash] The converted hash
|
10
|
-
def
|
10
|
+
def symbolize_keys_recursively
|
11
11
|
inject({}) do |hash, (key, value)|
|
12
|
-
hash.merge(key.to_sym => value.respond_to?(:
|
12
|
+
hash.merge(key.to_sym => value.respond_to?(:symbolize_keys_recursively) ? value.symbolize_keys_recursively : value)
|
13
13
|
end
|
14
14
|
end
|
15
15
|
|
16
|
+
# @deprecated Renamed to {#symbolize_keys_recursively}
|
17
|
+
def symbolize_keys
|
18
|
+
symbolize_keys_recursively
|
19
|
+
end
|
20
|
+
|
16
21
|
# Returns a new hash where all keys are recursively converted to strings by
|
17
|
-
# calling {Nanoc::ArrayExtensions#
|
18
|
-
# {Nanoc::HashExtensions#
|
22
|
+
# calling {Nanoc::ArrayExtensions#stringify_keys_recursively} or
|
23
|
+
# {Nanoc::HashExtensions#stringify_keys_recursively}.
|
19
24
|
#
|
20
25
|
# @return [Hash] The converted hash
|
21
|
-
def
|
26
|
+
def stringify_keys_recursively
|
22
27
|
inject({}) do |hash, (key, value)|
|
23
|
-
hash.merge(key.to_s => value.respond_to?(:
|
28
|
+
hash.merge(key.to_s => value.respond_to?(:stringify_keys_recursively) ? value.stringify_keys_recursively : value)
|
24
29
|
end
|
25
30
|
end
|
26
31
|
|
32
|
+
# @deprecated Renamed to {#stringify_keys_recursively}
|
33
|
+
def stringify_keys
|
34
|
+
stringify_keys_recursively
|
35
|
+
end
|
36
|
+
|
27
37
|
# Freezes the contents of the hash, as well as all hash values. The hash
|
28
38
|
# values will be frozen using {#freeze_recursively} if they respond to
|
29
39
|
# that message, or #freeze if they do not.
|
@@ -9,14 +9,8 @@ module Nanoc::PathnameExtensions
|
|
9
9
|
#
|
10
10
|
# @api private
|
11
11
|
def checksum
|
12
|
-
|
13
|
-
|
14
|
-
until io.eof
|
15
|
-
data = io.read(2**10)
|
16
|
-
digest.update(data)
|
17
|
-
end
|
18
|
-
end
|
19
|
-
digest.hexdigest
|
12
|
+
stat = File.stat(self.to_s)
|
13
|
+
stat.size.to_s + '-' + stat.mtime.to_s
|
20
14
|
end
|
21
15
|
|
22
16
|
end
|
@@ -14,23 +14,43 @@ module Nanoc
|
|
14
14
|
# classes should extend this module.
|
15
15
|
module PluginMethods
|
16
16
|
|
17
|
-
#
|
17
|
+
# @overload identifiers(*identifiers)
|
18
18
|
#
|
19
|
-
#
|
20
|
-
# this plugin.
|
19
|
+
# Sets the identifiers for this plugin.
|
21
20
|
#
|
22
|
-
#
|
21
|
+
# @param [Array<Symbol>] identifiers A list of identifiers to assign to
|
22
|
+
# this plugin.
|
23
|
+
#
|
24
|
+
# @return [void]
|
25
|
+
#
|
26
|
+
# @overload identifiers
|
27
|
+
#
|
28
|
+
# @return [Array<Symbol>] The identifiers for this plugin
|
23
29
|
def identifiers(*identifiers)
|
24
|
-
|
30
|
+
if identifiers.empty?
|
31
|
+
Nanoc::PluginRegistry.instance.identifiers_of(self.superclass, self)
|
32
|
+
else
|
33
|
+
register(self, *identifiers)
|
34
|
+
end
|
25
35
|
end
|
26
36
|
|
27
|
-
#
|
37
|
+
# @overload identifier(identifier)
|
28
38
|
#
|
29
|
-
#
|
39
|
+
# Sets the identifier for this plugin.
|
30
40
|
#
|
31
|
-
#
|
32
|
-
|
33
|
-
|
41
|
+
# @param [Symbol] identifier An identifier to assign to this plugin.
|
42
|
+
#
|
43
|
+
# @return [void]
|
44
|
+
#
|
45
|
+
# @overload identifier
|
46
|
+
#
|
47
|
+
# @return [Symbol] The first identifier for this plugin
|
48
|
+
def identifier(identifier=nil)
|
49
|
+
if identifier
|
50
|
+
self.identifiers(identifier)
|
51
|
+
else
|
52
|
+
Nanoc::PluginRegistry.instance.identifiers_of(self.superclass, self).first
|
53
|
+
end
|
34
54
|
end
|
35
55
|
|
36
56
|
# Registers the given class as a plugin with the given identifier.
|
@@ -81,7 +101,8 @@ module Nanoc
|
|
81
101
|
# is recommended to use the shared instance (obtained from
|
82
102
|
# {Nanoc::PluginRegistry.instance}).
|
83
103
|
def initialize
|
84
|
-
@
|
104
|
+
@identifiers_to_classes = {}
|
105
|
+
@classes_to_identifiers = {}
|
85
106
|
end
|
86
107
|
|
87
108
|
# Registers the given class as a plugin.
|
@@ -99,13 +120,26 @@ module Nanoc
|
|
99
120
|
#
|
100
121
|
# @return [void]
|
101
122
|
def register(superclass, class_or_name, *identifiers)
|
102
|
-
@
|
123
|
+
@identifiers_to_classes[superclass] ||= {}
|
124
|
+
@classes_to_identifiers[superclass] ||= {}
|
103
125
|
|
104
126
|
identifiers.each do |identifier|
|
105
|
-
@
|
127
|
+
@identifiers_to_classes[superclass][identifier.to_sym] = class_or_name
|
128
|
+
(@classes_to_identifiers[superclass][name_for_class(class_or_name)] ||= []) << identifier.to_sym
|
106
129
|
end
|
107
130
|
end
|
108
131
|
|
132
|
+
# @param [Class] superclass The superclass of the plugin. For example:
|
133
|
+
# {Nanoc::Filter}, {Nanoc::Extra::VCS}.
|
134
|
+
#
|
135
|
+
# @param [Class, String] class_or_name The class to get the identifiers for.
|
136
|
+
# This can also be a string containing the name of the class.
|
137
|
+
#
|
138
|
+
# @return [Array<Symbol>] An array of identifiers for the given class
|
139
|
+
def identifiers_of(superclass, klass)
|
140
|
+
(@classes_to_identifiers[superclass] || {})[name_for_class(klass)] || []
|
141
|
+
end
|
142
|
+
|
109
143
|
# Finds the plugin that is a subclass of the given class and has the given
|
110
144
|
# name.
|
111
145
|
#
|
@@ -115,8 +149,8 @@ module Nanoc
|
|
115
149
|
#
|
116
150
|
# @return [Class, nil] The plugin with the given name
|
117
151
|
def find(klass, name)
|
118
|
-
@
|
119
|
-
resolve(@
|
152
|
+
@identifiers_to_classes[klass] ||= {}
|
153
|
+
resolve(@identifiers_to_classes[klass][name.to_sym], klass)
|
120
154
|
end
|
121
155
|
|
122
156
|
# Returns all plugins of the given class.
|
@@ -125,9 +159,9 @@ module Nanoc
|
|
125
159
|
#
|
126
160
|
# @return [Enumerable<Class>] A collection of class plugins
|
127
161
|
def find_all(klass)
|
128
|
-
@
|
162
|
+
@identifiers_to_classes[klass] ||= {}
|
129
163
|
res = {}
|
130
|
-
@
|
164
|
+
@identifiers_to_classes[klass].each_pair { |k,v| res[k] = resolve(v, k) }
|
131
165
|
res
|
132
166
|
end
|
133
167
|
|
@@ -139,7 +173,7 @@ module Nanoc
|
|
139
173
|
# @return [Array<Hash>] A list of all plugins in the format described
|
140
174
|
def all
|
141
175
|
plugins = []
|
142
|
-
@
|
176
|
+
@identifiers_to_classes.each_pair do |superclass, submap|
|
143
177
|
submap.each_pair do |identifier, klass|
|
144
178
|
# Find existing plugin
|
145
179
|
existing_plugin = plugins.find do |p|
|
@@ -181,7 +215,11 @@ module Nanoc
|
|
181
215
|
end
|
182
216
|
end
|
183
217
|
memoize :resolve
|
184
|
-
|
218
|
+
|
219
|
+
def name_for_class(klass)
|
220
|
+
klass.to_s.sub(/^(::)?/, '::')
|
221
|
+
end
|
222
|
+
|
185
223
|
end
|
186
224
|
|
187
225
|
# @deprecated Use {Nanoc::PluginRegistry.instance} instead
|