nanoc 3.8.0 → 4.0.0a1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +1 -0
- data/Gemfile.lock +322 -0
- data/NEWS.md +6 -0
- data/bin/nanoc +0 -18
- data/lib/nanoc.rb +5 -3
- data/lib/nanoc/base.rb +24 -6
- data/lib/nanoc/base/checksummer.rb +6 -4
- data/lib/nanoc/base/compilation/checksum_store.rb +4 -4
- data/lib/nanoc/base/compilation/compiled_content_cache.rb +5 -5
- data/lib/nanoc/base/compilation/compiler.rb +60 -65
- data/lib/nanoc/base/compilation/compiler_dsl.rb +11 -9
- data/lib/nanoc/base/compilation/dependency_tracker.rb +24 -38
- data/lib/nanoc/base/compilation/filter.rb +22 -7
- data/lib/nanoc/base/compilation/item_rep_proxy.rb +14 -12
- data/lib/nanoc/base/compilation/item_rep_recorder_proxy.rb +8 -8
- data/lib/nanoc/base/compilation/outdatedness_checker.rb +32 -32
- data/lib/nanoc/base/compilation/outdatedness_reasons.rb +3 -1
- data/lib/nanoc/base/compilation/rule.rb +9 -7
- data/lib/nanoc/base/compilation/rule_context.rb +15 -15
- data/lib/nanoc/base/compilation/rule_memory_calculator.rb +3 -3
- data/lib/nanoc/base/compilation/rule_memory_store.rb +7 -7
- data/lib/nanoc/base/compilation/rules_collection.rb +28 -30
- data/lib/nanoc/base/context.rb +2 -2
- data/lib/nanoc/base/core_ext/array.rb +17 -25
- data/lib/nanoc/base/core_ext/hash.rb +17 -25
- data/lib/nanoc/base/core_ext/pathname.rb +4 -2
- data/lib/nanoc/base/core_ext/string.rb +5 -3
- data/lib/nanoc/base/directed_graph.rb +4 -9
- data/lib/nanoc/base/error.rb +7 -0
- data/lib/nanoc/base/errors.rb +16 -23
- data/lib/nanoc/base/memoization.rb +4 -2
- data/lib/nanoc/base/notification_center.rb +3 -1
- data/lib/nanoc/base/plugin_registry.rb +14 -21
- data/lib/nanoc/base/result_data/item_rep.rb +43 -88
- data/lib/nanoc/base/source_data/code_snippet.rb +6 -4
- data/lib/nanoc/base/source_data/configuration.rb +3 -1
- data/lib/nanoc/base/source_data/data_source.rb +12 -94
- data/lib/nanoc/base/source_data/identifier.rb +50 -0
- data/lib/nanoc/base/source_data/item.rb +24 -67
- data/lib/nanoc/base/source_data/item_array.rb +6 -4
- data/lib/nanoc/base/source_data/layout.rb +17 -28
- data/lib/nanoc/base/source_data/site.rb +33 -44
- data/lib/nanoc/base/store.rb +3 -5
- data/lib/nanoc/base/temp_filename_factory.rb +3 -2
- data/lib/nanoc/base/views/config.rb +19 -0
- data/lib/nanoc/base/views/item.rb +77 -0
- data/lib/nanoc/base/views/item_collection.rb +43 -0
- data/lib/nanoc/base/views/item_rep.rb +125 -0
- data/lib/nanoc/base/views/layout.rb +42 -0
- data/lib/nanoc/base/views/layout_collection.rb +26 -0
- data/lib/nanoc/base/views/mutable_config.rb +9 -0
- data/lib/nanoc/base/views/mutable_item.rb +9 -0
- data/lib/nanoc/base/views/mutable_item_collection.rb +18 -0
- data/lib/nanoc/base/views/mutable_layout.rb +9 -0
- data/lib/nanoc/base/views/mutable_layout_collection.rb +18 -0
- data/lib/nanoc/base/views/site.rb +35 -0
- data/lib/nanoc/cli.rb +3 -6
- data/lib/nanoc/cli/ansi_string_colorizer.rb +2 -0
- data/lib/nanoc/cli/cleaning_stream.rb +2 -0
- data/lib/nanoc/cli/command_runner.rb +8 -42
- data/lib/nanoc/cli/commands/check.rb +2 -2
- data/lib/nanoc/cli/commands/compile.rb +19 -34
- data/lib/nanoc/cli/commands/create-site.rb +46 -83
- data/lib/nanoc/cli/commands/deploy.rb +4 -4
- data/lib/nanoc/cli/commands/shell.rb +1 -1
- data/lib/nanoc/cli/commands/show-plugins.rb +4 -6
- data/lib/nanoc/cli/error_handler.rb +4 -14
- data/lib/nanoc/cli/logger.rb +2 -0
- data/lib/nanoc/cli/stream_cleaners.rb +1 -0
- data/lib/nanoc/cli/stream_cleaners/abstract.rb +2 -0
- data/lib/nanoc/cli/stream_cleaners/ansi_colors.rb +2 -0
- data/lib/nanoc/cli/stream_cleaners/utf8.rb +2 -0
- data/lib/nanoc/data_sources.rb +1 -17
- data/lib/nanoc/data_sources/filesystem.rb +6 -37
- data/lib/nanoc/data_sources/filesystem_unified.rb +5 -3
- data/lib/nanoc/data_sources/filesystem_verbose.rb +5 -3
- data/lib/nanoc/data_sources/static.rb +4 -2
- data/lib/nanoc/extra.rb +1 -13
- data/lib/nanoc/extra/checking.rb +1 -0
- data/lib/nanoc/extra/checking/check.rb +4 -2
- data/lib/nanoc/extra/checking/checks.rb +1 -0
- data/lib/nanoc/extra/checking/checks/css.rb +1 -0
- data/lib/nanoc/extra/checking/checks/external_links.rb +2 -0
- data/lib/nanoc/extra/checking/checks/html.rb +1 -0
- data/lib/nanoc/extra/checking/checks/internal_links.rb +2 -0
- data/lib/nanoc/extra/checking/checks/mixed_content.rb +2 -0
- data/lib/nanoc/extra/checking/checks/stale.rb +1 -0
- data/lib/nanoc/extra/checking/dsl.rb +1 -0
- data/lib/nanoc/extra/checking/issue.rb +1 -0
- data/lib/nanoc/extra/checking/runner.rb +3 -3
- data/lib/nanoc/extra/core_ext/pathname.rb +5 -3
- data/lib/nanoc/extra/core_ext/time.rb +4 -2
- data/lib/nanoc/extra/deployer.rb +3 -1
- data/lib/nanoc/extra/deployers.rb +1 -0
- data/lib/nanoc/extra/deployers/fog.rb +2 -0
- data/lib/nanoc/extra/deployers/rsync.rb +2 -0
- data/lib/nanoc/extra/filesystem_tools.rb +3 -7
- data/lib/nanoc/extra/jruby_nokogiri_warner.rb +1 -0
- data/lib/nanoc/extra/link_collector.rb +1 -0
- data/lib/nanoc/extra/piper.rb +2 -1
- data/lib/nanoc/extra/pruner.rb +5 -3
- data/lib/nanoc/filters.rb +1 -2
- data/lib/nanoc/filters/asciidoc.rb +2 -0
- data/lib/nanoc/filters/bluecloth.rb +1 -0
- data/lib/nanoc/filters/coffeescript.rb +2 -0
- data/lib/nanoc/filters/colorize_syntax.rb +1 -12
- data/lib/nanoc/filters/erb.rb +2 -1
- data/lib/nanoc/filters/erubis.rb +2 -1
- data/lib/nanoc/filters/haml.rb +2 -1
- data/lib/nanoc/filters/handlebars.rb +2 -0
- data/lib/nanoc/filters/kramdown.rb +1 -0
- data/lib/nanoc/filters/less.rb +1 -0
- data/lib/nanoc/filters/markaby.rb +1 -0
- data/lib/nanoc/filters/maruku.rb +1 -0
- data/lib/nanoc/filters/mustache.rb +2 -0
- data/lib/nanoc/filters/pandoc.rb +1 -0
- data/lib/nanoc/filters/rainpress.rb +1 -0
- data/lib/nanoc/filters/rdiscount.rb +1 -0
- data/lib/nanoc/filters/rdoc.rb +1 -0
- data/lib/nanoc/filters/redcarpet.rb +2 -0
- data/lib/nanoc/filters/redcloth.rb +1 -0
- data/lib/nanoc/filters/relativize_paths.rb +1 -0
- data/lib/nanoc/filters/rubypants.rb +1 -0
- data/lib/nanoc/filters/sass.rb +1 -0
- data/lib/nanoc/filters/sass/sass_filesystem_importer.rb +2 -0
- data/lib/nanoc/filters/slim.rb +3 -1
- data/lib/nanoc/filters/typogruby.rb +2 -0
- data/lib/nanoc/filters/uglify_js.rb +1 -0
- data/lib/nanoc/filters/xsl.rb +2 -0
- data/lib/nanoc/filters/yui_compressor.rb +2 -0
- data/lib/nanoc/helpers/blogging.rb +30 -30
- data/lib/nanoc/helpers/breadcrumbs.rb +2 -2
- data/lib/nanoc/helpers/capturing.rb +6 -17
- data/lib/nanoc/helpers/filtering.rb +3 -3
- data/lib/nanoc/helpers/link_to.rb +3 -3
- data/lib/nanoc/helpers/rendering.rb +11 -11
- data/lib/nanoc/helpers/xml_sitemap.rb +3 -3
- data/lib/nanoc/tasks.rb +1 -0
- data/lib/nanoc/tasks/clean.rake +1 -1
- data/lib/nanoc/version.rb +1 -1
- data/tasks/doc.rake +2 -1
- data/tasks/test.rake +7 -1
- data/test/base/checksummer_spec.rb +15 -15
- data/test/base/core_ext/array_spec.rb +10 -10
- data/test/base/core_ext/hash_spec.rb +16 -16
- data/test/base/core_ext/pathname_spec.rb +2 -2
- data/test/base/core_ext/string_spec.rb +9 -9
- data/test/base/temp_filename_factory_spec.rb +3 -7
- data/test/base/test_checksum_store.rb +5 -5
- data/test/base/test_code_snippet.rb +3 -3
- data/test/base/test_compiler.rb +29 -29
- data/test/base/test_compiler_dsl.rb +23 -23
- data/test/base/test_context.rb +4 -4
- data/test/base/test_data_source.rb +17 -7
- data/test/base/test_dependency_tracker.rb +29 -29
- data/test/base/test_directed_graph.rb +27 -27
- data/test/base/test_item.rb +23 -21
- data/test/base/test_item_array.rb +18 -18
- data/test/base/test_item_rep.rb +76 -76
- data/test/base/test_item_rep_recorder_proxy.rb +4 -4
- data/test/base/test_layout.rb +8 -16
- data/test/base/test_memoization.rb +4 -4
- data/test/base/test_notification_center.rb +6 -6
- data/test/base/test_outdatedness_checker.rb +18 -18
- data/test/base/test_plugin.rb +1 -1
- data/test/base/test_rule.rb +2 -2
- data/test/base/test_rule_context.rb +5 -5
- data/test/base/test_site.rb +62 -38
- data/test/base/test_store.rb +2 -2
- data/test/cli/commands/test_check.rb +1 -1
- data/test/cli/commands/test_compile.rb +24 -18
- data/test/cli/commands/test_create_site.rb +5 -7
- data/test/cli/commands/test_deploy.rb +1 -1
- data/test/data_sources/test_filesystem.rb +22 -67
- data/test/data_sources/test_filesystem_unified.rb +10 -23
- data/test/data_sources/test_filesystem_verbose.rb +8 -53
- data/test/data_sources/test_static.rb +9 -9
- data/test/extra/checking/checks/test_stale.rb +1 -1
- data/test/extra/core_ext/test_pathname.rb +3 -3
- data/test/extra/core_ext/test_time.rb +4 -4
- data/test/extra/test_filesystem_tools.rb +1 -1
- data/test/filters/test_handlebars.rb +3 -3
- data/test/filters/test_less.rb +6 -6
- data/test/filters/test_mustache.rb +2 -2
- data/test/filters/test_relativize_paths.rb +81 -81
- data/test/filters/test_sass.rb +7 -7
- data/test/filters/test_xsl.rb +6 -6
- data/test/helper.rb +1 -1
- data/test/helpers/test_blogging.rb +78 -99
- data/test/helpers/test_breadcrumbs.rb +12 -12
- data/test/helpers/test_capturing.rb +10 -11
- data/test/helpers/test_filtering.rb +6 -6
- data/test/helpers/test_rendering.rb +3 -3
- data/test/helpers/test_tagging.rb +7 -7
- data/test/helpers/test_xml_sitemap.rb +34 -33
- metadata +19 -43
- data/lib/nanoc/cli/commands/autocompile.rb +0 -69
- data/lib/nanoc/cli/commands/create-item.rb +0 -55
- data/lib/nanoc/cli/commands/create-layout.rb +0 -68
- data/lib/nanoc/cli/commands/sync.rb +0 -32
- data/lib/nanoc/cli/commands/update.rb +0 -63
- data/lib/nanoc/cli/commands/validate-css.rb +0 -20
- data/lib/nanoc/cli/commands/validate-html.rb +0 -20
- data/lib/nanoc/cli/commands/validate-links.rb +0 -27
- data/lib/nanoc/cli/commands/watch.rb +0 -176
- data/lib/nanoc/data_sources/deprecated/delicious.rb +0 -38
- data/lib/nanoc/data_sources/deprecated/last_fm.rb +0 -85
- data/lib/nanoc/data_sources/deprecated/twitter.rb +0 -34
- data/lib/nanoc/extra/auto_compiler.rb +0 -99
- data/lib/nanoc/extra/chick.rb +0 -117
- data/lib/nanoc/extra/file_proxy.rb +0 -36
- data/lib/nanoc/extra/validators.rb +0 -8
- data/lib/nanoc/extra/validators/links.rb +0 -18
- data/lib/nanoc/extra/validators/w3c.rb +0 -23
- data/lib/nanoc/extra/vcs.rb +0 -62
- data/lib/nanoc/extra/vcses.rb +0 -15
- data/lib/nanoc/extra/vcses/bazaar.rb +0 -21
- data/lib/nanoc/extra/vcses/dummy.rb +0 -20
- data/lib/nanoc/extra/vcses/git.rb +0 -21
- data/lib/nanoc/extra/vcses/mercurial.rb +0 -21
- data/lib/nanoc/extra/vcses/subversion.rb +0 -21
- data/lib/nanoc/filters/coderay.rb +0 -19
- data/lib/nanoc3.rb +0 -3
- data/lib/nanoc3/cli.rb +0 -3
- data/lib/nanoc3/tasks.rb +0 -3
- data/test/cli/commands/test_create_item.rb +0 -10
- data/test/cli/commands/test_create_layout.rb +0 -24
- data/test/cli/commands/test_sync.rb +0 -27
- data/test/cli/commands/test_update.rb +0 -6
- data/test/cli/commands/test_watch.rb +0 -74
- data/test/extra/test_auto_compiler.rb +0 -437
- data/test/extra/test_vcs.rb +0 -18
- data/test/extra/validators/test_links.rb +0 -4
- data/test/extra/validators/test_w3c.rb +0 -37
- data/test/filters/test_coderay.rb +0 -40
@@ -0,0 +1,50 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module Nanoc
|
4
|
+
class Identifier
|
5
|
+
include Comparable
|
6
|
+
|
7
|
+
def initialize(string)
|
8
|
+
@string = "/#{string}/".gsub(/^\/+|\/+$/, '/').freeze
|
9
|
+
end
|
10
|
+
|
11
|
+
def ==(other)
|
12
|
+
to_s == other.to_s
|
13
|
+
end
|
14
|
+
alias_method :eql?, :==
|
15
|
+
|
16
|
+
def hash
|
17
|
+
self.class.hash ^ to_s.hash
|
18
|
+
end
|
19
|
+
|
20
|
+
def =~(pat)
|
21
|
+
to_s =~ pat
|
22
|
+
end
|
23
|
+
|
24
|
+
def <=>(other)
|
25
|
+
to_s <=> other.to_s
|
26
|
+
end
|
27
|
+
|
28
|
+
# @return [String]
|
29
|
+
def chop
|
30
|
+
to_s.chop
|
31
|
+
end
|
32
|
+
|
33
|
+
# @return [String]
|
34
|
+
def +(string)
|
35
|
+
to_s + string
|
36
|
+
end
|
37
|
+
|
38
|
+
def to_s
|
39
|
+
@string
|
40
|
+
end
|
41
|
+
|
42
|
+
def to_str
|
43
|
+
@string
|
44
|
+
end
|
45
|
+
|
46
|
+
def inspect
|
47
|
+
"<Nanoc::Identifier #{to_s.inspect}>"
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -1,29 +1,21 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
|
-
module Nanoc
|
3
|
+
module Nanoc::Int
|
4
4
|
# Represents a compileable item in a site. It has content and attributes, as
|
5
5
|
# well as an identifier (which starts and ends with a slash). It can also
|
6
6
|
# store the modification time to speed up compilation.
|
7
|
+
#
|
8
|
+
# @api private
|
7
9
|
class Item
|
8
|
-
extend Nanoc::Memoization
|
10
|
+
extend Nanoc::Int::Memoization
|
9
11
|
|
10
12
|
# @return [Hash] This item's attributes
|
11
13
|
attr_accessor :attributes
|
12
14
|
|
13
|
-
#
|
14
|
-
#
|
15
|
-
# Identifiers start and end with a slash. They are comparable to paths on
|
16
|
-
# the filesystem, with the difference that file system paths usually do
|
17
|
-
# not have a trailing slash. The item hierarchy (parent and children of
|
18
|
-
# items) is determined by the item identifier.
|
19
|
-
#
|
20
|
-
# The root page (the home page) has the identifier “/”, which means
|
21
|
-
# that it is the ancestor of all other items.
|
22
|
-
#
|
23
|
-
# @return [String] This item's identifier
|
15
|
+
# @return [Nanoc::Identifier] This item's identifier
|
24
16
|
attr_accessor :identifier
|
25
17
|
|
26
|
-
# @return [Array<Nanoc::ItemRep>] This item’s list of item reps
|
18
|
+
# @return [Array<Nanoc::Int::ItemRep>] This item’s list of item reps
|
27
19
|
attr_reader :reps
|
28
20
|
|
29
21
|
# @return [String] This item's raw, uncompiled content of this item (only
|
@@ -34,14 +26,14 @@ module Nanoc
|
|
34
26
|
# item’s content
|
35
27
|
attr_reader :raw_filename
|
36
28
|
|
37
|
-
# @return [Nanoc::Site] The site this item belongs to
|
29
|
+
# @return [Nanoc::Int::Site] The site this item belongs to
|
38
30
|
attr_accessor :site
|
39
31
|
|
40
|
-
# @return [Nanoc::Item, nil] The parent item of this item. This can be
|
32
|
+
# @return [Nanoc::Int::Item, nil] The parent item of this item. This can be
|
41
33
|
# nil even for non-root items.
|
42
34
|
attr_accessor :parent
|
43
35
|
|
44
|
-
# @return [Array<Nanoc::Item>] The child items of this item
|
36
|
+
# @return [Array<Nanoc::Int::Item>] The child items of this item
|
45
37
|
attr_accessor :children
|
46
38
|
|
47
39
|
# Creates a new item with the given content or filename, attributes and
|
@@ -55,21 +47,13 @@ module Nanoc
|
|
55
47
|
#
|
56
48
|
# @param [String] identifier This item's identifier.
|
57
49
|
#
|
58
|
-
# @param [
|
59
|
-
# compatibility, this can be a Time instance indicating the time when
|
60
|
-
# this item was last modified (mtime).
|
61
|
-
#
|
62
|
-
# @option params [Time, nil] :mtime (nil) The time when this item was last
|
63
|
-
# modified. Deprecated; pass the modification time as the `:mtime`
|
64
|
-
# attribute instead.
|
50
|
+
# @param [Hash] params Extra parameters.
|
65
51
|
#
|
66
52
|
# @option params [Symbol, nil] :binary (true) Whether or not this item is
|
67
53
|
# binary
|
68
|
-
def initialize(raw_content_or_raw_filename, attributes, identifier, params =
|
54
|
+
def initialize(raw_content_or_raw_filename, attributes, identifier, params = {})
|
69
55
|
# Parse params
|
70
|
-
params
|
71
|
-
params = { mtime: params } if params.is_a?(Time)
|
72
|
-
params[:binary] = false unless params.key?(:binary)
|
56
|
+
params = params.merge(binary: false) unless params.key?(:binary)
|
73
57
|
|
74
58
|
if raw_content_or_raw_filename.nil?
|
75
59
|
raise "attempted to create an item with no content/filename (identifier #{identifier})"
|
@@ -85,8 +69,8 @@ module Nanoc
|
|
85
69
|
end
|
86
70
|
|
87
71
|
# Get rest of params
|
88
|
-
@attributes = attributes.
|
89
|
-
@identifier = identifier
|
72
|
+
@attributes = attributes.__nanoc_symbolize_keys_recursively
|
73
|
+
@identifier = Nanoc::Identifier.new(identifier)
|
90
74
|
|
91
75
|
# Set mtime
|
92
76
|
@attributes.merge!(mtime: params[:mtime]) if params[:mtime]
|
@@ -101,7 +85,7 @@ module Nanoc
|
|
101
85
|
#
|
102
86
|
# @param [Symbol] rep_name The name of the representation to return
|
103
87
|
#
|
104
|
-
# @return [Nanoc::ItemRep] The representation with the given name
|
88
|
+
# @return [Nanoc::Int::ItemRep] The representation with the given name
|
105
89
|
def rep_named(rep_name)
|
106
90
|
@reps.find { |r| r.name == rep_name }
|
107
91
|
end
|
@@ -129,7 +113,7 @@ module Nanoc
|
|
129
113
|
rep_name = params[:rep] || :default
|
130
114
|
rep = reps.find { |r| r.name == rep_name }
|
131
115
|
if rep.nil?
|
132
|
-
raise Nanoc::Errors::Generic,
|
116
|
+
raise Nanoc::Int::Errors::Generic,
|
133
117
|
"No rep named #{rep_name.inspect} was found."
|
134
118
|
end
|
135
119
|
|
@@ -152,7 +136,7 @@ module Nanoc
|
|
152
136
|
# Get rep
|
153
137
|
rep = reps.find { |r| r.name == rep_name }
|
154
138
|
if rep.nil?
|
155
|
-
raise Nanoc::Errors::Generic,
|
139
|
+
raise Nanoc::Int::Errors::Generic,
|
156
140
|
"No rep named #{rep_name.inspect} was found."
|
157
141
|
end
|
158
142
|
|
@@ -166,30 +150,8 @@ module Nanoc
|
|
166
150
|
#
|
167
151
|
# @return [Object] The value of the requested attribute
|
168
152
|
def [](key)
|
169
|
-
Nanoc::NotificationCenter.post(:visit_started, self)
|
170
|
-
Nanoc::NotificationCenter.post(:visit_ended, self)
|
171
|
-
|
172
|
-
# Get captured content (hax)
|
173
|
-
# TODO: [in nanoc 4.0] remove me
|
174
|
-
if key.to_s =~ /^content_for_(.*)$/
|
175
|
-
@@_content_for_warning_issued ||= false
|
176
|
-
@@_capturing_helper_included ||= false
|
177
|
-
|
178
|
-
# Warn
|
179
|
-
unless @@_content_for_warning_issued
|
180
|
-
warn 'WARNING: Accessing captured content should happen using the #content_for method defined in the Capturing helper instead of using item[:content_for_something]. The latter way of accessing captured content will be removed in nanoc 4.0.'
|
181
|
-
@@_content_for_warning_issued = true
|
182
|
-
end
|
183
|
-
|
184
|
-
# Include capturing helper if necessary
|
185
|
-
unless @@_capturing_helper_included
|
186
|
-
self.class.send(:include, ::Nanoc::Helpers::Capturing)
|
187
|
-
@@_capturing_helper_included = true
|
188
|
-
end
|
189
|
-
|
190
|
-
# Get content
|
191
|
-
return content_for(self, $1.to_sym)
|
192
|
-
end
|
153
|
+
Nanoc::Int::NotificationCenter.post(:visit_started, self)
|
154
|
+
Nanoc::Int::NotificationCenter.post(:visit_ended, self)
|
193
155
|
|
194
156
|
@attributes[key]
|
195
157
|
end
|
@@ -224,14 +186,14 @@ module Nanoc
|
|
224
186
|
#
|
225
187
|
# @return [Object] An unique reference to this object
|
226
188
|
def reference
|
227
|
-
[type, identifier]
|
189
|
+
[type, identifier.to_s]
|
228
190
|
end
|
229
191
|
|
230
192
|
# Prevents all further modifications to its attributes.
|
231
193
|
#
|
232
194
|
# @return [void]
|
233
195
|
def freeze
|
234
|
-
attributes.
|
196
|
+
attributes.__nanoc_freeze_recursively
|
235
197
|
children.freeze
|
236
198
|
identifier.freeze
|
237
199
|
raw_filename.freeze if raw_filename
|
@@ -244,10 +206,10 @@ module Nanoc
|
|
244
206
|
|
245
207
|
# @return [String] The checksum for this object. If its contents change,
|
246
208
|
# the checksum will change as well.
|
247
|
-
def
|
248
|
-
Nanoc::Checksummer.calc(self)
|
209
|
+
def __nanoc_checksum
|
210
|
+
Nanoc::Int::Checksummer.calc(self)
|
249
211
|
end
|
250
|
-
memoize :
|
212
|
+
memoize :__nanoc_checksum
|
251
213
|
|
252
214
|
def hash
|
253
215
|
self.class.hash ^ identifier.hash
|
@@ -288,10 +250,5 @@ module Nanoc
|
|
288
250
|
def forced_outdated?
|
289
251
|
@forced_outdated || false
|
290
252
|
end
|
291
|
-
|
292
|
-
# @deprecated Access the modification time using `item[:mtime]` instead.
|
293
|
-
def mtime
|
294
|
-
self[:mtime]
|
295
|
-
end
|
296
253
|
end
|
297
254
|
end
|
@@ -1,7 +1,9 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
|
-
module Nanoc
|
3
|
+
module Nanoc::Int
|
4
4
|
# Acts as an array, but allows fetching items using identifiers, e.g. `@items['/blah/']`.
|
5
|
+
#
|
6
|
+
# @api private
|
5
7
|
class ItemArray
|
6
8
|
include Enumerable
|
7
9
|
|
@@ -33,7 +35,7 @@ module Nanoc
|
|
33
35
|
if 1 == args.size && args.first.is_a?(String)
|
34
36
|
item_with_identifier(args.first)
|
35
37
|
elsif 1 == args.size && args.first.is_a?(Regexp)
|
36
|
-
@items.select { |i| i.identifier =~ args.first }
|
38
|
+
@items.select { |i| i.identifier.to_s =~ args.first }
|
37
39
|
else
|
38
40
|
@items[*args]
|
39
41
|
end
|
@@ -52,7 +54,7 @@ module Nanoc
|
|
52
54
|
|
53
55
|
def item_with_identifier(identifier)
|
54
56
|
if self.frozen?
|
55
|
-
@mapping[identifier]
|
57
|
+
@mapping[identifier.to_s]
|
56
58
|
else
|
57
59
|
@items.find { |i| i.identifier == identifier }
|
58
60
|
end
|
@@ -61,7 +63,7 @@ module Nanoc
|
|
61
63
|
def build_mapping
|
62
64
|
@mapping = {}
|
63
65
|
@items.each do |item|
|
64
|
-
@mapping[item.identifier] = item
|
66
|
+
@mapping[item.identifier.to_s] = item
|
65
67
|
end
|
66
68
|
@mapping.freeze
|
67
69
|
end
|
@@ -1,10 +1,12 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
|
-
module Nanoc
|
3
|
+
module Nanoc::Int
|
4
4
|
# Represents a layout in a nanoc site. It has content, attributes, an
|
5
5
|
# identifier and a modification time (to speed up compilation).
|
6
|
+
#
|
7
|
+
# @api private
|
6
8
|
class Layout
|
7
|
-
extend Nanoc::Memoization
|
9
|
+
extend Nanoc::Int::Memoization
|
8
10
|
|
9
11
|
# @return [String] The raw content of this layout
|
10
12
|
attr_reader :raw_content
|
@@ -12,8 +14,7 @@ module Nanoc
|
|
12
14
|
# @return [Hash] This layout's attributes
|
13
15
|
attr_reader :attributes
|
14
16
|
|
15
|
-
# @return [
|
16
|
-
# slash
|
17
|
+
# @return [Nanoc::Identifier] This layout's identifier
|
17
18
|
attr_accessor :identifier
|
18
19
|
|
19
20
|
# Creates a new layout.
|
@@ -24,22 +25,11 @@ module Nanoc
|
|
24
25
|
#
|
25
26
|
# @param [String] identifier This layout's identifier.
|
26
27
|
#
|
27
|
-
# @param [
|
28
|
-
|
29
|
-
# this layout was last modified (mtime).
|
30
|
-
#
|
31
|
-
# @option params [Time, nil] :mtime (nil) The time when this layout was
|
32
|
-
# last modified. Deprecated; pass the modification time as the `:mtime`
|
33
|
-
# attribute instead.
|
34
|
-
def initialize(raw_content, attributes, identifier, params = nil)
|
28
|
+
# @param [Hash] params Extra parameters. Unused.
|
29
|
+
def initialize(raw_content, attributes, identifier, params = {})
|
35
30
|
@raw_content = raw_content
|
36
|
-
@attributes = attributes.
|
37
|
-
@identifier = identifier
|
38
|
-
|
39
|
-
# Set mtime
|
40
|
-
params ||= {}
|
41
|
-
params = { mtime: params } if params.is_a?(Time)
|
42
|
-
@attributes.merge(mtime: params[:mtime]) if params[:mtime]
|
31
|
+
@attributes = attributes.__nanoc_symbolize_keys_recursively
|
32
|
+
@identifier = Nanoc::Identifier.new(identifier)
|
43
33
|
end
|
44
34
|
|
45
35
|
# Requests the attribute with the given key.
|
@@ -51,6 +41,10 @@ module Nanoc
|
|
51
41
|
@attributes[key]
|
52
42
|
end
|
53
43
|
|
44
|
+
def []=(key, value)
|
45
|
+
@attributes[key] = value
|
46
|
+
end
|
47
|
+
|
54
48
|
# Returns the type of this object. Will always return `:layout`, because
|
55
49
|
# this is a layout. For items, this method returns `:item`.
|
56
50
|
#
|
@@ -65,7 +59,7 @@ module Nanoc
|
|
65
59
|
#
|
66
60
|
# @return [void]
|
67
61
|
def freeze
|
68
|
-
attributes.
|
62
|
+
attributes.__nanoc_freeze_recursively
|
69
63
|
identifier.freeze
|
70
64
|
raw_content.freeze
|
71
65
|
end
|
@@ -85,10 +79,10 @@ module Nanoc
|
|
85
79
|
|
86
80
|
# @return [String] The checksum for this object. If its contents change,
|
87
81
|
# the checksum will change as well.
|
88
|
-
def
|
89
|
-
Nanoc::Checksummer.calc(self)
|
82
|
+
def __nanoc_checksum
|
83
|
+
Nanoc::Int::Checksummer.calc(self)
|
90
84
|
end
|
91
|
-
memoize :
|
85
|
+
memoize :__nanoc_checksum
|
92
86
|
|
93
87
|
def hash
|
94
88
|
self.class.hash ^ identifier.hash
|
@@ -115,10 +109,5 @@ module Nanoc
|
|
115
109
|
@attributes,
|
116
110
|
@identifier = *source
|
117
111
|
end
|
118
|
-
|
119
|
-
# @deprecated Access the modification time using `layout[:mtime]` instead.
|
120
|
-
def mtime
|
121
|
-
self[:mtime]
|
122
|
-
end
|
123
112
|
end
|
124
113
|
end
|
@@ -1,20 +1,22 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
|
-
module Nanoc
|
3
|
+
module Nanoc::Int
|
4
4
|
# The in-memory representation of a nanoc site. It holds references to the
|
5
5
|
# following site data:
|
6
6
|
#
|
7
|
-
# * {#items} — the list of items ({Nanoc::Item})
|
8
|
-
# * {#layouts} — the list of layouts ({Nanoc::Layout})
|
9
|
-
# * {#code_snippets} — the list of code snippets ({Nanoc::CodeSnippet})
|
7
|
+
# * {#items} — the list of items ({Nanoc::Int::Item})
|
8
|
+
# * {#layouts} — the list of layouts ({Nanoc::Int::Layout})
|
9
|
+
# * {#code_snippets} — the list of code snippets ({Nanoc::Int::CodeSnippet})
|
10
10
|
# * {#data_sources} — the list of data sources ({Nanoc::DataSource})
|
11
11
|
#
|
12
12
|
# In addition, each site has a {#config} hash which stores the site
|
13
13
|
# configuration.
|
14
14
|
#
|
15
|
-
# The physical representation of a {Nanoc::Site} is usually a directory
|
15
|
+
# The physical representation of a {Nanoc::Int::Site} is usually a directory
|
16
16
|
# that contains a configuration file, site data, a rakefile, a rules file,
|
17
17
|
# etc. The way site data is stored depends on the data source.
|
18
|
+
#
|
19
|
+
# @api private
|
18
20
|
class Site
|
19
21
|
# The default configuration for a data source. A data source's
|
20
22
|
# configuration overrides these options.
|
@@ -26,7 +28,7 @@ module Nanoc
|
|
26
28
|
}
|
27
29
|
|
28
30
|
# The default configuration for a site. A site's configuration overrides
|
29
|
-
# these options: when a {Nanoc::Site} is created with a configuration
|
31
|
+
# these options: when a {Nanoc::Int::Site} is created with a configuration
|
30
32
|
# that lacks some options, the default value will be taken from
|
31
33
|
# `DEFAULT_CONFIG`.
|
32
34
|
DEFAULT_CONFIG = {
|
@@ -61,9 +63,9 @@ module Nanoc
|
|
61
63
|
# Returns the compiler for this site. Will create a new compiler if none
|
62
64
|
# exists yet.
|
63
65
|
#
|
64
|
-
# @return [Nanoc::Compiler] The compiler for this site
|
66
|
+
# @return [Nanoc::Int::Compiler] The compiler for this site
|
65
67
|
def compiler
|
66
|
-
@compiler ||= Compiler.new(self)
|
68
|
+
@compiler ||= Nanoc::Int::Compiler.new(self)
|
67
69
|
end
|
68
70
|
|
69
71
|
# Returns the data sources for this site. Will create a new data source if
|
@@ -72,7 +74,7 @@ module Nanoc
|
|
72
74
|
# @return [Array<Nanoc::DataSource>] The list of data sources for this
|
73
75
|
# site
|
74
76
|
#
|
75
|
-
# @raise [Nanoc::Errors::UnknownDataSource] if the site configuration
|
77
|
+
# @raise [Nanoc::Int::Errors::UnknownDataSource] if the site configuration
|
76
78
|
# specifies an unknown data source
|
77
79
|
def data_sources
|
78
80
|
load_code_snippets
|
@@ -81,16 +83,7 @@ module Nanoc
|
|
81
83
|
@config[:data_sources].map do |data_source_hash|
|
82
84
|
# Get data source class
|
83
85
|
data_source_class = Nanoc::DataSource.named(data_source_hash[:type])
|
84
|
-
raise Nanoc::Errors::UnknownDataSource.new(data_source_hash[:type]) if data_source_class.nil?
|
85
|
-
|
86
|
-
# Warn about deprecated data sources
|
87
|
-
# TODO: [in nanoc 4.0] remove me
|
88
|
-
case data_source_hash[:type]
|
89
|
-
when 'filesystem'
|
90
|
-
warn "Warning: the 'filesystem' data source has been renamed to 'filesystem_verbose'. Using 'filesystem' will work in nanoc 3.1.x, but it will likely not work anymore in a future release of nanoc. Please update your data source configuration and replace 'filesystem' with 'filesystem_verbose'."
|
91
|
-
when 'filesystem_combined', 'filesystem_compact'
|
92
|
-
warn "Warning: the 'filesystem_combined' and 'filesystem_compact' data source has been merged into the new 'filesystem_unified' data source. Using 'filesystem_combined' and 'filesystem_compact' will work in nanoc 3.1.x, but it will likely not work anymore in a future release of nanoc. Please update your data source configuration and replace 'filesystem_combined' and 'filesystem_compact with 'filesystem_unified'."
|
93
|
-
end
|
86
|
+
raise Nanoc::Int::Errors::UnknownDataSource.new(data_source_hash[:type]) if data_source_class.nil?
|
94
87
|
|
95
88
|
# Create data source
|
96
89
|
data_source_class.new(
|
@@ -105,7 +98,7 @@ module Nanoc
|
|
105
98
|
|
106
99
|
# Returns this site’s code snippets.
|
107
100
|
#
|
108
|
-
# @return [Array<Nanoc::CodeSnippet>] The list of code snippets in this
|
101
|
+
# @return [Array<Nanoc::Int::CodeSnippet>] The list of code snippets in this
|
109
102
|
# site
|
110
103
|
def code_snippets
|
111
104
|
load
|
@@ -114,7 +107,7 @@ module Nanoc
|
|
114
107
|
|
115
108
|
# Returns this site’s items.
|
116
109
|
#
|
117
|
-
# @return [Array<Nanoc::Item>] The list of items in this site
|
110
|
+
# @return [Array<Nanoc::Int::Item>] The list of items in this site
|
118
111
|
def items
|
119
112
|
load
|
120
113
|
@items
|
@@ -122,7 +115,7 @@ module Nanoc
|
|
122
115
|
|
123
116
|
# Returns this site’s layouts.
|
124
117
|
#
|
125
|
-
# @return [Array<Nanoc::Layouts>] The list of layout in this site
|
118
|
+
# @return [Array<Nanoc::Int::Layouts>] The list of layout in this site
|
126
119
|
def layouts
|
127
120
|
load
|
128
121
|
@layouts
|
@@ -183,14 +176,14 @@ module Nanoc
|
|
183
176
|
|
184
177
|
item_map = {}
|
185
178
|
@items.each do |item|
|
186
|
-
item_map[item.identifier] = item
|
179
|
+
item_map[item.identifier.to_s] = item
|
187
180
|
end
|
188
181
|
|
189
182
|
@items.each do |item|
|
190
|
-
parent_id_end = item.identifier.rindex('/', -2)
|
183
|
+
parent_id_end = item.identifier.to_s.rindex('/', -2)
|
191
184
|
next unless parent_id_end
|
192
185
|
|
193
|
-
parent_id = item.identifier[0..parent_id_end]
|
186
|
+
parent_id = item.identifier.to_s[0..parent_id_end]
|
194
187
|
parent = item_map[parent_id]
|
195
188
|
next unless parent
|
196
189
|
|
@@ -215,18 +208,12 @@ module Nanoc
|
|
215
208
|
#
|
216
209
|
# @return [void]
|
217
210
|
def freeze
|
218
|
-
config.
|
211
|
+
config.__nanoc_freeze_recursively
|
219
212
|
items.each(&:freeze)
|
220
213
|
layouts.each(&:freeze)
|
221
214
|
code_snippets.each(&:freeze)
|
222
215
|
end
|
223
216
|
|
224
|
-
# @deprecated It is no longer necessary to explicitly load site data. It
|
225
|
-
# is safe to remove all {#load_data} calls.
|
226
|
-
def load_data(_force = false)
|
227
|
-
warn 'It is no longer necessary to call Nanoc::Site#load_data. This method no longer has any effect. All calls to this method can be safely removed.'
|
228
|
-
end
|
229
|
-
|
230
217
|
# Loads the site data. It is not necessary to call this method explicitly;
|
231
218
|
# it will be called when it is necessary.
|
232
219
|
#
|
@@ -317,7 +304,7 @@ module Nanoc
|
|
317
304
|
@code_snippets = []
|
318
305
|
config[:lib_dirs].each do |lib|
|
319
306
|
code_snippets = Dir["#{lib}/**/*.rb"].sort.map do |filename|
|
320
|
-
Nanoc::CodeSnippet.new(
|
307
|
+
Nanoc::Int::CodeSnippet.new(
|
321
308
|
File.read(filename),
|
322
309
|
filename
|
323
310
|
)
|
@@ -337,11 +324,11 @@ module Nanoc
|
|
337
324
|
@items_loaded = true
|
338
325
|
|
339
326
|
# Get items
|
340
|
-
@items = Nanoc::ItemArray.new
|
327
|
+
@items = Nanoc::Int::ItemArray.new
|
341
328
|
data_sources.each do |ds|
|
342
329
|
items_in_ds = ds.items
|
343
330
|
items_in_ds.each do |i|
|
344
|
-
i.identifier = File.join(ds.items_root, i.identifier)
|
331
|
+
i.identifier = Nanoc::Identifier.new(File.join(ds.items_root, i.identifier.to_s))
|
345
332
|
i.site = self
|
346
333
|
end
|
347
334
|
@items.concat(items_in_ds)
|
@@ -358,14 +345,16 @@ module Nanoc
|
|
358
345
|
@layouts = []
|
359
346
|
data_sources.each do |ds|
|
360
347
|
layouts_in_ds = ds.layouts
|
361
|
-
layouts_in_ds.each
|
348
|
+
layouts_in_ds.each do |l|
|
349
|
+
l.identifier = Nanoc::Identifier.new(File.join(ds.layouts_root, l.identifier.to_s))
|
350
|
+
end
|
362
351
|
@layouts.concat(layouts_in_ds)
|
363
352
|
end
|
364
353
|
end
|
365
354
|
|
366
355
|
# Loads a configuration file.
|
367
356
|
def load_config(config_path)
|
368
|
-
YAML.load_file(config_path).
|
357
|
+
YAML.load_file(config_path).__nanoc_symbolize_keys_recursively
|
369
358
|
end
|
370
359
|
|
371
360
|
def apply_parent_config(config, config_paths = [])
|
@@ -374,10 +363,10 @@ module Nanoc
|
|
374
363
|
config.delete(:parent_config_file)
|
375
364
|
config_path = File.absolute_path(parent_config_file, File.dirname(config_paths.last))
|
376
365
|
unless File.file?(config_path)
|
377
|
-
raise Nanoc::Errors::GenericTrivial, "Could not find parent configuration file '#{parent_config_file}'"
|
366
|
+
raise Nanoc::Int::Errors::GenericTrivial, "Could not find parent configuration file '#{parent_config_file}'"
|
378
367
|
end
|
379
368
|
if config_paths.include?(config_path)
|
380
|
-
raise Nanoc::Errors::GenericTrivial, "Cycle detected. Could not use parent configuration file '#{parent_config_file}'"
|
369
|
+
raise Nanoc::Int::Errors::GenericTrivial, "Cycle detected. Could not use parent configuration file '#{parent_config_file}'"
|
381
370
|
end
|
382
371
|
parent_config = load_config(config_path)
|
383
372
|
apply_parent_config(parent_config, config_paths + [config_path]).merge(config)
|
@@ -390,7 +379,7 @@ module Nanoc
|
|
390
379
|
seen = Set.new
|
391
380
|
objects.each do |obj|
|
392
381
|
if seen.include?(obj.identifier)
|
393
|
-
raise Nanoc::Errors::DuplicateIdentifier.new(obj.identifier, type)
|
382
|
+
raise Nanoc::Int::Errors::DuplicateIdentifier.new(obj.identifier, type)
|
394
383
|
end
|
395
384
|
seen << obj.identifier
|
396
385
|
end
|
@@ -402,14 +391,14 @@ module Nanoc
|
|
402
391
|
if dir_or_config_hash.is_a? String
|
403
392
|
# Check whether it is supported
|
404
393
|
if dir_or_config_hash != '.'
|
405
|
-
warn 'WARNING: Calling Nanoc::Site.new with a directory that is not the current working directory is not supported. It is recommended to change the directory before calling Nanoc::Site.new. For example, instead of Nanoc::Site.new(\'abc\'), use Dir.chdir(\'abc\') { Nanoc::Site.new(\'.\') }.'
|
394
|
+
warn 'WARNING: Calling Nanoc::Int::Site.new with a directory that is not the current working directory is not supported. It is recommended to change the directory before calling Nanoc::Int::Site.new. For example, instead of Nanoc::Int::Site.new(\'abc\'), use Dir.chdir(\'abc\') { Nanoc::Int::Site.new(\'.\') }.'
|
406
395
|
end
|
407
396
|
|
408
397
|
# Read config from nanoc.yaml/config.yaml in given dir
|
409
398
|
config_path = Dir.chdir(dir_or_config_hash) do
|
410
399
|
filename = self.class.config_filename_for_cwd
|
411
400
|
if filename.nil?
|
412
|
-
raise Nanoc::Errors::GenericTrivial, 'Could not find nanoc.yaml or config.yaml in the current working directory'
|
401
|
+
raise Nanoc::Int::Errors::GenericTrivial, 'Could not find nanoc.yaml or config.yaml in the current working directory'
|
413
402
|
end
|
414
403
|
File.absolute_path(filename, dir_or_config_hash)
|
415
404
|
end
|
@@ -417,7 +406,7 @@ module Nanoc
|
|
417
406
|
@config = apply_parent_config(load_config(config_path), [config_path])
|
418
407
|
else
|
419
408
|
# Use passed config hash
|
420
|
-
@config = apply_parent_config(dir_or_config_hash.
|
409
|
+
@config = apply_parent_config(dir_or_config_hash.__nanoc_symbolize_keys_recursively)
|
421
410
|
end
|
422
411
|
|
423
412
|
# Merge config with default config
|
@@ -427,7 +416,7 @@ module Nanoc
|
|
427
416
|
@config[:data_sources] = @config[:data_sources].map { |ds| DEFAULT_DATA_SOURCE_CONFIG.merge(ds) }
|
428
417
|
|
429
418
|
# Convert to proper configuration
|
430
|
-
@config = Nanoc::Configuration.new(@config)
|
419
|
+
@config = Nanoc::Int::Configuration.new(@config)
|
431
420
|
end
|
432
421
|
end
|
433
422
|
end
|