class Asciidoctor::DocTest::GeneratorTask

Rake task for generating output examples. @see Generator

Constants

TRUE_VALUES

List of values representing true.

Attributes

converter_opts[RW]

@return [Hash] options for Asciidoctor converter. @see AsciidocRenderer#initialize

examples_path[RW]

This attribute is used only for the default {#input_suite}. @return (see DocTest.examples_path)

force[RW]

@return [Boolean] whether to rewrite an already existing testing

example. May be overriden with +FORCE+ variable on the command line
(default: false).
input_suite[RW]

@return [BaseExamplesSuite] an instance of {BaseExamplesSuite} subclass

to read the reference input examples
(default: +Asciidoc::ExamplesSuite.new(examples_path: examples_path)+).
name[RW]

@return [#to_sym] name of the task.

output_suite[RW]

@return [BaseExamplesSuite] an instance of {BaseExamplesSuite} subclass

to read and generate the output examples.
pattern[RW]

@return [String] glob pattern to select examples to (re)generate.

May be overriden with +PATTERN+ variable on the command line
(default: *:*).
renderer_opts[RW]

@return [Hash] options for Asciidoctor converter. @see AsciidocRenderer#initialize

title[RW]

@return [String] title of the task’s description.

Public Class Methods

new(name) { |self| ... } click to toggle source

@param name [#to_sym] name of the task. @yield The block to configure this task.

# File lib/asciidoctor/doctest/generator_task.rb, line 57
def initialize(name)
  @name = name
  @examples_path = DocTest.examples_path.dup
  @force = false
  @input_suite = nil
  @output_suite = nil
  @converter_opts = {}
  @pattern = '*:*'
  @title = "Generate testing examples #{pattern}#{" for #{name}" if name != :generate}."

  yield self

  fail 'The output_suite is not provided!' unless @output_suite
  if @output_suite.examples_path.first == DocTest::BUILTIN_EXAMPLES_PATH
    fail "The examples_path in output suite is invalid: #{@output_suite.examples_path}"
  end

  @input_suite ||= Asciidoc::ExamplesSuite.new(examples_path: @examples_path)
  @renderer ||= AsciidocRenderer.new(converter_opts)

  define
end

Public Instance Methods

force?() click to toggle source
# File lib/asciidoctor/doctest/generator_task.rb, line 84
def force?
  return TRUE_VALUES.include?(ENV['FORCE'].downcase) if ENV.key? 'FORCE'
  !!force
end

Private Instance Methods

define() click to toggle source
# File lib/asciidoctor/doctest/generator_task.rb, line 91
def define
  desc description

  task name.to_sym do
    puts title
    Generator.generate! output_suite, input_suite, @renderer,
                        pattern: pattern, rewrite: force?
  end
  self
end
description() click to toggle source
# File lib/asciidoctor/doctest/generator_task.rb, line 102
      def description
        <<-EOS.unindent
          #{title}

          Options (environment variables):
            PATTERN   glob pattern to select examples to (re)generate. [default: #{@pattern}]
                      E.g. *:*, block_toc:basic, block*:*, *list:with*, ...
            FORCE     overwrite existing examples (yes/no)? [default: #{@force ? 'yes' : 'no'}]

        EOS
      end