Module: Asciidoctor::Converter

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

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

DefaultFactory::PROVIDED

Instance Attribute Summary collapse

Class Method 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)

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.

Raises:

  • (::NotImplementedError)


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