Class: Metanorma::Registry

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/metanorma/registry/registry.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeRegistry

TODO: make aliases configurable



16
17
18
19
20
21
22
23
24
# File 'lib/metanorma/registry/registry.rb', line 16

def initialize
  @processors = {}
  @tastes = Metanorma::TasteRegister.instance
  tastealiases = @tastes.available_tastes.each_with_object({}) do |x, m|
    m[x] = @tastes.taste_info(x)[:base_flavor]
  end
  @aliases = { csd: :cc, m3d: :m3aawg, mpfd: :mpfa, csand: :csa }
    .merge tastealiases
end

Instance Attribute Details

#processorsObject (readonly)

Returns the value of attribute processors.



13
14
15
# File 'lib/metanorma/registry/registry.rb', line 13

def processors
  @processors
end

#tastesObject (readonly)

Returns the value of attribute tastes.



13
14
15
# File 'lib/metanorma/registry/registry.rb', line 13

def tastes
  @tastes
end

Instance Method Details

#alias(flavour) ⇒ Object



26
27
28
# File 'lib/metanorma/registry/registry.rb', line 26

def alias(flavour)
  @aliases[flavour]
end

#find_processor(short) ⇒ Object



41
42
43
# File 'lib/metanorma/registry/registry.rb', line 41

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

#output_formatsObject



49
50
51
52
53
54
# File 'lib/metanorma/registry/registry.rb', line 49

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

#register(processor) ⇒ Object



30
31
32
33
34
35
36
37
38
39
# File 'lib/metanorma/registry/registry.rb', line 30

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

#root_tagsObject



56
57
58
59
60
61
62
63
64
# File 'lib/metanorma/registry/registry.rb', line 56

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

#supported_backendsObject



45
46
47
# File 'lib/metanorma/registry/registry.rb', line 45

def supported_backends
  @processors.keys
end