class Asciidoctor::Converter::CompositeConverter - asciidoctor-1.5.6.2 Documentation

# class Asciidoctor::Converter::CompositeConverter

A {Converter} implementation that delegates to the chain of {Converter} objects passed to the constructor. Selects the first {Converter} that identifies itself as the handler for a given transform.

### Attributes

converters[R]

Get the Array of Converter objects in the chain

### Public Class Methods

new(backend, *converters) click to toggle source

    # File lib/asciidoctor/converter/composite.rb, line 10
    def initialize backend, *converters
      @backend = backend
      (@converters = converters.flatten.compact).each do |converter|
        converter.composed self if converter.respond_to? :composed
      end
      @converter_map = {}
    end

### Public Instance Methods

convert(node, transform = nil, opts = {}) click to toggle source

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

node - the AbstractNode to convert transform - the optional String transform, or the name of the node if no

    transform is specified. (default: nil)

opts - an optional Hash that is passed to the delegate's convert method. (default: {})

Returns the String result returned from the delegate's convert method

    # File lib/asciidoctor/converter/composite.rb, line 28
    def convert node, transform = nil, opts = {}
      transform ||= node.node_name
      (converter_for transform).convert node, transform, opts
    end

Also aliased as: convert_with_options
convert_with_options(node, transform = nil, opts = {})

Alias for backward compatibility.

Alias for: convert
converter_for(transform) click to toggle source

Public: Retrieve the converter for the specified transform.

Returns the matching [Converter] object

    # File lib/asciidoctor/converter/composite.rb, line 39
    def converter_for transform
      @converter_map[transform] ||= (find_converter transform)
    end

find_converter(transform) click to toggle source

Internal: Find the converter for the specified transform. Raise an exception if no converter is found.

Returns the matching [Converter] object

    # File lib/asciidoctor/converter/composite.rb, line 47
    def find_converter transform
      @converters.each do |candidate|
        return candidate if candidate.handles? transform
      end
      raise %Q(Could not find a converter to handle transform: #{transform})
    end