metanorma 2.3.6 → 2.3.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4eef0412dfe852af4d9501f0728dbd623eecaf6e34be11e260c3e39d56b1cc38
4
- data.tar.gz: d056fba553e88322f4ba3e7b26f79b7a1b0742baa69b1df2e214304c44f10f54
3
+ metadata.gz: '097d46fb29b83f41c643c4985cf3083ef2f49c53c46cbcb5586b2497b502b81b'
4
+ data.tar.gz: e020ab24c572c384ae47965fe1b84a71951d20745ff2385a4eec3aa4fb66c80a
5
5
  SHA512:
6
- metadata.gz: ffe39fe5dcc28776e081ec29f2a95db589483a84aa05cd9f5e97753151c036c9952d1f9b4feb160022f9849f6b71fdfb3d82ad4837e424514480d0664d6a1a3a
7
- data.tar.gz: 60ed129530b14a6cc95d833ed35e981e0fc119a34db65f643bb74e65bbde2b59d4da3ac51173d259f83c7f20c6920a81be7472da8194f9f73e4266af4e076ee2
6
+ metadata.gz: e2447f50b14b180ec78b8e6ec17b4a5de8f059b0a9091aa6cdb2a5c43e0792a836afa283143ad26fb7caf60fe27212e7e939bf0cacb3b3d3f9bd263ec7787ea0
7
+ data.tar.gz: 68ad569a5c042a89cc9caf4645a44d5f6e5c8511449eb60bce1563915535c639d7dc59fa737b1839bb9e6a9f85a156e8a9bccd8a91115bd192d6e2137c11c8fd
@@ -49,45 +49,47 @@ module Metanorma
49
49
  private
50
50
 
51
51
  # Select the appropriate Relaton parser class for the given flavor tag.
52
+ # Uses the flavor's Item class (not Bibdata) because in Relaton 2.x,
53
+ # Bibdata.from_xml produces a generic Relaton::Bib::ItemData instance
54
+ # (due to BibdataShared resolving `model ItemData` in the definer's scope),
55
+ # while Item.from_xml correctly produces a flavor-specific ItemData instance.
52
56
  # @param tag [String, nil] flavor tag (e.g. "iso", "ietf")
53
- # @param bibdata [Boolean] true when parsing a <bibdata> element (has <ext>);
54
- # false when parsing a <bibitem> element (no <ext>)
55
- # @return [Class] Relaton parser class (Bibdata or Bibitem subclass)
56
- def mn2relaton_parser(tag, bibdata: false)
57
+ # @return [Class] Relaton Item parser class
58
+ def mn2relaton_parser(tag)
57
59
  case tag
58
60
  when "bipm"
59
- require "relaton/bipm" unless defined?(::Relaton::Bipm::Bibdata)
60
- bibdata ? ::Relaton::Bipm::Bibdata : ::Relaton::Bipm::Bibitem
61
+ require "relaton/bipm" unless defined?(::Relaton::Bipm::Item)
62
+ ::Relaton::Bipm::Item
61
63
  when "bsi"
62
- require "relaton/bsi" unless defined?(::Relaton::Bsi::Bibdata)
63
- bibdata ? ::Relaton::Bsi::Bibdata : ::Relaton::Bsi::Bibitem
64
+ require "relaton/bsi" unless defined?(::Relaton::Bsi::Item)
65
+ ::Relaton::Bsi::Item
64
66
  when "ietf"
65
- require "relaton/ietf" unless defined?(::Relaton::Ietf::Bibdata)
66
- bibdata ? ::Relaton::Ietf::Bibdata : ::Relaton::Ietf::Bibitem
67
+ require "relaton/ietf" unless defined?(::Relaton::Ietf::Item)
68
+ ::Relaton::Ietf::Item
67
69
  when "iho"
68
- require "relaton/iho" unless defined?(::Relaton::Iho::Bibdata)
69
- bibdata ? ::Relaton::Iho::Bibdata : ::Relaton::Iho::Bibitem
70
+ require "relaton/iho" unless defined?(::Relaton::Iho::Item)
71
+ ::Relaton::Iho::Item
70
72
  when "itu"
71
- require "relaton/itu" unless defined?(::Relaton::Itu::Bibdata)
72
- bibdata ? ::Relaton::Itu::Bibdata : ::Relaton::Itu::Bibitem
73
+ require "relaton/itu" unless defined?(::Relaton::Itu::Item)
74
+ ::Relaton::Itu::Item
73
75
  when "iec"
