Module: Asciidoctor::Extensions

Defined in:
lib/asciidoctor/extensions.rb

Overview

Asciidoctor processor.

Defined Under Namespace

Modules: BlockProcessorDsl, DocinfoProcessorDsl, DocumentProcessorDsl, IncludeProcessorDsl, InlineMacroProcessorDsl, MacroProcessorDsl, SyntaxProcessorDsl Classes: BlockMacroProcessor, BlockProcessor, DocinfoProcessor, Extension, Group, IncludeProcessor, InlineMacroProcessor, MacroProcessor, Postprocessor, Preprocessor, Processor, ProcessorExtension, Registry, TreeProcessor

Constant Summary collapse

Treeprocessor =

Alias deprecated class name for backwards compatibility

TreeProcessor

Class Method Summary collapse

Class Method Details

.create(name = nil, &block) ⇒ Object



1491
1492
1493
1494
1495
1496
1497
# File 'lib/asciidoctor/extensions.rb', line 1491

def create name = nil, &block
  if block_given?
    Registry.new (name || generate_name) => block
  else
    Registry.new
  end
end

.generate_nameObject



1478
1479
1480
# File 'lib/asciidoctor/extensions.rb', line 1478

def generate_name
  %(extgrp#{next_auto_id})
end

.groupsObject



1487
1488
1489
# File 'lib/asciidoctor/extensions.rb', line 1487

def groups
  @groups ||= {}
end

.next_auto_idObject



1482
1483
1484
1485
# File 'lib/asciidoctor/extensions.rb', line 1482

def next_auto_id
  @auto_id ||= -1
  @auto_id += 1
end

.register(*args, &block) ⇒ Proc, Class or Object

Registers an extension Group that subsequently registers a collection of extensions.

Registers the extension Group specified under the given name. If a name is not given, one is calculated by appending the next value in a 0-based index to the string “extgrp”. For instance, the first unnamed extension group to be registered is assigned the name “extgrp0” if a name is not specified.

The names are not yet used, but are intended for selectively activating extensions in the future.

If the extension group argument is a String or a Symbol, it gets resolved to a Class before being registered.

Examples:

Asciidoctor::Extensions.register UmlExtensions
Asciidoctor::Extensions.register :uml, UmlExtensions
Asciidoctor::Extensions.register do
  block_processor :plantuml, PlantUmlBlock
end
Asciidoctor::Extensions.register :uml do
  block_processor :plantuml, PlantUmlBlock
end

Parameters:

  • name

    The name under which this extension group is registered (optional, default: nil)

  • group

    A block (Proc), a Class, a String or Symbol name of a Class or an Object instance of a Class.

Returns:

  • (Proc, Class or Object)

    Returns the Proc, Class or Object instance, matching the type passed to this method.



1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
# File 'lib/asciidoctor/extensions.rb', line 1533

def register *args, &block
  argc = args.size
  if block_given?
    resolved_group = block
  elsif (group = args.pop)
    # QUESTION should we instantiate the group class here or defer until activation??
    resolved_group = (Helpers.resolve_class group) || group
  else
    raise ::ArgumentError, %(Extension group to register not specified)
  end
  name = args.pop || generate_name
  unless args.empty?
    raise ::ArgumentError, %(Wrong number of arguments (#{argc} for 1..2))
  end
  groups[name.to_sym] = resolved_group
end

.unregister(*names) ⇒ void

This method returns an undefined value.

Unregister statically-registered extension groups by name.

Parameters:

  • names

    one or more Symbol or String group names to unregister



1563
1564
1565
1566
# File 'lib/asciidoctor/extensions.rb', line 1563

def unregister *names
  names.each_with_object(groups) {|group, catalog| catalog.delete group.to_sym }
  nil
end

.unregister_allvoid

This method returns an undefined value.

Unregister all statically-registered extension groups.



1553
1554
1555
1556
# File 'lib/asciidoctor/extensions.rb', line 1553

def unregister_all
  @groups = {}
  nil
end