nanoc 4.0.0b3 → 4.0.0b4
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 +4 -2
- data/NEWS.md +10 -0
- data/TODO.md +15 -0
- data/lib/nanoc/base.rb +4 -27
- data/lib/nanoc/base/checksummer.rb +69 -19
- data/lib/nanoc/base/compilation/compiler.rb +14 -12
- data/lib/nanoc/base/compilation/compiler_dsl.rb +2 -0
- data/lib/nanoc/base/compilation/filter.rb +4 -2
- data/lib/nanoc/base/compilation/outdatedness_checker.rb +7 -7
- data/lib/nanoc/base/compilation/rule.rb +5 -6
- data/lib/nanoc/base/compilation/rule_context.rb +16 -34
- data/lib/nanoc/base/compilation/rule_memory_calculator.rb +3 -3
- data/lib/nanoc/base/compilation/rules_collection.rb +4 -10
- data/lib/nanoc/base/context.rb +2 -0
- data/lib/nanoc/base/core_ext/array.rb +0 -10
- data/lib/nanoc/base/core_ext/hash.rb +0 -10
- data/lib/nanoc/base/core_ext/pathname.rb +0 -9
- data/lib/nanoc/base/core_ext/string.rb +0 -10
- data/lib/nanoc/base/entities.rb +5 -0
- data/lib/nanoc/base/entities/content.rb +86 -0
- data/lib/nanoc/base/entities/document.rb +56 -0
- data/lib/nanoc/base/{source_data → entities}/identifier.rb +12 -1
- data/lib/nanoc/base/entities/layout.rb +8 -0
- data/lib/nanoc/base/{pattern.rb → entities/pattern.rb} +0 -0
- data/lib/nanoc/base/errors.rb +2 -1
- data/lib/nanoc/base/result_data/item_rep.rb +13 -278
- data/lib/nanoc/base/services.rb +5 -0
- data/lib/nanoc/base/services/executor.rb +141 -0
- data/lib/nanoc/base/services/item_rep_writer.rb +40 -0
- data/lib/nanoc/base/{notification_center.rb → services/notification_center.rb} +0 -0
- data/lib/nanoc/base/services/recording_executor.rb +41 -0
- data/lib/nanoc/base/{temp_filename_factory.rb → services/temp_filename_factory.rb} +0 -0
- data/lib/nanoc/base/source_data/code_snippet.rb +0 -6
- data/lib/nanoc/base/source_data/data_source.rb +4 -3
- data/lib/nanoc/base/source_data/item.rb +23 -213
- data/lib/nanoc/base/source_data/site.rb +0 -1
- data/lib/nanoc/base/views.rb +18 -0
- data/lib/nanoc/base/views/config.rb +1 -1
- data/lib/nanoc/base/views/item.rb +8 -73
- data/lib/nanoc/base/views/item_rep.rb +9 -0
- data/lib/nanoc/base/views/item_rep_collection.rb +17 -0
- data/lib/nanoc/base/views/layout.rb +1 -40
- data/lib/nanoc/base/views/mixins/document.rb +76 -0
- data/lib/nanoc/base/views/mixins/mutable_document.rb +22 -0
- data/lib/nanoc/base/views/mutable_identifiable_collection.rb +1 -1
- data/lib/nanoc/base/views/mutable_item.rb +1 -18
- data/lib/nanoc/base/views/mutable_item_collection.rb +6 -2
- data/lib/nanoc/base/views/mutable_layout.rb +1 -8
- data/lib/nanoc/cli/commands/compile.rb +1 -2
- data/lib/nanoc/cli/commands/create-site.rb +5 -5
- data/lib/nanoc/cli/commands/show-data.rb +11 -1
- data/lib/nanoc/data_sources/filesystem.rb +17 -10
- data/lib/nanoc/helpers/capturing.rb +1 -2
- data/lib/nanoc/helpers/filtering.rb +13 -1
- data/lib/nanoc/helpers/rendering.rb +4 -2
- data/lib/nanoc/version.rb +1 -1
- data/test/base/core_ext/array_spec.rb +0 -7
- data/test/base/core_ext/hash_spec.rb +0 -13
- data/test/base/core_ext/pathname_spec.rb +0 -33
- data/test/base/core_ext/string_spec.rb +0 -10
- data/test/base/test_compiler_dsl.rb +3 -3
- data/test/base/test_data_source.rb +2 -2
- data/test/base/test_item.rb +5 -129
- data/test/base/test_item_rep.rb +26 -558
- data/test/base/test_layout.rb +2 -26
- data/test/base/test_rule.rb +3 -3
- data/test/base/test_rule_context.rb +34 -15
- data/test/data_sources/test_filesystem.rb +2 -2
- data/test/data_sources/test_filesystem_unified.rb +39 -33
- data/test/extra/checking/checks/test_html.rb +0 -1
- data/test/extra/checking/checks/test_mixed_content.rb +3 -3
- data/test/extra/deployers/test_fog.rb +24 -24
- data/test/filters/test_less.rb +4 -4
- data/test/filters/test_sass.rb +10 -5
- data/test/filters/test_xsl.rb +6 -0
- data/test/helpers/test_capturing.rb +0 -1
- data/test/helpers/test_filtering.rb +5 -19
- data/test/helpers/test_tagging.rb +6 -6
- metadata +18 -11
- data/lib/nanoc/base/compilation/item_rep_proxy.rb +0 -109
- data/lib/nanoc/base/compilation/item_rep_recorder_proxy.rb +0 -97
- data/lib/nanoc/base/source_data/layout.rb +0 -111
- data/test/base/checksummer_spec.rb +0 -256
- data/test/base/test_item_rep_recorder_proxy.rb +0 -17
@@ -0,0 +1,18 @@
|
|
1
|
+
require_relative 'views/mixins/document'
|
2
|
+
require_relative 'views/mixins/mutable_document'
|
3
|
+
|
4
|
+
require_relative 'views/config'
|
5
|
+
require_relative 'views/identifiable_collection'
|
6
|
+
require_relative 'views/item'
|
7
|
+
require_relative 'views/item_collection'
|
8
|
+
require_relative 'views/item_rep'
|
9
|
+
require_relative 'views/item_rep_collection'
|
10
|
+
require_relative 'views/layout'
|
11
|
+
require_relative 'views/layout_collection'
|
12
|
+
require_relative 'views/mutable_config'
|
13
|
+
require_relative 'views/mutable_identifiable_collection'
|
14
|
+
require_relative 'views/mutable_item'
|
15
|
+
require_relative 'views/mutable_item_collection'
|
16
|
+
require_relative 'views/mutable_layout'
|
17
|
+
require_relative 'views/mutable_layout_collection'
|
18
|
+
require_relative 'views/site'
|
@@ -1,61 +1,6 @@
|
|
1
1
|
module Nanoc
|
2
2
|
class ItemView
|
3
|
-
|
4
|
-
NONE = Object.new
|
5
|
-
|
6
|
-
# @api private
|
7
|
-
def initialize(item)
|
8
|
-
@item = item
|
9
|
-
end
|
10
|
-
|
11
|
-
# @api private
|
12
|
-
def unwrap
|
13
|
-
@item
|
14
|
-
end
|
15
|
-
|
16
|
-
# @see Object#==
|
17
|
-
def ==(other)
|
18
|
-
identifier == other.identifier
|
19
|
-
end
|
20
|
-
alias_method :eql?, :==
|
21
|
-
|
22
|
-
# @see Object#hash
|
23
|
-
def hash
|
24
|
-
self.class.hash ^ identifier.hash
|
25
|
-
end
|
26
|
-
|
27
|
-
# @return [Nanoc::Identifier]
|
28
|
-
def identifier
|
29
|
-
@item.identifier
|
30
|
-
end
|
31
|
-
|
32
|
-
# @see Hash#fetch
|
33
|
-
def fetch(key, fallback=NONE, &block)
|
34
|
-
res = @item[key] # necessary for dependency tracking
|
35
|
-
|
36
|
-
if @item.attributes.key?(key)
|
37
|
-
res
|
38
|
-
else
|
39
|
-
if !fallback.equal?(NONE)
|
40
|
-
fallback
|
41
|
-
elsif block_given?
|
42
|
-
yield(key)
|
43
|
-
else
|
44
|
-
raise KeyError, "key not found: #{key.inspect}"
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
# @see Hash#key?
|
50
|
-
def key?(key)
|
51
|
-
_res = @item[key] # necessary for dependency tracking
|
52
|
-
@item.attributes.key?(key)
|
53
|
-
end
|
54
|
-
|
55
|
-
# @see Hash#[]
|
56
|
-
def [](key)
|
57
|
-
@item[key]
|
58
|
-
end
|
3
|
+
include Nanoc::DocumentViewMixin
|
59
4
|
|
60
5
|
# Returns the compiled content.
|
61
6
|
#
|
@@ -70,7 +15,7 @@ module Nanoc
|
|
70
15
|
#
|
71
16
|
# @return [String] The content of the given rep at the given snapshot.
|
72
17
|
def compiled_content(params = {})
|
73
|
-
|
18
|
+
reps.fetch(params.fetch(:rep, :default)).compiled_content(params)
|
74
19
|
end
|
75
20
|
|
76
21
|
# Returns the item path, as used when being linked to. It starts
|
@@ -87,7 +32,7 @@ module Nanoc
|
|
87
32
|
#
|
88
33
|
# @return [String] The item’s path.
|
89
34
|
def path(params = {})
|
90
|
-
|
35
|
+
reps.fetch(params.fetch(:rep, :default)).path(params)
|
91
36
|
end
|
92
37
|
|
93
38
|
# Returns the children of this item. For items with identifiers that have
|
@@ -95,7 +40,7 @@ module Nanoc
|
|
95
40
|
#
|
96
41
|
# @return [Enumerable<Nanoc::ItemView>]
|
97
42
|
def children
|
98
|
-
|
43
|
+
unwrap.children.map { |i| Nanoc::ItemView.new(i) }
|
99
44
|
end
|
100
45
|
|
101
46
|
# Returns the parent of this item, if one exists. For items with identifiers
|
@@ -105,34 +50,24 @@ module Nanoc
|
|
105
50
|
#
|
106
51
|
# @return [nil] if the item has no parent
|
107
52
|
def parent
|
108
|
-
|
53
|
+
unwrap.parent && Nanoc::ItemView.new(unwrap.parent)
|
109
54
|
end
|
110
55
|
|
111
56
|
# @return [Boolean] True if the item is binary, false otherwise
|
112
57
|
def binary?
|
113
|
-
|
114
|
-
end
|
115
|
-
|
116
|
-
# For textual items, returns the raw (source) content of this item; for
|
117
|
-
# binary items, returns `nil`.
|
118
|
-
#
|
119
|
-
# @return [String] if the item is textual
|
120
|
-
#
|
121
|
-
# @return [nil] if the item is binary
|
122
|
-
def raw_content
|
123
|
-
@item.raw_content
|
58
|
+
unwrap.content.binary?
|
124
59
|
end
|
125
60
|
|
126
61
|
# Returns the representations of this item.
|
127
62
|
#
|
128
63
|
# @return [Nanoc::ItemRepCollectionView]
|
129
64
|
def reps
|
130
|
-
Nanoc::ItemRepCollectionView.new(
|
65
|
+
Nanoc::ItemRepCollectionView.new(unwrap.reps)
|
131
66
|
end
|
132
67
|
|
133
68
|
# @api private
|
134
69
|
def raw_filename
|
135
|
-
|
70
|
+
unwrap.content.filename
|
136
71
|
end
|
137
72
|
end
|
138
73
|
end
|
@@ -35,6 +35,9 @@ module Nanoc
|
|
35
35
|
#
|
36
36
|
# @return [String] The content at the given snapshot.
|
37
37
|
def compiled_content(params = {})
|
38
|
+
Nanoc::Int::NotificationCenter.post(:visit_started, unwrap.item)
|
39
|
+
Nanoc::Int::NotificationCenter.post(:visit_ended, unwrap.item)
|
40
|
+
|
38
41
|
@item_rep.compiled_content(params)
|
39
42
|
end
|
40
43
|
|
@@ -48,6 +51,9 @@ module Nanoc
|
|
48
51
|
#
|
49
52
|
# @return [String] The item rep’s path.
|
50
53
|
def path(params = {})
|
54
|
+
Nanoc::Int::NotificationCenter.post(:visit_started, unwrap.item)
|
55
|
+
Nanoc::Int::NotificationCenter.post(:visit_ended, unwrap.item)
|
56
|
+
|
51
57
|
@item_rep.path(params)
|
52
58
|
end
|
53
59
|
|
@@ -60,6 +66,9 @@ module Nanoc
|
|
60
66
|
|
61
67
|
# @api private
|
62
68
|
def raw_path(params = {})
|
69
|
+
Nanoc::Int::NotificationCenter.post(:visit_started, unwrap.item)
|
70
|
+
Nanoc::Int::NotificationCenter.post(:visit_ended, unwrap.item)
|
71
|
+
|
63
72
|
@item_rep.raw_path(params)
|
64
73
|
end
|
65
74
|
|
@@ -44,5 +44,22 @@ module Nanoc
|
|
44
44
|
res = @item_reps.find { |ir| ir.name == rep_name }
|
45
45
|
res && Nanoc::ItemRepView.new(res)
|
46
46
|
end
|
47
|
+
|
48
|
+
# Return the item rep with the given name, or raises an exception if there
|
49
|
+
# is no rep with the given name.
|
50
|
+
#
|
51
|
+
# @param [Symbol] rep_name
|
52
|
+
#
|
53
|
+
# @return [Nanoc::ItemRepView]
|
54
|
+
#
|
55
|
+
# @raise if no rep was found
|
56
|
+
def fetch(rep_name)
|
57
|
+
res = @item_reps.find { |ir| ir.name == rep_name }
|
58
|
+
if res
|
59
|
+
Nanoc::ItemRepView.new(res)
|
60
|
+
else
|
61
|
+
raise Nanoc::Int::Errors::Generic, "No rep named #{rep_name.inspect} was found."
|
62
|
+
end
|
63
|
+
end
|
47
64
|
end
|
48
65
|
end
|
@@ -1,44 +1,5 @@
|
|
1
1
|
module Nanoc
|
2
2
|
class LayoutView
|
3
|
-
|
4
|
-
def initialize(layout)
|
5
|
-
@layout = layout
|
6
|
-
end
|
7
|
-
|
8
|
-
# @api private
|
9
|
-
def unwrap
|
10
|
-
@layout
|
11
|
-
end
|
12
|
-
|
13
|
-
# @see Object#==
|
14
|
-
def ==(other)
|
15
|
-
identifier == other.identifier
|
16
|
-
end
|
17
|
-
alias_method :eql?, :==
|
18
|
-
|
19
|
-
# @see Object#hash
|
20
|
-
def hash
|
21
|
-
self.class.hash ^ identifier.hash
|
22
|
-
end
|
23
|
-
|
24
|
-
# @return [Nanoc::Identifier]
|
25
|
-
def identifier
|
26
|
-
@layout.identifier
|
27
|
-
end
|
28
|
-
|
29
|
-
# @see Hash#[]
|
30
|
-
def [](key)
|
31
|
-
@layout[key]
|
32
|
-
end
|
33
|
-
|
34
|
-
# @api private
|
35
|
-
def reference
|
36
|
-
@layout.reference
|
37
|
-
end
|
38
|
-
|
39
|
-
# @api private
|
40
|
-
def raw_content
|
41
|
-
@layout.raw_content
|
42
|
-
end
|
3
|
+
include Nanoc::DocumentViewMixin
|
43
4
|
end
|
44
5
|
end
|
@@ -0,0 +1,76 @@
|
|
1
|
+
module Nanoc
|
2
|
+
module DocumentViewMixin
|
3
|
+
# @api private
|
4
|
+
NONE = Object.new
|
5
|
+
|
6
|
+
# @api private
|
7
|
+
def initialize(document)
|
8
|
+
@document = document
|
9
|
+
end
|
10
|
+
|
11
|
+
# @api private
|
12
|
+
def unwrap
|
13
|
+
@document
|
14
|
+
end
|
15
|
+
|
16
|
+
# @see Object#==
|
17
|
+
def ==(other)
|
18
|
+
identifier == other.identifier
|
19
|
+
end
|
20
|
+
alias_method :eql?, :==
|
21
|
+
|
22
|
+
# @see Object#hash
|
23
|
+
def hash
|
24
|
+
self.class.hash ^ identifier.hash
|
25
|
+
end
|
26
|
+
|
27
|
+
# @return [Nanoc::Identifier]
|
28
|
+
def identifier
|
29
|
+
unwrap.identifier
|
30
|
+
end
|
31
|
+
|
32
|
+
# @see Hash#[]
|
33
|
+
def [](key)
|
34
|
+
Nanoc::Int::NotificationCenter.post(:visit_started, unwrap)
|
35
|
+
Nanoc::Int::NotificationCenter.post(:visit_ended, unwrap)
|
36
|
+
|
37
|
+
unwrap.attributes[key]
|
38
|
+
end
|
39
|
+
|
40
|
+
# @see Hash#fetch
|
41
|
+
def fetch(key, fallback = NONE, &_block)
|
42
|
+
Nanoc::Int::NotificationCenter.post(:visit_started, unwrap)
|
43
|
+
Nanoc::Int::NotificationCenter.post(:visit_ended, unwrap)
|
44
|
+
|
45
|
+
if unwrap.attributes.key?(key)
|
46
|
+
unwrap.attributes[key]
|
47
|
+
else
|
48
|
+
if !fallback.equal?(NONE)
|
49
|
+
fallback
|
50
|
+
elsif block_given?
|
51
|
+
yield(key)
|
52
|
+
else
|
53
|
+
raise KeyError, "key not found: #{key.inspect}"
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
# @see Hash#key?
|
59
|
+
def key?(key)
|
60
|
+
Nanoc::Int::NotificationCenter.post(:visit_started, unwrap)
|
61
|
+
Nanoc::Int::NotificationCenter.post(:visit_ended, unwrap)
|
62
|
+
|
63
|
+
unwrap.attributes.key?(key)
|
64
|
+
end
|
65
|
+
|
66
|
+
# @api private
|
67
|
+
def reference
|
68
|
+
unwrap.reference
|
69
|
+
end
|
70
|
+
|
71
|
+
# @api private
|
72
|
+
def raw_content
|
73
|
+
unwrap.content.string
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module Nanoc
|
2
|
+
module MutableDocumentViewMixin
|
3
|
+
# Sets the value for the given attribute.
|
4
|
+
#
|
5
|
+
# @param [Symbol] key
|
6
|
+
#
|
7
|
+
# @see Hash#[]=
|
8
|
+
def []=(key, value)
|
9
|
+
unwrap.attributes[key] = value
|
10
|
+
end
|
11
|
+
|
12
|
+
# Updates the attributes based on the given hash.
|
13
|
+
#
|
14
|
+
# @param [Hash] hash
|
15
|
+
#
|
16
|
+
# @return [self]
|
17
|
+
def update_attributes(hash)
|
18
|
+
hash.each { |k, v| unwrap.attributes[k] = v }
|
19
|
+
self
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -1,22 +1,5 @@
|
|
1
1
|
module Nanoc
|
2
2
|
class MutableItemView < Nanoc::ItemView
|
3
|
-
|
4
|
-
#
|
5
|
-
# @param [Symbol] key
|
6
|
-
#
|
7
|
-
# @see Hash#[]=
|
8
|
-
def []=(key, value)
|
9
|
-
unwrap[key] = value
|
10
|
-
end
|
11
|
-
|
12
|
-
# Updates the attributes based on the given hash.
|
13
|
-
#
|
14
|
-
# @param [Hash] hash
|
15
|
-
#
|
16
|
-
# @return [self]
|
17
|
-
def update_attributes(hash)
|
18
|
-
hash.each { |k, v| unwrap[k] = v }
|
19
|
-
self
|
20
|
-
end
|
3
|
+
include Nanoc::MutableDocumentViewMixin
|
21
4
|
end
|
22
5
|
end
|
@@ -17,12 +17,16 @@ module Nanoc
|
|
17
17
|
#
|
18
18
|
# @param [Hash] params Extra parameters.
|
19
19
|
#
|
20
|
-
# @option params [
|
20
|
+
# @option params [Boolean] :binary (false) Whether or not this item is
|
21
21
|
# binary
|
22
22
|
#
|
23
|
+
# @option params [String] :filename (nil) Absolute path to the file
|
24
|
+
# containing this content (if any)
|
25
|
+
#
|
23
26
|
# @return [self]
|
24
27
|
def create(content, attributes, identifier, params = {})
|
25
|
-
|
28
|
+
content = Nanoc::Int::Content.create(content, params)
|
29
|
+
@objects << Nanoc::Int::Item.new(content, attributes, identifier)
|
26
30
|
self
|
27
31
|
end
|
28
32
|
end
|
@@ -1,12 +1,5 @@
|
|
1
1
|
module Nanoc
|
2
2
|
class MutableLayoutView < Nanoc::LayoutView
|
3
|
-
|
4
|
-
#
|
5
|
-
# @param [Symbol] key
|
6
|
-
#
|
7
|
-
# @see Hash#[]=
|
8
|
-
def []=(key, value)
|
9
|
-
unwrap[key] = value
|
10
|
-
end
|
3
|
+
include Nanoc::MutableDocumentViewMixin
|
11
4
|
end
|
12
5
|
end
|
@@ -65,8 +65,7 @@ module Nanoc::CLI::Commands
|
|
65
65
|
require 'tempfile'
|
66
66
|
setup_diffs
|
67
67
|
old_contents = {}
|
68
|
-
Nanoc::Int::NotificationCenter.on(:will_write_rep) do |rep,
|
69
|
-
path = rep.raw_path(snapshot: snapshot)
|
68
|
+
Nanoc::Int::NotificationCenter.on(:will_write_rep) do |rep, path|
|
70
69
|
old_contents[rep] = File.file?(path) ? File.read(path) : nil
|
71
70
|
end
|
72
71
|
Nanoc::Int::NotificationCenter.on(:rep_written) do |rep, path, _is_created, _is_modified|
|