74
- require "relaton/iec" unless defined?(::Relaton::Iec::Bibdata)
75
- bibdata ? ::Relaton::Iec::Bibdata : ::Relaton::Iec::Bibitem
76
+ require "relaton/iec" unless defined?(::Relaton::Iec::Item)
77
+ ::Relaton::Iec::Item
76
78
  when "iso"
77
- require "relaton/iso" unless defined?(::Relaton::Iso::Bibdata)
78
- bibdata ? ::Relaton::Iso::Bibdata : ::Relaton::Iso::Bibitem
79
+ require "relaton/iso" unless defined?(::Relaton::Iso::Item)
80
+ ::Relaton::Iso::Item
79
81
  when "nist"
80
- require "relaton/nist" unless defined?(::Relaton::Nist::Bibdata)
81
- bibdata ? ::Relaton::Nist::Bibdata : ::Relaton::Nist::Bibitem
82
+ require "relaton/nist" unless defined?(::Relaton::Nist::Item)
83
+ ::Relaton::Nist::Item
82
84
  when "ogc"
83
- require "relaton/ogc" unless defined?(::Relaton::Ogc::Bibdata)
84
- bibdata ? ::Relaton::Ogc::Bibdata : ::Relaton::Ogc::Bibitem
85
+ require "relaton/ogc" unless defined?(::Relaton::Ogc::Item)
86
+ ::Relaton::Ogc::Item
85
87
  else
86
- bibdata ? ::Relaton::Bib::Bibdata : ::Relaton::Bib::Bibitem
88
+ ::Relaton::Bib::Item
87
89
  end
88
90
  rescue LoadError => e
89
- warn "Warning: Failed to load relaton gem for '#{tag}': #{e.message}. Falling back to Relaton::Bib::Bibdata/Bibitem"
90
- bibdata ? ::Relaton::Bib::Bibdata : ::Relaton::Bib::Bibitem
91
+ warn "Warning: Failed to load relaton gem for '#{tag}': #{e.message}. Falling back to Relaton::Bib::Item"
92
+ ::Relaton::Bib::Item
91
93
  end
92
94
 
93
95
  # #param xml [Nokogiri::XML::Document, Nokogiri::XML::Element]
@@ -101,7 +103,7 @@ module Metanorma
101
103
  r = if b.name == "bibitem"
102
104
  ::Relaton::Bib::Bibitem
103
105
  else
104
- mn2relaton_parser(xml.root["flavor"], bibdata: true)
106
+ mn2relaton_parser(xml.root["flavor"])
105
107
  end
106
108
  # Relaton doesn't understand Pres XML tags
107
109
  b.xpath("//xmlns:fmt-identifier").each(&:remove)
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative "../../util/util"
3
+ require "metanorma-core"
4
4
 
5
5
  module Metanorma
6
6
  class Collection
@@ -3,7 +3,7 @@ require "htmlentities"
3
3
  require "mime/types"
4
4
  require_relative "fileprocess"
5
5
  require_relative "../../util/fontist_helper"
6
- require_relative "../../util/util"
6
+ require "metanorma-core"
7
7
  require_relative "../filelookup/filelookup"
8
8
  require_relative "../multilingual/multilingual"
9
9
  require_relative "utils"
@@ -1,6 +1,6 @@
1
1
  require "yaml"
2
2
  require "fileutils"
3
- require_relative "../../util/util"
3
+ require "metanorma-core"
4
4
  require_relative "../xrefprocess/xrefprocess"
5
5
  require_relative "collection"
6
6
  require "concurrent-ruby"
@@ -156,28 +156,15 @@ module Metanorma
156
156
  # style.gsub(%r{url\(#([^()]+)\)}, "url(#\\1_#{document_suffix})")
157
157
  # end
158
158
 
159
- class Dummy
160
- def attr(_key); end
161
- end
162
-
163
159
  def load_isodoc(flavor, presxml: false)
164
- x = Asciidoctor.load nil, backend: flavor.to_sym
165
- if presxml
166
- x.converter.presentation_xml_converter(Dummy.new)
167
- else
168
- x.converter.html_converter(Dummy.new) # to obtain Isodoc class
169
- end
160
+ Metanorma::Core::Isodoc.resolve_converter(flavor, presxml: presxml)
170
161
  end
