Skip to content

Commit

Permalink
Rename render/renderer_opts to convert/converter_opts (fixes #2)
Browse files Browse the repository at this point in the history
To be consistent with Asciidoctor.
  • Loading branch information
jirutka committed Dec 25, 2014
1 parent 232d905 commit 97c06af
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 23 deletions.
8 changes: 4 additions & 4 deletions README.adoc
Expand Up @@ -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
----
Expand All @@ -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'
Expand Down Expand Up @@ -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
----
Expand Down
17 changes: 10 additions & 7 deletions lib/asciidoctor/doctest/asciidoc_renderer.rb
Expand Up @@ -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

Expand Down Expand Up @@ -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

##
Expand Down
2 changes: 1 addition & 1 deletion lib/asciidoctor/doctest/base_examples_suite.rb
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion lib/asciidoctor/doctest/generator.rb
Expand Up @@ -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?}).
Expand Down
11 changes: 7 additions & 4 deletions lib/asciidoctor/doctest/generator_task.rb
Expand Up @@ -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.
Expand All @@ -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}."

Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/asciidoctor/doctest/html/examples_suite.rb
Expand Up @@ -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".
Expand Down
5 changes: 4 additions & 1 deletion lib/asciidoctor/doctest/test.rb
Expand Up @@ -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.
Expand Down
8 changes: 4 additions & 4 deletions spec/html/examples_suite_spec.rb
Expand Up @@ -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 }

Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 97c06af

Please sign in to comment.