nanoc 4.11.0 → 4.11.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (154) hide show
  1. checksums.yaml +4 -4
  2. data/NEWS.md +6 -0
  3. data/lib/nanoc.rb +4 -7
  4. data/lib/nanoc/base.rb +3 -3
  5. data/lib/nanoc/base/assertions.rb +1 -1
  6. data/lib/nanoc/base/entities.rb +2 -20
  7. data/lib/nanoc/base/entities/action_sequence.rb +60 -64
  8. data/lib/nanoc/base/entities/checksum_collection.rb +23 -21
  9. data/lib/nanoc/base/entities/dependency.rb +24 -22
  10. data/lib/nanoc/base/entities/outdatedness_reasons.rb +74 -72
  11. data/lib/nanoc/base/entities/outdatedness_status.rb +19 -17
  12. data/lib/nanoc/base/entities/props.rb +119 -117
  13. data/lib/nanoc/base/entities/site.rb +46 -50
  14. data/lib/nanoc/base/errors.rb +183 -198
  15. data/lib/nanoc/base/repos.rb +4 -2
  16. data/lib/nanoc/base/repos/action_sequence_store.rb +44 -42
  17. data/lib/nanoc/base/repos/aggregate_data_source.rb +24 -22
  18. data/lib/nanoc/base/repos/checksum_store.rb +51 -49
  19. data/lib/nanoc/base/repos/compiled_content_cache.rb +47 -45
  20. data/lib/nanoc/base/repos/compiled_content_store.rb +76 -0
  21. data/lib/nanoc/base/repos/config_loader.rb +74 -72
  22. data/lib/nanoc/base/repos/dependency_store.rb +174 -172
  23. data/lib/nanoc/base/repos/in_mem_data_source.rb +17 -15
  24. data/lib/nanoc/base/repos/item_rep_repo.rb +26 -24
  25. data/lib/nanoc/base/repos/outdatedness_store.rb +50 -48
  26. data/lib/nanoc/base/repos/prefixed_data_source.rb +21 -19
  27. data/lib/nanoc/base/repos/site_loader.rb +75 -73
  28. data/lib/nanoc/base/repos/store.rb +93 -91
  29. data/lib/nanoc/base/services.rb +7 -3
  30. data/lib/nanoc/base/services/action_provider.rb +23 -21
  31. data/lib/nanoc/base/services/action_sequence_builder.rb +42 -34
  32. data/lib/nanoc/base/services/compilation_context.rb +49 -47
  33. data/lib/nanoc/base/services/compiler.rb +177 -170
  34. data/lib/nanoc/base/services/compiler/phases.rb +8 -1
  35. data/lib/nanoc/base/services/compiler/phases/abstract.rb +44 -38
  36. data/lib/nanoc/base/services/compiler/phases/cache.rb +34 -28
  37. data/lib/nanoc/base/services/compiler/phases/mark_done.rb +17 -11
  38. data/lib/nanoc/base/services/compiler/phases/notify.rb +21 -0
  39. data/lib/nanoc/base/services/compiler/phases/recalculate.rb +37 -31
  40. data/lib/nanoc/base/services/compiler/phases/resume.rb +47 -48
  41. data/lib/nanoc/base/services/compiler/phases/write.rb +65 -59
  42. data/lib/nanoc/base/services/compiler/stage.rb +27 -8
  43. data/lib/nanoc/base/services/compiler/stages.rb +7 -1
  44. data/lib/nanoc/base/services/compiler/stages/build_reps.rb +25 -19
  45. data/lib/nanoc/base/services/compiler/stages/calculate_checksums.rb +34 -28
  46. data/lib/nanoc/base/services/compiler/stages/cleanup.rb +33 -27
  47. data/lib/nanoc/base/services/compiler/stages/compile_reps.rb +79 -69
  48. data/lib/nanoc/base/services/compiler/stages/determine_outdatedness.rb +46 -40
  49. data/lib/nanoc/base/services/compiler/stages/forget_outdated_dependencies.rb +15 -9
  50. data/lib/nanoc/base/services/compiler/stages/load_stores.rb +28 -22
  51. data/lib/nanoc/base/services/compiler/stages/postprocess.rb +16 -10
  52. data/lib/nanoc/base/services/compiler/stages/preprocess.rb +25 -19
  53. data/lib/nanoc/base/services/compiler/stages/prune.rb +23 -17
  54. data/lib/nanoc/base/services/compiler/stages/store_post_compilation_state.rb +15 -9
  55. data/lib/nanoc/base/services/compiler/stages/store_pre_compilation_state.rb +26 -20
  56. data/lib/nanoc/base/services/compiler_loader.rb +26 -24
  57. data/lib/nanoc/base/services/dependency_tracker.rb +47 -45
  58. data/lib/nanoc/base/services/executor.rb +16 -15
  59. data/lib/nanoc/base/services/filter.rb +37 -5
  60. data/lib/nanoc/base/services/instrumentor.rb +12 -10
  61. data/lib/nanoc/base/services/item_rep_builder.rb +21 -19
  62. data/lib/nanoc/base/services/item_rep_router.rb +72 -70
  63. data/lib/nanoc/base/services/item_rep_selector.rb +48 -46
  64. data/lib/nanoc/base/services/item_rep_writer.rb +58 -53
  65. data/lib/nanoc/base/services/outdatedness_checker.rb +181 -179
  66. data/lib/nanoc/base/services/outdatedness_rule.rb +23 -21
  67. data/lib/nanoc/base/services/outdatedness_rules.rb +5 -3
  68. data/lib/nanoc/base/services/outdatedness_rules/attributes_modified.rb +28 -24
  69. data/lib/nanoc/base/services/outdatedness_rules/code_snippets_modified.rb +20 -16
  70. data/lib/nanoc/base/services/outdatedness_rules/content_modified.rb +13 -9
  71. data/lib/nanoc/base/services/outdatedness_rules/item_collection_extended.rb +12 -8
  72. data/lib/nanoc/base/services/outdatedness_rules/layout_collection_extended.rb +12 -8
  73. data/lib/nanoc/base/services/outdatedness_rules/not_written.rb +10 -6
  74. data/lib/nanoc/base/services/outdatedness_rules/rules_modified.rb +39 -35
  75. data/lib/nanoc/base/services/outdatedness_rules/uses_always_outdated_filter.rb +19 -15
  76. data/lib/nanoc/base/services/pruner.rb +2 -2
  77. data/lib/nanoc/base/views.rb +7 -0
  78. data/lib/nanoc/base/views/basic_item_view.rb +1 -1
  79. data/lib/nanoc/base/views/compilation_item_rep_view.rb +2 -2
  80. data/lib/nanoc/base/views/identifiable_collection_view.rb +2 -2
  81. data/lib/nanoc/base/views/mixins/document_view_mixin.rb +1 -1
  82. data/lib/nanoc/base/views/mixins/mutable_document_view_mixin.rb +5 -5
  83. data/lib/nanoc/base/views/mutable_item_collection_view.rb +3 -3
  84. data/lib/nanoc/base/views/mutable_layout_collection_view.rb +2 -2
  85. data/lib/nanoc/base/views/view_context_for_compilation.rb +6 -6
  86. data/lib/nanoc/base/views/view_context_for_pre_compilation.rb +2 -2
  87. data/lib/nanoc/base/views/view_context_for_shell.rb +2 -2
  88. data/lib/nanoc/checking/check.rb +1 -1
  89. data/lib/nanoc/cli/commands/compile_listeners/abstract.rb +24 -7
  90. data/lib/nanoc/cli/commands/compile_listeners/debug_printer.rb +79 -15
  91. data/lib/nanoc/cli/commands/compile_listeners/diff_generator.rb +4 -7
  92. data/lib/nanoc/cli/commands/compile_listeners/file_action_printer.rb +15 -24
  93. data/lib/nanoc/cli/commands/compile_listeners/timing_recorder.rb +22 -18
  94. data/lib/nanoc/cli/commands/create-site.rb +2 -7
  95. data/lib/nanoc/cli/commands/shell.rb +1 -1
  96. data/lib/nanoc/cli/commands/show-data.rb +9 -9
  97. data/lib/nanoc/cli/logger.rb +1 -1
  98. data/lib/nanoc/data_sources/filesystem.rb +8 -8
  99. data/lib/nanoc/filters/erb.rb +1 -1
  100. data/lib/nanoc/filters/erubi.rb +1 -1
  101. data/lib/nanoc/filters/erubis.rb +1 -1
  102. data/lib/nanoc/filters/haml.rb +1 -1
  103. data/lib/nanoc/filters/sass.rb +1 -1
  104. data/lib/nanoc/filters/slim.rb +1 -1
  105. data/lib/nanoc/helpers/breadcrumbs.rb +2 -2
  106. data/lib/nanoc/helpers/capturing.rb +9 -8
  107. data/lib/nanoc/helpers/filtering.rb +2 -2
  108. data/lib/nanoc/helpers/rendering.rb +1 -1
  109. data/lib/nanoc/rule_dsl.rb +10 -0
  110. data/lib/nanoc/rule_dsl/action_provider.rb +3 -3
  111. data/lib/nanoc/rule_dsl/action_recorder.rb +3 -3
  112. data/lib/nanoc/rule_dsl/action_sequence_calculator.rb +7 -7
  113. data/lib/nanoc/rule_dsl/compilation_rule.rb +2 -2
  114. data/lib/nanoc/rule_dsl/compilation_rule_context.rb +9 -9
  115. data/lib/nanoc/rule_dsl/compiler_dsl.rb +4 -4
  116. data/lib/nanoc/rule_dsl/routing_rule.rb +3 -3
  117. data/lib/nanoc/rule_dsl/rule.rb +5 -5
  118. data/lib/nanoc/rule_dsl/rule_context.rb +3 -3
  119. data/lib/nanoc/rule_dsl/rules_collection.rb +4 -4
  120. data/lib/nanoc/spec.rb +15 -15
  121. data/lib/nanoc/version.rb +1 -1
  122. metadata +10 -111
  123. data/lib/nanoc/base/contracts_support.rb +0 -130
  124. data/lib/nanoc/base/core_ext.rb +0 -5
  125. data/lib/nanoc/base/core_ext/array.rb +0 -50
  126. data/lib/nanoc/base/core_ext/hash.rb +0 -54
  127. data/lib/nanoc/base/core_ext/string.rb +0 -16
  128. data/lib/nanoc/base/entities/code_snippet.rb +0 -53
  129. data/lib/nanoc/base/entities/configuration-schema.json +0 -122
  130. data/lib/nanoc/base/entities/configuration.rb +0 -206
  131. data/lib/nanoc/base/entities/content.rb +0 -112
  132. data/lib/nanoc/base/entities/context.rb +0 -70
  133. data/lib/nanoc/base/entities/directed_graph.rb +0 -195
  134. data/lib/nanoc/base/entities/document.rb +0 -125
  135. data/lib/nanoc/base/entities/identifiable_collection.rb +0 -141
  136. data/lib/nanoc/base/entities/identifier.rb +0 -222
  137. data/lib/nanoc/base/entities/item.rb +0 -10
  138. data/lib/nanoc/base/entities/item_collection.rb +0 -14
  139. data/lib/nanoc/base/entities/item_rep.rb +0 -91
  140. data/lib/nanoc/base/entities/layout.rb +0 -10
  141. data/lib/nanoc/base/entities/layout_collection.rb +0 -14
  142. data/lib/nanoc/base/entities/lazy_value.rb +0 -43
  143. data/lib/nanoc/base/entities/pattern.rb +0 -85
  144. data/lib/nanoc/base/entities/processing_action.rb +0 -21
  145. data/lib/nanoc/base/entities/processing_actions.rb +0 -5
  146. data/lib/nanoc/base/entities/processing_actions/filter.rb +0 -36
  147. data/lib/nanoc/base/entities/processing_actions/layout.rb +0 -36
  148. data/lib/nanoc/base/entities/processing_actions/snapshot.rb +0 -46
  149. data/lib/nanoc/base/entities/snapshot_def.rb +0 -22
  150. data/lib/nanoc/base/repos/data_source.rb +0 -168
  151. data/lib/nanoc/base/repos/snapshot_repo.rb +0 -67
  152. data/lib/nanoc/base/services/checksummer.rb +0 -274
  153. data/lib/nanoc/base/services/notification_center.rb +0 -87
  154. data/lib/nanoc/base/services/temp_filename_factory.rb +0 -52