171
162
 
172
163
  def isodoc_create(flavor, lang, script, xml, presxml: false)
173
- isodoc = Util::load_isodoc(flavor, presxml: presxml)
174
- isodoc.i18n_init(lang, script, nil) # read in internationalisation
175
- # TODO locale?
176
- isodoc.metadata_init(lang, script, nil, isodoc.i18n)
177
- isodoc.xref_init(lang, script, nil, isodoc.i18n, {})
178
- isodoc.xrefs.klass.meta = isodoc.meta
179
- isodoc.info(xml, nil)
180
- isodoc
164
+ conv = Metanorma::Core::Isodoc.resolve_converter(flavor,
165
+ presxml: presxml)
166
+ Metanorma::Core::Isodoc.init(conv, lang: lang, script: script,
167
+ xml: xml)
181
168
  end
182
169
 
183
170
  def asciidoc_dummy_header
@@ -11,7 +11,7 @@ require_relative "writeable"
11
11
  require_relative "validator"
12
12
  require_relative "compile_options"
13
13
  require_relative "../util/fontist_helper"
14
- require_relative "../util/util"
14
+ require "metanorma-core"
15
15
  require_relative "extract"
16
16
  require_relative "../collection/sectionsplit/sectionsplit"
17
17
  require_relative "../util/worker_pool"
@@ -3,58 +3,16 @@
3
3
  module Metanorma
4
4
  class Compile
5
5
  module Flavor
6
- # Load the flavor gem for the given standard type
7
- # @param stdtype [Symbol] the standard type
8
- # @return [void]
9
6
  def load_flavor(stdtype)
10
- new_stdtype = taste2flavor(stdtype)
11
- flavor = stdtype2flavor_gem(new_stdtype)
12
- @registry.supported_backends.include? new_stdtype or
13
- Util.log("[metanorma] Info: Loading `#{flavor}` gem "\
14
- "for standard type `#{stdtype}`.", :info)
15
- require_flavor(flavor)
16
- @registry.supported_backends.include? new_stdtype or
17
- Util.log("[metanorma] Error: The `#{flavor}` gem does not "\
18
- "support the standard type #{stdtype}. Exiting.", :fatal)
7
+ Metanorma::Core::FlavorLoader.load_flavor(stdtype)
19
8
  end
20
9
 
21
10
  def taste2flavor(stdtype)
22
- stdtype = stdtype.to_sym
23
- tastes = Metanorma::TasteRegister.instance.aliases
24
- tastes[stdtype] and stdtype = tastes[stdtype].to_sym
25
- stdtype
11
+ Metanorma::Core::FlavorLoader.taste2flavor(stdtype)
26
12
  end
27
13
 
28
- # Convert the standard type to the flavor gem name
29
- # @param stdtype [Symbol] the standard type
30
- # @return [String] the flavor gem name
31
14
  def stdtype2flavor_gem(stdtype)
32
- "metanorma-#{stdtype}"
33
- end
34
-
35
- private
36
-
37
- def require_flavor(flavor)
38
- require flavor
39
- Util.log("[metanorma] Info: gem `#{flavor}` loaded.", :info)
40
- rescue LoadError => e
41
- error_log = "#{Date.today}-error.log"
42
- File.write(error_log, e)
43
-
44
- msg = <<~MSG
45
- Error: #{e.message}
46
- Metanorma has encountered an exception.
47
-
48
- If this problem persists, please report this issue at the following link:
49
-
50
- * https://github.com/metanorma/metanorma/issues/new
51
-
52
- Please attach the #{error_log} file.
53
- Your valuable feedback is very much appreciated!
54
-
55
- - The Metanorma team
56
- MSG
57
- Util.log(msg, :fatal)
15
+ Metanorma::Core::FlavorLoader.stdtype2flavor_gem(stdtype)
58
16
  end
59
17
  end
60
18
  end
@@ -1,3 +1,3 @@
1
1
  module Metanorma
2
- VERSION = "2.3.6".freeze
2
+ VERSION = "2.3.8".freeze
3
3
  end
data/lib/metanorma.rb CHANGED
@@ -5,13 +5,7 @@ class Array
5
5
  end
6
6
 
7
7
  require "metanorma/version"
