nanoc3 3.2.4 → 3.3.0
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.
- metadata +14 -313
- data/.gemtest +0 -0
- data/ChangeLog +0 -3
- data/Gemfile +0 -29
- data/LICENSE +0 -19
- data/NEWS.md +0 -449
- data/README.md +0 -108
- data/Rakefile +0 -14
- data/bin/nanoc3 +0 -12
- data/doc/yardoc_templates/default/layout/html/footer.erb +0 -10
- data/lib/nanoc3.rb +0 -28
- data/lib/nanoc3/base.rb +0 -49
- data/lib/nanoc3/base/compilation/checksum_store.rb +0 -57
- data/lib/nanoc3/base/compilation/compiled_content_cache.rb +0 -62
- data/lib/nanoc3/base/compilation/compiler.rb +0 -455
- data/lib/nanoc3/base/compilation/compiler_dsl.rb +0 -214
- data/lib/nanoc3/base/compilation/dependency_tracker.rb +0 -196
- data/lib/nanoc3/base/compilation/filter.rb +0 -165
- data/lib/nanoc3/base/compilation/item_rep_proxy.rb +0 -102
- data/lib/nanoc3/base/compilation/item_rep_recorder_proxy.rb +0 -88
- data/lib/nanoc3/base/compilation/outdatedness_checker.rb +0 -223
- data/lib/nanoc3/base/compilation/outdatedness_reasons.rb +0 -46
- data/lib/nanoc3/base/compilation/rule.rb +0 -73
- data/lib/nanoc3/base/compilation/rule_context.rb +0 -84
- data/lib/nanoc3/base/compilation/rule_memory_calculator.rb +0 -40
- data/lib/nanoc3/base/compilation/rule_memory_store.rb +0 -53
- data/lib/nanoc3/base/compilation/rules_collection.rb +0 -231
- data/lib/nanoc3/base/context.rb +0 -47
- data/lib/nanoc3/base/core_ext.rb +0 -6
- data/lib/nanoc3/base/core_ext/array.rb +0 -62
- data/lib/nanoc3/base/core_ext/hash.rb +0 -63
- data/lib/nanoc3/base/core_ext/pathname.rb +0 -26
- data/lib/nanoc3/base/core_ext/string.rb +0 -46
- data/lib/nanoc3/base/directed_graph.rb +0 -275
- data/lib/nanoc3/base/errors.rb +0 -174
- data/lib/nanoc3/base/memoization.rb +0 -67
- data/lib/nanoc3/base/notification_center.rb +0 -84
- data/lib/nanoc3/base/ordered_hash.rb +0 -200
- data/lib/nanoc3/base/plugin_registry.rb +0 -165
- data/lib/nanoc3/base/result_data/item_rep.rb +0 -488
- data/lib/nanoc3/base/source_data/code_snippet.rb +0 -58
- data/lib/nanoc3/base/source_data/configuration.rb +0 -24
- data/lib/nanoc3/base/source_data/data_source.rb +0 -234
- data/lib/nanoc3/base/source_data/item.rb +0 -301
- data/lib/nanoc3/base/source_data/layout.rb +0 -130
- data/lib/nanoc3/base/source_data/site.rb +0 -361
- data/lib/nanoc3/base/store.rb +0 -135
- data/lib/nanoc3/cli.rb +0 -133
- data/lib/nanoc3/cli/command.rb +0 -139
- data/lib/nanoc3/cli/commands/autocompile.rb +0 -60
- data/lib/nanoc3/cli/commands/compile.rb +0 -280
- data/lib/nanoc3/cli/commands/create_item.rb +0 -62
- data/lib/nanoc3/cli/commands/create_layout.rb +0 -75
- data/lib/nanoc3/cli/commands/create_site.rb +0 -410
- data/lib/nanoc3/cli/commands/debug.rb +0 -119
- data/lib/nanoc3/cli/commands/info.rb +0 -98
- data/lib/nanoc3/cli/commands/nanoc.rb +0 -37
- data/lib/nanoc3/cli/commands/update.rb +0 -72
- data/lib/nanoc3/cli/commands/view.rb +0 -84
- data/lib/nanoc3/cli/commands/watch.rb +0 -125
- data/lib/nanoc3/cli/error_handler.rb +0 -193
- data/lib/nanoc3/cli/logger.rb +0 -91
- data/lib/nanoc3/data_sources.rb +0 -29
- data/lib/nanoc3/data_sources/deprecated/delicious.rb +0 -42
- data/lib/nanoc3/data_sources/deprecated/last_fm.rb +0 -87
- data/lib/nanoc3/data_sources/deprecated/twitter.rb +0 -38
- data/lib/nanoc3/data_sources/filesystem.rb +0 -299
- data/lib/nanoc3/data_sources/filesystem_unified.rb +0 -116
- data/lib/nanoc3/data_sources/filesystem_verbose.rb +0 -86
- data/lib/nanoc3/extra.rb +0 -22
- data/lib/nanoc3/extra/auto_compiler.rb +0 -103
- data/lib/nanoc3/extra/chick.rb +0 -125
- data/lib/nanoc3/extra/core_ext.rb +0 -4
- data/lib/nanoc3/extra/core_ext/enumerable.rb +0 -33
- data/lib/nanoc3/extra/core_ext/time.rb +0 -19
- data/lib/nanoc3/extra/deployers.rb +0 -11
- data/lib/nanoc3/extra/deployers/rsync.rb +0 -114
- data/lib/nanoc3/extra/file_proxy.rb +0 -40
- data/lib/nanoc3/extra/validators.rb +0 -12
- data/lib/nanoc3/extra/validators/links.rb +0 -264
- data/lib/nanoc3/extra/validators/w3c.rb +0 -95
- data/lib/nanoc3/extra/vcs.rb +0 -66
- data/lib/nanoc3/extra/vcses.rb +0 -17
- data/lib/nanoc3/extra/vcses/bazaar.rb +0 -25
- data/lib/nanoc3/extra/vcses/dummy.rb +0 -24
- data/lib/nanoc3/extra/vcses/git.rb +0 -25
- data/lib/nanoc3/extra/vcses/mercurial.rb +0 -25
- data/lib/nanoc3/extra/vcses/subversion.rb +0 -25
- data/lib/nanoc3/filters.rb +0 -53
- data/lib/nanoc3/filters/asciidoc.rb +0 -38
- data/lib/nanoc3/filters/bluecloth.rb +0 -19
- data/lib/nanoc3/filters/coderay.rb +0 -21
- data/lib/nanoc3/filters/colorize_syntax.rb +0 -261
- data/lib/nanoc3/filters/erb.rb +0 -35
- data/lib/nanoc3/filters/erubis.rb +0 -27
- data/lib/nanoc3/filters/haml.rb +0 -27
- data/lib/nanoc3/filters/kramdown.rb +0 -20
- data/lib/nanoc3/filters/less.rb +0 -53
- data/lib/nanoc3/filters/markaby.rb +0 -20
- data/lib/nanoc3/filters/maruku.rb +0 -20
- data/lib/nanoc3/filters/mustache.rb +0 -24
- data/lib/nanoc3/filters/rainpress.rb +0 -19
- data/lib/nanoc3/filters/rdiscount.rb +0 -22
- data/lib/nanoc3/filters/rdoc.rb +0 -33
- data/lib/nanoc3/filters/redcarpet.rb +0 -27
- data/lib/nanoc3/filters/redcloth.rb +0 -47
- data/lib/nanoc3/filters/relativize_paths.rb +0 -45
- data/lib/nanoc3/filters/rubypants.rb +0 -20
- data/lib/nanoc3/filters/sass.rb +0 -66
- data/lib/nanoc3/filters/slim.rb +0 -25
- data/lib/nanoc3/filters/typogruby.rb +0 -23
- data/lib/nanoc3/filters/uglify_js.rb +0 -42
- data/lib/nanoc3/helpers.rb +0 -16
- data/lib/nanoc3/helpers/blogging.rb +0 -319
- data/lib/nanoc3/helpers/breadcrumbs.rb +0 -40
- data/lib/nanoc3/helpers/capturing.rb +0 -138
- data/lib/nanoc3/helpers/filtering.rb +0 -50
- data/lib/nanoc3/helpers/html_escape.rb +0 -55
- data/lib/nanoc3/helpers/link_to.rb +0 -151
- data/lib/nanoc3/helpers/rendering.rb +0 -140
- data/lib/nanoc3/helpers/tagging.rb +0 -71
- data/lib/nanoc3/helpers/text.rb +0 -44
- data/lib/nanoc3/helpers/xml_sitemap.rb +0 -76
- data/lib/nanoc3/tasks.rb +0 -10
- data/lib/nanoc3/tasks/clean.rake +0 -16
- data/lib/nanoc3/tasks/clean.rb +0 -29
- data/lib/nanoc3/tasks/deploy/rsync.rake +0 -14
- data/lib/nanoc3/tasks/validate.rake +0 -92
- data/nanoc3.gemspec +0 -49
- data/tasks/doc.rake +0 -16
- data/tasks/test.rake +0 -44
- data/test/base/core_ext/array_spec.rb +0 -73
- data/test/base/core_ext/hash_spec.rb +0 -98
- data/test/base/core_ext/pathname_spec.rb +0 -27
- data/test/base/core_ext/string_spec.rb +0 -37
- data/test/base/test_checksum_store.rb +0 -35
- data/test/base/test_code_snippet.rb +0 -31
- data/test/base/test_compiler.rb +0 -316
- data/test/base/test_compiler_dsl.rb +0 -161
- data/test/base/test_context.rb +0 -31
- data/test/base/test_data_source.rb +0 -46
- data/test/base/test_dependency_tracker.rb +0 -262
- data/test/base/test_directed_graph.rb +0 -283
- data/test/base/test_filter.rb +0 -83
- data/test/base/test_item.rb +0 -179
- data/test/base/test_item_rep.rb +0 -553
- data/test/base/test_layout.rb +0 -59
- data/test/base/test_memoization.rb +0 -90
- data/test/base/test_notification_center.rb +0 -34
- data/test/base/test_outdatedness_checker.rb +0 -394
- data/test/base/test_plugin.rb +0 -30
- data/test/base/test_rule.rb +0 -19
- data/test/base/test_rule_context.rb +0 -65
- data/test/base/test_site.rb +0 -190
- data/test/cli/commands/test_compile.rb +0 -33
- data/test/cli/commands/test_create_item.rb +0 -14
- data/test/cli/commands/test_create_layout.rb +0 -28
- data/test/cli/commands/test_create_site.rb +0 -24
- data/test/cli/commands/test_help.rb +0 -12
- data/test/cli/commands/test_info.rb +0 -11
- data/test/cli/commands/test_update.rb +0 -10
- data/test/cli/test_cli.rb +0 -102
- data/test/cli/test_error_handler.rb +0 -29
- data/test/cli/test_logger.rb +0 -10
- data/test/data_sources/test_filesystem.rb +0 -433
- data/test/data_sources/test_filesystem_unified.rb +0 -536
- data/test/data_sources/test_filesystem_verbose.rb +0 -357
- data/test/extra/core_ext/test_enumerable.rb +0 -30
- data/test/extra/core_ext/test_time.rb +0 -15
- data/test/extra/deployers/test_rsync.rb +0 -232
- data/test/extra/test_auto_compiler.rb +0 -417
- data/test/extra/test_file_proxy.rb +0 -19
- data/test/extra/test_vcs.rb +0 -22
- data/test/extra/validators/test_links.rb +0 -51
- data/test/extra/validators/test_w3c.rb +0 -47
- data/test/filters/test_asciidoc.rb +0 -22
- data/test/filters/test_bluecloth.rb +0 -18
- data/test/filters/test_coderay.rb +0 -44
- data/test/filters/test_colorize_syntax.rb +0 -283
- data/test/filters/test_erb.rb +0 -99
- data/test/filters/test_erubis.rb +0 -70
- data/test/filters/test_haml.rb +0 -96
- data/test/filters/test_kramdown.rb +0 -18
- data/test/filters/test_less.rb +0 -113
- data/test/filters/test_markaby.rb +0 -24
- data/test/filters/test_maruku.rb +0 -18
- data/test/filters/test_mustache.rb +0 -25
- data/test/filters/test_rainpress.rb +0 -29
- data/test/filters/test_rdiscount.rb +0 -31
- data/test/filters/test_rdoc.rb +0 -18
- data/test/filters/test_redcarpet.rb +0 -63
- data/test/filters/test_redcloth.rb +0 -33
- data/test/filters/test_relativize_paths.rb +0 -332
- data/test/filters/test_rubypants.rb +0 -18
- data/test/filters/test_sass.rb +0 -229
- data/test/filters/test_slim.rb +0 -35
- data/test/filters/test_typogruby.rb +0 -21
- data/test/filters/test_uglify_js.rb +0 -30
- data/test/gem_loader.rb +0 -11
- data/test/helper.rb +0 -179
- data/test/helpers/test_blogging.rb +0 -754
- data/test/helpers/test_breadcrumbs.rb +0 -81
- data/test/helpers/test_capturing.rb +0 -41
- data/test/helpers/test_filtering.rb +0 -106
- data/test/helpers/test_html_escape.rb +0 -32
- data/test/helpers/test_link_to.rb +0 -249
- data/test/helpers/test_rendering.rb +0 -89
- data/test/helpers/test_tagging.rb +0 -87
- data/test/helpers/test_text.rb +0 -24
- data/test/helpers/test_xml_sitemap.rb +0 -103
- data/test/tasks/test_clean.rb +0 -67
|
@@ -1,214 +0,0 @@
|
|
|
1
|
-
# encoding: utf-8
|
|
2
|
-
|
|
3
|
-
module Nanoc3
|
|
4
|
-
|
|
5
|
-
# Contains methods that will be executed by the site’s `Rules` file.
|
|
6
|
-
class CompilerDSL
|
|
7
|
-
|
|
8
|
-
# Creates a new compiler DSL for the given collection of rules.
|
|
9
|
-
#
|
|
10
|
-
# @api private
|
|
11
|
-
#
|
|
12
|
-
# @param [Nanoc3::RulesCollection] rules_collection The collection of
|
|
13
|
-
# rules to modify when loading this DSL
|
|
14
|
-
#
|
|
15
|
-
# @param [Hash] config The site configuration
|
|
16
|
-
def initialize(rules_collection, config)
|
|
17
|
-
@rules_collection = rules_collection
|
|
18
|
-
@config = config
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
# Creates a preprocessor block that will be executed after all data is
|
|
22
|
-
# loaded, but before the site is compiled.
|
|
23
|
-
#
|
|
24
|
-
# @yield The block that will be executed before site compilation starts
|
|
25
|
-
#
|
|
26
|
-
# @return [void]
|
|
27
|
-
def preprocess(&block)
|
|
28
|
-
@rules_collection.preprocessor = block
|
|
29
|
-
end
|
|
30
|
-
|
|
31
|
-
# Creates a compilation rule for all items whose identifier match the
|
|
32
|
-
# given identifier, which may either be a string containing the *
|
|
33
|
-
# wildcard, or a regular expression.
|
|
34
|
-
#
|
|
35
|
-
# This rule will be applicable to reps with a name equal to `:default`;
|
|
36
|
-
# this can be changed by giving an explicit `:rep` parameter.
|
|
37
|
-
#
|
|
38
|
-
# An item rep will be compiled by calling the given block and passing the
|
|
39
|
-
# rep as a block argument.
|
|
40
|
-
#
|
|
41
|
-
# @param [String] identifier A pattern matching identifiers of items that
|
|
42
|
-
# should be compiled using this rule
|
|
43
|
-
#
|
|
44
|
-
# @option params [Symbol] :rep (:default) The name of the representation
|
|
45
|
-
# that should be compiled using this rule
|
|
46
|
-
#
|
|
47
|
-
# @yield The block that will be executed when an item matching this
|
|
48
|
-
# compilation rule needs to be compiled
|
|
49
|
-
#
|
|
50
|
-
# @return [void]
|
|
51
|
-
#
|
|
52
|
-
# @example Compiling the default rep of the `/foo/` item
|
|
53
|
-
#
|
|
54
|
-
# compile '/foo/' do
|
|
55
|
-
# rep.filter :erb
|
|
56
|
-
# end
|
|
57
|
-
#
|
|
58
|
-
# @example Compiling the `:raw` rep of the `/bar/` item
|
|
59
|
-
#
|
|
60
|
-
# compile '/bar/', :rep => :raw do
|
|
61
|
-
# # do nothing
|
|
62
|
-
# end
|
|
63
|
-
def compile(identifier, params={}, &block)
|
|
64
|
-
# Require block
|
|
65
|
-
raise ArgumentError.new("#compile requires a block") unless block_given?
|
|
66
|
-
|
|
67
|
-
# Get rep name
|
|
68
|
-
rep_name = params[:rep] || :default
|
|
69
|
-
|
|
70
|
-
# Create rule
|
|
71
|
-
rule = Rule.new(identifier_to_regex(identifier), rep_name, block)
|
|
72
|
-
@rules_collection.add_item_compilation_rule(rule)
|
|
73
|
-
end
|
|
74
|
-
|
|
75
|
-
# Creates a routing rule for all items whose identifier match the
|
|
76
|
-
# given identifier, which may either be a string containing the `*`
|
|
77
|
-
# wildcard, or a regular expression.
|
|
78
|
-
#
|
|
79
|
-
# This rule will be applicable to reps with a name equal to `:default`;
|
|
80
|
-
# this can be changed by giving an explicit `:rep` parameter.
|
|
81
|
-
#
|
|
82
|
-
# The path of an item rep will be determined by calling the given block
|
|
83
|
-
# and passing the rep as a block argument.
|
|
84
|
-
#
|
|
85
|
-
# @param [String] identifier A pattern matching identifiers of items that
|
|
86
|
-
# should be routed using this rule
|
|
87
|
-
#
|
|
88
|
-
# @option params [Symbol] :rep (:default) The name of the representation
|
|
89
|
-
# that should be routed using this rule
|
|
90
|
-
#
|
|
91
|
-
# @yield The block that will be executed when an item matching this
|
|
92
|
-
# compilation rule needs to be routed
|
|
93
|
-
#
|
|
94
|
-
# @return [void]
|
|
95
|
-
#
|
|
96
|
-
# @example Routing the default rep of the `/foo/` item
|
|
97
|
-
#
|
|
98
|
-
# route '/foo/' do
|
|
99
|
-
# item.identifier + 'index.html'
|
|
100
|
-
# end
|
|
101
|
-
#
|
|
102
|
-
# @example Routing the `:raw` rep of the `/bar/` item
|
|
103
|
-
#
|
|
104
|
-
# route '/bar/', :rep => :raw do
|
|
105
|
-
# '/raw' + item.identifier + 'index.txt'
|
|
106
|
-
# end
|
|
107
|
-
def route(identifier, params={}, &block)
|
|
108
|
-
# Require block
|
|
109
|
-
raise ArgumentError.new("#route requires a block") unless block_given?
|
|
110
|
-
|
|
111
|
-
# Get rep name
|
|
112
|
-
rep_name = params[:rep] || :default
|
|
113
|
-
snapshot_name = params[:snapshot] || :last
|
|
114
|
-
|
|
115
|
-
# Create rule
|
|
116
|
-
rule = Rule.new(identifier_to_regex(identifier), rep_name, block, :snapshot_name => snapshot_name)
|
|
117
|
-
@rules_collection.add_item_routing_rule(rule)
|
|
118
|
-
end
|
|
119
|
-
|
|
120
|
-
# Creates a layout rule for all layouts whose identifier match the given
|
|
121
|
-
# identifier, which may either be a string containing the * wildcard, or a
|
|
122
|
-
# regular expression. The layouts matching the identifier will be filtered
|
|
123
|
-
# using the filter specified in the second argument. The params hash
|
|
124
|
-
# contains filter arguments that will be passed to the filter.
|
|
125
|
-
#
|
|
126
|
-
# @param [String] identifier A pattern matching identifiers of layouts
|
|
127
|
-
# that should be filtered using this rule
|
|
128
|
-
#
|
|
129
|
-
# @param [Symbol] filter_name The name of the filter that should be run
|
|
130
|
-
# when processing the layout
|
|
131
|
-
#
|
|
132
|
-
# @param [Hash] params Extra filter arguments that should be passed to the
|
|
133
|
-
# filter when processing the layout (see {Nanoc3::Filter#run})
|
|
134
|
-
#
|
|
135
|
-
# @return [void]
|
|
136
|
-
#
|
|
137
|
-
# @example Specifying the filter to use for a layout
|
|
138
|
-
#
|
|
139
|
-
# layout '/default/', :erb
|
|
140
|
-
#
|
|
141
|
-
# @example Using custom filter arguments for a layout
|
|
142
|
-
#
|
|
143
|
-
# layout '/custom/', :haml, :format => :html5
|
|
144
|
-
def layout(identifier, filter_name, params={})
|
|
145
|
-
@rules_collection.layout_filter_mapping[identifier_to_regex(identifier)] = [ filter_name, params ]
|
|
146
|
-
end
|
|
147
|
-
|
|
148
|
-
# Creates a pair of compilation and routing rules that indicate that the
|
|
149
|
-
# specified item(s) should be copied to the output folder as-is. The items
|
|
150
|
-
# are selected using an identifier, which may either be a string
|
|
151
|
-
# containing the `*` wildcard, or a regular expression.
|
|
152
|
-
#
|
|
153
|
-
# This meta-rule will be applicable to reps with a name equal to
|
|
154
|
-
# `:default`; this can be changed by giving an explicit `:rep` parameter.
|
|
155
|
-
#
|
|
156
|
-
# @param [String] identifier A pattern matching identifiers of items that
|
|
157
|
-
# should be processed using this meta-rule
|
|
158
|
-
#
|
|
159
|
-
# @option params [Symbol] :rep (:default) The name of the representation
|
|
160
|
-
# that should be routed using this rule
|
|
161
|
-
#
|
|
162
|
-
# @return [void]
|
|
163
|
-
#
|
|
164
|
-
# @since 3.2.0
|
|
165
|
-
#
|
|
166
|
-
# @example Copying the `/foo/` item as-is
|
|
167
|
-
#
|
|
168
|
-
# passthrough '/foo/'
|
|
169
|
-
#
|
|
170
|
-
# @example Copying the `:raw` rep of the `/bar/` item as-is
|
|
171
|
-
#
|
|
172
|
-
# passthrough '/bar/', :rep => :raw
|
|
173
|
-
def passthrough(identifier, params={})
|
|
174
|
-
# Require no block
|
|
175
|
-
raise ArgumentError.new("#passthrough does not require a block") if block_given?
|
|
176
|
-
|
|
177
|
-
# Get rep name
|
|
178
|
-
rep_name = params[:rep] || :default
|
|
179
|
-
|
|
180
|
-
# Create compilation rule
|
|
181
|
-
compilation_block = proc { }
|
|
182
|
-
compilation_rule = Rule.new(identifier_to_regex(identifier), rep_name, compilation_block)
|
|
183
|
-
@rules_collection.add_item_compilation_rule(compilation_rule, :before)
|
|
184
|
-
|
|
185
|
-
# Create routing rule
|
|
186
|
-
routing_block = proc do
|
|
187
|
-
item.identifier.chop + '.' + item[:extension]
|
|
188
|
-
end
|
|
189
|
-
routing_rule = Rule.new(identifier_to_regex(identifier), rep_name, routing_block)
|
|
190
|
-
@rules_collection.add_item_routing_rule(routing_rule, :before)
|
|
191
|
-
end
|
|
192
|
-
|
|
193
|
-
private
|
|
194
|
-
|
|
195
|
-
# Converts the given identifier, which can contain the '*' or '+'
|
|
196
|
-
# wildcard characters, matching zero or more resp. one or more
|
|
197
|
-
# characters, to a regex. For example, 'foo/*/bar' is transformed
|
|
198
|
-
# into /^foo\/(.*?)\/bar$/ and 'foo+' is transformed into /^foo(.+?)/.
|
|
199
|
-
def identifier_to_regex(identifier)
|
|
200
|
-
if identifier.is_a? String
|
|
201
|
-
# Add leading/trailing slashes if necessary
|
|
202
|
-
new_identifier = identifier.dup
|
|
203
|
-
new_identifier[/^/] = '/' if identifier[0,1] != '/'
|
|
204
|
-
new_identifier[/$/] = '/' unless [ '*', '/' ].include?(identifier[-1,1])
|
|
205
|
-
|
|
206
|
-
/^#{new_identifier.gsub('*', '(.*?)').gsub('+', '(.+?)')}$/
|
|
207
|
-
else
|
|
208
|
-
identifier
|
|
209
|
-
end
|
|
210
|
-
end
|
|
211
|
-
|
|
212
|
-
end
|
|
213
|
-
|
|
214
|
-
end
|
|
@@ -1,196 +0,0 @@
|
|
|
1
|
-
# encoding: utf-8
|
|
2
|
-
|
|
3
|
-
module Nanoc3
|
|
4
|
-
|
|
5
|
-
# Responsible for remembering dependencies between items and layouts. It is
|
|
6
|
-
# used to speed up compilation by only letting an item be recompiled when it
|
|
7
|
-
# is outdated or any of its dependencies (or dependencies’ dependencies,
|
|
8
|
-
# etc) is outdated.
|
|
9
|
-
#
|
|
10
|
-
# The dependencies tracked by the dependency tracker are not dependencies
|
|
11
|
-
# based on an item’s or a layout’s content. When one object uses an
|
|
12
|
-
# attribute of another object, then this is also treated as a dependency.
|
|
13
|
-
# While dependencies based on an item’s or layout’s content (handled in
|
|
14
|
-
# {Nanoc3::Compiler}) cannot be mutually recursive, the more general
|
|
15
|
-
# dependencies in Nanoc3::DependencyTracker can (e.g. item A can use an
|
|
16
|
-
# attribute of item B and vice versa without problems).
|
|
17
|
-
#
|
|
18
|
-
# The dependency tracker remembers the dependency information between runs.
|
|
19
|
-
# Dependency information is stored in the `tmp/dependencies` file.
|
|
20
|
-
#
|
|
21
|
-
# @api private
|
|
22
|
-
class DependencyTracker < ::Nanoc3::Store
|
|
23
|
-
|
|
24
|
-
# @return [Array<Nanoc3::Item, Nanoc3::Layout>] The list of items and
|
|
25
|
-
# layouts that are being tracked by the dependency tracker
|
|
26
|
-
attr_reader :objects
|
|
27
|
-
|
|
28
|
-
# @return [Nanoc3::Compiler] The compiler that corresponds to this
|
|
29
|
-
# dependency tracker
|
|
30
|
-
attr_accessor :compiler
|
|
31
|
-
|
|
32
|
-
# Creates a new dependency tracker for the given items and layouts.
|
|
33
|
-
#
|
|
34
|
-
# @param [Array<Nanoc3::Item, Nanoc3::Layout>] objects The list of items
|
|
35
|
-
# and layouts whose dependencies should be managed
|
|
36
|
-
def initialize(objects)
|
|
37
|
-
super('tmp/dependencies', 4)
|
|
38
|
-
|
|
39
|
-
@objects = objects
|
|
40
|
-
|
|
41
|
-
@graph = Nanoc3::DirectedGraph.new([ nil ] + @objects)
|
|
42
|
-
end
|
|
43
|
-
|
|
44
|
-
# Starts listening for dependency messages (`:visit_started` and
|
|
45
|
-
# `:visit_ended`) and start recording dependencies.
|
|
46
|
-
#
|
|
47
|
-
# @return [void]
|
|
48
|
-
def start
|
|
49
|
-
# Initialize dependency stack. An object will be pushed onto this stack
|
|
50
|
-
# when it is visited. Therefore, an object on the stack always depends
|
|
51
|
-
# on all objects pushed above it.
|
|
52
|
-
@stack = []
|
|
53
|
-
|
|
54
|
-
# Register start of visits
|
|
55
|
-
Nanoc3::NotificationCenter.on(:visit_started, self) do |obj|
|
|
56
|
-
self.record_dependency(@stack[-1], obj) unless @stack.empty?
|
|
57
|
-
@stack.push(obj)
|
|
58
|
-
end
|
|
59
|
-
|
|
60
|
-
# Register end of visits
|
|
61
|
-
Nanoc3::NotificationCenter.on(:visit_ended, self) do |obj|
|
|
62
|
-
@stack.pop
|
|
63
|
-
end
|
|
64
|
-
end
|
|
65
|
-
|
|
66
|
-
# Stop listening for dependency messages and stop recording dependencies.
|
|
67
|
-
#
|
|
68
|
-
# @return [void]
|
|
69
|
-
def stop
|
|
70
|
-
# Unregister
|
|
71
|
-
Nanoc3::NotificationCenter.remove(:visit_started, self)
|
|
72
|
-
Nanoc3::NotificationCenter.remove(:visit_ended, self)
|
|
73
|
-
end
|
|
74
|
-
|
|
75
|
-
# Returns the direct dependencies for the given object.
|
|
76
|
-
#
|
|
77
|
-
# The direct dependencies of the given object include the items and
|
|
78
|
-
# layouts that, when outdated will cause the given object to be marked as
|
|
79
|
-
# outdated. Indirect dependencies will not be returned (e.g. if A depends
|
|
80
|
-
# on B which depends on C, then the direct dependencies of A do not
|
|
81
|
-
# include C).
|
|
82
|
-
#
|
|
83
|
-
# The direct predecessors can include nil, which indicates an item that is
|
|
84
|
-
# no longer present in the site.
|
|
85
|
-
#
|
|
86
|
-
# @param [Nanoc3::Item, Nanoc3::Layout] object The object for
|
|
87
|
-
# which to fetch the direct predecessors
|
|
88
|
-
#
|
|
89
|
-
# @return [Array<Nanoc3::Item, Nanoc3::Layout, nil>] The direct
|
|
90
|
-
# predecessors of
|
|
91
|
-
# the given object
|
|
92
|
-
def objects_causing_outdatedness_of(object)
|
|
93
|
-
@graph.direct_predecessors_of(object)
|
|
94
|
-
end
|
|
95
|
-
|
|
96
|
-
# Returns the direct inverse dependencies for the given object.
|
|
97
|
-
#
|
|
98
|
-
# The direct inverse dependencies of the given object include the objects
|
|
99
|
-
# that will be marked as outdated when the given object is outdated.
|
|
100
|
-
# Indirect dependencies will not be returned (e.g. if A depends on B which
|
|
101
|
-
# depends on C, then the direct inverse dependencies of C do not include
|
|
102
|
-
# A).
|
|
103
|
-
#
|
|
104
|
-
# @param [Nanoc3::Item, Nanoc3::Layout] object The object for which to
|
|
105
|
-
# fetch the direct successors
|
|
106
|
-
#
|
|
107
|
-
# @return [Array<Nanoc3::Item, Nanoc3::Layout>] The direct successors of
|
|
108
|
-
# the given object
|
|
109
|
-
def objects_outdated_due_to(object)
|
|
110
|
-
@graph.direct_successors_of(object).compact
|
|
111
|
-
end
|
|
112
|
-
|
|
113
|
-
# Records a dependency from `src` to `dst` in the dependency graph. When
|
|
114
|
-
# `dst` is oudated, `src` will also become outdated.
|
|
115
|
-
#
|
|
116
|
-
# @param [Nanoc3::Item, Nanoc3::Layout] src The source of the dependency,
|
|
117
|
-
# i.e. the object that will become outdated if dst is outdated
|
|
118
|
-
#
|
|
119
|
-
# @param [Nanoc3::Item, Nanoc3::Layout] dst The destination of the
|
|
120
|
-
# dependency, i.e. the object that will cause the source to become
|
|
121
|
-
# outdated if the destination is outdated
|
|
122
|
-
#
|
|
123
|
-
# @return [void]
|
|
124
|
-
def record_dependency(src, dst)
|
|
125
|
-
# Warning! dst and src are *reversed* here!
|
|
126
|
-
@graph.add_edge(dst, src) unless src == dst
|
|
127
|
-
end
|
|
128
|
-
|
|
129
|
-
# Empties the list of dependencies for the given object. This is necessary
|
|
130
|
-
# before recompiling the given object, because otherwise old dependencies
|
|
131
|
-
# will stick around and new dependencies will appear twice. This function
|
|
132
|
-
# removes all incoming edges for the given vertex.
|
|
133
|
-
#
|
|
134
|
-
# @api private
|
|
135
|
-
#
|
|
136
|
-
# @param [Nanoc3::Item, Nanoc3::Layout] object The object for which to
|
|
137
|
-
# forget all dependencies
|
|
138
|
-
#
|
|
139
|
-
# @return [void]
|
|
140
|
-
def forget_dependencies_for(object)
|
|
141
|
-
@graph.delete_edges_to(object)
|
|
142
|
-
end
|
|
143
|
-
|
|
144
|
-
# @deprecated Use {#store} instead
|
|
145
|
-
def store_graph
|
|
146
|
-
self.store
|
|
147
|
-
end
|
|
148
|
-
|
|
149
|
-
# @deprecated Use {#load} instead
|
|
150
|
-
def load_graph
|
|
151
|
-
self.load
|
|
152
|
-
end
|
|
153
|
-
|
|
154
|
-
# @see Nanoc3::Store#unload
|
|
155
|
-
def unload
|
|
156
|
-
@graph = Nanoc3::DirectedGraph.new([ nil ] + @objects)
|
|
157
|
-
end
|
|
158
|
-
|
|
159
|
-
protected
|
|
160
|
-
|
|
161
|
-
def data
|
|
162
|
-
{
|
|
163
|
-
:edges => @graph.edges,
|
|
164
|
-
:vertices => @graph.vertices.map { |obj| obj && obj.reference }
|
|
165
|
-
}
|
|
166
|
-
end
|
|
167
|
-
|
|
168
|
-
def data=(new_data)
|
|
169
|
-
# Create new graph
|
|
170
|
-
@graph = Nanoc3::DirectedGraph.new([ nil ] + @objects)
|
|
171
|
-
|
|
172
|
-
# Load vertices
|
|
173
|
-
previous_objects = new_data[:vertices].map do |reference|
|
|
174
|
-
@objects.find { |obj| reference == obj.reference }
|
|
175
|
-
end
|
|
176
|
-
|
|
177
|
-
# Load edges
|
|
178
|
-
new_data[:edges].each do |edge|
|
|
179
|
-
from_index, to_index = *edge
|
|
180
|
-
from = from_index && previous_objects[from_index]
|
|
181
|
-
to = to_index && previous_objects[to_index]
|
|
182
|
-
@graph.add_edge(from, to)
|
|
183
|
-
end
|
|
184
|
-
|
|
185
|
-
# Record dependency from all items on new items
|
|
186
|
-
new_objects = (@objects - previous_objects)
|
|
187
|
-
new_objects.each do |new_obj|
|
|
188
|
-
@objects.each do |obj|
|
|
189
|
-
@graph.add_edge(new_obj, obj)
|
|
190
|
-
end
|
|
191
|
-
end
|
|
192
|
-
end
|
|
193
|
-
|
|
194
|
-
end
|
|
195
|
-
|
|
196
|
-
end
|
|
@@ -1,165 +0,0 @@
|
|
|
1
|
-
# encoding: utf-8
|
|
2
|
-
|
|
3
|
-
module Nanoc3
|
|
4
|
-
|
|
5
|
-
# Nanoc3::Filter is responsible for filtering items. It is the superclass
|
|
6
|
-
# for all textual filters.
|
|
7
|
-
#
|
|
8
|
-
# A filter instance should only be used once. Filters should not be reused
|
|
9
|
-
# since they store state.
|
|
10
|
-
#
|
|
11
|
-
# When creating a filter with a hash containing assigned variables, those
|
|
12
|
-
# variables will be made available in the `@assigns` instance variable and
|
|
13
|
-
# the {#assigns} method. The assigns itself will also be available as
|
|
14
|
-
# instance variables and instance methods.
|
|
15
|
-
#
|
|
16
|
-
# @example Accessing assigns in different ways
|
|
17
|
-
#
|
|
18
|
-
# filter = SomeFilter.new({ :foo => 'bar' })
|
|
19
|
-
# filter.instance_eval { @assigns[:foo] }
|
|
20
|
-
# # => 'bar'
|
|
21
|
-
# filter.instance_eval { assigns[:foo] }
|
|
22
|
-
# # => 'bar'
|
|
23
|
-
# filter.instance_eval { @foo }
|
|
24
|
-
# # => 'bar'
|
|
25
|
-
# filter.instance_eval { foo }
|
|
26
|
-
# # => 'bar'
|
|
27
|
-
#
|
|
28
|
-
# @abstract Subclass and override {#run} to implement a custom filter.
|
|
29
|
-
class Filter < Context
|
|
30
|
-
|
|
31
|
-
# The path to the directory where temporary binary items are stored
|
|
32
|
-
TMP_BINARY_ITEMS_DIR = 'tmp/binary_items'
|
|
33
|
-
|
|
34
|
-
# A hash containing variables that will be made available during
|
|
35
|
-
# filtering.
|
|
36
|
-
#
|
|
37
|
-
# @return [Hash]
|
|
38
|
-
attr_reader :assigns
|
|
39
|
-
|
|
40
|
-
extend Nanoc3::PluginRegistry::PluginMethods
|
|
41
|
-
|
|
42
|
-
class << self
|
|
43
|
-
|
|
44
|
-
# Sets the new type for the filter. The type can be `:binary` (default)
|
|
45
|
-
# or `:text`. The given argument can either be a symbol indicating both
|
|
46
|
-
# “from” and “to” types, or a hash where the only key is the “from” type
|
|
47
|
-
# and the only value is the “to” type.
|
|
48
|
-
#
|
|
49
|
-
# @example Specifying a text-to-text filter
|
|
50
|
-
#
|
|
51
|
-
# type :text
|
|
52
|
-
#
|
|
53
|
-
# @example Specifying a text-to-binary filter
|
|
54
|
-
#
|
|
55
|
-
# type :text => :binary
|
|
56
|
-
#
|
|
57
|
-
# @param [Symbol, Hash] arg The new type of this filter
|
|
58
|
-
#
|
|
59
|
-
# @return [void]
|
|
60
|
-
def type(arg)
|
|
61
|
-
if arg.is_a?(Hash)
|
|
62
|
-
@from, @to = arg.keys[0], arg.values[0]
|
|
63
|
-
else
|
|
64
|
-
@from, @to = arg, arg
|
|
65
|
-
end
|
|
66
|
-
end
|
|
67
|
-
|
|
68
|
-
# @return [Boolean] True if this filter can be applied to binary item
|
|
69
|
-
# representations, false otherwise
|
|
70
|
-
def from_binary?
|
|
71
|
-
(@from || :text) == :binary
|
|
72
|
-
end
|
|
73
|
-
|
|
74
|
-
# @return [Boolean] True if this filter results in a binary item
|
|
75
|
-
# representation, false otherwise
|
|
76
|
-
def to_binary?
|
|
77
|
-
(@to || :text) == :binary
|
|
78
|
-
end
|
|
79
|
-
|
|
80
|
-
end
|
|
81
|
-
|
|
82
|
-
# Creates a new filter that has access to the given assigns.
|
|
83
|
-
#
|
|
84
|
-
# @param [Hash] hash A hash containing variables that should be made
|
|
85
|
-
# available during filtering.
|
|
86
|
-
def initialize(hash={})
|
|
87
|
-
@assigns = hash
|
|
88
|
-
super
|
|
89
|
-
end
|
|
90
|
-
|
|
91
|
-
# Runs the filter on the given content or filename.
|
|
92
|
-
#
|
|
93
|
-
# @abstract
|
|
94
|
-
#
|
|
95
|
-
# @param [String] content_or_filename The unprocessed content that should
|
|
96
|
-
# be filtered (if the item is a textual item) or the path to the file
|
|
97
|
-
# that should be filtered (if the item is a binary item)
|
|
98
|
-
#
|
|
99
|
-
# @param [Hash] params A hash containing parameters. Filter subclasses can
|
|
100
|
-
# use these parameters to allow modifying the filter's behaviour.
|
|
101
|
-
#
|
|
102
|
-
# @return [String, void] If the filter output binary content, the return
|
|
103
|
-
# value is undefined; if the filter outputs textual content, the return
|
|
104
|
-
# value will be the filtered content.
|
|
105
|
-
def run(content_or_filename, params={})
|
|
106
|
-
raise NotImplementedError.new("Nanoc3::Filter subclasses must implement #run")
|
|
107
|
-
end
|
|
108
|
-
|
|
109
|
-
# Returns a filename that is used to write data to. This method is only
|
|
110
|
-
# used on binary items. When running a binary filter on a file, the
|
|
111
|
-
# resulting file must end up in the location returned by this method.
|
|
112
|
-
#
|
|
113
|
-
# The returned filename will be absolute, so it is safe to change to
|
|
114
|
-
# another directory inside the filter.
|
|
115
|
-
#
|
|
116
|
-
# @return [String] The output filename
|
|
117
|
-
def output_filename
|
|
118
|
-
@output_filename ||= begin
|
|
119
|
-
FileUtils.mkdir_p(TMP_BINARY_ITEMS_DIR)
|
|
120
|
-
tempfile = Tempfile.new(filename.gsub(/[^a-z]/, '-'), TMP_BINARY_ITEMS_DIR)
|
|
121
|
-
new_filename = tempfile.path
|
|
122
|
-
tempfile.close!
|
|
123
|
-
|
|
124
|
-
File.expand_path(new_filename)
|
|
125
|
-
end
|
|
126
|
-
end
|
|
127
|
-
|
|
128
|
-
# Returns the filename associated with the item that is being filtered.
|
|
129
|
-
# It is in the format `item <identifier> (rep <name>)`.
|
|
130
|
-
#
|
|
131
|
-
# @return [String] The filename
|
|
132
|
-
def filename
|
|
133
|
-
if assigns[:layout]
|
|
134
|
-
"layout #{assigns[:layout].identifier}"
|
|
135
|
-
elsif assigns[:item]
|
|
136
|
-
"item #{assigns[:item].identifier} (rep #{assigns[:item_rep].name})"
|
|
137
|
-
else
|
|
138
|
-
'?'
|
|
139
|
-
end
|
|
140
|
-
end
|
|
141
|
-
|
|
142
|
-
# Creates a dependency from the item that is currently being filtered onto
|
|
143
|
-
# the given collection of items. In other words, require the given items
|
|
144
|
-
# to be compiled first before this items is processed.
|
|
145
|
-
#
|
|
146
|
-
# @param [Array<Nanoc3::Item>] items The items that are depended on.
|
|
147
|
-
#
|
|
148
|
-
# @return [void]
|
|
149
|
-
def depend_on(items)
|
|
150
|
-
# Notify
|
|
151
|
-
items.each do |item|
|
|
152
|
-
Nanoc3::NotificationCenter.post(:visit_started, item)
|
|
153
|
-
Nanoc3::NotificationCenter.post(:visit_ended, item)
|
|
154
|
-
end
|
|
155
|
-
|
|
156
|
-
# Raise unmet dependency error if necessary
|
|
157
|
-
items.each do |item|
|
|
158
|
-
rep = item.reps.find { |r| !r.compiled? }
|
|
159
|
-
raise Nanoc3::Errors::UnmetDependency.new(rep) if rep
|
|
160
|
-
end
|
|
161
|
-
end
|
|
162
|
-
|
|
163
|
-
end
|
|
164
|
-
|
|
165
|
-
end
|