Class: Asciidoctor::Diagram::BasicSource
- Inherits:
-
Object
- Object
- Asciidoctor::Diagram::BasicSource
show all
- Includes:
- DiagramSource
- Defined in:
- lib/asciidoctor-diagram/diagram_source.rb
Overview
Base class for diagram source implementations that uses an md5 checksum of the source code of a diagram to determine if it has been updated or not.
Instance Attribute Summary collapse
Instance Method Summary
collapse
#base_dir, #code, #find_command, #global_attr, #load_code, #to_s
Constructor Details
#initialize(block_processor, parent_block, attributes) ⇒ BasicSource
Returns a new instance of BasicSource.
153
154
155
156
157
|
# File 'lib/asciidoctor-diagram/diagram_source.rb', line 153
def initialize(block_processor, parent_block, attributes)
@block_processor = block_processor
@parent_block = parent_block
@attributes = attributes
end
|
Instance Attribute Details
#attributes ⇒ Object
Returns the value of attribute attributes.
151
152
153
|
# File 'lib/asciidoctor-diagram/diagram_source.rb', line 151
def attributes
@attributes
end
|
Instance Method Details
#attr(name, default_value = nil, inherit = diagram_type) ⇒ Object
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
|
# File 'lib/asciidoctor-diagram/diagram_source.rb', line 175
def attr(name, default_value = nil, inherit = diagram_type)
name = name.to_s if ::Symbol === name
name = [name] unless name.is_a?(Enumerable)
value = name.lazy.map { |n| @attributes[n] }.reject { |v| v.nil? }.first
if value.nil? && inherit
inherited_values = name.lazy.map do |n|
case inherit
when String, Symbol
@parent_block.attr("#{inherit.to_s}-#{n}", default_value, true)
else
@parent_block.attr(n, default_value, inherit)
end
end
value = inherited_values.reject { |v| v.nil? }.first
end
value || default_value
end
|
#checksum ⇒ Object
204
205
206
|
# File 'lib/asciidoctor-diagram/diagram_source.rb', line 204
def checksum
@checksum ||= compute_checksum(code)
end
|
#config ⇒ Object
167
168
169
|
# File 'lib/asciidoctor-diagram/diagram_source.rb', line 167
def config
@block_processor.config
end
|
200
201
202
|
# File 'lib/asciidoctor-diagram/diagram_source.rb', line 200
def create_image_metadata
{:checksum => checksum}
end
|
#diagram_type ⇒ Object
159
160
161
|
# File 'lib/asciidoctor-diagram/diagram_source.rb', line 159
def diagram_type
@block_processor.name.downcase
end
|
#image_name ⇒ Object
171
172
173
|
# File 'lib/asciidoctor-diagram/diagram_source.rb', line 171
def image_name
attr('target', 'diag-' + checksum)
end
|
#resolve_path(target, start = base_dir) ⇒ Object
163
164
165
|
# File 'lib/asciidoctor-diagram/diagram_source.rb', line 163
def resolve_path target, start = base_dir
@parent_block.normalize_system_path(target, start)
end
|
#should_process?(image_file, image_metadata) ⇒ Boolean
196
197
198
|
# File 'lib/asciidoctor-diagram/diagram_source.rb', line 196
def should_process?(image_file, image_metadata)
image_metadata[:checksum] != checksum
end
|