8
- require "asciidoctor"
9
- require "metanorma/util/util"
10
- require "metanorma/config/config"
11
- require "metanorma/input"
12
- require "metanorma/registry/registry"
13
- require "metanorma/processor/processor"
14
- require "metanorma/asciidoctor_extensions"
8
+ require "metanorma-core"
15
9
  require "metanorma/compile/compile"
16
10
  require "metanorma/collection/collection"
17
11
  require "metanorma/collection/manifest/manifest"
data/metanorma.gemspec CHANGED
@@ -29,12 +29,12 @@ Gem::Specification.new do |spec|
29
29
  spec.add_runtime_dependency "fontist", ">= 2.1.2"
30
30
  spec.add_runtime_dependency "htmlentities"
31
31
  spec.add_runtime_dependency "isodoc", ">= 3.5.0"
32
- #spec.add_runtime_dependency "metanorma-standoc", ">= 3.4.0"
33
32
  spec.add_runtime_dependency "marcel"
34
- spec.add_runtime_dependency "metanorma-taste", "~> 1.0.0"
33
+ spec.add_runtime_dependency "metanorma-core"
34
+ spec.add_runtime_dependency "metanorma-standoc"
35
35
  spec.add_runtime_dependency "mn2pdf", "~> 2"
36
36
  spec.add_runtime_dependency "nokogiri"
37
- spec.add_development_dependency "canon", "= 0.1.3"
37
+ spec.add_development_dependency "canon"
38
38
  spec.add_development_dependency "metanorma-iho"
39
39
  spec.add_development_dependency "metanorma-iso"
40
40
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: metanorma
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.3.6
4
+ version: 2.3.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2026-04-13 00:00:00.000000000 Z
11
+ date: 2026-04-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: asciidoctor
@@ -95,19 +95,33 @@ dependencies:
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0'
97
97
  - !ruby/object:Gem::Dependency
98
- name: metanorma-taste
98
+ name: metanorma-core
99
99
  requirement: !ruby/object:Gem::Requirement
100
100
  requirements:
101
- - - "~>"
101
+ - - ">="
102
102
  - !ruby/object:Gem::Version
103
- version: 1.0.0
103
+ version: '0'
104
104
  type: :runtime
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
- - - "~>"
108
+ - - ">="
109
109
  - !ruby/object:Gem::Version
110
- version: 1.0.0
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: metanorma-standoc
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :runtime
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
111
125
  - !ruby/object:Gem::Dependency
112
126
  name: mn2pdf
113
127
  requirement: !ruby/object:Gem::Requirement
@@ -140,16 +154,16 @@ dependencies:
140
154
  name: canon
141
155
  requirement: !ruby/object:Gem::Requirement
142
156
  requirements:
143
- - - '='
157
+ - - ">="
144
158
  - !ruby/object:Gem::Version
145
- version: 0.1.3
159
+ version: '0'
146
160
  type: :development
147
161
  prerelease: false
148
162
  version_requirements: !ruby/object:Gem::Requirement
149
163
  requirements:
150
- - - '='
164
+ - - ">="
151
165
  - !ruby/object:Gem::Version
152
- version: 0.1.3
166
+ version: '0'
153
167
  - !ruby/object:Gem::Dependency
154
168
  name: metanorma-iho
155
169
  requirement: !ruby/object:Gem::Requirement
@@ -214,8 +228,6 @@ files:
214
228
  - README.adoc
215
229
  - lib/metanorma.rb
216
230
  - lib/metanorma/array_monkeypatch.rb
217
- - lib/metanorma/asciidoctor_extensions.rb
218
- - lib/metanorma/asciidoctor_extensions/glob_include_processor.rb
219
231
  - lib/metanorma/collection/collection.rb
220
232
  - lib/metanorma/collection/config/bibdata.rb
221
233
  - lib/metanorma/collection/config/compile_options.rb
@@ -256,15 +268,7 @@ files:
256
268
  - lib/metanorma/compile/render.rb
257
269
  - lib/metanorma/compile/validator.rb
258
270
  - lib/metanorma/compile/writeable.rb
259
- - lib/metanorma/config/config.rb
260
- - lib/metanorma/input.rb
261
- - lib/metanorma/input/asciidoc.rb
262
- - lib/metanorma/input/base.rb
263
- - lib/metanorma/processor.rb
264
- - lib/metanorma/processor/processor.rb
265
- - lib/metanorma/registry/registry.rb
266
271
  - lib/metanorma/util/fontist_helper.rb
