Module: Asciidoctor::Converter
Overview
puts Asciidoctor.convert_file ‘sample.adoc’, safe: :safe
Defined Under Namespace
Modules: BackendTraits, Config, DefaultFactory, Factory Classes: Base, CompositeConverter, CustomFactory, DefaultFactoryProxy, DocBook5Converter, Html5Converter, ManPageConverter, TemplateConverter
Constant Summary
Constants included from DefaultFactory
Instance Attribute Summary collapse
-
#backend ⇒ Object
readonly
The String backend name that this converter is handling.
Class Method Summary collapse
-
.derive_backend_traits(backend) ⇒ Hash
Derive backend traits (basebackend, filetype, outfilesuffix, htmlsyntax) from the given backend.
Instance Method Summary collapse
-
#convert(node, transform = nil, opts = nil) ⇒ String
Converts an AbstractNode using the given transform.
-
#handles?(transform) ⇒ Boolean
Reports whether the current converter is able to convert this node (by its transform name).
-
#initialize(backend, opts = {}) ⇒ Converter
Creates a new instance of this Converter.
Methods included from DefaultFactory
Methods included from Factory
#converters, #create, create, default, #for, new, #register
Instance Attribute Details
#backend ⇒ Object (readonly)
The String backend name that this converter is handling.
48 49 50 |
# File 'lib/asciidoctor/converter.rb', line 48 def backend @backend end |
Class Method Details
.derive_backend_traits(backend) ⇒ Hash
Derive backend traits (basebackend, filetype, outfilesuffix, htmlsyntax) from the given backend.
90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/asciidoctor/converter.rb', line 90 def self.derive_backend_traits backend return {} unless backend if (t_outfilesuffix = DEFAULT_EXTENSIONS[(t_basebackend = backend.sub TrailingDigitsRx, '')]) t_filetype = t_outfilesuffix.slice 1, t_outfilesuffix.length else t_outfilesuffix = %(.#{t_filetype = t_basebackend}) end t_filetype == 'html' ? { basebackend: t_basebackend, filetype: t_filetype, htmlsyntax: 'html', outfilesuffix: t_outfilesuffix } : { basebackend: t_basebackend, filetype: t_filetype, outfilesuffix: t_outfilesuffix } end |
Instance Method Details
#convert(node, transform = nil, opts = nil) ⇒ String
Converts an AbstractNode using the given transform.
This method must be implemented by a concrete converter class.
71 72 73 |
# File 'lib/asciidoctor/converter.rb', line 71 def convert node, transform = nil, opts = nil raise ::NotImplementedError, %(#{self.class} (backend: #{@backend}) must implement the ##{__method__} method) end |
#handles?(transform) ⇒ Boolean
Reports whether the current converter is able to convert this node (by its transform name). Used by the CompositeConverter to select which converter to use to handle a given node. Returns true by default.
81 82 83 |
# File 'lib/asciidoctor/converter.rb', line 81 def handles? transform true end |
#initialize(backend, opts = {}) ⇒ Converter
Creates a new instance of this Asciidoctor::Converter.
56 57 58 |
# File 'lib/asciidoctor/converter.rb', line 56 def initialize backend, opts = {} @backend = backend end |