lib/asciidoctor/extensions.rb in asciidoctor-2.0.17 vs lib/asciidoctor/extensions.rb in asciidoctor-2.0.18

- old
+ new

@@ -511,12 +511,17 @@ # registered to handle this name and, if found, invokes its {Processor#process} # method to build a corresponding node in the document tree. # # If the process method returns an instance of Block, the content model of that # Block is :compound, and the Block contains at least one line, the parser will - # parse those lines into blocks an assigned them to the returned block. + # parse those lines into blocks and append them to the returned block. # + # If your custom block can be applied to a paragraph or delimited block, and you + # want to preserve the content model of the input, check whether the value of + # the cloaked-context attribute is :paragraph. If it is, set the content model of + # the returned block to :simple. Otherwise, set the content model to :compound. + # # AsciiDoc example: # # [shout] # Get a move on. # @@ -714,10 +719,11 @@ # Public: Returns the Hash of {Group} classes, instances, and/or Procs that have been registered with this registry. attr_reader :groups def initialize groups = {} @groups = groups + reset @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 # Public: Activates all the global extension {Group}s and the extension {Group}s @@ -725,10 +731,11 @@ # # document - the {Asciidoctor::Document} on which the extensions are to be used. # # Returns the instance of this [Registry]. def activate document + reset if @document @document = document unless (ext_groups = Extensions.groups.values + @groups.values).empty? ext_groups.each do |group| case group when ::Proc @@ -1343,11 +1350,11 @@ 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}) + raise ::NoMethodError, %(No block specified to process #{kind_name} extension at #{block.source_location.join ':'}) end processor.freeze extension = ProcessorExtension.new kind, processor else processor, config = resolve_args args, 2 @@ -1387,14 +1394,14 @@ 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}) + raise ::ArgumentError, %(No name specified for #{kind_name} extension at #{block.source_location.join ':'}) end unless processor.process_block_given? - raise ::NoMethodError, %(No block specified to process #{kind_name} extension at #{block.source_location}) + raise ::NoMethodError, %(No block specified to process #{kind_name} extension at #{block.source_location.join ':'}) end processor.freeze kind_store[name] = ProcessorExtension.new kind, processor else processor, name, config = resolve_args args, 3 @@ -1422,10 +1429,15 @@ raise ::ArgumentError, %(Invalid arguments specified for registering #{kind_name} extension: #{args}) end end end + def reset + @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 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) @@ -1526,10 +1538,10 @@ # # names - one or more Symbol or String group names to unregister # # Returns nothing def unregister *names - names.each {|group| @groups.delete group.to_sym } + names.each_with_object(groups) {|group, catalog| catalog.delete group.to_sym } nil end end end end