Module: Asciidoctor::Reducer

Defined in:
lib/asciidoctor/reducer/version.rb,
lib/asciidoctor/reducer/extensions.rb,
lib/asciidoctor/reducer/preprocessor.rb,
lib/asciidoctor/reducer/tree_processor.rb,
lib/asciidoctor/reducer/include_mapper/extension.rb,
lib/asciidoctor/reducer/include_directive_tracker.rb,
lib/asciidoctor/reducer/conditional_directive_tracker.rb,
lib/asciidoctor/reducer/cli.rb,
lib/asciidoctor/reducer/api.rb

Defined Under Namespace

Modules: Cli, ConditionalDirectiveTracker, Extensions, IncludeDirectiveTracker Classes: IncludeMapper, Preprocessor, TreeProcessor

Constant Summary collapse

VERSION =
'1.0.6'

Class Method Summary collapse

Class Method Details

.reduce(input, opts = {}) ⇒ Asciidoctor::Document?

Reduces the AsciiDoc source and either returns the reduced Asciidoctor::Document or writes the source to a file.

This method accepts all the options supported by Asciidoctor.load.

Parameters:

  • input (String, File, Pathname)

    the AsciiDoc source to reduce.

  • opts (Hash) (defaults to: {})

    additional options to configure the behavior of the reducer.

Options Hash (opts):

  • :to (File, Pathname, Class) — default: nil

    the target to which to write the reduced source.

Returns:

  • (Asciidoctor::Document, nil)

    the reduced document object or nil if the :to option is specified.



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/asciidoctor/reducer/api.rb', line 19

def reduce input, opts = {}
  opts = opts&.merge || {}
  if (extension_registry = Extensions.prepare_registry opts[:extension_registry] || opts[:extensions])
    opts[:extension_registry] = extension_registry
  end
  opts[:safe] ||= :safe
  to = opts.delete :to
  case input
  when ::File
    doc = ::Asciidoctor.load_file input, opts
  when ::Pathname
    doc = ::Asciidoctor.load_file input.to_path, opts
  else
    doc = ::Asciidoctor.load input, opts
  end
  write doc, to
end

.reduce_file(input_file, opts = {}) ⇒ Asciidoctor::Document?

Reduces the AsciiDoc file and either returns the reduced Asciidoctor::Document or writes the source to a file.

This method accepts all the options supported by Asciidoctor.load.

Parameters:

  • input_file (String)

    the path of the AsciiDoc file to reduce.

  • opts (Hash) (defaults to: {})

    additional options to configure the behavior of the reducer.

Options Hash (opts):

  • :to (File, Pathname, Class) — default: nil

    the target to which to write the reduced source.

Returns:

  • (Asciidoctor::Document, nil)

    the reduced document object or nil if the :to option is specified.



46
47
48
# File 'lib/asciidoctor/reducer/api.rb', line 46

def reduce_file input_file, opts = {}
  reduce (::Pathname.new input_file), opts
end