class Asciidoctor::DocTest::GeneratorTask
Rake task for generating output examples. @see Generator
Constants
- TRUE_VALUES
List of values representing
true
.
Attributes
@return [Hash] options for Asciidoctor
converter. @see AsciidocRenderer#initialize
This attribute is used only for the default {#input_suite}. @return (see DocTest.examples_path
)
@return [Boolean] whether to rewrite an already existing testing
example. May be overriden with +FORCE+ variable on the command line (default: false).
@return [BaseExamplesSuite] an instance of {BaseExamplesSuite} subclass
to read the reference input examples (default: +Asciidoc::ExamplesSuite.new(examples_path: examples_path)+).
@return [#to_sym] name of the task.
@return [BaseExamplesSuite] an instance of {BaseExamplesSuite} subclass
to read and generate the output examples.
@return [String] glob pattern to select examples to (re)generate.
May be overriden with +PATTERN+ variable on the command line (default: *:*).
@return [Hash] options for Asciidoctor
converter. @see AsciidocRenderer#initialize
@return [String] title of the task’s description.
Public Class Methods
@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
# 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
# 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
# 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