Module: Asciidoctor::Converter

Extended by:
DefaultFactory
Included in:
Base
Defined in:
lib/asciidoctor/converter.rb

Overview

puts Asciidoctor.convert_file ‘sample.adoc’

Defined Under Namespace

Modules: BackendTraits, Config, DefaultFactory, Factory Classes: Base, CompositeConverter, CustomFactory, DefaultFactoryProxy, DocBook5Converter, Html5Converter, ManPageConverter, TemplateConverter

Constant Summary

Constants included from DefaultFactory

DefaultFactory::PROVIDED

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from DefaultFactory

for, register, unregister_all

Methods included from Factory

#converters, #create, create, default, #for, new, #register

Instance Attribute Details

#backendObject (readonly)

Public: The String backend name that this converter is handling.



49
50
51
# File 'lib/asciidoctor/converter.rb', line 49

def backend
  @backend
end

Instance Method Details

#convert(node, transform = nil, opts = nil) ⇒ Object

Public: Converts an AbstractNode using the given transform.

This method must be implemented by a concrete converter class.

node - The concrete instance of AbstractNode to convert. transform - An optional String transform that hints at which transformation should be applied to this node. If a

transform is not given, the transform is often derived from the value of the {AbstractNode#node_name}
property. (optional, default: nil)

opts - An optional Hash of options hints about how to convert the node. (optional, default: nil)

Returns the [String] result.

Raises:

  • (::NotImplementedError)


72
73
74
# File 'lib/asciidoctor/converter.rb', line 72

def convert node, transform = nil, opts = nil
  raise ::NotImplementedError, %(#{self.class} (backend: #{@backend}) must implement the ##{__method__} method)
end

#handles?(transform) ⇒ Boolean

Public: 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.

transform - the String name of the node transformation (typically the node name).

Returns a [Boolean] indicating whether this converter can handle the specified transform.

Returns:

  • (Boolean)


82
83
84
# File 'lib/asciidoctor/converter.rb', line 82

def handles? transform
  true
end

#initialize(backend, opts = {}) ⇒ Object

Public: Creates a new instance of this Asciidoctor::Converter.

backend - The String backend name (aka format) to which this converter converts. opts - An options Hash (optional, default: {})

Returns a new [Converter] instance.



57
58
59
# File 'lib/asciidoctor/converter.rb', line 57

def initialize backend, opts = {}
  @backend = backend
end