Class | Asciidoctor::Converter::TemplateConverter |
In: |
lib/asciidoctor/converter/template.rb
|
Parent: | Converter::Base |
A {Converter} implementation that uses templates composed in template languages supported by {github.com/rtomayko/tilt Tilt} to convert {AbstractNode} objects from a parsed AsciiDoc document tree to the backend format.
The converter scans the specified directories for template files that are supported by Tilt. If an engine name (e.g., "slim") is specified in the options Hash passed to the constructor, the scan is restricted to template files that have a matching extension (e.g., ".slim"). The scanner trims any extensions from the basename of the file and uses the resulting name as the key under which to store the template. When the {Converter#convert} method is invoked, the transform argument is used to select the template from this table and use it to convert the node.
For example, the template file "path/to/templates/paragraph.html.slim" will be registered as the "paragraph" transform. The template is then used to convert a paragraph {Block} object from the parsed AsciiDoc tree to an HTML backend format (e.g., "html5").
As an optimization, scan results and templates are cached for the lifetime of the Ruby process. If the {rubygems.org/gems/thread_safe thread_safe} gem is installed, these caches are guaranteed to be thread safe. If this gem is not present, there is no such guarantee and a warning will be issued.
DEFAULT_ENGINE_OPTIONS | = | { :erb => { :trim => '<' }, # TODO line 466 of haml/compiler.rb sorts the attributes; file an issue to make this configurable # NOTE AsciiDoc syntax expects HTML/XML output to use double quotes around attribute values :haml => { :format => :xhtml, :attr_wrapper => '"', :escape_attrs => false, :ugly => true }, :slim => { :disable_escape => true, :sort_attrs => false, :pretty => false } |
Public: Convert an {AbstractNode} to the backend format using the named template.
Looks for a template that matches the value of the {AbstractNode#node_name} property if a template name is not specified.
node - the AbstractNode to convert template_name - the String name of the template to use, or the value of
the node_name property on the node if a template name is not specified. (optional, default: nil)
opts - an optional Hash that is passed as local variables to the
template. (optional, default: {})
Returns the [String] result from rendering the template
Public: Checks whether there is a Tilt template registered with the specified name.
name - the String template name
Returns a [Boolean] that indicates whether a Tilt template is registered for the specified template name.
Internal: Scans the template directories specified in the constructor for Tilt-supported templates, loads the templates and stores the in a Hash that is accessible via the {TemplateConverter#templates} method.
Returns nothing