Sha256: f256e9127dbb9024bd8df1995d3be17af13069cbb9e15d47d751ee88cc07b275

Contents?: true

Size: 1.29 KB

Versions: 36

Compression:

Stored size: 1.29 KB

Contents

# Registry of all Metanorma types and entry points
#

require 'singleton'

class Error < StandardError
end

module Metanorma
  class Registry
    include Singleton

    attr_reader :processors

    def initialize
      @processors = {}
      @aliases = {csd: :cc, m3d: :m3aawg, mpfd: :mpfa, csand: :csa}
    end

    def alias(x)
      @aliases[x]
    end

    def register processor
      raise Error unless processor < ::Metanorma::Processor
      p = processor.new
      # p.short[-1] is the canonical name
      short = Array(p.short)
      @processors[short[-1]] = p
      short.each do |s|
        @aliases[s] = short[-1]
      end
      Array(p.short)
      Util.log("[metanorma] processor \"#{Array(p.short)[0]}\" registered", :info)
    end

    def find_processor(short)
      @processors[short.to_sym]
    end

    def supported_backends
      @processors.keys
    end

    def processors
      @processors
    end

    def output_formats
      @processors.inject({}) do |acc, (k,v)|
        acc[k] = v.output_formats
        acc
      end
    end

    def root_tags
      @processors.inject({}) do |acc, (k,v)|
        if v.asciidoctor_backend
          x = Asciidoctor.load nil, {backend: v.asciidoctor_backend}
          acc[k] = x.converter.xml_root_tag
        end
        acc
      end
    end
  end
end

Version data entries

36 entries across 36 versions & 2 rubygems

Version Path
metanorma-1.4.3 lib/metanorma/registry.rb
metanorma-1.4.2 lib/metanorma/registry.rb
metanorma-1.4.1 lib/metanorma/registry.rb
metanorma-1.4.0 lib/metanorma/registry.rb
metanorma-1.3.12 lib/metanorma/registry.rb
metanorma-1.3.11 lib/metanorma/registry.rb
metanorma-1.3.10 lib/metanorma/registry.rb
metanorma-1.3.9.1 lib/metanorma/registry.rb
metanorma-1.3.9 lib/metanorma/registry.rb
metanorma-1.3.8 lib/metanorma/registry.rb
metanorma-1.3.7 lib/metanorma/registry.rb
metanorma-1.3.6 lib/metanorma/registry.rb
metanorma-1.3.5 lib/metanorma/registry.rb
metanorma-1.3.4 lib/metanorma/registry.rb
metanorma-1.3.3 lib/metanorma/registry.rb
metanorma-1.3.2 lib/metanorma/registry.rb
metanorma-1.3.1 lib/metanorma/registry.rb
metanorma-1.3.0 lib/metanorma/registry.rb
metanorma-1.2.8 lib/metanorma/registry.rb
metanorma-1.2.7 lib/metanorma/registry.rb