nanoc-core 4.11.4 → 4.11.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7ae42507c2bd9926280d8ad198a38578676110ddb6864b7f23d9d743a6c4e6ec
4
- data.tar.gz: 76a1b941f030ee96ad01133b23e78cb1b74861e2ddd5f89147caf58fbccc8bc4
3
+ metadata.gz: 92b6e637e84298375cd003e335ee6bf5226551e27cbe5113ab5d78696f57f68c
4
+ data.tar.gz: 70ebd03b63bbbb75f3f40c3147c8db7d1805bbaa4242f96cc25e38184873494f
5
5
  SHA512:
6
- metadata.gz: b3ddf024cd0850616dd067a9c120519d1eea6e24efd236e78ce0fb9de30065f34117c52b429ff0e4045a1872ab34f15891c618a67ce084d6313c9e19febfac25
7
- data.tar.gz: ed2c07319632a3f4f4222f95fa280c1bd5f460d9b4a3561a62c35c1eba1291cae8c19a5028db18cbdea8b269d6f600fa8ed73222c6366bc84b72c4050a5f7744
6
+ metadata.gz: 7c7c2f35bbd945c28e6d0a42e5f69a10545c892728230bd51d501ece35ba2b9016bd1ed4fbb401f9003703231f04064060c04933aae058cdf2c4c39a53779a46
7
+ data.tar.gz: 07d70bd63c2d69ee64a214df9b7b8ecd57220232d53dfb89ad4c9e9ae34544cd373d66fce8f6ff7f27c31d6d59de2c99f5a228fb7ed9e5c651f30e4662ef0658
@@ -19,7 +19,7 @@ module Nanoc
19
19
  }.freeze
20
20
 
21
21
  # The default configuration for a site. A site's configuration overrides
22
- # these options: when a {Nanoc::Int::Site} is created with a configuration
22
+ # these options: when a {Nanoc::Core::Site} is created with a configuration
23
23
  # that lacks some options, the default value will be taken from
24
24
  # `DEFAULT_CONFIG`.
