Class: Asciidoctor::Converter::CompositeConverter
- Defined in:
- lib/asciidoctor/converter/composite.rb
Overview
identifies itself as the handler for a given transform.
Constant Summary
Constants included from DefaultFactory
Instance Attribute Summary collapse
-
#converters ⇒ Object
readonly
Get the Array of Converter objects in the chain.
Attributes included from Asciidoctor::Converter
Instance Method Summary collapse
-
#convert(node, transform = nil, opts = nil) ⇒ Object
Delegates to the first converter that identifies itself as the handler for the given transform.
-
#converter_for(transform) ⇒ Converter
Retrieve the converter for the specified transform.
-
#find_converter(transform) ⇒ Converter
Find the converter for the specified transform.
-
#initialize(backend, *converters, backend_traits_source: nil) ⇒ CompositeConverter
constructor
A new instance of CompositeConverter.
Methods inherited from Base
#content_only, #handles?, #skip
Methods included from Asciidoctor::Converter
derive_backend_traits, #handles?
Methods included from DefaultFactory
#for, #register, #unregister_all
Methods included from Factory
create, #create, default, #for, new, #register
Methods included from Logging
#logger, #message_with_context
Constructor Details
#initialize(backend, *converters, backend_traits_source: nil) ⇒ CompositeConverter
Returns a new instance of CompositeConverter.
10 11 12 13 14 15 |
# File 'lib/asciidoctor/converter/composite.rb', line 10 def initialize backend, *converters, backend_traits_source: nil @backend = backend (@converters = converters).each {|converter| converter.composed self if converter.respond_to? :composed } init_backend_traits backend_traits_source.backend_traits if backend_traits_source @converter_cache = ::Hash.new {|hash, key| hash[key] = find_converter key } end |
Instance Attribute Details
#converters ⇒ Object (readonly)
Get the Array of Converter objects in the chain
8 9 10 |
# File 'lib/asciidoctor/converter/composite.rb', line 8 def converters @converters end |
Instance Method Details
#convert(node, transform = nil, opts = nil) ⇒ Object
Delegates to the first converter that identifies itself as the handler for the given transform. The optional Hash is passed as the last option to the delegate’s convert method.
27 28 29 |
# File 'lib/asciidoctor/converter/composite.rb', line 27 def convert node, transform = nil, opts = nil (converter_for transform ||= node.node_name).convert node, transform, opts end |
#converter_for(transform) ⇒ Converter
Retrieve the converter for the specified transform.
34 35 36 |
# File 'lib/asciidoctor/converter/composite.rb', line 34 def converter_for transform @converter_cache[transform] end |
#find_converter(transform) ⇒ Converter
Find the converter for the specified transform.
42 43 44 45 |
# File 'lib/asciidoctor/converter/composite.rb', line 42 def find_converter transform @converters.each {|candidate| return candidate if candidate.handles? transform } raise %(Could not find a converter to handle transform: #{transform}) end |