class Asciidoctor::Extensions::Registry

stored in the registry during parsing.
methods for registering or defining a processor and looks up extensions
Registry holds the extensions which have been registered and activated, has
Public: The primary entry point into the extension system.

def activate document

Returns the instance of this [Registry].

document - the {Asciidoctor::Document} on which the extensions are to be used.

associated with this registry.
Public: Activates all the global extension {Group}s and the extension {Group}s
def activate document
  @document = document
  unless (ext_groups = Extensions.groups.values + @groups.values).empty?
    ext_groups.each do |group|
      case group
      when ::Proc
        case group.arity
        when 0, -1
          instance_exec(&group)
        when 1
          group.call self
        end
      when ::Class
        group.new.activate self
      else
        group.activate self
      end
    end
  end
  self
end

def add_document_processor kind, args, &block

def add_document_processor kind, args, &block
  kind_name = kind.to_s.tr '_', ' '
  kind_class_symbol = kind_name.split.map {|it| it.capitalize }.join.to_sym
  kind_class = Extensions.const_get kind_class_symbol, false
  kind_java_class = (defined? ::AsciidoctorJ) ? (::AsciidoctorJ::Extensions.const_get kind_class_symbol, false) : nil
  kind_store = instance_variable_get(%(@#{kind}_extensions).to_sym) || instance_variable_set(%(@#{kind}_extensions).to_sym, [])
  # style 1: specified as block
  extension = if block_given?
    config = resolve_args args, 1
    (processor = kind_class.new config).singleton_class.enable_dsl
    if block.arity == 0
      processor.instance_exec(&block)
    else
      yield processor
    end
    unless processor.process_block_given?
      raise ::ArgumentError, %(No block specified to process #{kind_name} extension at #{block.source_location})
    end
    processor.freeze
    ProcessorExtension.new kind, processor
  else
    processor, config = resolve_args args, 2
    # style 2: specified as Class or String class name
    if (processor_class = Helpers.resolve_class processor)
      unless processor_class < kind_class || (kind_java_class && processor_class < kind_java_class)
        raise ::ArgumentError, %(Invalid type for #{kind_name} extension: #{processor})
      end
      processor_instance = processor_class.new config
      processor_instance.freeze
      ProcessorExtension.new kind, processor_instance
    # style 3: specified as instance
    elsif kind_class === processor || (kind_java_class && kind_java_class === processor)
      processor.update_config config
      processor.freeze
      ProcessorExtension.new kind, processor
    else
      raise ::ArgumentError, %(Invalid arguments specified for registering #{kind_name} extension: #{args})
    end
  end
  extension.config[:position] == :>> ? (kind_store.unshift extension) : (kind_store << extension)
  extension
end

def add_syntax_processor kind, args, &block

def add_syntax_processor kind, args, &block
  kind_name = kind.to_s.tr '_', ' '
  kind_class_symbol = (kind_name.split.map {|it| it.capitalize } << 'Processor').join.to_sym
  kind_class = Extensions.const_get kind_class_symbol, false
  kind_java_class = (defined? ::AsciidoctorJ) ? (::AsciidoctorJ::Extensions.const_get kind_class_symbol, false) : nil
  kind_store = instance_variable_get(%(@#{kind}_extensions).to_sym) || instance_variable_set(%(@#{kind}_extensions).to_sym, {})
  # style 1: specified as block
  if block_given?
    name, config = resolve_args args, 2
    (processor = kind_class.new (as_symbol name), config).singleton_class.enable_dsl
    if block.arity == 0
      processor.instance_exec(&block)
    else
      yield processor
    end
    unless (name = as_symbol processor.name)
      raise ::ArgumentError, %(No name specified for #{kind_name} extension at #{block.source_location})
    end
    unless processor.process_block_given?
      raise ::NoMethodError, %(No block specified to process #{kind_name} extension at #{block.source_location})
    end
    processor.freeze
    kind_store[name] = ProcessorExtension.new kind, processor
  else
    processor, name, config = resolve_args args, 3
    # style 2: specified as Class or String class name
    if (processor_class = Helpers.resolve_class processor)
      unless processor_class < kind_class || (kind_java_class && processor_class < kind_java_class)
        raise ::ArgumentError, %(Class specified for #{kind_name} extension does not inherit from #{kind_class}: #{processor})
      end
      processor_instance = processor_class.new as_symbol(name), config
      unless (name = as_symbol processor_instance.name)
        raise ::ArgumentError, %(No name specified for #{kind_name} extension: #{processor})
      end
      processor_instance.freeze
      kind_store[name] = ProcessorExtension.new kind, processor_instance
    # style 3: specified as instance
    elsif kind_class === processor || (kind_java_class && kind_java_class === processor)
      processor.update_config config
      # TODO need a test for this override!
      unless (name = name ? (processor.name = as_symbol name) : (as_symbol processor.name))
        raise ::ArgumentError, %(No name specified for #{kind_name} extension: #{processor})
      end
      processor.freeze
      kind_store[name] = ProcessorExtension.new kind, processor
    else
      raise ::ArgumentError, %(Invalid arguments specified for registering #{kind_name} extension: #{args})
    end
  end
end

def as_symbol name

def as_symbol name
  name ? name.to_sym : nil
end

def block *args, &block

registry and manages the instance of this BlockProcessor.
Returns an instance of the [Extension] proxy object that is stored in the

end
end
...
process do |parent, reader, attrs|
block :shout do
# as a method block with an explicit block name

end
end
...
process do |parent, reader, attrs|
named :shout
block do
# as a method block

block 'ShoutBlock', :shout
# as a name of a BlockProcessor subclass with an explicit block name

block 'ShoutBlock'
# as a name of a BlockProcessor subclass

block ShoutBlock.new, :shout
# as an instance of a BlockProcessor subclass with an explicit block name

block ShoutBlock.new
# as an instance of a BlockProcessor subclass

block ShoutBlock, :shout
# as a BlockProcessor subclass with an explicit block name

block ShoutBlock
# as a BlockProcessor subclass

Examples

is raised.
BlockProcessor instance. If a name still cannot be determined, an error
is not passed as an argument, it gets read from the name property of the
paragraph) that this processor is registered to handle. If a block name
to a Symbol) of the AsciiDoc block content (i.e., delimited block or
first argument to this method. The second argument is the name (coersed
Unless the BlockProcessor is passed as the method block, it must be the

* A method block (i.e., Proc) that conforms to the BlockProcessor contract
* The String name of a BlockProcessor subclass
* An instance of a BlockProcessor subclass
* A BlockProcessor subclass

The BlockProcessor may be one of four types:

AsciiDoc source annotated with the specified block name (i.e., style).
process the block content (i.e., delimited block or paragraph) in the
Public: Registers a {BlockProcessor} with the extension registry to
def block *args, &block
  add_syntax_processor :block, args, &block
end

def block_macro *args, &block

registry and manages the instance of this BlockMacroProcessor.
Returns an instance of the [Extension] proxy object that is stored in the

end
end
...
process do |parent, target, attrs|
block_macro :gist do
# as a method block with an explicit macro name

end
end
...
process do |parent, target, attrs|
named :gist
block_macro do
# as a method block

block_macro 'GistBlockMacro', :gist
# as a name of a BlockMacroProcessor subclass with an explicit macro name

block_macro 'GistBlockMacro'
# as a name of a BlockMacroProcessor subclass

block_macro GistBlockMacro.new, :gist
# as an instance of a BlockMacroProcessor subclass with an explicit macro name

block_macro GistBlockMacro.new
# as an instance of a BlockMacroProcessor subclass

block_macro GistBlockMacro, :gist
# as a BlockMacroProcessor subclass with an explicit macro name

block_macro GistBlockMacro
# as a BlockMacroProcessor subclass

Examples

If a name still cannot be determined, an error is raised.
it gets read from the name property of the BlockMacroProcessor instance.
registered to handle. If a block macro name is not passed as an argument,
(coersed to a Symbol) of the AsciiDoc block macro that this processor is
the first argument to this method. The second argument is the name
Unless the BlockMacroProcessor is passed as the method block, it must be

* A method block (i.e., Proc) that conforms to the BlockMacroProcessor contract
* The String name of a BlockMacroProcessor subclass
* An instance of a BlockMacroProcessor subclass
* A BlockMacroProcessor subclass

The BlockMacroProcessor may be one of four types:

process a block macro with the specified name.
Public: Registers a {BlockMacroProcessor} with the extension registry to
def block_macro *args, &block
  add_syntax_processor :block_macro, args, &block
end

def block_macros?

Returns a [Boolean] indicating whether any BlockMacroProcessor extensions are registered.

Public: Checks whether any {BlockMacroProcessor} extensions have been registered.
def block_macros?
  !!@block_macro_extensions
end

def blocks?

Returns a [Boolean] indicating whether any BlockProcessor extensions are registered.

Public: Checks whether any {BlockProcessor} extensions have been registered.
def blocks?
  !!@block_extensions
end

def docinfo_processor *args, &block

instance of this DocinfoProcessor.
Returns the [Extension] stored in the registry that proxies the

end
end
'footer content'
at_location :footer
process do |doc|
docinfo_processor do
# as a method block

docinfo_processor 'MetaRobotsDocinfoProcessor'
# as a name of a DocinfoProcessor subclass

docinfo_processor JQueryDocinfoProcessor.new, location: :footer
# as an instance of a DocinfoProcessor subclass with an explicit location

docinfo_processor MetaRobotsDocinfoProcessor
# as an DocinfoProcessor subclass

Examples

first argument to this method.
Unless the DocinfoProcessor is passed as the method block, it must be the

* A method block (i.e., Proc) that conforms to the DocinfoProcessor contract
* The String name of a DocinfoProcessor subclass
* An instance of a DocinfoProcessor subclass
* A DocinfoProcessor subclass

The DocinfoProcessor may be one of four types:

add additionnal docinfo to the document.
Public: Registers an {DocinfoProcessor} with the extension registry to
def docinfo_processor *args, &block
  add_document_processor :docinfo_processor, args, &block
end

def docinfo_processors location = nil

Returns an [Array] of Extension proxy objects.

location - A Symbol for selecting docinfo extensions at a given location (:head or :footer) (default: nil)

DocinfoProcessor instances stored in this registry.
Public: Retrieves the {Extension} proxy objects for all the
def docinfo_processors location = nil
  if @docinfo_processor_extensions
    if location
      @docinfo_processor_extensions.select {|ext| ext.config[:location] == location }
    else
      @docinfo_processor_extensions
    end
  else
    nil
  end
end

def docinfo_processors? location = nil

Returns a [Boolean] indicating whether any DocinfoProcessor extensions are registered.

location - A Symbol for selecting docinfo extensions at a given location (:head or :footer) (default: nil)

Public: Checks whether any {DocinfoProcessor} extensions have been registered.
def docinfo_processors? location = nil
  if @docinfo_processor_extensions
    if location
      @docinfo_processor_extensions.any? {|ext| ext.config[:location] == location }
    else
      true
    end
  else
    false
  end
end

def find_block_extension name

corresponding BlockProcessor or nil if a match is not found.
Returns the [Extension] object stored in the registry that proxies the

name - the String or Symbol (coersed to a Symbol) macro name

to handle block content with the name.
Public: Retrieves the {Extension} proxy object for the BlockProcessor registered
def find_block_extension name
  @block_extensions[name.to_sym]
end

def find_block_macro_extension name

cooresponding BlockMacroProcessor or nil if a match is not found.
Returns the [Extension] object stored in the registry that proxies the

name - the String or Symbol (coersed to a Symbol) macro name

to handle a block macro with the specified name.
Public: Retrieves the {Extension} proxy object for the BlockMacroProcessor registered
def find_block_macro_extension name
  @block_macro_extensions[name.to_sym]
end

def find_inline_macro_extension name

cooresponding InlineMacroProcessor or nil if a match is not found.
Returns the [Extension] object stored in the registry that proxies the

name - the String or Symbol (coersed to a Symbol) macro name

to handle an inline macro with the specified name.
Public: Retrieves the {Extension} proxy object for the InlineMacroProcessor registered
def find_inline_macro_extension name
  @inline_macro_extensions[name.to_sym]
end

def include_processor *args, &block

instance of this IncludeProcessor.
Returns the [Extension] stored in the registry that proxies the

end
end
...
process do |document, output|
include_processor do
# as a method block

include_processor 'GitIncludeProcessor'
# as a name of a Postprocessor subclass

include_processor GitIncludeProcessor.new
# as an instance of a Postprocessor subclass

include_processor GitIncludeProcessor
# as an IncludeProcessor subclass

Examples

first argument to this method.
Unless the IncludeProcessor is passed as the method block, it must be the

* A method block (i.e., Proc) that conforms to the IncludeProcessor contract
* The String name of a IncludeProcessor subclass
* An instance of a IncludeProcessor subclass
* A IncludeProcessor subclass

The IncludeProcessor may be one of four types:

a shot at handling the include directive.
Public: Registers an {IncludeProcessor} with the extension registry to have
def include_processor *args, &block
  add_document_processor :include_processor, args, &block
end

def include_processors

Returns an [Array] of Extension proxy objects.

IncludeProcessor instances stored in this registry.
Public: Retrieves the {Extension} proxy objects for all the
def include_processors
  @include_processor_extensions
end

def include_processors?

Returns a [Boolean] indicating whether any IncludeProcessor extensions are registered.

Public: Checks whether any {IncludeProcessor} extensions have been registered.
def include_processors?
  !!@include_processor_extensions
end

def initialize groups = {}

def initialize groups = {}
  @groups = groups
  @preprocessor_extensions = @tree_processor_extensions = @postprocessor_extensions = @include_processor_extensions = @docinfo_processor_extensions = @block_extensions = @block_macro_extensions = @inline_macro_extensions = nil
  @document = nil
end

def inline_macro *args, &block

registry and manages the instance of this InlineMacroProcessor.
Returns an instance of the [Extension] proxy object that is stored in the

end
end
...
process do |parent, target, attrs|
inline_macro :chrome do
# as a method block with an explicit macro name

end
end
...
process do |parent, target, attrs|
named :chrome
inline_macro do
# as a method block

inline_macro 'ChromeInlineMacro', :chrome
# as a name of an InlineMacroProcessor subclass with an explicit macro name

inline_macro 'ChromeInlineMacro'
# as a name of an InlineMacroProcessor subclass

inline_macro ChromeInlineMacro.new, :chrome
# as an instance of an InlineMacroProcessor subclass with an explicit macro name

inline_macro ChromeInlineMacro.new
# as an instance of an InlineMacroProcessor subclass

inline_macro ChromeInlineMacro, :chrome
# as an InlineMacroProcessor subclass with an explicit macro name

inline_macro ChromeInlineMacro
# as an InlineMacroProcessor subclass

Examples

If a name still cannot be determined, an error is raised.
it gets read from the name property of the InlineMacroProcessor instance.
registered to handle. If a block macro name is not passed as an argument,
(coersed to a Symbol) of the AsciiDoc block macro that this processor is
the first argument to this method. The second argument is the name
Unless the InlineMacroProcessor is passed as the method block, it must be

* A method block (i.e., Proc) that conforms to the InlineMacroProcessor contract
* The String name of an InlineMacroProcessor subclass
* An instance of an InlineMacroProcessor subclass
* An InlineMacroProcessor subclass

The InlineMacroProcessor may be one of four types:

process an inline macro with the specified name.
Public: Registers a {InlineMacroProcessor} with the extension registry to
def inline_macro *args, &block
  add_syntax_processor :inline_macro, args, &block
end

def inline_macros

Returns an [Array] of Extension proxy objects.

InlineMacroProcessor instances in this registry.
Public: Retrieves the {Extension} proxy objects for all
def inline_macros
  @inline_macro_extensions.values
end

def inline_macros?

Returns a [Boolean] indicating whether any IncludeMacroProcessor extensions are registered.

Public: Checks whether any {InlineMacroProcessor} extensions have been registered.
def inline_macros?
  !!@inline_macro_extensions
end

def postprocessor *args, &block

instance of this Postprocessor.
Returns the [Extension] stored in the registry that proxies the

end
end
...
process do |document, output|
postprocessor do
# as a method block

postprocessor 'AnalyticsPostprocessor'
# as a name of a Postprocessor subclass

postprocessor AnalyticsPostprocessor.new
# as an instance of a Postprocessor subclass

postprocessor AnalyticsPostprocessor
# as a Postprocessor subclass

Examples

first argument to this method.
Unless the Postprocessor is passed as the method block, it must be the

* A method block (i.e., Proc) that conforms to the Postprocessor contract
* The String name of a Postprocessor subclass
* An instance of a Postprocessor subclass
* A Postprocessor subclass

The Postprocessor may be one of four types:

the output after conversion is complete.
Public: Registers a {Postprocessor} with the extension registry to process
def postprocessor *args, &block
  add_document_processor :postprocessor, args, &block
end

def postprocessors

Returns an [Array] of Extension proxy objects.

Postprocessor instances in this registry.
Public: Retrieves the {Extension} proxy objects for all
def postprocessors
  @postprocessor_extensions
end

def postprocessors?

Returns a [Boolean] indicating whether any Postprocessor extensions are registered.

Public: Checks whether any {Postprocessor} extensions have been registered.
def postprocessors?
  !!@postprocessor_extensions
end

def prefer *args, &block

of this processor.
Returns the [Extension] stored in the registry that proxies the instance

end
end
...
process do |document, reader, target, attrs|
prefer :include_processor do

Examples

processor of its kind in the extension registry.
Public: Inserts the document processor {Extension} instance as the first
def prefer *args, &block
  extension = ProcessorExtension === (arg0 = args.shift) ? arg0 : (send arg0, *args, &block)
  extensions_store = instance_variable_get(%(@#{extension.kind}_extensions).to_sym)
  extensions_store.unshift extensions_store.delete extension
  extension
end

def preprocessor *args, &block

instance of this Preprocessor.
Returns the [Extension] stored in the registry that proxies the

end
end
...
process do |doc, reader|
preprocessor do
# as a method block

preprocessor 'FrontMatterPreprocessor'
# as a name of a Preprocessor subclass

preprocessor FrontMatterPreprocessor.new
# as an instance of a Preprocessor subclass

preprocessor FrontMatterPreprocessor
# as a Preprocessor subclass

Examples

first argument to this method.
Unless the Preprocessor is passed as the method block, it must be the

* A method block (i.e., Proc) that conforms to the Preprocessor contract
* The String name of a Preprocessor subclass
* An instance of a Preprocessor subclass
* A Preprocessor subclass

The Preprocessor may be one of four types:

the AsciiDoc source before parsing begins.
Public: Registers a {Preprocessor} with the extension registry to process
def preprocessor *args, &block
  add_document_processor :preprocessor, args, &block
end

def preprocessors

Returns an [Array] of Extension proxy objects.

Preprocessor instances in this registry.
Public: Retrieves the {Extension} proxy objects for all
def preprocessors
  @preprocessor_extensions
end

def preprocessors?

Returns a [Boolean] indicating whether any Preprocessor extensions are registered.

Public: Checks whether any {Preprocessor} extensions have been registered.
def preprocessors?
  !!@preprocessor_extensions
end

def registered_for_block? name, context

the block name and context or false if no match is found.
Returns the [Extension] proxy object for the BlockProcessor that matches

handle the specified block name appearing on the specified context.
Public: Checks whether any {BlockProcessor} extensions are registered to
def registered_for_block? name, context
  if (ext = @block_extensions[name.to_sym])
    (ext.config[:contexts].include? context) ? ext : false
  else
    false
  end
end

def registered_for_block_macro? name

TODO only allow blank target if format is :short
--
the macro name or false if no match is found.
Returns the [Extension] proxy object for the BlockMacroProcessor that matches

name - the String or Symbol (coersed to a Symbol) macro name

handle the block macro with the specified name.
Public: Checks whether any {BlockMacroProcessor} extensions are registered to
def registered_for_block_macro? name
  (ext = @block_macro_extensions[name.to_sym]) ? ext : false
end

def registered_for_inline_macro? name

the macro name or false if no match is found.
Returns the [Extension] proxy object for the InlineMacroProcessor that matches

name - the String or Symbol (coersed to a Symbol) macro name

handle the inline macro with the specified name.
Public: Checks whether any {InlineMacroProcessor} extensions are registered to
def registered_for_inline_macro? name
  (ext = @inline_macro_extensions[name.to_sym]) ? ext : false
end

def resolve_args args, expect

def resolve_args args, expect
  opts = ::Hash === args[-1] ? args.pop : {}
  return opts if expect == 1
  if (missing = expect - 1 - args.size) > 0
    args += (::Array.new missing)
  elsif missing < 0
    args.pop(-missing)
  end
  args << opts
  args
end

def tree_processor *args, &block

instance of this TreeProcessor.
Returns the [Extension] stored in the registry that proxies the

end
end
...
process do |document|
tree_processor do
# as a method block

tree_processor 'ShellTreeProcessor'
# as a name of a TreeProcessor subclass

tree_processor ShellTreeProcessor.new
# as an instance of a TreeProcessor subclass

tree_processor ShellTreeProcessor
# as a TreeProcessor subclass

Examples

first argument to this method.
Unless the TreeProcessor is passed as the method block, it must be the

* A method block (i.e., Proc) that conforms to the TreeProcessor contract
* The String name of a TreeProcessor subclass
* An instance of a TreeProcessor subclass
* A TreeProcessor subclass

The TreeProcessor may be one of four types:

the AsciiDoc source after parsing is complete.
Public: Registers a {TreeProcessor} with the extension registry to process
def tree_processor *args, &block
  add_document_processor :tree_processor, args, &block
end

def tree_processors

Returns an [Array] of Extension proxy objects.

TreeProcessor instances in this registry.
Public: Retrieves the {Extension} proxy objects for all
def tree_processors
  @tree_processor_extensions
end

def tree_processors?

Returns a [Boolean] indicating whether any TreeProcessor extensions are registered.

Public: Checks whether any {TreeProcessor} extensions have been registered.
def tree_processors?
  !!@tree_processor_extensions
end