summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Allen <dan.j.allen@gmail.com>2019-02-07 22:31:26 -0700
committerGitHub <noreply@github.com>2019-02-07 22:31:26 -0700
commit453e5e90ffb2685a3c49a1452c7986deeef804ba (patch)
tree8737c430e20e4fcc869548fef65337bb5c8fdf81
parentfe75b2af5faf43b25c59fce6df0685d8fb693144 (diff)
resolves #3056 create a template converter even if backend is not recognized (PR #3057)
-rw-r--r--lib/asciidoctor/converter.rb12
-rw-r--r--test/converter_test.rb6
-rw-r--r--test/fixtures/custom-backends/haml/html5-tweaks/embedded.html.haml1
3 files changed, 14 insertions, 5 deletions
diff --git a/lib/asciidoctor/converter.rb b/lib/asciidoctor/converter.rb
index a50944e7..a82464c7 100644
--- a/lib/asciidoctor/converter.rb
+++ b/lib/asciidoctor/converter.rb
@@ -203,9 +203,8 @@ module Converter
registry[backend]
end
- # Public: Create a new Converter object that can be used to convert the {AbstractNode} (typically a {Document}) to
- # the format suggested by the backend. This method accepts an optional Hash of options that are passed on to the
- # converter's constructor.
+ # Public: Create a new Converter object that can be used to convert {AbstractNode}s to the format associated with
+ # the backend. This method accepts an optional Hash of options that are passed to the converter's constructor.
#
# If a custom Converter is found to convert the specified backend, it's instantiated (if necessary) and returned
# immediately. If a custom Converter is not found, an attempt is made to find a built-in converter. If the
@@ -220,13 +219,16 @@ module Converter
#
# Returns the [Converter] instance.
def create backend, opts = {}
+ template_dirs = opts[:template_dirs]
if (converter = self.for backend)
converter = converter.new backend, opts if ::Class === converter
- if opts[:template_dirs] && BackendTraits === converter && converter.supports_templates?
- CompositeConverter.new backend, (TemplateConverter.new backend, opts[:template_dirs], opts), converter, backend_traits_source: converter
+ if template_dirs && BackendTraits === converter && converter.supports_templates?
+ CompositeConverter.new backend, (TemplateConverter.new backend, template_dirs, opts), converter, backend_traits_source: converter
else
converter
end
+ elsif template_dirs
+ TemplateConverter.new backend, template_dirs, opts
end
end
diff --git a/test/converter_test.rb b/test/converter_test.rb
index db11d1a0..35b81be9 100644
--- a/test/converter_test.rb
+++ b/test/converter_test.rb
@@ -153,6 +153,12 @@ context 'Converter' do
assert_xpath '//aside/header/following-sibling::p[text()="Sidebar content"]', output, 1
end
+ test 'should create template converter even when a converter is not registered for the specified backend' do
+ input = 'paragraph content'
+ output = convert_string_to_embedded input, backend: :unknown, template_dir: (fixture_path 'custom-backends/haml/html5-tweaks'), template_cache: false
+ assert_equal '<p>paragraph content</p>', output
+ end
+
test 'should use built-in global cache to cache templates' do
begin
Asciidoctor::Converter::TemplateConverter.clear_caches if defined? Asciidoctor::Converter::TemplateConverter
diff --git a/test/fixtures/custom-backends/haml/html5-tweaks/embedded.html.haml b/test/fixtures/custom-backends/haml/html5-tweaks/embedded.html.haml
new file mode 100644
index 00000000..7125c22c
--- /dev/null
+++ b/test/fixtures/custom-backends/haml/html5-tweaks/embedded.html.haml
@@ -0,0 +1 @@
+=content