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, basebackend = nil) ⇒ 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, basebackend = nil) ⇒ Hash
Derive backend traits (basebackend, filetype, outfilesuffix, htmlsyntax) from the given backend.
91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/asciidoctor/converter.rb', line 91 def self.derive_backend_traits backend, basebackend = nil return {} unless backend if (outfilesuffix = DEFAULT_EXTENSIONS[(basebackend ||= backend.sub TrailingDigitsRx, '')]) filetype = outfilesuffix.slice 1, outfilesuffix.length else outfilesuffix = %(.#{filetype = basebackend}) end filetype == 'html' ? { basebackend: basebackend, filetype: filetype, htmlsyntax: 'html', outfilesuffix: outfilesuffix } : { basebackend: basebackend, filetype: filetype, outfilesuffix: 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 |