Module: Asciidoctor::Diagram::Extensions::DiagramSource

Included in:
BasicSource, ReaderSource
Defined in:
lib/asciidoctor-diagram/extensions.rb

Overview

This module describes the duck-typed interface that diagram sources must implement. Implementations may include this module but it is not required.

Instance Method Summary collapse

Instance Method Details

#attr(name, default_value = nil, inherit = true) ⇒ Object

This method is abstract.

Get the value for the specified attribute. First look in the attributes on this node and return the value of the attribute if found. Otherwise, if this node is a child of the Document node, look in the attributes of the Document node and return the value of the attribute if found. Otherwise, return the default value, which defaults to nil.

Parameters:

  • name (String, Symbol)

    the name of the attribute to lookup

  • default_value (Object) (defaults to: nil)

    the value to return if the attribute is not found

Returns:

  • the value of the attribute or the default value if the attribute is not found in the attributes of this node or the document node

Raises:

  • (NotImplementedError)


315
316
317
# File 'lib/asciidoctor-diagram/extensions.rb', line 315

def attr(name, default_value = nil, inherit = true)
  raise NotImplementedError.new
end

#base_dirString

This method is abstract.

Returns the base directory against which relative paths in this diagram should be resolved.

Returns:

  • (String)

    the base directory against which relative paths in this diagram should be resolved

Raises:

  • (NotImplementedError)


321
322
323
# File 'lib/asciidoctor-diagram/extensions.rb', line 321

def base_dir
  raise NotImplementedError.new
end

#codeString

This method is abstract.

Returns the String representation of the source code for the diagram.

Returns:

  • (String)

    the String representation of the source code for the diagram

Raises:

  • (NotImplementedError)


299
300
301
# File 'lib/asciidoctor-diagram/extensions.rb', line 299

def code
  raise NotImplementedError.new
end

#create_image_metadataHash

Creates an image metadata Hash that will be stored to disk alongside the generated image file. The contents of this Hash are reread during subsequent document processing and then passed to the should_process? method where it can be used to determine if the diagram should be regenerated or not. The default implementation returns an empty Hash.

Returns:

  • (Hash)

    a Hash containing metadata



345
346
347
# File 'lib/asciidoctor-diagram/extensions.rb', line 345

def 
  {}
end

#image_nameString

This method is abstract.

Returns the base name for the image file that will be produced.

Returns:

  • (String)

    the base name for the image file that will be produced

Raises:

  • (NotImplementedError)


293
294
295
# File 'lib/asciidoctor-diagram/extensions.rb', line 293

def image_name
  raise NotImplementedError.new
end

#should_process?(image_file, image_metadata) ⇒ Boolean

Determines if the diagram should be regenerated or not. The default implementation of this method simply returns true.

Parameters:

  • image_file (String)

    the path to the previously generated version of the image

  • image_metadata (Hash)

    the image metadata Hash that was stored during the previous diagram generation pass

Returns:

  • (Boolean)

    true if the diagram should be regenerated; false otherwise



336
337
338
# File 'lib/asciidoctor-diagram/extensions.rb', line 336

def should_process?(image_file, )
  true
end

#to_sObject

Alias for code



326
327
328
# File 'lib/asciidoctor-diagram/extensions.rb', line 326

def to_s
  code
end