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,73 +0,0 @@
|
|
|
1
|
-
# encoding: utf-8
|
|
2
|
-
|
|
3
|
-
module Nanoc3
|
|
4
|
-
|
|
5
|
-
# Contains the processing information for a item.
|
|
6
|
-
class Rule
|
|
7
|
-
|
|
8
|
-
# @return [Regexp] The regex that determines which items this rule can be
|
|
9
|
-
# applied to. This rule can be applied to items with a identifier
|
|
10
|
-
# matching this regex.
|
|
11
|
-
attr_reader :identifier_regex
|
|
12
|
-
|
|
13
|
-
# @return [Symbol] The name of the representation that will be compiled
|
|
14
|
-
# using this rule
|
|
15
|
-
attr_reader :rep_name
|
|
16
|
-
|
|
17
|
-
# @return [Symbol] The name of the snapshot this rule will apply to.
|
|
18
|
-
# Ignored for compilation rules, but used for routing rules.
|
|
19
|
-
#
|
|
20
|
-
# @since 3.2.0
|
|
21
|
-
attr_reader :snapshot_name
|
|
22
|
-
|
|
23
|
-
# Creates a new item compilation rule with the given identifier regex,
|
|
24
|
-
# compiler and block. The block will be called during compilation with the
|
|
25
|
-
# item rep as its argument.
|
|
26
|
-
#
|
|
27
|
-
# @param [Regexp] identifier_regex A regular expression that will be used
|
|
28
|
-
# to determine whether this rule is applicable to certain items.
|
|
29
|
-
#
|
|
30
|
-
# @param [String, Symbol] rep_name The name of the item representation
|
|
31
|
-
# where this rule can be applied to
|
|
32
|
-
#
|
|
33
|
-
# @param [Proc] block A block that will be called when matching items are
|
|
34
|
-
# compiled
|
|
35
|
-
#
|
|
36
|
-
# @option params [Symbol, nil] :snapshot (nil) The name of the snapshot
|
|
37
|
-
# this rule will apply to. Ignored for compilation rules, but used for
|
|
38
|
-
# routing rules.
|
|
39
|
-
def initialize(identifier_regex, rep_name, block, params={})
|
|
40
|
-
@identifier_regex = identifier_regex
|
|
41
|
-
@rep_name = rep_name.to_sym
|
|
42
|
-
@snapshot_name = params[:snapshot_name]
|
|
43
|
-
|
|
44
|
-
@block = block
|
|
45
|
-
end
|
|
46
|
-
|
|
47
|
-
# @param [Nanoc3::Item] item The item to check
|
|
48
|
-
#
|
|
49
|
-
# @return [Boolean] true if this rule can be applied to the given item
|
|
50
|
-
# rep, false otherwise
|
|
51
|
-
def applicable_to?(item)
|
|
52
|
-
item.identifier =~ @identifier_regex
|
|
53
|
-
end
|
|
54
|
-
|
|
55
|
-
# Applies this rule to the given item rep.
|
|
56
|
-
#
|
|
57
|
-
# @param [Nanoc3::ItemRep] rep The item representation where this rule
|
|
58
|
-
# should be applied to
|
|
59
|
-
#
|
|
60
|
-
# @option params [Nanoc3::Compiler] :compiler The compiler
|
|
61
|
-
#
|
|
62
|
-
# @raise [ArgumentError] if no compiler is passed
|
|
63
|
-
#
|
|
64
|
-
# @return [void]
|
|
65
|
-
def apply_to(rep, params={})
|
|
66
|
-
compiler = params[:compiler] or raise ArgumentError, "Required :compiler option is missing"
|
|
67
|
-
rep = Nanoc3::ItemRepProxy.new(rep, compiler) unless rep.is_proxy?
|
|
68
|
-
Nanoc3::RuleContext.new(:rep => rep, :compiler => compiler).instance_eval &@block
|
|
69
|
-
end
|
|
70
|
-
|
|
71
|
-
end
|
|
72
|
-
|
|
73
|
-
end
|
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
module Nanoc3
|
|
2
|
-
|
|
3
|
-
# Provides a context in which compilation and routing rules can be executed.
|
|
4
|
-
# It provides access to the item representation that is being compiled or
|
|
5
|
-
# routed.
|
|
6
|
-
#
|
|
7
|
-
# The following variables will be available in this rules context:
|
|
8
|
-
#
|
|
9
|
-
# * `rep` ({Nanoc3::ItemRep}) - The current item rep
|
|
10
|
-
# * `item` ({Nanoc3::Item}) - The current item
|
|
11
|
-
# * `site` ({Nanoc3::Site}) - The site
|
|
12
|
-
# * `config` ({Hash}) - The site configuration
|
|
13
|
-
# * `items` ({Array}<{Nanoc3::Item}>) - A list of all items
|
|
14
|
-
# * `layouts` ({Array}<{Nanoc3::Layout}>) - A list of all layouts
|
|
15
|
-
#
|
|
16
|
-
# @api private
|
|
17
|
-
class RuleContext < Context
|
|
18
|
-
|
|
19
|
-
# @option params [Nanoc3::ItemRep] :rep The item representation that will
|
|
20
|
-
# be processed in this rule context
|
|
21
|
-
#
|
|
22
|
-
# @option params [Nanoc3::Compiler] :compiler The compiler that is being
|
|
23
|
-
# used to compile the site
|
|
24
|
-
#
|
|
25
|
-
# @raise [ArgumentError] if the `:rep` or the `:compiler` option is
|
|
26
|
-
# missing
|
|
27
|
-
def initialize(params={})
|
|
28
|
-
rep = params[:rep] or raise ArgumentError, "Required :rep option is missing"
|
|
29
|
-
compiler = params[:compiler] or raise ArgumentError, "Required :compiler option is missing"
|
|
30
|
-
|
|
31
|
-
super({
|
|
32
|
-
:rep => rep,
|
|
33
|
-
:item => rep.item,
|
|
34
|
-
:site => compiler.site,
|
|
35
|
-
:config => compiler.site.config,
|
|
36
|
-
:items => compiler.site.items,
|
|
37
|
-
:layouts => compiler.site.layouts
|
|
38
|
-
})
|
|
39
|
-
end
|
|
40
|
-
|
|
41
|
-
# Filters the current representation (calls {Nanoc3::ItemRep#filter} with
|
|
42
|
-
# the given arguments on the rep).
|
|
43
|
-
#
|
|
44
|
-
# @see Nanoc3::ItemRep#filter
|
|
45
|
-
#
|
|
46
|
-
# @param [Symbol] filter_name The name of the filter to run the item
|
|
47
|
-
# representations' content through
|
|
48
|
-
#
|
|
49
|
-
# @param [Hash] filter_args The filter arguments that should be passed to
|
|
50
|
-
# the filter's #run method
|
|
51
|
-
#
|
|
52
|
-
# @return [void]
|
|
53
|
-
def filter(filter_name, filter_args={})
|
|
54
|
-
rep.filter(filter_name, filter_args)
|
|
55
|
-
end
|
|
56
|
-
|
|
57
|
-
# Layouts the current representation (calls {Nanoc3::ItemRep#layout} with
|
|
58
|
-
# the given arguments on the rep).
|
|
59
|
-
#
|
|
60
|
-
# @see Nanoc3::ItemRep#layout
|
|
61
|
-
#
|
|
62
|
-
# @param [String] layout_identifier The identifier of the layout the item
|
|
63
|
-
# should be laid out with
|
|
64
|
-
#
|
|
65
|
-
# @return [void]
|
|
66
|
-
def layout(layout_identifier)
|
|
67
|
-
rep.layout(layout_identifier)
|
|
68
|
-
end
|
|
69
|
-
|
|
70
|
-
# Creates a snapshot of the current compiled item content. Calls
|
|
71
|
-
# {Nanoc3::ItemRep#snapshot} with the given arguments on the rep.
|
|
72
|
-
#
|
|
73
|
-
# @see Nanoc3::ItemRep#snapshot
|
|
74
|
-
#
|
|
75
|
-
# @param [Symbol] snapshot_name The name of the snapshot to create
|
|
76
|
-
#
|
|
77
|
-
# @return [void]
|
|
78
|
-
def snapshot(snapshot_name)
|
|
79
|
-
rep.snapshot(snapshot_name)
|
|
80
|
-
end
|
|
81
|
-
|
|
82
|
-
end
|
|
83
|
-
|
|
84
|
-
end
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
# encoding: utf-8
|
|
2
|
-
|
|
3
|
-
module Nanoc3
|
|
4
|
-
|
|
5
|
-
# Calculates rule memories for objects that can be run through a rule (item
|
|
6
|
-
# representations and layouts).
|
|
7
|
-
#
|
|
8
|
-
# @api private
|
|
9
|
-
class RuleMemoryCalculator
|
|
10
|
-
|
|
11
|
-
extend Nanoc3::Memoization
|
|
12
|
-
|
|
13
|
-
# @option params [Nanoc3::RulesCollection] rules_collection The rules
|
|
14
|
-
# collection
|
|
15
|
-
def initialize(params={})
|
|
16
|
-
@rules_collection = params[:rules_collection] or
|
|
17
|
-
raise ArgumentError, "Required :rules_collection option is missing"
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
# @param [#reference] obj The object to calculate the rule memory for
|
|
21
|
-
#
|
|
22
|
-
# @return [Array] The caluclated rule memory for the given object
|
|
23
|
-
def [](obj)
|
|
24
|
-
result = case obj.type
|
|
25
|
-
when :item_rep
|
|
26
|
-
@rules_collection.new_rule_memory_for_rep(obj)
|
|
27
|
-
when :layout
|
|
28
|
-
@rules_collection.new_rule_memory_for_layout(obj)
|
|
29
|
-
else
|
|
30
|
-
raise RuntimeError,
|
|
31
|
-
"Do not know how to calculate the rule memory for #{obj.inspect}"
|
|
32
|
-
end
|
|
33
|
-
|
|
34
|
-
result
|
|
35
|
-
end
|
|
36
|
-
memoize :[]
|
|
37
|
-
|
|
38
|
-
end
|
|
39
|
-
|
|
40
|
-
end
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
# encoding: utf-8
|
|
2
|
-
|
|
3
|
-
module Nanoc3
|
|
4
|
-
|
|
5
|
-
# Stores rule memories for objects that can be run through a rule (item
|
|
6
|
-
# representations and layouts).
|
|
7
|
-
#
|
|
8
|
-
# @api private
|
|
9
|
-
class RuleMemoryStore < ::Nanoc3::Store
|
|
10
|
-
|
|
11
|
-
# @option params [Nanoc3::Site] site The site where this rule memory store
|
|
12
|
-
# belongs to
|
|
13
|
-
def initialize(params={})
|
|
14
|
-
super('tmp/rule_memory', 1)
|
|
15
|
-
|
|
16
|
-
@site = params[:site] if params.has_key?(:site)
|
|
17
|
-
|
|
18
|
-
@rule_memories = {}
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
# @param [Nanoc3::ItemRep, Nanoc3::Layout] obj The item representation or
|
|
22
|
-
# the layout to get the rule memory for
|
|
23
|
-
#
|
|
24
|
-
# @return [Array] The rule memory for the given object
|
|
25
|
-
def [](obj)
|
|
26
|
-
@rule_memories[obj.reference]
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
# @param [Nanoc3::ItemRep, Nanoc3::Layout] obj The item representation or
|
|
30
|
-
# the layout to set the rule memory for
|
|
31
|
-
#
|
|
32
|
-
# @param [Array] rule_memory The new rule memory to be stored
|
|
33
|
-
#
|
|
34
|
-
# @return [void]
|
|
35
|
-
def []=(obj, rule_memory)
|
|
36
|
-
@rule_memories[obj.reference] = rule_memory
|
|
37
|
-
end
|
|
38
|
-
|
|
39
|
-
protected
|
|
40
|
-
|
|
41
|
-
# @see Nanoc3::Store#data
|
|
42
|
-
def data
|
|
43
|
-
@rule_memories
|
|
44
|
-
end
|
|
45
|
-
|
|
46
|
-
# @see Nanoc3::Store#data=
|
|
47
|
-
def data=(new_data)
|
|
48
|
-
@rule_memories = new_data
|
|
49
|
-
end
|
|
50
|
-
|
|
51
|
-
end
|
|
52
|
-
|
|
53
|
-
end
|
|
@@ -1,231 +0,0 @@
|
|
|
1
|
-
# encoding: utf-8
|
|
2
|
-
|
|
3
|
-
module Nanoc3
|
|
4
|
-
|
|
5
|
-
# Keeps track of the rules in a site.
|
|
6
|
-
#
|
|
7
|
-
# @api private
|
|
8
|
-
class RulesCollection
|
|
9
|
-
|
|
10
|
-
extend Nanoc3::Memoization
|
|
11
|
-
|
|
12
|
-
# @return [Array<Nanoc3::Rule>] The list of item compilation rules that
|
|
13
|
-
# will be used to compile items.
|
|
14
|
-
attr_reader :item_compilation_rules
|
|
15
|
-
|
|
16
|
-
# @return [Array<Nanoc3::Rule>] The list of routing rules that will be
|
|
17
|
-
# used to give all items a path.
|
|
18
|
-
attr_reader :item_routing_rules
|
|
19
|
-
|
|
20
|
-
# The hash containing layout-to-filter mapping rules. This hash is
|
|
21
|
-
# ordered: iterating over the hash will happen in insertion order.
|
|
22
|
-
#
|
|
23
|
-
# @return [Hash] The layout-to-filter mapping rules
|
|
24
|
-
attr_reader :layout_filter_mapping
|
|
25
|
-
|
|
26
|
-
# @return [Proc] The code block that will be executed after all data is
|
|
27
|
-
# loaded but before the site is compiled
|
|
28
|
-
attr_accessor :preprocessor
|
|
29
|
-
|
|
30
|
-
# @param [Nanoc3::Compiler] compiler The site’s compiler
|
|
31
|
-
def initialize(compiler)
|
|
32
|
-
@compiler = compiler
|
|
33
|
-
|
|
34
|
-
@item_compilation_rules = []
|
|
35
|
-
@item_routing_rules = []
|
|
36
|
-
@layout_filter_mapping = OrderedHash.new
|
|
37
|
-
end
|
|
38
|
-
|
|
39
|
-
# Add the given rule to the list of item compilation rules.
|
|
40
|
-
#
|
|
41
|
-
# @param [Nanoc3::Rule] rule The item compilation rule to add
|
|
42
|
-
#
|
|
43
|
-
# @param [:before, :after] position The place where the rule should be
|
|
44
|
-
# added (either at the beginning or the end of the list of rules)
|
|
45
|
-
#
|
|
46
|
-
# @return [void]
|
|
47
|
-
def add_item_compilation_rule(rule, position=:after)
|
|
48
|
-
case position
|
|
49
|
-
when :before
|
|
50
|
-
@item_compilation_rules.unshift(rule)
|
|
51
|
-
when :after
|
|
52
|
-
@item_compilation_rules << rule
|
|
53
|
-
else
|
|
54
|
-
raise "#add_item_routing_rule expected position to be :after or :before"
|
|
55
|
-
end
|
|
56
|
-
end
|
|
57
|
-
|
|
58
|
-
# Add the given rule to the list of item routing rules.
|
|
59
|
-
#
|
|
60
|
-
# @param [Nanoc3::Rule] rule The item routing rule to add
|
|
61
|
-
#
|
|
62
|
-
# @param [:before, :after] position The place where the rule should be
|
|
63
|
-
# added (either at the beginning or the end of the list of rules)
|
|
64
|
-
#
|
|
65
|
-
# @return [void]
|
|
66
|
-
def add_item_routing_rule(rule, position=:after)
|
|
67
|
-
case position
|
|
68
|
-
when :before
|
|
69
|
-
@item_routing_rules.unshift(rule)
|
|
70
|
-
when :after
|
|
71
|
-
@item_routing_rules << rule
|
|
72
|
-
else
|
|
73
|
-
raise "#add_item_routing_rule expected position to be :after or :before"
|
|
74
|
-
end
|
|
75
|
-
end
|
|
76
|
-
|
|
77
|
-
# @param [Nanoc3::Item] item The item for which the compilation rules
|
|
78
|
-
# should be retrieved
|
|
79
|
-
#
|
|
80
|
-
# @return [Array] The list of item compilation rules for the given item
|
|
81
|
-
def item_compilation_rules_for(item)
|
|
82
|
-
@item_compilation_rules.select { |r| r.applicable_to?(item) }
|
|
83
|
-
end
|
|
84
|
-
|
|
85
|
-
# Loads this site’s rules.
|
|
86
|
-
#
|
|
87
|
-
# @return [void]
|
|
88
|
-
def load
|
|
89
|
-
# Find rules file
|
|
90
|
-
rules_filenames = [ 'Rules', 'rules', 'Rules.rb', 'rules.rb' ]
|
|
91
|
-
rules_filename = rules_filenames.find { |f| File.file?(f) }
|
|
92
|
-
raise Nanoc3::Errors::NoRulesFileFound.new if rules_filename.nil?
|
|
93
|
-
|
|
94
|
-
# Get rule data
|
|
95
|
-
@data = File.read(rules_filename)
|
|
96
|
-
|
|
97
|
-
# Load DSL
|
|
98
|
-
dsl.instance_eval(@data, "./#{rules_filename}")
|
|
99
|
-
end
|
|
100
|
-
|
|
101
|
-
# Unloads this site’s rules.
|
|
102
|
-
#
|
|
103
|
-
# @return [void]
|
|
104
|
-
def unload
|
|
105
|
-
@item_compilation_rules = []
|
|
106
|
-
@item_routing_rules = []
|
|
107
|
-
@layout_filter_mapping = OrderedHash.new
|
|
108
|
-
end
|
|
109
|
-
|
|
110
|
-
# Finds the first matching compilation rule for the given item
|
|
111
|
-
# representation.
|
|
112
|
-
#
|
|
113
|
-
# @param [Nanoc3::ItemRep] rep The item rep for which to fetch the rule
|
|
114
|
-
#
|
|
115
|
-
# @return [Nanoc3::Rule, nil] The compilation rule for the given item rep,
|
|
116
|
-
# or nil if no rules have been found
|
|
117
|
-
def compilation_rule_for(rep)
|
|
118
|
-
@item_compilation_rules.find do |rule|
|
|
119
|
-
rule.applicable_to?(rep.item) && rule.rep_name == rep.name
|
|
120
|
-
end
|
|
121
|
-
end
|
|
122
|
-
|
|
123
|
-
# Finds the first matching routing rule for the given item representation.
|
|
124
|
-
#
|
|
125
|
-
# @param [Nanoc3::ItemRep] rep The item rep for which to fetch the rule
|
|
126
|
-
#
|
|
127
|
-
# @return [Nanoc3::Rule, nil] The routing rule for the given item rep, or
|
|
128
|
-
# nil if no rules have been found
|
|
129
|
-
def routing_rule_for(rep)
|
|
130
|
-
@item_routing_rules.find do |rule|
|
|
131
|
-
rule.applicable_to?(rep.item) && rule.rep_name == rep.name
|
|
132
|
-
end
|
|
133
|
-
end
|
|
134
|
-
|
|
135
|
-
# Returns the list of routing rules that can be applied to the given item
|
|
136
|
-
# representation. For each snapshot, the first matching rule will be
|
|
137
|
-
# returned. The result is a hash containing the corresponding rule for
|
|
138
|
-
# each snapshot.
|
|
139
|
-
#
|
|
140
|
-
# @param [Nanoc3::ItemRep] rep The item rep for which to fetch the rules
|
|
141
|
-
#
|
|
142
|
-
# @return [Hash<Symbol, Nanoc3::Rule>] The routing rules for the given rep
|
|
143
|
-
def routing_rules_for(rep)
|
|
144
|
-
rules = {}
|
|
145
|
-
@item_routing_rules.each do |rule|
|
|
146
|
-
next if !rule.applicable_to?(rep.item)
|
|
147
|
-
next if rule.rep_name != rep.name
|
|
148
|
-
next if rules.has_key?(rule.snapshot_name)
|
|
149
|
-
|
|
150
|
-
rules[rule.snapshot_name] = rule
|
|
151
|
-
end
|
|
152
|
-
rules
|
|
153
|
-
end
|
|
154
|
-
|
|
155
|
-
# Finds the filter name and arguments to use for the given layout.
|
|
156
|
-
#
|
|
157
|
-
# @param [Nanoc3::Layout] layout The layout for which to fetch the filter.
|
|
158
|
-
#
|
|
159
|
-
# @return [Array, nil] A tuple containing the filter name and the filter
|
|
160
|
-
# arguments for the given layout.
|
|
161
|
-
def filter_for_layout(layout)
|
|
162
|
-
@layout_filter_mapping.each_pair do |layout_identifier, filter_name_and_args|
|
|
163
|
-
return filter_name_and_args if layout.identifier =~ layout_identifier
|
|
164
|
-
end
|
|
165
|
-
nil
|
|
166
|
-
end
|
|
167
|
-
|
|
168
|
-
# Returns the Nanoc3::CompilerDSL that should be used for this site.
|
|
169
|
-
def dsl
|
|
170
|
-
Nanoc3::CompilerDSL.new(self, @compiler.site.config)
|
|
171
|
-
end
|
|
172
|
-
memoize :dsl
|
|
173
|
-
|
|
174
|
-
# Returns an object that can be used for uniquely identifying objects.
|
|
175
|
-
#
|
|
176
|
-
# @return [Object] An unique reference to this object
|
|
177
|
-
def reference
|
|
178
|
-
:rules
|
|
179
|
-
end
|
|
180
|
-
|
|
181
|
-
# @return [String] The checksum for this object. If its contents change,
|
|
182
|
-
# the checksum will change as well.
|
|
183
|
-
def checksum
|
|
184
|
-
@data.checksum
|
|
185
|
-
end
|
|
186
|
-
|
|
187
|
-
def inspect
|
|
188
|
-
"<#{self.class}:0x#{self.object_id.to_s(16)}>"
|
|
189
|
-
end
|
|
190
|
-
|
|
191
|
-
# @param [Nanoc3::ItemRep] rep The item representation to get the rule
|
|
192
|
-
# memory for
|
|
193
|
-
#
|
|
194
|
-
# @return [Array] The rule memory for the given item representation
|
|
195
|
-
def new_rule_memory_for_rep(rep)
|
|
196
|
-
recording_proxy = rep.to_recording_proxy
|
|
197
|
-
compilation_rule_for(rep).apply_to(recording_proxy, :compiler => @compiler)
|
|
198
|
-
recording_proxy.rule_memory
|
|
199
|
-
end
|
|
200
|
-
memoize :new_rule_memory_for_rep
|
|
201
|
-
|
|
202
|
-
# @param [Nanoc3::Layout] layout The layout to get the rule memory for
|
|
203
|
-
#
|
|
204
|
-
# @return [Array] The rule memory for the given layout
|
|
205
|
-
def new_rule_memory_for_layout(layout)
|
|
206
|
-
filter_for_layout(layout)
|
|
207
|
-
end
|
|
208
|
-
memoize :new_rule_memory_for_layout
|
|
209
|
-
|
|
210
|
-
# @param [Nanoc3::Item] obj The object for which to check the rule memory
|
|
211
|
-
#
|
|
212
|
-
# @return [Boolean] true if the rule memory for the given object has
|
|
213
|
-
# changed since the last compilation, false otherwise
|
|
214
|
-
def rule_memory_differs_for(obj)
|
|
215
|
-
!rule_memory_store[obj].eql?(rule_memory_calculator[obj])
|
|
216
|
-
end
|
|
217
|
-
memoize :rule_memory_differs_for
|
|
218
|
-
|
|
219
|
-
# @return [Nanoc3::RuleMemoryStore] The rule memory store
|
|
220
|
-
def rule_memory_store
|
|
221
|
-
@compiler.rule_memory_store
|
|
222
|
-
end
|
|
223
|
-
|
|
224
|
-
# @return [Nanoc3::RuleMemoryCalculator] The rule memory calculator
|
|
225
|
-
def rule_memory_calculator
|
|
226
|
-
@compiler.rule_memory_calculator
|
|
227
|
-
end
|
|
228
|
-
|
|
229
|
-
end
|
|
230
|
-
|
|
231
|
-
end
|