Module: Asciidoctor::Converter::DefaultFactory

Includes:
Factory
Included in:
Asciidoctor::Converter, DefaultFactoryProxy
Defined in:
lib/asciidoctor/converter.rb

Overview

Mixed into the Asciidoctor::Converter module to provide the global registry of converters that are registered statically.

This registry includes built-in converters for HTML 5, DocBook 5 and man(ual) page, as well as any custom converters that have been discovered or explicitly registered. Converter registration is synchronized (where applicable) and is thus guaranteed to be thread safe.

Constant Summary collapse

PROVIDED =
{
  'docbook5' => %(#{__dir__}/converter/docbook5),
  'html5' => %(#{__dir__}/converter/html5),
  'manpage' => %(#{__dir__}/converter/manpage),
}

Instance Method Summary collapse

Methods included from Factory

#converters, create, #create, default, new

Instance Method Details

#for(backend) ⇒ Object



315
316
317
318
319
320
321
322
323
# File 'lib/asciidoctor/converter.rb', line 315

def for backend
  @@registry.fetch backend do
    PROVIDED[backend] ? (@@mutex.synchronize do
      # require is thread-safe, so no reason to refetch
      require PROVIDED[backend]
      @@registry[backend]
    end) : catch_all
  end
end

#register(converter, *backends) ⇒ Object



300
301
302
303
304
305
306
# File 'lib/asciidoctor/converter.rb', line 300

def register converter, *backends
  if @@mutex.owned?
    backends.each {|backend| backend == '*' ? (@@catch_all = converter) : (@@registry = @@registry.merge backend => converter) }
  else
    @@mutex.synchronize { register converter, *backends }
  end
end

#unregister_allObject



308
309
310
311
312
313
# File 'lib/asciidoctor/converter.rb', line 308

def unregister_all
  @@mutex.synchronize do
    @@registry = @@registry.select {|backend| PROVIDED[backend] }
    @@catch_all = nil
  end
end