diff --git a/README.adoc b/README.adoc index ca69f98..6e3d223 100644 --- a/README.adoc +++ b/README.adoc @@ -80,14 +80,14 @@ DocTest.examples_path.unshift 'test/examples/asciidoc' DocTest.examples_path.unshift 'test/examples/shiny' ---- -. Create test file `test/templates_test.rb` and extend class link:{src-base}/test.rb[DocTest::Test]. Specify `renderer_opts` and then call `generate_tests!` macro with a specific subclass of `BaseExamplesSuite`: +. Create test file `test/templates_test.rb` and extend class link:{src-base}/test.rb[DocTest::Test]. Specify `converter_opts` and then call `generate_tests!` macro with a specific subclass of `BaseExamplesSuite`: + [source] ---- require 'test_helper' class TestTemplates < DocTest::Test - renderer_opts template_dirs: 'data/templates' + converter_opts template_dirs: 'data/templates' generate_tests! DocTest::HTML::ExamplesSuite end ---- @@ -109,7 +109,7 @@ end DocTest::GeneratorTask.new(:generate) do |task| task.output_suite = DocTest::HTML::ExamplesSuite.new(examples_path: 'test/examples/shiny') - task.renderer_opts[:template_dirs] = 'data/templates' + task.converter_opts[:template_dirs] = 'data/templates' # # add extra input examples (optional) task.examples_path.unshift 'test/examples/asciidoc' @@ -223,7 +223,7 @@ If it’s not your case, then you must overwrite it: [source] ---- class TestShiny < DocTest::Test - renderer_opts template_dirs: 'data/templates' + converter_opts template_dirs: 'data/templates' generate_tests! DocTest::HTML::ExamplesSuite.new(paragraph_xpath: './div/p/node()') end ---- diff --git a/lib/asciidoctor/doctest/asciidoc_renderer.rb b/lib/asciidoctor/doctest/asciidoc_renderer.rb index 9c02210..bcd5b28 100644 --- a/lib/asciidoctor/doctest/asciidoc_renderer.rb +++ b/lib/asciidoctor/doctest/asciidoc_renderer.rb @@ -5,7 +5,7 @@ module Asciidoctor module DocTest ## - # This class is basically a wrapper for +Asciidoctor.render+ that allows to + # This class is basically a wrapper for +Asciidoctor.convert+ that allows to # preset and validate some common parameters. class AsciidocRenderer @@ -49,23 +49,26 @@ def initialize(backend_name: nil, converter: nil, template_dirs: [], end ## - # Renders the given +text+ in AsciiDoc syntax with Asciidoctor using the - # tested backend. + # Converts the given +text+ into AsciiDoc syntax with Asciidoctor using + # the tested backend. # # @param text [#to_s] the input text in AsciiDoc syntax. # @param opts [Hash] options to pass to Asciidoctor. - # @return [String] rendered input. + # @return [String] converted input. # - def render(text, opts = {}) - renderer_opts = { + def convert(text, opts = {}) + converter_opts = { safe: :safe, backend: backend_name, converter: converter, template_dirs: template_dirs }.merge(opts) - Asciidoctor.render(text.to_s, renderer_opts) + Asciidoctor.convert(text.to_s, converter_opts) end + + # Alias for backward compatibility. + alias_method :render, :convert end ## diff --git a/lib/asciidoctor/doctest/base_examples_suite.rb b/lib/asciidoctor/doctest/base_examples_suite.rb index c871eeb..29e7824 100644 --- a/lib/asciidoctor/doctest/base_examples_suite.rb +++ b/lib/asciidoctor/doctest/base_examples_suite.rb @@ -62,7 +62,7 @@ def serialize(examples) # @abstract # @param example [BaseExample] the input example to convert. # @param opts [Hash] the options to pass to a new example. - # @param renderer [#render] + # @param renderer [#convert] # @return [BaseExample] # :nocov: def convert_example(example, opts, renderer) diff --git a/lib/asciidoctor/doctest/generator.rb b/lib/asciidoctor/doctest/generator.rb index 5b1f6ed..8ce1dbd 100644 --- a/lib/asciidoctor/doctest/generator.rb +++ b/lib/asciidoctor/doctest/generator.rb @@ -17,7 +17,7 @@ module Generator # {BaseExamplesSuite} subclass to read the reference input # examples. # - # @param renderer [#render] + # @param renderer [#convert] # # @param pattern [String] glob-like pattern to select examples to # (re)generate (see {BaseExample#name_match?}). diff --git a/lib/asciidoctor/doctest/generator_task.rb b/lib/asciidoctor/doctest/generator_task.rb index 4892d18..0482a29 100644 --- a/lib/asciidoctor/doctest/generator_task.rb +++ b/lib/asciidoctor/doctest/generator_task.rb @@ -39,13 +39,16 @@ class GeneratorTask < Rake::TaskLib # (default: *:*). attr_accessor :pattern - # @return [Hash] options for Asciidoctor renderer. + # @return [Hash] options for Asciidoctor converter. # @see AsciidocRenderer#initialize - attr_accessor :renderer_opts + attr_accessor :converter_opts # @return [String] title of the task's description. attr_accessor :title + # Alias for backward compatibility. + alias_method :renderer_opts, :converter_opts + ## # @param name [#to_sym] name of the task. @@ -56,7 +59,7 @@ def initialize(name) @force = false @input_suite = nil @output_suite = nil - @renderer_opts = {} + @converter_opts = {} @pattern = '*:*' @title = "Generate testing examples #{pattern}#{" for #{name}" if name != :generate}." @@ -68,7 +71,7 @@ def initialize(name) end @input_suite ||= Asciidoc::ExamplesSuite.new(examples_path: @examples_path) - @renderer ||= AsciidocRenderer.new(renderer_opts) + @renderer ||= AsciidocRenderer.new(converter_opts) define end diff --git a/lib/asciidoctor/doctest/html/examples_suite.rb b/lib/asciidoctor/doctest/html/examples_suite.rb index c02c2b7..1873011 100644 --- a/lib/asciidoctor/doctest/html/examples_suite.rb +++ b/lib/asciidoctor/doctest/html/examples_suite.rb @@ -81,7 +81,7 @@ def create_example(*args) def convert_example(example, opts, renderer) header_footer = !!opts[:header_footer] || example.name.start_with?('document') - html = renderer.render(example.to_s, header_footer: header_footer) + html = renderer.convert(example.to_s, header_footer: header_footer) html = parse_html(html, !header_footer) # When asserting inline examples, ignore paragraph "wrapper". diff --git a/lib/asciidoctor/doctest/test.rb b/lib/asciidoctor/doctest/test.rb index 832f16f..9530ef1 100644 --- a/lib/asciidoctor/doctest/test.rb +++ b/lib/asciidoctor/doctest/test.rb @@ -14,10 +14,13 @@ class Test < Minitest::Test ## # (see AsciidocRenderer#initialize) - def self.renderer_opts(**kwargs) + def self.converter_opts(**kwargs) @renderer = AsciidocRenderer.new(**kwargs) end + # Alias for backward compatibility. + alias_class_method :renderer_opts, :converter_opts + ## # Generates tests for all the input/output examples. # When some output example is missing, it's reported as skipped test. diff --git a/spec/html/examples_suite_spec.rb b/spec/html/examples_suite_spec.rb index 9bf560b..f5a46b1 100644 --- a/spec/html/examples_suite_spec.rb +++ b/spec/html/examples_suite_spec.rb @@ -155,7 +155,7 @@ let(:input) { create_example 's:dummy', content: '*chunky* bacon' } let(:opts) { {dummy: 'value'} } let(:renderer) { double 'AsciidocRenderer' } - let(:renderer_opts) { {header_footer: false} } + let(:converter_opts) { {header_footer: false} } subject(:result) { suite.convert_example input, opts, renderer } @@ -175,8 +175,8 @@ end before do - expect(renderer).to receive(:render) - .with(input.content, renderer_opts).and_return(rendered) + expect(renderer).to receive(:convert) + .with(input.content, converter_opts).and_return(rendered) end it 'returns instance of HTML::Example' do @@ -218,7 +218,7 @@ context 'with example named /^document.*/' do let(:input) { create_example 'document:dummy', content: '*chunky* bacon' } - let(:renderer_opts) { {header_footer: true} } + let(:converter_opts) { {header_footer: true} } it 'renders content with :header_footer => true' do suite.convert_example input, {}, renderer