25
25
  DEFAULT_CONFIG = {
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Nanoc
4
+ module Core
5
+ # @api private
6
+ # A dependency between two items/layouts.
7
+ class Dependency
8
+ include Nanoc::Core::ContractsSupport
9
+
10
+ C_OBJ_FROM = C::Or[Nanoc::Core::Item, Nanoc::Core::Layout, Nanoc::Core::Configuration, Nanoc::Core::IdentifiableCollection]
11
+ C_OBJ_TO = Nanoc::Core::Item
12
+
13
+ contract C::None => C::Maybe[C_OBJ_FROM]
14
+ attr_reader :from
15
+
16
+ contract C::None => C::Maybe[C_OBJ_TO]
17
+ attr_reader :to
18
+
19
+ contract C::None => Nanoc::Core::DependencyProps
20
+ attr_reader :props
21
+
22
+ contract C::Maybe[C_OBJ_FROM], C::Maybe[C_OBJ_TO], Nanoc::Core::DependencyProps => C::Any
23
+ def initialize(from, to, props)
24
+ @from = from
25
+ @to = to
26
+ @props = props
27
+ end
28
+
29
+ contract C::None => String
30
+ def inspect
31
+ "Dependency(#{@from.inspect} -> #{@to.inspect}, #{@props.inspect})"
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,150 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Nanoc
4
+ module Core
5
+ # @api private
6
+ class DependencyProps
7
+ include Nanoc::Core::ContractsSupport
8
+
9
+ attr_reader :attributes
10
+ attr_reader :raw_content
11
+
12
+ # TODO: Split raw_content for documents and collections
13
+ C_RAW_CONTENT = C::Or[C::IterOf[C::Or[String, Regexp]], C::Bool]
14
+ C_ATTRS = C::Or[C::IterOf[Symbol], C::Bool]
15
+ contract C::KeywordArgs[raw_content: C::Optional[C_RAW_CONTENT], attributes: C::Optional[C_ATTRS], compiled_content: C::Optional[C::Bool], path: C::Optional[C::Bool]] => C::Any
16
+ def initialize(raw_content: false, attributes: false, compiled_content: false, path: false)
17
+ @compiled_content = compiled_content
18
+ @path = path
19
+
20
+ @attributes =
21
+ case attributes
22
+ when Set
23
+ attributes
24
+ when Enumerable
25
+ Set.new(attributes)
26
+ else
27
+ attributes
28
+ end
29
+
30
+ @raw_content =
31
+ case raw_content
32
+ when Set
33
+ raw_content
34
+ when Enumerable
35
+ Set.new(raw_content)
36
+ else
37
+ raw_content
38
+ end
39
+ end
40
+
41
+ contract C::None => String
42
+ def inspect
43
+ (+'').tap do |s|
44
+ s << 'Props('
45
+ s << (raw_content? ? 'r' : '_')
46
+ s << (attributes? ? 'a' : '_')
47
+ s << (compiled_content? ? 'c' : '_')
48
+ s << (path? ? 'p' : '_')
49
+ s << ')'
50
+ end
51
+ end
52
+
53
+ contract C::None => String
54
+ def to_s
55
+ (+'').tap do |s|
56
+ s << (raw_content? ? 'r' : '_')
57
+ s << (attributes? ? 'a' : '_')
58
+ s << (compiled_content? ? 'c' : '_')
59
+ s << (path? ? 'p' : '_')
60
+ end
61
+ end
62
+
63
+ contract C::None => C::Bool
64
+ def raw_content?
65
+ case @raw_content
66
+ when Enumerable
67
+ @raw_content.any?
68
+ else
69
+ @raw_content
70
+ end
71
+ end
72
+
73
+ contract C::None => C::Bool
74
+ def attributes?
75
+ case @attributes
76
+ when Enumerable
77
+ @attributes.any?
78
+ else
79
+ @attributes
80
+ end
81
+ end
82
+
83
+ contract C::None => C::Bool
84
+ def compiled_content?
85
+ @compiled_content
86
+ end
87
+
88
+ contract C::None => C::Bool
89
+ def path?
90
+ @path
91
+ end
92
+
93
+ contract Nanoc::Core::DependencyProps => Nanoc::Core::DependencyProps
94
+ def merge(other)
95
+ DependencyProps.new(
96
+ raw_content: merge_raw_content(other),
97
+ attributes: merge_attributes(other),
98
+ compiled_content: compiled_content? || other.compiled_content?,
99
+ path: path? || other.path?,
100
+ )
101
+ end
102
+
103
+ def merge_raw_content(other)
104
+ merge_prop(raw_content, other.raw_content)
105
+ end
106
+
107
+ def merge_attributes(other)
108
+ merge_prop(attributes, other.attributes)
109
+ end
110
+
111
+ def merge_prop(own, other)
112
+ case own
113
+ when true
114
+ true
115
+ when false
116
+ other
117
+ else
118
+ case other
119
+ when true
120
+ true
121
+ when false
122
+ own
123
+ else
124
+ own + other
125
+ end
126
+ end
127
+ end
128
+
129
+ contract C::None => Set
130
+ def active
131
+ Set.new.tap do |pr|
132
+ pr << :raw_content if raw_content?
133
+ pr << :attributes if attributes?
134
+ pr << :compiled_content if compiled_content?
135
+ pr << :path if path?
136
+ end
137
+ end
138
+
139
+ contract C::None => Hash
140
+ def to_h
141
+ {
142
+ raw_content: raw_content,
143
+ attributes: attributes,
144
+ compiled_content: compiled_content?,
145
+ path: path?,
146
+ }
147
+ end
148
+ end
149
+ end
150
+ end
@@ -2,7 +2,7 @@
2
2
 
3
3
  module Nanoc
4
4
  module Core
5
- class InMemDataSource < Nanoc::Core::DataSource
5
+ class InMemoryDataSource < Nanoc::Core::DataSource
6
6
  attr_reader :items
7
7
  attr_reader :layouts
8
8
 
@@ -0,0 +1,71 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Nanoc
4
+ module Core
5
+ # @api private
6
+ class Site
7
+ # Error that is raised when multiple items or layouts with the same identifier exist.
8
+ class DuplicateIdentifierError < ::Nanoc::Core::Error
9
+ def initialize(identifier, type)
10
+ super("There are multiple #{type}s with the #{identifier} identifier.")
11
+ end
12
+ end
13
+
14
+ include Nanoc::Core::ContractsSupport
15
+
16
+ attr_reader :code_snippets
17
+ attr_reader :config
18
+ attr_accessor :data_source
19
+
20
+ contract C::KeywordArgs[config: Nanoc::Core::Configuration, code_snippets: C::IterOf[Nanoc::Core::CodeSnippet], data_source: C::Named['Nanoc::Core::DataSource']] => C::Any
21
+ def initialize(config:, code_snippets:, data_source:)
22
+ @config = config
23
+ @code_snippets = code_snippets
24
+ @data_source = data_source
25
+
26
+ @preprocessed = false
27
+
28
+ ensure_identifier_uniqueness(@data_source.items, 'item')
29
+ ensure_identifier_uniqueness(@data_source.layouts, 'layout')
30
+ end
31
+
32
+ def mark_as_preprocessed
33
+ @preprocessed = true
34
+ end
35
+
36
+ def preprocessed?
37
+ @preprocessed
38
+ end
39
+
40
+ def items
41
+ @data_source.items
42
+ end
43
+
44
+ def layouts
45
+ @data_source.layouts
46
+ end
47
+
48
+ contract C::None => self
49
+ def freeze
50
+ config.freeze
51
+ items.freeze
52
+ layouts.freeze
53
+ code_snippets.__nanoc_freeze_recursively
54
+ self
55
+ end
56
+
57
+ contract C::IterOf[C::Or[Nanoc::Core::Item, Nanoc::Core::Layout]], String => self
58
+ def ensure_identifier_uniqueness(objects, type)
59
+ seen = Set.new
60
+ objects.each do |obj|
61
+ if seen.include?(obj.identifier)
62
+ raise DuplicateIdentifierError.new(obj.identifier, type)
63
+ end
64
+
65
+ seen << obj.identifier
66
+ end
67
+ self
68
+ end
69
+ end
70
+ end
71
+ end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Nanoc
4
4
  module Core
5
- VERSION = '4.11.4'
5
+ VERSION = '4.11.5'
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nanoc-core
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.11.4
4
+ version: 4.11.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Denis Defreyne
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-04-28 00:00:00.000000000 Z
11
+ date: 2019-04-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ddmemoize
@@ -135,12 +135,14 @@ files:
135
135
  - lib/nanoc/core/core_ext/hash.rb
136
136
  - lib/nanoc/core/core_ext/string.rb
137
137
  - lib/nanoc/core/data_source.rb
138
+ - lib/nanoc/core/dependency.rb
139
+ - lib/nanoc/core/dependency_props.rb
138
140
  - lib/nanoc/core/directed_graph.rb
139
141
  - lib/nanoc/core/document.rb
140
142
  - lib/nanoc/core/error.rb
141
143
  - lib/nanoc/core/identifiable_collection.rb
142
144
  - lib/nanoc/core/identifier.rb
143
- - lib/nanoc/core/in_mem_data_source.rb
145
+ - lib/nanoc/core/in_memory_data_source.rb
144
146
  - lib/nanoc/core/instrumentor.rb
145
147
  - lib/nanoc/core/item.rb
146
148
  - lib/nanoc/core/item_collection.rb
@@ -156,6 +158,7 @@ files:
156
158
  - lib/nanoc/core/processing_actions/layout.rb
157
159
  - lib/nanoc/core/processing_actions/snapshot.rb
158
160
  - lib/nanoc/core/regexp_pattern.rb
161
+ - lib/nanoc/core/site.rb
159
162
  - lib/nanoc/core/snapshot_def.rb
160
163
  - lib/nanoc/core/string_pattern.rb
161
164
  - lib/nanoc/core/temp_filename_factory.rb