Class: Asciidoctor::DocTest::AsciidocConverter
- Inherits:
-
Object
- Object
- Asciidoctor::DocTest::AsciidocConverter
- Defined in:
- lib/asciidoctor/doctest/asciidoc_converter.rb
Overview
This class is basically a wrapper for Asciidoctor.convert
that allows to preset and validate some common parameters.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#default_opts ⇒ Hash
(also: #opts)
readonly
The default options to be passed to Asciidoctor.
Instance Method Summary collapse
-
#convert(text, opts = {}) ⇒ String
(also: #call)
Converts the given
text
into AsciiDoc syntax with Asciidoctor using the tested backend. -
#initialize(opts = {}) ⇒ AsciidocConverter
constructor
A new instance of AsciidocConverter.
Constructor Details
#initialize(opts = {}) ⇒ AsciidocConverter
Returns a new instance of AsciidocConverter.
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/asciidoctor/doctest/asciidoc_converter.rb', line 50 def initialize(opts = {}) opts = opts.rekey(&:to_sym).rekey(:backend_name => :backend) template_dirs = Array(opts[:template_dirs]).freeze template_dirs.each do |path| fail ArgumentError, "Templates directory '#{path}' doesn't exist!" unless Dir.exist? path end unless template_dirs.empty? opts[:template_dirs] = template_dirs opts[:converter] ||= NoFallbackTemplateConverter unless opts[:templates_fallback] end opts[:safe] ||= :safe opts.delete(:backend) if opts[:backend].blank? @default_opts = opts end |
Instance Attribute Details
#default_opts ⇒ Hash (readonly) Also known as: opts
Returns the default options to be passed to Asciidoctor.
17 18 19 |
# File 'lib/asciidoctor/doctest/asciidoc_converter.rb', line 17 def default_opts @default_opts end |
Instance Method Details
#convert(text, opts = {}) ⇒ String Also known as: call
Converts the given text
into AsciiDoc syntax with Asciidoctor using the tested backend.
78 79 80 |
# File 'lib/asciidoctor/doctest/asciidoc_converter.rb', line 78 def convert(text, opts = {}) Asciidoctor.convert(text.to_s, @default_opts + opts) end |