@@ -1,112 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Nanoc
4
- module Int
5
- # Abstract content.
6
- #
7
- # The filename is the full filename on the default filesystem. It can be
8
- # nil. It is used by filters such as Sass, which look up items on the
9
- # filesystem.
10
- #
11
- # @abstract
12
- #
13
- # @api private
14
- class Content
15
- include Nanoc::Int::ContractsSupport
16
-
17
- # @return [String, nil]
18
- attr_reader :filename
19
-
20
- contract C::Maybe[String] => C::Any
21
- # @param [String, nil] filename
22
- def initialize(filename)
23
- if filename && Pathname.new(filename).relative?
24
- raise ArgumentError, 'Content filename is not absolute'
25
- end
26
-
27
- @filename = filename
28
- end
29
-
30
- contract C::None => self
31
- def freeze
32
- super
33
- @filename.freeze
34
- self
35
- end
36
-
37
- contract C::Or[Nanoc::Int::Content, String, Proc], C::KeywordArgs[binary: C::Optional[C::Bool], filename: C::Optional[C::Maybe[String]]] => self
38
- # @param [Nanoc::Int::Content, String, Proc] content The uncompiled item
39
- # content (if it is textual content) or the path to the filename
40
- # containing the content (if this is binary content).
41
- #
42
- # @param [Boolean] binary Whether or not this item is binary
43
- #
44
- # @param [String] filename Absolute path to the file containing this
45
- # content (if any)
46
- def self.create(content, binary: false, filename: nil)
47
- if content.nil?
48
- raise ArgumentError, 'Cannot create nil content'
49
- elsif content.is_a?(Nanoc::Int::Content)
50
- content
51
- elsif binary
52
- Nanoc::Int::BinaryContent.new(content)
53
- else
54
- Nanoc::Int::TextualContent.new(content, filename: filename)
55
- end
56
- end
57
-
58
- # @abstract
59
- #
60
- # @return [Boolean]
61
- def binary?
62
- raise NotImplementedError
63
- end
64
- end
65
-
66
- # @api private
67
- class TextualContent < Content
68
- contract C::None => String
69
- # @return [String]
70
- def string
71
- @string.value
72
- end
73
-
74
- contract C::Or[String, Proc], C::KeywordArgs[filename: C::Optional[C::Maybe[String]]] => C::Any
75
- def initialize(string, filename: nil)
76
- super(filename)
77
- @string = Nanoc::Int::LazyValue.new(string)
78
- end
79
-
80
- contract C::None => self
81
- def freeze
82
- super
83
- @string.freeze
84
- self
85
- end
86
-
87
- contract C::None => C::Bool
88
- def binary?
89
- false
90
- end
91
-
92
- contract C::None => Array
93
- def marshal_dump
94
- [filename, string]
95
- end
96
-
97
- contract Array => C::Any
98
- def marshal_load(array)
99
- @filename = array[0]
100
- @string = Nanoc::Int::LazyValue.new(array[1])
101
- end
102
- end
103
-
104
- # @api private
105
- class BinaryContent < Content
106
- contract C::None => C::Bool
107
- def binary?
108
- true
109
- end
110
- end
111
- end
112
- end
@@ -1,70 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Nanoc::Int
4
- # Provides a context and a binding for use in filters such as the ERB and
5
- # Haml ones.
6
- #
7
- # @api private
8
- class Context
9
- # Creates a new context based off the contents of the hash.
10
- #
11
- # Each pair in the hash will be converted to an instance variable and an
12
- # instance method. For example, passing the hash `{ :foo => 'bar' }` will
13
- # cause `@foo` to have the value `"bar"`, and the instance method `#foo`
14
- # to return the same value `"bar"`.
15
- #
16
- # @param [Hash] hash A list of key-value pairs to make available
17
- #
18
- # @example Defining a context and accessing values
19
- #
20
- # context = Nanoc::Int::Context.new(
21
- # :name => 'Max Payne',
22
- # :location => 'in a cheap motel'
23
- # )
24
- # context.instance_eval do
25
- # "I am #{name} and I am hiding #{@location}."
26
- # end
27
- # # => "I am Max Payne and I am hiding in a cheap motel."
28
- def initialize(hash)
29
- hash.each_pair do |key, value|
30
- instance_variable_set('@' + key.to_s, value)
31
- end
32
- end
33
-
34
- # Returns a binding for this instance.
35
- #
36
- # @return [Binding] A binding for this instance
37
- # rubocop:disable Naming/AccessorMethodName
38
- def get_binding
39
- binding
40
- end
41
- # rubocop:enable Naming/AccessorMethodName
42
-
43
- def method_missing(method, *args, &blk)
44
- ivar_name = '@' + method.to_s
45
- if instance_variable_defined?(ivar_name)
46
- instance_variable_get(ivar_name)
47
- else
48
- super
49
- end
50
- end
51
-
52
- def respond_to_missing?(method, include_all)
53
- ivar_name = '@' + method.to_s
54
-
55
- valid_ivar_name =
56
- if defined?(Contracts)
57
- ivar_name =~ /\A@[A-Za-z_]+\z/
58
- else
59
- true # probably good enough
60
- end
61
-
62
- (valid_ivar_name && instance_variable_defined?(ivar_name)) || super
63
- end
64
-
65
- def include(mod)
66
- metaclass = class << self; self; end
67
- metaclass.instance_eval { include(mod) }
68
- end
69
- end
70
- end
@@ -1,195 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Nanoc::Int
4
- # Represents a directed graph. It is used by the dependency tracker for
5
- # storing and querying dependencies between items.
6
- #
7
- # @example Creating and using a directed graph
8
- #
9
- # # Create a graph with three vertices
10
- # graph = Nanoc::Int::DirectedGraph.new(%w( a b c d e f g ))
11
- #
12
- # # Add edges
13
- # graph.add_edge('a', 'b')
14
- # graph.add_edge('b', 'c')
15
- # graph.add_edge('b', 'f')
16
- # graph.add_edge('b', 'g')
17
- # graph.add_edge('c', 'd')
18
- # graph.add_edge('d', 'e')
19
- #
20
- # # Get (direct) predecessors
21
- # graph.direct_predecessors_of('b').sort
22
- # # => %w( a )
23
- # graph.predecessors_of('e').sort
24
- # # => %w( a b c d )
25
- #
26
- # # Modify edges
27
- # graph.delete_edges_to('c')
28
- #
29
- # # Get (direct) predecessors again
30
- # graph.direct_predecessors_of('e').sort
31
- # # => %w( d )
32
- # graph.predecessors_of('e').sort
33
- # # => %w( c d )
34
- #
35
- # @api private
36
- class DirectedGraph
37
- # @group Creating a graph
38
-
39
- # Creates a new directed graph with the given vertices.
40
- def initialize(vertices)
41
- @vertices = {}
42
- @next_vertex_idx = 0
43
- vertices.each do |v|
44
- @vertices[v] = @next_vertex_idx.tap { @next_vertex_idx += 1 }
45
- end
46
-
47
- @to_graph = {}
48
-
49
- @edge_props = {}
50
-
51
- invalidate_caches
52
- end
53
-
54
- def inspect
55
- s = []
56
-
57
- @vertices.each_pair do |v2, _|
58
- direct_predecessors_of(v2).each do |v1|
59
- s << [v1.inspect + ' -> ' + v2.inspect + ' props=' + @edge_props[[v1, v2]].inspect]
60
- end
61
- end
62
-
63
- self.class.to_s + '(' + s.join(', ') + ')'
64
- end
65
-
66
- # @group Modifying the graph
67
-
68
- # Adds an edge from the first vertex to the second vertex.
69
- #
70
- # @param from Vertex where the edge should start
71
- #
72
- # @param to Vertex where the edge should end
73
- #
74
- # @return [void]
75
- def add_edge(from, to, props: nil)
76
- add_vertex(from)
77
- add_vertex(to)
78
-
79
- @to_graph[to] ||= Set.new
80
- @to_graph[to] << from
81
-
82
- if props
83
- @edge_props[[from, to]] = props
84
- end
85
-
86
- invalidate_caches
87
- end
88
-
89
- # Adds the given vertex to the graph.
90
- #
91
- # @param vertex The vertex to add to the graph
92
- #
93
- # @return [void]
94
- def add_vertex(vertex)
95
- return if @vertices.key?(vertex)
96
-
97
- @vertices[vertex] = @next_vertex_idx.tap { @next_vertex_idx += 1 }
98
- end
99
-
100
- # Deletes all edges going to the given vertex.
101
- #
102
- # @param to Vertex to which all edges should be removed
103
- #
104
- # @return [void]
105
- def delete_edges_to(to)
106
- return if @to_graph[to].nil?
107
-
108
- @to_graph[to].each do |from|
109
- @edge_props.delete([from, to])
110
- end
111
- @to_graph.delete(to)
112
-
113
- invalidate_caches
114
- end
115
-
116
- # @group Querying the graph
117
-
118
- # Returns the direct predecessors of the given vertex, i.e. the vertices
119
- # x where there is an edge from x to the given vertex y.
120
- #
121
- # @param to The vertex of which the predecessors should be calculated
122
- #
123
- # @return [Array] Direct predecessors of the given vertex
124
- def direct_predecessors_of(to)
125
- @to_graph.fetch(to, Set.new)
126
- end
127
-
128
- # Returns the predecessors of the given vertex, i.e. the vertices x for
129
- # which there is a path from x to the given vertex y.
130
- #
131
- # @param to The vertex of which the predecessors should be calculated
132
- #
133
- # @return [Array] Predecessors of the given vertex
134
- def predecessors_of(to)
135
- @predecessors[to] ||= recursively_find_vertices(to, :direct_predecessors_of)
136
- end
137
-
138
- def props_for(from, to)
139
- @edge_props[[from, to]]
140
- end
141
-
142
- # @return [Array] The list of all vertices in this graph.
143
- def vertices
144
- @vertices.keys.sort_by { |v| @vertices[v] }
145
- end
146
-
147
- # Returns an array of tuples representing the edges. The result of this
148
- # method may take a while to compute and should be cached if possible.
149
- #
150
- # @return [Array] The list of all edges in this graph.
151
- def edges
152
- result = []
153
- @vertices.each_pair do |v2, i2|
154
- direct_predecessors_of(v2).map { |v1| [@vertices[v1], v1] }.each do |i1, v1|
155
- result << [i1, i2, @edge_props[[v1, v2]]]
156
- end
157
- end
158
- result
159
- end
160
-
161
- private
162
-
163
- # Invalidates cached data. This method should be called when the internal
164
- # graph representation is changed.
165
- def invalidate_caches
166
- @predecessors = {}
167
- end
168
-
169
- # Recursively finds vertices, starting at the vertex start, using the
170
- # given method, which should be a symbol to a method that takes a vertex
171
- # and returns related vertices (e.g. predecessors, successors).
172
- def recursively_find_vertices(start, method)
173
- all_vertices = Set.new
174
-
175
- processed_vertices = Set.new
176
- unprocessed_vertices = [start]
177
-
178
- until unprocessed_vertices.empty?
179
- # Get next unprocessed vertex
180
- vertex = unprocessed_vertices.pop
181
- next if processed_vertices.include?(vertex)
182
-
183
- processed_vertices << vertex
184
-
185
- # Add predecessors of this vertex
186
- send(method, vertex).each do |v|
187
- all_vertices << v unless all_vertices.include?(v)
188
- unprocessed_vertices << v
189
- end
190
- end
191
-
192
- all_vertices
193
- end
194
- end
195
- end
@@ -1,125 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Nanoc
4
- module Int
5
- # @api private
6
- class Document
7
- include Nanoc::Int::ContractsSupport
8
-
9
- # @return [Nanoc::Int::Content]
10
- attr_reader :content
11
-
12
- # @return [Hash]
13
- def attributes
14
- @attributes.value
15
- end
16
-
17
- # @return [Nanoc::Identifier]
18
- attr_reader :identifier
19
-
20
- # @return [String, nil]
21
- attr_accessor :checksum_data
22
-
23
- # @return [String, nil]
24
- attr_accessor :content_checksum_data
25
-
26
- # @return [String, nil]
27
- attr_accessor :attributes_checksum_data
28
-
29
- c_content = C::Or[String, Nanoc::Int::Content]
30
- c_attributes = C::Or[Hash, Proc]
31
- c_identifier = C::Or[String, Nanoc::Identifier]
32
- c_checksum_data = C::KeywordArgs[
33
- checksum_data: C::Optional[C::Maybe[String]],
34
- content_checksum_data: C::Optional[C::Maybe[String]],
35
- attributes_checksum_data: C::Optional[C::Maybe[String]],
36
- ]
37
-
38
- contract c_content, c_attributes, c_identifier, c_checksum_data => C::Any
39
- # @param [String, Nanoc::Int::Content] content
40
- #
41
- # @param [Hash, Proc] attributes
42
- #
43
- # @param [String, Nanoc::Identifier] identifier
44
- #
45
- # @param [String, nil] checksum_data
46
- #
47
- # @param [String, nil] content_checksum_data
48
- #
49
- # @param [String, nil] attributes_checksum_data
50
- def initialize(content, attributes, identifier, checksum_data: nil, content_checksum_data: nil, attributes_checksum_data: nil)
51
- @content = Nanoc::Int::Content.create(content)
52
- @attributes = Nanoc::Int::LazyValue.new(attributes).map(&:__nanoc_symbolize_keys_recursively)
53
- @identifier = Nanoc::Identifier.from(identifier)
54
-
55
- @checksum_data = checksum_data
56
- @content_checksum_data = content_checksum_data
57
- @attributes_checksum_data = attributes_checksum_data
58
- end
59
-
60
- contract C::None => self
61
- # @return [void]
62
- def freeze
63
- super
64
- @content.freeze
65
- @attributes.freeze
66
- self
67
- end
68
-
69
- contract String => self
70
- def with_identifier_prefix(prefix)
71
- other = dup
72
- other.identifier = @identifier.prefix(prefix)
73
- other
74
- end
75
-
76
- contract C::None => String
77
- # @abstract
78
- #
79
- # @return Unique reference to this object
80
- def reference
81
- raise NotImplementedError
82
- end
83
-
84
- contract C::Or[Nanoc::Identifier, String] => Nanoc::Identifier
85
- def identifier=(new_identifier)
86
- @identifier = Nanoc::Identifier.from(new_identifier)
87
- end
88
-
89
- contract Nanoc::Int::Content => C::Any
90
- def content=(new_content)
91
- @content = new_content
92
-
93
- @checksum_data = nil
94
- @content_checksum_data = nil
95
- end
96
-
97
- def set_attribute(key, value)
98
- attributes[key] = value
99
-
100
- @checksum_data = nil
101
- @attributes_checksum_data = nil
102
- end
103
-
104
- contract C::None => String
105
- def inspect
106
- "<#{self.class} identifier=\"#{identifier}\">"
107
- end
108
-
109
- contract C::None => C::Num
110
- def hash
111
- self.class.hash ^ identifier.hash
112
- end
113
-
114
- contract C::Any => C::Bool
115
- def ==(other)
116
- other.respond_to?(:identifier) && identifier == other.identifier
117
- end
118
-
119
- contract C::Any => C::Bool
120
- def eql?(other)
121
- other.is_a?(self.class) && identifier == other.identifier
122
- end
123
- end
124
- end
125
- end