nanoc 3.6.7 → 3.6.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/CONTRIBUTING.md +9 -13
- data/Gemfile +5 -1
- data/Gemfile.lock +70 -45
- data/NEWS.md +15 -1
- data/README.md +12 -119
- data/doc/yardoc_handlers/identifier.rb +34 -0
- data/lib/nanoc/base/compilation/checksum_store.rb +2 -2
- data/lib/nanoc/base/compilation/compiler.rb +3 -3
- data/lib/nanoc/base/compilation/compiler_dsl.rb +20 -15
- data/lib/nanoc/base/compilation/dependency_tracker.rb +4 -4
- data/lib/nanoc/base/compilation/filter.rb +5 -5
- data/lib/nanoc/base/compilation/item_rep_proxy.rb +2 -2
- data/lib/nanoc/base/compilation/item_rep_recorder_proxy.rb +3 -3
- data/lib/nanoc/base/compilation/outdatedness_checker.rb +49 -46
- data/lib/nanoc/base/compilation/rule.rb +6 -4
- data/lib/nanoc/base/compilation/rule_context.rb +10 -4
- data/lib/nanoc/base/compilation/rule_memory_calculator.rb +8 -7
- data/lib/nanoc/base/compilation/rule_memory_store.rb +2 -2
- data/lib/nanoc/base/compilation/rules_collection.rb +2 -2
- data/lib/nanoc/base/core_ext/array.rb +2 -2
- data/lib/nanoc/base/core_ext/date.rb +4 -2
- data/lib/nanoc/base/core_ext/hash.rb +3 -3
- data/lib/nanoc/base/core_ext/pathname.rb +1 -1
- data/lib/nanoc/base/directed_graph.rb +6 -6
- data/lib/nanoc/base/errors.rb +1 -1
- data/lib/nanoc/base/memoization.rb +4 -4
- data/lib/nanoc/base/notification_center.rb +1 -1
- data/lib/nanoc/base/ordered_hash.rb +207 -179
- data/lib/nanoc/base/plugin_registry.rb +7 -7
- data/lib/nanoc/base/result_data/item_rep.rb +25 -26
- data/lib/nanoc/base/source_data/code_snippet.rb +2 -2
- data/lib/nanoc/base/source_data/configuration.rb +1 -1
- data/lib/nanoc/base/source_data/data_source.rb +2 -2
- data/lib/nanoc/base/source_data/item.rb +16 -15
- data/lib/nanoc/base/source_data/item_array.rb +4 -4
- data/lib/nanoc/base/source_data/layout.rb +5 -5
- data/lib/nanoc/base/source_data/site.rb +6 -6
- data/lib/nanoc/base/store.rb +8 -8
- data/lib/nanoc/cli/cleaning_stream.rb +11 -12
- data/lib/nanoc/cli/command_runner.rb +8 -8
- data/lib/nanoc/cli/commands/autocompile.rb +5 -4
- data/lib/nanoc/cli/commands/check.rb +12 -11
- data/lib/nanoc/cli/commands/compile.rb +50 -52
- data/lib/nanoc/cli/commands/create-item.rb +6 -6
- data/lib/nanoc/cli/commands/create-layout.rb +6 -6
- data/lib/nanoc/cli/commands/create-site.rb +10 -13
- data/lib/nanoc/cli/commands/deploy.rb +11 -11
- data/lib/nanoc/cli/commands/prune.rb +10 -10
- data/lib/nanoc/cli/commands/shell.rb +7 -7
- data/lib/nanoc/cli/commands/show-data.rb +22 -23
- data/lib/nanoc/cli/commands/show-plugins.rb +3 -3
- data/lib/nanoc/cli/commands/show-rules.rb +8 -8
- data/lib/nanoc/cli/commands/sync.rb +4 -2
- data/lib/nanoc/cli/commands/update.rb +4 -4
- data/lib/nanoc/cli/commands/validate-css.rb +3 -3
- data/lib/nanoc/cli/commands/validate-html.rb +3 -3
- data/lib/nanoc/cli/commands/validate-links.rb +3 -3
- data/lib/nanoc/cli/commands/view.rb +5 -3
- data/lib/nanoc/cli/commands/watch.rb +12 -12
- data/lib/nanoc/cli/error_handler.rb +58 -58
- data/lib/nanoc/cli/logger.rb +6 -6
- data/lib/nanoc/cli/stream_cleaners/abstract.rb +1 -1
- data/lib/nanoc/cli/stream_cleaners.rb +0 -1
- data/lib/nanoc/cli.rb +24 -22
- data/lib/nanoc/data_sources/deprecated/delicious.rb +1 -1
- data/lib/nanoc/data_sources/deprecated/last_fm.rb +16 -14
- data/lib/nanoc/data_sources/deprecated/twitter.rb +1 -1
- data/lib/nanoc/data_sources/filesystem.rb +22 -20
- data/lib/nanoc/data_sources/filesystem_unified.rb +4 -5
- data/lib/nanoc/data_sources/filesystem_verbose.rb +2 -3
- data/lib/nanoc/data_sources/static.rb +2 -2
- data/lib/nanoc/extra/auto_compiler.rb +3 -3
- data/lib/nanoc/extra/checking/check.rb +3 -3
- data/lib/nanoc/extra/checking/checks/css.rb +2 -2
- data/lib/nanoc/extra/checking/checks/external_links.rb +9 -9
- data/lib/nanoc/extra/checking/checks/html.rb +2 -3
- data/lib/nanoc/extra/checking/checks/internal_links.rb +6 -7
- data/lib/nanoc/extra/checking/checks/stale.rb +6 -6
- data/lib/nanoc/extra/checking/dsl.rb +1 -1
- data/lib/nanoc/extra/checking/runner.rb +19 -19
- data/lib/nanoc/extra/chick.rb +11 -9
- data/lib/nanoc/extra/core_ext/pathname.rb +1 -2
- data/lib/nanoc/extra/core_ext/time.rb +2 -2
- data/lib/nanoc/extra/core_ext.rb +0 -1
- data/lib/nanoc/extra/deployer.rb +2 -2
- data/lib/nanoc/extra/deployers/fog.rb +12 -12
- data/lib/nanoc/extra/deployers/rsync.rb +6 -6
- data/lib/nanoc/extra/file_proxy.rb +1 -1
- data/lib/nanoc/extra/filesystem_tools.rb +5 -5
- data/lib/nanoc/extra/link_collector.rb +4 -3
- data/lib/nanoc/extra/pruner.rb +5 -5
- data/lib/nanoc/extra/validators/links.rb +3 -3
- data/lib/nanoc/extra/vcs.rb +1 -1
- data/lib/nanoc/filters/asciidoc.rb +3 -3
- data/lib/nanoc/filters/bluecloth.rb +1 -1
- data/lib/nanoc/filters/coderay.rb +2 -2
- data/lib/nanoc/filters/coffeescript.rb +2 -0
- data/lib/nanoc/filters/colorize_syntax.rb +16 -16
- data/lib/nanoc/filters/erb.rb +5 -5
- data/lib/nanoc/filters/erubis.rb +1 -1
- data/lib/nanoc/filters/haml.rb +1 -1
- data/lib/nanoc/filters/handlebars.rb +2 -2
- data/lib/nanoc/filters/kramdown.rb +1 -1
- data/lib/nanoc/filters/less.rb +1 -1
- data/lib/nanoc/filters/markaby.rb +1 -1
- data/lib/nanoc/filters/maruku.rb +1 -1
- data/lib/nanoc/filters/mustache.rb +1 -1
- data/lib/nanoc/filters/pandoc.rb +1 -1
- data/lib/nanoc/filters/rainpress.rb +1 -1
- data/lib/nanoc/filters/rdiscount.rb +1 -1
- data/lib/nanoc/filters/rdoc.rb +1 -1
- data/lib/nanoc/filters/redcarpet.rb +2 -2
- data/lib/nanoc/filters/redcloth.rb +9 -9
- data/lib/nanoc/filters/relativize_paths.rb +7 -8
- data/lib/nanoc/filters/rubypants.rb +1 -1
- data/lib/nanoc/filters/sass/sass_filesystem_importer.rb +1 -1
- data/lib/nanoc/filters/sass.rb +1 -1
- data/lib/nanoc/filters/slim.rb +1 -1
- data/lib/nanoc/filters/typogruby.rb +1 -1
- data/lib/nanoc/filters/uglify_js.rb +1 -1
- data/lib/nanoc/filters/xsl.rb +9 -7
- data/lib/nanoc/filters/yui_compressor.rb +2 -0
- data/lib/nanoc/helpers/blogging.rb +6 -6
- data/lib/nanoc/helpers/breadcrumbs.rb +1 -1
- data/lib/nanoc/helpers/capturing.rb +2 -2
- data/lib/nanoc/helpers/filtering.rb +1 -1
- data/lib/nanoc/helpers/html_escape.rb +3 -3
- data/lib/nanoc/helpers/link_to.rb +6 -6
- data/lib/nanoc/helpers/rendering.rb +2 -2
- data/lib/nanoc/helpers/tagging.rb +2 -2
- data/lib/nanoc/helpers/text.rb +1 -1
- data/lib/nanoc/helpers/xml_sitemap.rb +2 -2
- data/lib/nanoc/version.rb +1 -1
- data/lib/nanoc.rb +3 -2
- data/nanoc.gemspec +2 -6
- data/tasks/rubocop.rake +5 -0
- data/test/base/test_compiler_dsl.rb +20 -1
- data/test/cli/commands/test_compile.rb +4 -3
- data/test/cli/test_error_handler.rb +32 -0
- data/test/filters/test_erb.rb +1 -1
- data/test/filters/test_less.rb +1 -1
- data/test/filters/test_xsl.rb +95 -8
- metadata +30 -84
@@ -97,7 +97,7 @@ module Nanoc
|
|
97
97
|
# @return [void]
|
98
98
|
def setup
|
99
99
|
@setup ||= begin
|
100
|
-
|
100
|
+
requires.each { |r| require r }
|
101
101
|
true
|
102
102
|
end
|
103
103
|
end
|
@@ -108,7 +108,7 @@ module Nanoc
|
|
108
108
|
#
|
109
109
|
# @param [Hash] hash A hash containing variables that should be made
|
110
110
|
# available during filtering.
|
111
|
-
def initialize(hash={})
|
111
|
+
def initialize(hash = {})
|
112
112
|
@assigns = hash
|
113
113
|
super
|
114
114
|
end
|
@@ -119,7 +119,7 @@ module Nanoc
|
|
119
119
|
# @see {#run}
|
120
120
|
def setup_and_run(*args)
|
121
121
|
self.class.setup
|
122
|
-
|
122
|
+
run(*args)
|
123
123
|
end
|
124
124
|
|
125
125
|
# Runs the filter on the given content or filename.
|
@@ -136,8 +136,8 @@ module Nanoc
|
|
136
136
|
# @return [String, void] If the filter output binary content, the return
|
137
137
|
# value is undefined; if the filter outputs textual content, the return
|
138
138
|
# value will be the filtered content.
|
139
|
-
def run(content_or_filename, params={})
|
140
|
-
raise NotImplementedError.new(
|
139
|
+
def run(content_or_filename, params = {})
|
140
|
+
raise NotImplementedError.new('Nanoc::Filter subclasses must implement #run')
|
141
141
|
end
|
142
142
|
|
143
143
|
# Returns a filename that is used to write data to. This method is only
|
@@ -42,7 +42,7 @@ module Nanoc
|
|
42
42
|
# filter's #run method
|
43
43
|
#
|
44
44
|
# @return [void]
|
45
|
-
def filter(name, args={})
|
45
|
+
def filter(name, args = {})
|
46
46
|
set_assigns
|
47
47
|
@item_rep.filter(name, args)
|
48
48
|
end
|
@@ -59,7 +59,7 @@ module Nanoc
|
|
59
59
|
# @param [String] layout_identifier The identifier of the layout to use
|
60
60
|
#
|
61
61
|
# @return [void]
|
62
|
-
def layout(layout_identifier, extra_filter_args={})
|
62
|
+
def layout(layout_identifier, extra_filter_args = {})
|
63
63
|
set_assigns
|
64
64
|
|
65
65
|
layout = layout_with_identifier(layout_identifier)
|
@@ -49,14 +49,14 @@ module Nanoc
|
|
49
49
|
# @return [void]
|
50
50
|
#
|
51
51
|
# @see Nanoc::ItemRepProxy#filter, Nanoc::ItemRep#filter
|
52
|
-
def filter(name, args={})
|
52
|
+
def filter(name, args = {})
|
53
53
|
@rule_memory << [ :filter, name, args ]
|
54
54
|
end
|
55
55
|
|
56
56
|
# @return [void]
|
57
57
|
#
|
58
58
|
# @see Nanoc::ItemRepProxy#layout, Nanoc::ItemRep#layout
|
59
|
-
def layout(layout_identifier, extra_filter_args=nil)
|
59
|
+
def layout(layout_identifier, extra_filter_args = nil)
|
60
60
|
if extra_filter_args
|
61
61
|
@rule_memory << [ :layout, layout_identifier, extra_filter_args ]
|
62
62
|
else
|
@@ -67,7 +67,7 @@ module Nanoc
|
|
67
67
|
# @return [void]
|
68
68
|
#
|
69
69
|
# @see Nanoc::ItemRep#snapshot
|
70
|
-
def snapshot(snapshot_name, params={})
|
70
|
+
def snapshot(snapshot_name, params = {})
|
71
71
|
@rule_memory << [ :snapshot, snapshot_name, params ]
|
72
72
|
|
73
73
|
# Count
|
@@ -17,13 +17,16 @@ module Nanoc
|
|
17
17
|
#
|
18
18
|
# @option params [Nanoc::DependencyTracker] :dependency_tracker (nil) The
|
19
19
|
# dependency tracker for the given site.
|
20
|
-
def initialize(params={})
|
21
|
-
@site = params
|
22
|
-
'Nanoc::OutdatednessChecker#initialize needs a :site parameter'
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
20
|
+
def initialize(params = {})
|
21
|
+
@site = params.fetch(:site) do
|
22
|
+
raise ArgumentError, 'Nanoc::OutdatednessChecker#initialize needs a :site parameter'
|
23
|
+
end
|
24
|
+
@checksum_store = params.fetch(:checksum_store) do
|
25
|
+
raise ArgumentError, 'Nanoc::OutdatednessChecker#initialize needs a :checksum_store parameter'
|
26
|
+
end
|
27
|
+
@dependency_tracker = params.fetch(:dependency_tracker) do
|
28
|
+
raise ArgumentError, 'Nanoc::OutdatednessChecker#initialize needs a :dependency_tracker parameter'
|
29
|
+
end
|
27
30
|
|
28
31
|
@basic_outdatedness_reasons = {}
|
29
32
|
@outdatedness_reasons = {}
|
@@ -83,43 +86,43 @@ module Nanoc
|
|
83
86
|
# given object is outdated, or nil if the object is not outdated.
|
84
87
|
def basic_outdatedness_reason_for(obj)
|
85
88
|
case obj.type
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
89
|
+
when :item_rep
|
90
|
+
# Outdated if rules outdated
|
91
|
+
return Nanoc::OutdatednessReasons::RulesModified if
|
92
|
+
rule_memory_differs_for(obj)
|
93
|
+
|
94
|
+
# Outdated if checksums are missing or different
|
95
|
+
return Nanoc::OutdatednessReasons::NotEnoughData if !checksums_available?(obj.item)
|
96
|
+
return Nanoc::OutdatednessReasons::SourceModified if !checksums_identical?(obj.item)
|
97
|
+
|
98
|
+
# Outdated if compiled file doesn't exist (yet)
|
99
|
+
return Nanoc::OutdatednessReasons::NotWritten if obj.raw_path && !File.file?(obj.raw_path)
|
100
|
+
|
101
|
+
# Outdated if code snippets outdated
|
102
|
+
return Nanoc::OutdatednessReasons::CodeSnippetsModified if site.code_snippets.any? do |cs|
|
103
|
+
object_modified?(cs)
|
104
|
+
end
|
105
|
+
|
106
|
+
# Outdated if configuration outdated
|
107
|
+
return Nanoc::OutdatednessReasons::ConfigurationModified if object_modified?(site.config)
|
108
|
+
|
109
|
+
# Not outdated
|
110
|
+
return nil
|
111
|
+
when :item
|
112
|
+
obj.reps.find { |rep| basic_outdatedness_reason_for(rep) }
|
113
|
+
when :layout
|
114
|
+
# Outdated if rules outdated
|
115
|
+
return Nanoc::OutdatednessReasons::RulesModified if
|
116
|
+
rule_memory_differs_for(obj)
|
117
|
+
|
118
|
+
# Outdated if checksums are missing or different
|
119
|
+
return Nanoc::OutdatednessReasons::NotEnoughData if !checksums_available?(obj)
|
120
|
+
return Nanoc::OutdatednessReasons::SourceModified if !checksums_identical?(obj)
|
121
|
+
|
122
|
+
# Not outdated
|
123
|
+
return nil
|
124
|
+
else
|
125
|
+
raise "do not know how to check outdatedness of #{obj.inspect}"
|
123
126
|
end
|
124
127
|
end
|
125
128
|
memoize :basic_outdatedness_reason_for
|
@@ -135,12 +138,12 @@ module Nanoc
|
|
135
138
|
# indefinitely. It should not be necessary to pass this a custom value.
|
136
139
|
#
|
137
140
|
# @return [Boolean] true if the object is outdated, false otherwise
|
138
|
-
def outdated_due_to_dependencies?(obj, processed=Set.new)
|
141
|
+
def outdated_due_to_dependencies?(obj, processed = Set.new)
|
139
142
|
# Convert from rep to item if necessary
|
140
143
|
obj = obj.item if obj.type == :item_rep
|
141
144
|
|
142
145
|
# Get from cache
|
143
|
-
if @objects_outdated_due_to_dependencies.
|
146
|
+
if @objects_outdated_due_to_dependencies.key?(obj)
|
144
147
|
return @objects_outdated_due_to_dependencies[obj]
|
145
148
|
end
|
146
149
|
|
@@ -36,7 +36,7 @@ module Nanoc
|
|
36
36
|
# @option params [Symbol, nil] :snapshot (nil) The name of the snapshot
|
37
37
|
# this rule will apply to. Ignored for compilation rules, but used for
|
38
38
|
# routing rules.
|
39
|
-
def initialize(identifier_regex, rep_name, block, params={})
|
39
|
+
def initialize(identifier_regex, rep_name, block, params = {})
|
40
40
|
@identifier_regex = identifier_regex
|
41
41
|
@rep_name = rep_name.to_sym
|
42
42
|
@snapshot_name = params[:snapshot_name]
|
@@ -62,10 +62,12 @@ module Nanoc
|
|
62
62
|
# @raise [ArgumentError] if no compiler is passed
|
63
63
|
#
|
64
64
|
# @return [void]
|
65
|
-
def apply_to(rep, params={})
|
66
|
-
compiler = params
|
65
|
+
def apply_to(rep, params = {})
|
66
|
+
compiler = params.fetch(:compiler) do
|
67
|
+
raise ArgumentError, 'Required :compiler option is missing'
|
68
|
+
end
|
67
69
|
rep = Nanoc::ItemRepProxy.new(rep, compiler) unless rep.is_proxy?
|
68
|
-
Nanoc::RuleContext.new(:rep => rep, :compiler => compiler).instance_eval
|
70
|
+
Nanoc::RuleContext.new(:rep => rep, :compiler => compiler).instance_eval(&@block)
|
69
71
|
end
|
70
72
|
|
71
73
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
1
3
|
module Nanoc
|
2
4
|
|
3
5
|
# Provides a context in which compilation and routing rules can be executed.
|
@@ -24,9 +26,13 @@ module Nanoc
|
|
24
26
|
#
|
25
27
|
# @raise [ArgumentError] if the `:rep` or the `:compiler` option is
|
26
28
|
# missing
|
27
|
-
def initialize(params={})
|
28
|
-
rep
|
29
|
-
|
29
|
+
def initialize(params = {})
|
30
|
+
rep = params.fetch(:rep) do
|
31
|
+
raise ArgumentError, 'Required :rep option is missing'
|
32
|
+
end
|
33
|
+
compiler = params.fetch(:compiler) do
|
34
|
+
raise ArgumentError, 'Required :compiler option is missing'
|
35
|
+
end
|
30
36
|
|
31
37
|
super({
|
32
38
|
:rep => rep,
|
@@ -51,7 +57,7 @@ module Nanoc
|
|
51
57
|
# the filter's #run method
|
52
58
|
#
|
53
59
|
# @return [void]
|
54
|
-
def filter(filter_name, filter_args={})
|
60
|
+
def filter(filter_name, filter_args = {})
|
55
61
|
rep.filter(filter_name, filter_args)
|
56
62
|
end
|
57
63
|
|
@@ -12,24 +12,25 @@ module Nanoc
|
|
12
12
|
|
13
13
|
# @option params [Nanoc::RulesCollection] rules_collection The rules
|
14
14
|
# collection
|
15
|
-
def initialize(params={})
|
16
|
-
@rules_collection = params
|
17
|
-
raise ArgumentError,
|
15
|
+
def initialize(params = {})
|
16
|
+
@rules_collection = params.fetch(:rules_collection) do
|
17
|
+
raise ArgumentError, 'Required :rules_collection option is missing'
|
18
|
+
end
|
18
19
|
end
|
19
20
|
|
20
21
|
# @param [#reference] obj The object to calculate the rule memory for
|
21
22
|
#
|
22
23
|
# @return [Array] The caluclated rule memory for the given object
|
23
24
|
def [](obj)
|
24
|
-
result =
|
25
|
+
result =
|
26
|
+
case obj.type
|
25
27
|
when :item_rep
|
26
28
|
@rules_collection.new_rule_memory_for_rep(obj)
|
27
29
|
when :layout
|
28
30
|
@rules_collection.new_rule_memory_for_layout(obj)
|
29
31
|
else
|
30
|
-
raise
|
31
|
-
|
32
|
-
end
|
32
|
+
raise "Do not know how to calculate the rule memory for #{obj.inspect}"
|
33
|
+
end
|
33
34
|
|
34
35
|
result
|
35
36
|
end
|
@@ -10,10 +10,10 @@ module Nanoc
|
|
10
10
|
|
11
11
|
# @option params [Nanoc::Site] site The site where this rule memory store
|
12
12
|
# belongs to
|
13
|
-
def initialize(params={})
|
13
|
+
def initialize(params = {})
|
14
14
|
super('tmp/rule_memory', 1)
|
15
15
|
|
16
|
-
@site = params[:site] if params.
|
16
|
+
@site = params[:site] if params.key?(:site)
|
17
17
|
|
18
18
|
@rule_memories = {}
|
19
19
|
end
|
@@ -125,7 +125,7 @@ module Nanoc
|
|
125
125
|
@item_routing_rules.each do |rule|
|
126
126
|
next if !rule.applicable_to?(rep.item)
|
127
127
|
next if rule.rep_name != rep.name
|
128
|
-
next if rules.
|
128
|
+
next if rules.key?(rule.snapshot_name)
|
129
129
|
|
130
130
|
rules[rule.snapshot_name] = rule
|
131
131
|
end
|
@@ -136,7 +136,7 @@ module Nanoc
|
|
136
136
|
#
|
137
137
|
# @param [Nanoc::Layout] layout The layout for which to fetch the filter.
|
138
138
|
#
|
139
|
-
# @return [Array, nil] A tuple containing the filter name and the filter
|
139
|
+
# @return [Array, nil] A tuple containing the filter name and the filter
|
140
140
|
# arguments for the given layout.
|
141
141
|
def filter_for_layout(layout)
|
142
142
|
@layout_filter_mapping.each_pair do |layout_identifier, filter_name_and_args|
|
@@ -9,7 +9,7 @@ module Nanoc::ArrayExtensions
|
|
9
9
|
# @return [Array] The converted array
|
10
10
|
def symbolize_keys_recursively
|
11
11
|
array = []
|
12
|
-
|
12
|
+
each do |element|
|
13
13
|
array << (element.respond_to?(:symbolize_keys_recursively) ? element.symbolize_keys_recursively : element)
|
14
14
|
end
|
15
15
|
array
|
@@ -26,7 +26,7 @@ module Nanoc::ArrayExtensions
|
|
26
26
|
#
|
27
27
|
# @return [Array] The converted array
|
28
28
|
def stringify_keys_recursively
|
29
|
-
|
29
|
+
reduce([]) do |array, element|
|
30
30
|
array + [ element.respond_to?(:stringify_keys_recursively) ? element.stringify_keys_recursively : element ]
|
31
31
|
end
|
32
32
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
1
3
|
require 'date'
|
2
4
|
|
3
5
|
begin
|
@@ -5,12 +7,12 @@ begin
|
|
5
7
|
d.freeze
|
6
8
|
d.year
|
7
9
|
needs_patch = false
|
8
|
-
rescue
|
10
|
+
rescue
|
9
11
|
needs_patch = true
|
10
12
|
end
|
11
13
|
|
12
14
|
if needs_patch
|
13
|
-
|
15
|
+
|
14
16
|
class ::Date
|
15
17
|
|
16
18
|
[ :amjd, :jd, :day_fraction, :mjd, :ld, :civil, :ordinal, :commercial, :weeknum0, :weeknum1, :time, :wday, :julian?, :gregorian?, :leap? ].each do |m|
|
@@ -9,7 +9,7 @@ module Nanoc::HashExtensions
|
|
9
9
|
# @return [Hash] The converted hash
|
10
10
|
def symbolize_keys_recursively
|
11
11
|
hash = {}
|
12
|
-
|
12
|
+
each_pair do |key, value|
|
13
13
|
new_key = key.respond_to?(:to_sym) ? key.to_sym : key
|
14
14
|
new_value = value.respond_to?(:symbolize_keys_recursively) ? value.symbolize_keys_recursively : value
|
15
15
|
hash[new_key] = new_value
|
@@ -28,7 +28,7 @@ module Nanoc::HashExtensions
|
|
28
28
|
#
|
29
29
|
# @return [Hash] The converted hash
|
30
30
|
def stringify_keys_recursively
|
31
|
-
|
31
|
+
reduce({}) do |hash, (key, value)|
|
32
32
|
hash.merge(key.to_s => value.respond_to?(:stringify_keys_recursively) ? value.stringify_keys_recursively : value)
|
33
33
|
end
|
34
34
|
end
|
@@ -66,7 +66,7 @@ module Nanoc::HashExtensions
|
|
66
66
|
#
|
67
67
|
# @api private
|
68
68
|
def checksum
|
69
|
-
array =
|
69
|
+
array = to_a.sort_by { |kv| kv[0].to_s }
|
70
70
|
array.checksum
|
71
71
|
end
|
72
72
|
|
@@ -9,21 +9,21 @@ module Nanoc
|
|
9
9
|
#
|
10
10
|
# # Create a graph with three vertices
|
11
11
|
# graph = Nanoc::DirectedGraph.new(%w( a b c d ))
|
12
|
-
#
|
12
|
+
#
|
13
13
|
# # Add edges
|
14
14
|
# graph.add_edge('a', 'b')
|
15
15
|
# graph.add_edge('b', 'c')
|
16
16
|
# graph.add_edge('c', 'd')
|
17
|
-
#
|
17
|
+
#
|
18
18
|
# # Get (direct) predecessors
|
19
19
|
# graph.direct_predecessors_of('d').sort
|
20
20
|
# # => %w( c )
|
21
21
|
# graph.predecessors_of('d').sort
|
22
22
|
# # => %w( a b c )
|
23
|
-
#
|
23
|
+
#
|
24
24
|
# # Modify edges
|
25
25
|
# graph.delete_edge('a', 'b')
|
26
|
-
#
|
26
|
+
#
|
27
27
|
# # Get (direct) predecessors again
|
28
28
|
# graph.direct_predecessors_of('d').sort
|
29
29
|
# # => %w( c )
|
@@ -36,7 +36,7 @@ module Nanoc
|
|
36
36
|
# Creates a new directed graph with the given vertices.
|
37
37
|
def initialize(vertices)
|
38
38
|
@vertices = {}
|
39
|
-
vertices.each_with_index do |v,i|
|
39
|
+
vertices.each_with_index do |v, i|
|
40
40
|
@vertices[v] = i
|
41
41
|
end
|
42
42
|
|
@@ -102,7 +102,7 @@ module Nanoc
|
|
102
102
|
#
|
103
103
|
# @since 3.2.0
|
104
104
|
def add_vertex(v)
|
105
|
-
return if @vertices.
|
105
|
+
return if @vertices.key?(v)
|
106
106
|
|
107
107
|
@vertices[v] = @vertices.size
|
108
108
|
|
data/lib/nanoc/base/errors.rb
CHANGED
@@ -21,9 +21,9 @@ module Nanoc
|
|
21
21
|
# @example A fast fib function due to memoization
|
22
22
|
#
|
23
23
|
# class FibFast
|
24
|
-
#
|
24
|
+
#
|
25
25
|
# extend Nanoc::Memoization
|
26
|
-
#
|
26
|
+
#
|
27
27
|
# def run(n)
|
28
28
|
# if n == 0
|
29
29
|
# 0
|
@@ -34,7 +34,7 @@ module Nanoc
|
|
34
34
|
# end
|
35
35
|
# end
|
36
36
|
# memoize :run
|
37
|
-
#
|
37
|
+
#
|
38
38
|
# end
|
39
39
|
#
|
40
40
|
# @param [Symbol, String] method_name The name of the method to memoize
|
@@ -52,7 +52,7 @@ module Nanoc
|
|
52
52
|
@__memoization_cache[method_name] ||= {}
|
53
53
|
|
54
54
|
# Recalculate if necessary
|
55
|
-
if !@__memoization_cache[method_name].
|
55
|
+
if !@__memoization_cache[method_name].key?(args)
|
56
56
|
result = send(original_method_name, *args)
|
57
57
|
@__memoization_cache[method_name][args] = result
|
58
58
|
end
|