Class: Asciidoctor::DocTest::AsciidocRenderer
- Inherits:
-
Object
- Object
- Asciidoctor::DocTest::AsciidocRenderer
- Defined in:
- lib/asciidoctor/doctest/asciidoc_renderer.rb
Overview
This class is basically a wrapper for Asciidoctor.convert that allows to preset and validate some common parameters.
Instance Attribute Summary collapse
-
#backend_name ⇒ Object
readonly
Returns the value of attribute backend_name.
-
#converter ⇒ Object
readonly
Returns the value of attribute converter.
-
#template_dirs ⇒ Object
readonly
Returns the value of attribute template_dirs.
Instance Method Summary collapse
-
#convert(text, opts = {}) ⇒ String
(also: #render)
Converts the given
textinto AsciiDoc syntax with Asciidoctor using the tested backend. -
#initialize(backend_name: '', converter: nil, template_dirs: [], templates_fallback: false) ⇒ AsciidocRenderer
constructor
A new instance of AsciidocRenderer.
Constructor Details
#initialize(backend_name: '', converter: nil, template_dirs: [], templates_fallback: false) ⇒ AsciidocRenderer
Returns a new instance of AsciidocRenderer.
36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/asciidoctor/doctest/asciidoc_renderer.rb', line 36 def initialize(backend_name: '', converter: nil, template_dirs: [], templates_fallback: false) @backend_name = backend_name.freeze @converter = converter @converter ||= NoFallbackTemplateConverter unless template_dirs.empty? || templates_fallback template_dirs = Array.wrap(template_dirs).freeze template_dirs.each do |path| fail ArgumentError, "Templates directory '#{path}' doesn't exist!" unless Dir.exist? path end @template_dirs = template_dirs unless template_dirs.empty? end |
Instance Attribute Details
#backend_name ⇒ Object (readonly)
Returns the value of attribute backend_name.
12 13 14 |
# File 'lib/asciidoctor/doctest/asciidoc_renderer.rb', line 12 def backend_name @backend_name end |
#converter ⇒ Object (readonly)
Returns the value of attribute converter.
12 13 14 |
# File 'lib/asciidoctor/doctest/asciidoc_renderer.rb', line 12 def converter @converter end |
#template_dirs ⇒ Object (readonly)
Returns the value of attribute template_dirs.
12 13 14 |
# File 'lib/asciidoctor/doctest/asciidoc_renderer.rb', line 12 def template_dirs @template_dirs end |
Instance Method Details
#convert(text, opts = {}) ⇒ String Also known as: render
Converts the given text into AsciiDoc syntax with Asciidoctor using the tested backend.
58 59 60 61 62 63 64 65 66 67 |
# File 'lib/asciidoctor/doctest/asciidoc_renderer.rb', line 58 def convert(text, opts = {}) converter_opts = { safe: :safe, backend: backend_name, converter: converter, template_dirs: template_dirs }.merge(opts) Asciidoctor.convert(text.to_s, converter_opts) end |