Class | Asciidoctor::AbstractNode |
In: |
lib/asciidoctor/abstract_node.rb
|
Parent: | Object |
Public: An abstract base class that provides state and methods for managing a node of AsciiDoc content. The state and methods on this class are comment to all content segments in an AsciiDoc document.
attributes | [R] | Public: Get the Hash of attributes for this node |
context | [R] | Public: Get the Symbol context for this node |
document | [R] | Public: Get the Asciidoctor::Document to which this node belongs |
id | [RW] | Public: Get the id of this node |
parent | [R] | Public: Get the element which is the parent of this node |
Public: Get the value of the specified attribute
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.
name - the String or Symbol name of the attribute to lookup default - the Object value to return if the attribute is not found (default: nil) inherit - a Boolean indicating whether to check for the attribute on the
AsciiDoctor::Document if not found on this node (default: false)
return 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
Public: Check if the attribute is defined, optionally performing a comparison of its value if expected is not nil
Check if the attribute is defined. First look in the attributes on this node. If not found, and this node is a child of the Document node, look in the attributes of the Document node. If the attribute is found and a comparison value is specified (not nil), return whether the two values match. Otherwise, return whether the attribute was found.
name - the String or Symbol name of the attribute to lookup expect - the expected Object value of the attribute (default: nil) inherit - a Boolean indicating whether to check for the attribute on the
AsciiDoctor::Document if not found on this node (default: false)
return a Boolean indicating whether the attribute exists and, if a comparison value is specified, whether the value of the attribute matches the comparison value
Public: Generate a data URI that can be used to embed an image in the output document
First, and foremost, the target image path is cleaned if the document safe mode level is set to at least SafeMode::SAFE (a condition which is true by default) to prevent access to ancestor paths in the filesystem. The image data is then read and converted to Base64. Finally, a data URI is built which can be used in an image tag.
target_image - A String path to the target image asset_dir_key - The String attribute key used to lookup the directory where
the image is located (default: nil)
Returns A String data URI containing the content of the target image
Public: Get the execution context of this object (via Kernel#binding).
This method is used to set the ‘self’ reference as well as local variables that map to this method‘s arguments during the evaluation of a backend template.
Each object in Ruby has a binding context that can be used to set the ‘self’ reference in an evaluation context. Any arguments passed to this method are also available in the execution environment.
template - The BaseTemplate instance in which this binding will be active.
Bound to the local variable of the same name, template.
returns the execution context for this object so it can be be transferred to the backend template and binds the method arguments as local variables in that same environment.
Public: Construct a reference or data URI to an icon image for the specified icon name.
If the ‘icon’ attribute is set on this block, the name is ignored and the value of this attribute is used as the target image path. Otherwise, construct a target image path by concatenating the value of the ‘iconsdir’ attribute, the icon name and the value of the ‘icontype’ attribute (defaulting to ‘png’).
The target image path is then passed through the image_uri() method. If the ‘data-uri’ attribute is set on the document, the image will be safely converted to a data URI.
The return value of this method can be safely used in an image tag.
name - The String name of the icon
Returns A String reference or data URI for an icon image
Public: Construct a URI reference or data URI to the target image.
If the target image is a URI reference, then leave it untouched.
The target image is resolved relative to the directory retrieved from the specified attribute key, if provided.
If the ‘data-uri’ attribute is set on the document, and the safe mode level is less than SafeMode::SECURE, the image will be safely converted to a data URI by reading it from the same directory. If neither of these conditions are satisfied, a relative path (i.e., URL) will be returned.
The return value of this method can be safely used in an image tag.
target_image - A String path to the target image asset_dir_key - The String attribute key used to lookup the directory where
the image is located (default: 'imagesdir')
Returns A String reference or data URI for the target image
Public: Construct a URI reference to the target media.
If the target media is a URI reference, then leave it untouched.
The target media is resolved relative to the directory retrieved from the specified attribute key, if provided.
The return value can be safely used in a media tag (img, audio, video).
target - A String reference to the target media asset_dir_key - The String attribute key used to lookup the directory where
the media is located (default: 'imagesdir')
Returns A String reference for the target media
Public: Normalize the asset file or directory to a concrete and rinsed path
Delegates to normalize_system_path, with the start path set to the value of the base_dir instance variable on the Document object.
Public: Resolve and normalize a secure path from the target and start paths using the PathResolver.
See PathResolver::system_path(target, start, jail, opts) for details.
The most important functionality in this method is to prevent resolving a path outside of the jail (which defaults to the directory of the source file, stored in the base_dir instance variable on Document) if the document safe level is set to SafeMode::SAFE or greater (a condition which is true by default).
target - the String target path start - the String start (i.e., parent) path jail - the String jail path to confine the resolved path opts - an optional Hash of options to control processing (default: {}):
* :recover is used to control whether the processor should auto-recover when an illegal path is encountered * :target_name is used in messages to refer to the path being resolved
raises a SecurityError if a jail is specified and the resolved path is outside the jail.
returns a String path resolved from the start and target paths, with any parent references resolved and self references removed. If a jail is provided, this path will be guaranteed to be contained within the jail.
Public: Normalize the web page using the PathResolver.
See PathResolver::web_path(target, start) for details.
target - the String target path start - the String start (i.e, parent) path (optional, default: nil)
returns the resolved String path
Public: Read the contents of the file at the specified path. This method assumes that the path is safe to read. It checks that the file is readable before attempting to read it.
path - the String path from which to read the contents warn_on_failure - a Boolean that controls whether a warning is issued if
the file cannot be read
returns the contents of the file at the specified path, or nil if the file does not exist.
Public: Get the Asciidoctor::Renderer instance being used for the Asciidoctor::Document to which this node belongs
Public: Assign the value to the specified key in this block‘s attributes hash.
key - The attribute key (or name) val - The value to assign to the key
returns a flag indicating whether the assignment was performed
Public: Update the attributes of this node with the new values in the attributes argument.
If an attribute already exists with the same key, it‘s value will be overridden.
attributes - A Hash of attributes to assign to this node.
returns nothing