class Asciidoctor::Diagram::BasicSource
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.
Attributes
attributes[R]
Public Class Methods
new(block_processor, parent_block, attributes)
click to toggle source
# File lib/asciidoctor-diagram/diagram_source.rb, line 178 def initialize(block_processor, parent_block, attributes) @block_processor = block_processor @parent_block = parent_block @attributes = attributes end
Public Instance Methods
attr(name, default_value = nil, inherit = diagram_type)
click to toggle source
# File lib/asciidoctor-diagram/diagram_source.rb, line 200 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? attr_position = config[:positional_attrs] || 1 while value.nil? && !@attributes[attr_position].nil? if @attributes[attr_position] == name value = true end end end 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()
click to toggle source
# File lib/asciidoctor-diagram/diagram_source.rb, line 237 def checksum @checksum ||= "#{diagram_type.to_s}-#{compute_checksum(code)}" end
config()
click to toggle source
# File lib/asciidoctor-diagram/diagram_source.rb, line 192 def config @block_processor.config end
create_image_metadata()
click to toggle source
# File lib/asciidoctor-diagram/diagram_source.rb, line 233 def create_image_metadata {:checksum => checksum} end
diagram_type()
click to toggle source
# File lib/asciidoctor-diagram/diagram_source.rb, line 184 def diagram_type @block_processor.name.downcase end
image_name()
click to toggle source
# File lib/asciidoctor-diagram/diagram_source.rb, line 196 def image_name attr('target', 'diag-' + checksum) end
resolve_path(target, start = base_dir)
click to toggle source
# File lib/asciidoctor-diagram/diagram_source.rb, line 188 def resolve_path target, start = base_dir @parent_block.normalize_system_path(target, start) end
should_process?(image_file, image_metadata)
click to toggle source
# File lib/asciidoctor-diagram/diagram_source.rb, line 229 def should_process?(image_file, image_metadata) image_metadata[:checksum] != checksum end
Protected Instance Methods
resolve_diagram_subs()
click to toggle source
# File lib/asciidoctor-diagram/diagram_source.rb, line 243 def resolve_diagram_subs if @attributes.key? 'subs' @parent_block.resolve_block_subs @attributes['subs'], nil, 'diagram' else [] end end
Private Instance Methods
compute_checksum(code)
click to toggle source
# File lib/asciidoctor-diagram/diagram_source.rb, line 253 def compute_checksum(code) md5 = Digest::MD5.new md5 << code @attributes.each do |k, v| md5 << k.to_s if k md5 << v.to_s if v end "md5-#{md5.hexdigest}" end