267
- - lib/metanorma/util/util.rb
268
272
  - lib/metanorma/util/worker_pool.rb
269
273
  - lib/metanorma/version.rb
270
274
  - metanorma.gemspec
@@ -1,22 +0,0 @@
1
- module Metanorma
2
- module AsciidoctorExtensions
3
- class GlobIncludeProcessor < ::Asciidoctor::Extensions::IncludeProcessor
4
- def process(_doc, reader, target_glob, attributes)
5
- Dir[File.join reader.dir, target_glob].sort.reverse_each do |target|
6
- content = File.readlines target
7
- content.unshift "" unless attributes["adjoin-option"]
8
- reader.push_include content, target, target, 1, attributes
9
- end
10
- reader
11
- end
12
-
13
- def handles?(target)
14
- target.include? "*"
15
- end
16
- end
17
- end
18
- end
19
-
20
- Asciidoctor::Extensions.register do
21
- include_processor ::Metanorma::AsciidoctorExtensions::GlobIncludeProcessor
22
- end
@@ -1 +0,0 @@
1
- require_relative "asciidoctor_extensions/glob_include_processor"
@@ -1,23 +0,0 @@
1
- module Metanorma
2
- module Config
3
- def configure
4
- if block_given?
5
- yield configuration
6
- end
7
- end
8
-
9
- def configuration
10
- @configuration ||= Configuration.new
11
- end
12
- end
13
-
14
- class Configuration
15
- attr_accessor :logs
16
-
17
- def initialize
18
- @logs = %i[warning error fatal]
19
- end
20
- end
21
-
22
- extend Config
23
- end
@@ -1,95 +0,0 @@
1
- require "nokogiri"
2
-
3
- module Metanorma
4
- module Input
5
- class Asciidoc < Base
6
- def process(file, filename, type, options = {})
7
- require "asciidoctor"
8
- out_opts = { to_file: false, safe: :safe, backend: type,
9
- header_footer: true, log: options[:log],
10
- novalid: options[:novalid],
11
- attributes: ["nodoc", "stem", "docfile=#{filename}",
12
- "output_dir=#{options[:output_dir]}"] }
13
- ::Asciidoctor.convert(file, out_opts)
14
- end
15
-
16
- def header(file)
17
- ret = file.split("\n\n", 2) or return [nil, nil]
18
- ret[0] and ret[0] += "\n"
19
- [ret[0], ret[1]]
20
- end
21
-
22
- def extract_metanorma_options(file)
23
- hdr, = header(file)
24
- /\n:(?:mn-)?(?:document-class|flavor):\s+(?<type>\S[^\n]*)\n/ =~ hdr
25
- /\n:(?:mn-)?output-extensions:\s+(?<extensions>\S[^\n]*)\n/ =~ hdr
26
- /\n:(?:mn-)?relaton-output-file:\s+(?<relaton>\S[^\n]*)\n/ =~ hdr
27
- /\n(?<asciimath>:(?:mn-)?keep-asciimath:[^\n]*)\n/ =~ hdr
28
- /\n(?<novalid>:novalid:[^\n]*)\n/ =~ hdr
29
- if defined?(asciimath)
30
- asciimath =
31
- !asciimath.nil? && !/keep-asciimath:\s*false/.match?(asciimath)
32
- end
33
- asciimath = nil if asciimath == false
34
- {
35
- type: defined?(type) ? type&.strip : nil,
36
- extensions: defined?(extensions) ? extensions&.strip : nil,
37
- relaton: defined?(relaton) ? relaton&.strip : nil,
38
- asciimath: asciimath, novalid: !novalid.nil? || nil
39
- }.compact
40
- end
41
-
42
- def empty_attr(attr, name)
43
- attr&.sub(/^#{name}:\s*$/, "#{name}: true")&.sub(/^#{name}:\s+/, "")
44
- end
45
-
46
- ADOC_OPTIONS =
47
- %w(htmlstylesheet htmlcoverpage htmlintropage scripts
48
- scripts-override scripts-pdf wordstylesheet i18nyaml
49
- standardstylesheet header wordcoverpage wordintropage
50
- ulstyle olstyle htmlstylesheet-override bare toclevels
51
- htmltoclevels doctoclevels sectionsplit base-asset-path
52
- body-font header-font monospace-font title-font
53
- align-cross-elements wordstylesheet-override ieee-dtd
54
- pdf-encrypt pdf-encryption-length pdf-user-password
55
- pdf-owner-password pdf-allow-copy-content pdf-allow-edit-content
56
- pdf-allow-assemble-document pdf-allow-edit-annotations
57
- pdf-allow-print pdf-allow-print-hq pdf-allow-fill-in-forms
58
- pdf-stylesheet pdf-stylesheet-override relaton-render-config
59
- fonts font-license-agreement pdf-allow-access-content
60
- pdf-encrypt-metadata iso-word-template document-scheme
61
- localize-number iso-word-bg-strip-color modspec-identifier-base)
62
- .freeze
63
-
64
- EMPTY_ADOC_OPTIONS_DEFAULT_TRUE =
65
- %w(data-uri-image suppress-asciimath-dup use-xinclude
66
- source-highlighter).freeze
67
-
68
- EMPTY_ADOC_OPTIONS_DEFAULT_FALSE =
69
- %w(hierarchical-assets break-up-urls-in-tables toc-figures
70
- toc-tables toc-recommendations).freeze
71
-
72
- def attr_name_normalise(name)
73
- name.delete("-").sub(/override$/, "_override").sub(/pdf$/, "_pdf")
74
- .to_sym
75
- end
76
-
77
- def extract_options(file)
78
- hdr, = header(file)
79
- ret = ADOC_OPTIONS.each_with_object({}) do |w, acc|
80
- m = /\n:#{w}:\s+([^\n]+)\n/.match(hdr) or next
81
- acc[attr_name_normalise(w)] = m[1]&.strip
82
- end
83
- ret2 = EMPTY_ADOC_OPTIONS_DEFAULT_TRUE.each_with_object({}) do |w, acc|
84
- m = /\n:#{w}:([^\n]*)\n/.match(hdr) || [nil, "true"]
85
- acc[attr_name_normalise(w)] = (m[1].strip != "false")
86
- end
87
- ret3 = EMPTY_ADOC_OPTIONS_DEFAULT_FALSE.each_with_object({}) do |w, acc|
88
- m = /\n:#{w}:([^\n]*)\n/.match(hdr) || [nil, "false"]
89
- acc[attr_name_normalise(w)] = !["false"].include?(m[1].strip)
90
- end
91
- ret.merge(ret2).merge(ret3).compact
92
- end
93
- end
94
- end
95
- end
@@ -1,9 +0,0 @@
1
- module Metanorma
2
- module Input
3
- class Base
4
- def process(_file, _filename, _type)
5
- raise "This is an abstract class"
6
- end
7
- end
8
- end
9
- end
@@ -1,7 +0,0 @@
1
- require_relative "./input/base"
2
- require_relative "./input/asciidoc"
3
-
4
- module Metanorma
5
- module Input
6
- end
7
- end
@@ -1,54 +0,0 @@
1
- # Registry of all Metanorma types and entry points
2
- #
3
-
4
- module Metanorma
5
- class Processor
6
- attr_reader :short, :input_format, :asciidoctor_backend
7
-
8
- def initialize
9
- raise "This is an abstract class!"
10
- end
11
-
12
- def output_formats
13
- {
14
- xml: "xml",
15
- presentation: "presentation.xml",
16
- rxl: "rxl",
17
- }
18
- end
19
-
20
- def input_to_isodoc(file, filename, options = {})
21
- Metanorma::Input::Asciidoc.new.process(file, filename,
22
- @asciidoctor_backend, options)
23
- end
24
-
25
- # def input_to_isodoc(file, filename)
26
- # raise "This is an abstract class!"
27
- # end
28
-
29
- def use_presentation_xml(ext)
30
- case ext
31
- when :html, :doc, :pdf then true
32
- else
33
- false
34
- end
35
- end
36
-
37
- def options_preprocess(options)
38
- options[:output_formats] ||= output_formats
39
- end
40
-
41
- def output(isodoc_node, _inname, outname, _format, _options = {})
42
- File.open(outname, "w:UTF-8") { |f| f.write(isodoc_node) }
43
- end
44
-
45
- def extract_options(file)
46
- Metanorma::Input::Asciidoc.new.extract_options(file)
47
- .merge(output_formats: output_formats)
48
- end
49
-
50
- def extract_metanorma_options(file)
51
- Metanorma::Input::Asciidoc.new.extract_metanorma_options(file)
52
- end
53
- end
54
- end
@@ -1,6 +0,0 @@
1
- require_relative "./processor/processor"
2
-
3
- module Metanorma
4
- class Processor
5
- end
6
- end
@@ -1,188 +0,0 @@
1
- # Registry of all Metanorma types and entry points
2
-
3
- require "singleton"
4
- require "metanorma-taste"
5
-
6
- class Error < StandardError
7
- end
8
-
9
- module Metanorma
10
- # Central registry for managing Metanorma processors, flavors, and their aliases
11
- #
12
- # This singleton class provides a centralized registry for:
13
- # - Metanorma processors (document format processors)
14
- # - Flavor aliases (mapping legacy/alternative names to canonical flavors)
15
- # - Taste configurations (via TasteRegister integration)
16
- #
17
- # The registry maintains backward compatibility with legacy flavor names while
18
- # integrating with the modern TasteRegister system for dynamic taste management.
19
- #
20
- # @example Basic usage
21
- # registry = Metanorma::Registry.instance
22
- #
23
- # # Register a processor
24
- # registry.register(MyProcessor)
25
- #
26
- # # Look up flavor aliases
27
- # registry.alias(:csd) # => :cc
28
- #
29
- # # Register custom aliases
30
- # registry.register_alias(:my_flavor, :iso)
31
- #
32
- # @example Finding processors
33
- # processor = registry.find_processor(:iso)
34
- # formats = registry.output_formats
35
- # backends = registry.supported_backends
36
- class Registry
37
- include Singleton
38
-
39
- attr_reader :processors, :tastes
40
-
41
- # Default legacy aliases for backward compatibility
42
- # Maps old flavor names to their canonical equivalents
43
- DEFAULT_ALIASES = { csd: :cc, m3d: :m3aawg, mpfd: :mpfa, csand: :csa }.freeze
44
-
45
- # Initialize the registry with processors, tastes, and aliases
46
- #
47
- # Sets up the registry by:
48
- # 1. Initializing empty processors hash
49
- # 2. Connecting to the TasteRegister instance
50
- # 3. Initializing custom aliases with defaults
51
- def initialize
52
- @processors = {}
53
- @tastes = Metanorma::TasteRegister.instance
54
- @custom_aliases = DEFAULT_ALIASES.dup
55
- end
56
-
57
- # Look up the canonical flavor name for a given alias
58
- #
59
- # Checks aliases in priority order:
60
- # 1. Custom registered aliases (highest priority)
61
- # 2. Taste-based aliases from TasteRegister
62
- # 3. Returns nil if no alias found
63
- #
64
- # @param flavour [Symbol, String, nil] The flavor alias to look up
65
- # @return [Symbol, nil] The canonical flavor name, or nil if no alias exists
66
- #
67
- # @example
68
- # registry.alias(:csd) # => :cc (from DEFAULT_ALIASES)
69
- # registry.alias(:icc) # => :iso (from taste configuration)
70
- # registry.alias(:unknown) # => nil
71
- # registry.alias(nil) # => nil
72
- def alias(flavour)
73
- return nil if flavour.nil?
74
-
75
- flavour_sym = flavour.to_sym
76
-
77
- # Check custom aliases first (includes defaults)
78
- return @custom_aliases[flavour_sym] if @custom_aliases.key?(flavour_sym)
79
-
80
- # Then check taste aliases
81
- taste_aliases = @tastes.aliases
82
- taste_aliases[flavour_sym]
83
- end
84
-
85
- # Register a custom alias mapping
86
- #
87
- # Allows runtime registration of flavor aliases. Custom aliases take precedence
88
- # over taste-based aliases, allowing overrides of taste configurations.
89
- #
90
- # @param alias_name [Symbol, String] The alias name to register
91
- # @param target_flavor [Symbol, String] The canonical flavor it should map to
92
- #
93
- # @example
94
- # registry.register_alias(:my_custom, :iso)
95
- # registry.alias(:my_custom) # => :iso
96
- #
97
- # # Override a taste alias
98
- # registry.register_alias(:icc, :custom_iso)
99
- def register_alias(alias_name, target_flavor)
100
- @custom_aliases[alias_name.to_sym] = target_flavor.to_sym
101
- end
102
-
103
- # Register a Metanorma processor
104
- #
105
- # Registers a processor class and automatically creates aliases for all its
106
- # short names. The last short name is considered the canonical name.
107
- #
108
- # @param processor [Class] A processor class that inherits from Metanorma::Processor
109
- # @raise [Error] If the processor doesn't inherit from Metanorma::Processor
110
- # @return [Array<Symbol>] Array of short names for the processor
111
- #
112
- # @example
113
- # registry.register(Metanorma::ISO::Processor)
114
- # # Registers processor and creates aliases for all its short names
115
- def register(processor)
116
- unless processor < ::Metanorma::Processor
117
- raise Error, "Processor must inherit from Metanorma::Processor"
118
- end
119
-
120
- # The last short name is the canonical name
121
- processor_instance = processor.new
122
- short_names = Array(processor_instance.short)
123
- canonical_name = short_names.last
124
-
125
- # Register processor with canonical name
126
- @processors[canonical_name] = processor_instance
127
-
128
- # Create aliases for all short names pointing to canonical name
129
- short_names.each { |name| @custom_aliases[name] = canonical_name }
130
-
131
- Util.log("[metanorma] processor \"#{short_names.first}\" registered", :info)
132
- short_names
133
- end
134
-
135
- # Find a registered processor by its short name
136
- #
137
- # @param short [Symbol, String] The short name of the processor to find
138
- # @return [Metanorma::Processor, nil] The processor instance, or nil if not found
139
- #
140
- # @example
141
- # processor = registry.find_processor(:iso)
142
- # processor = registry.find_processor("iso")
143
- def find_processor(short)
144
- @processors[short.to_sym]
145
- end
146
-
147
- # Get list of all supported backend names
148
- #
149
- # @return [Array<Symbol>] Array of registered processor backend names
150
- #
151
- # @example
152
- # registry.supported_backends # => [:iso, :iec, :itu, ...]
153
- def supported_backends
154
- @processors.keys
155
- end
156
-
157
- # Get output formats supported by each registered processor
158
- #
159
- # @return [Hash<Symbol, Hash>] Hash mapping processor names to their output formats
160
- #
161
- # @example
162
- # registry.output_formats
163
- # # => { iso: { html: "html", pdf: "pdf", ... }, iec: { ... }, ... }
164
- def output_formats
165
- @processors.inject({}) do |acc, (k, v)|
166
- acc[k] = v.output_formats
167
- acc
168
- end
169
- end
170
-
171
- # Get XML root tags for processors with Asciidoctor backends
172
- #
173
- # @return [Hash<Symbol, String>] Hash mapping processor names to their XML root tags
174
- #
175
- # @example
176
- # registry.root_tags
177
- # # => { iso: "iso-standard", iec: "iec-standard", ... }
178
- def root_tags
179
- @processors.inject({}) do |acc, (k, v)|
180
- if v.asciidoctor_backend
181
- x = Asciidoctor.load nil, { backend: v.asciidoctor_backend }
182
- acc[k] = x.converter.xml_root_tag
183
- end
184
- acc
185
- end
186
- end
187
- end
188
- end
@@ -1,45 +0,0 @@
1
- module Metanorma
2
- module Util
3
- class << self
4
- def log(message, type = :info)
5
- log_types = Metanorma.configuration.logs.map(&:to_s) || []
6
-
7
- if log_types.include?(type.to_s)
8
- puts(message)
9
- end
10
-
11
- if type == :fatal
12
- abort
13
- end
14
- end
15
-
16
- # dependency ordering
17
- def sort_extensions_execution_ord(ext)
18
- case ext
19
- when :xml then 0
20
- when :rxl then 1
21
- when :presentation then 2
22
- else
23
- 99
24
- end
25
- end
26
-
27
- def sort_extensions_execution(ext)
28
- ext.sort do |a, b|
29
- sort_extensions_execution_ord(a) <=> sort_extensions_execution_ord(b)
30
- end
31
- end
32
-
33
- def recursive_string_keys(hash)
34
- case hash
35
- when Hash then hash.map do |k, v|
36
- [k.to_s, recursive_string_keys(v)]
37
- end.to_h
38
- when Enumerable then hash.map { |v| recursive_string_keys(v) }
39
- else
40
- hash
41
- end
42
- end
43
- end
44
- end
45
- end