metanorma-core 0.2.8 → 0.2.10
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 +4 -4
- data/lib/metanorma/core/flavor.rb +37 -2
- data/lib/metanorma/core/flavor_registry.rb +19 -7
- data/lib/metanorma/core/version.rb +1 -1
- data/lib/metanorma/input/asciidoc.rb +10 -1
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 3c3f877f38dea9a1dd3cfd0fa9ecb05e2fb05ef7433e5c2ef6f7f9c861765db5
|
|
4
|
+
data.tar.gz: 13fa04ed6359681aa73e33737425fd266dd0d34512e1e1bfc36236688d17f103
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: fb4ebb58b5a1b157e796773003032bff63e3d14b130449d9ab18fc511c6dacb15c9a76d4e3721b0d43fbbaf450fb29f28d8bb77f859a8d3cd2a178004bd89a5e
|
|
7
|
+
data.tar.gz: d0e5eeb4065a99eabfe40a1b0a1250545235a00c76b10b5e82f952d7a285066cb9215c6c614e6773c508e2496ec9d8571c31a7f75c784fec0ed1e53afbc31062
|
|
@@ -47,13 +47,48 @@ module Metanorma
|
|
|
47
47
|
entry.is_a?(Proc) ? entry.call(document, **options) : entry
|
|
48
48
|
end
|
|
49
49
|
|
|
50
|
-
def matches?(document_class)
|
|
50
|
+
def matches?(document_class, document = nil)
|
|
51
51
|
return false unless document_class.is_a?(Class)
|
|
52
52
|
|
|
53
53
|
root = model_root_class
|
|
54
54
|
return false unless root
|
|
55
|
+
return false unless document_class <= root
|
|
56
|
+
return true unless taste? && publisher_abbr
|
|
55
57
|
|
|
56
|
-
|
|
58
|
+
publisher_matches?(document)
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
# A taste stacked over its base shares the base's model root, so
|
|
62
|
+
# the class check alone cannot discriminate: several tastes
|
|
63
|
+
# (wmo, iala, icc over iho/standoc roots) match the same document
|
|
64
|
+
# class. The taste's publisher abbreviation against the document
|
|
65
|
+
# bibdata is the discriminator. Same reading as metanorma-taste's
|
|
66
|
+
# renderer gate: first author contributor carrying a non-empty
|
|
67
|
+
# organization abbreviation. A document without bibdata (probe
|
|
68
|
+
# fixtures, internal probes) matches on the class check alone;
|
|
69
|
+
# a bibdata that names no author abbreviation cannot claim the
|
|
70
|
+
# taste either — the base flavor serves such documents.
|
|
71
|
+
def publisher_matches?(document)
|
|
72
|
+
return true unless document.respond_to?(:bibdata)
|
|
73
|
+
|
|
74
|
+
contributors = document.bibdata&.contributor
|
|
75
|
+
return true unless contributors
|
|
76
|
+
|
|
77
|
+
contributors.each do |c|
|
|
78
|
+
roles = c.respond_to?(:role) ? Array(c.role) : []
|
|
79
|
+
author = roles.any? do |r|
|
|
80
|
+
(r.respond_to?(:type) ? r.type : r.to_s) == "author"
|
|
81
|
+
end
|
|
82
|
+
next unless author
|
|
83
|
+
|
|
84
|
+
org = c.respond_to?(:organization) ? c.organization : nil
|
|
85
|
+
next unless org
|
|
86
|
+
|
|
87
|
+
abbrev = org.respond_to?(:abbreviation) ? org.abbreviation : nil
|
|
88
|
+
abbrev = abbrev.to_s unless abbrev.is_a?(String)
|
|
89
|
+
return abbrev == publisher_abbr unless abbrev.empty?
|
|
90
|
+
end
|
|
91
|
+
false
|
|
57
92
|
end
|
|
58
93
|
|
|
59
94
|
def model_root_class
|
|
@@ -2,10 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|
module Metanorma
|
|
4
4
|
module Core
|
|
5
|
-
# The process-wide flavor/taste table.
|
|
6
|
-
#
|
|
7
|
-
# the harness defaults
|
|
8
|
-
# base chain by yielding nil
|
|
5
|
+
# The process-wide flavor/taste table. Resolution walks
|
|
6
|
+
# most-specific-first (tastes before their base flavors) so flavor
|
|
7
|
+
# gems win over the harness defaults and taste entries fall through
|
|
8
|
+
# to their base chain by yielding nil, independent of the order in
|
|
9
|
+
# which the gems happened to load.
|
|
9
10
|
class FlavorRegistry
|
|
10
11
|
include Enumerable
|
|
11
12
|
|
|
@@ -25,15 +26,15 @@ module Metanorma
|
|
|
25
26
|
end
|
|
26
27
|
|
|
27
28
|
def flavor_for(document)
|
|
28
|
-
|
|
29
|
+
most_specific_first.find { |f| f.matches?(document.class, document) }
|
|
29
30
|
end
|
|
30
31
|
|
|
31
32
|
# Renderer class for (document, format): walk matching entries
|
|
32
33
|
# most-specific-first; a taste without its own renderer for the
|
|
33
34
|
# format yields nil and falls through to the base flavor entry.
|
|
34
35
|
def renderer_for(format, document, **options)
|
|
35
|
-
|
|
36
|
-
next unless flavor.matches?(document.class)
|
|
36
|
+
most_specific_first.each do |flavor|
|
|
37
|
+
next unless flavor.matches?(document.class, document)
|
|
37
38
|
|
|
38
39
|
renderer = flavor.renderer_for(format, document, **options)
|
|
39
40
|
return renderer if renderer
|
|
@@ -51,6 +52,17 @@ module Metanorma
|
|
|
51
52
|
entry = find_by_name(entry.base_flavor) while entry&.base_flavor
|
|
52
53
|
entry
|
|
53
54
|
end
|
|
55
|
+
|
|
56
|
+
private
|
|
57
|
+
|
|
58
|
+
# Tastes before base flavors regardless of registration order:
|
|
59
|
+
# flavor gems self-register on their own load time, so a taste
|
|
60
|
+
# registered first (metanorma-taste loading before the base gem)
|
|
61
|
+
# would otherwise lose the reverse-order walk to its own base.
|
|
62
|
+
def most_specific_first
|
|
63
|
+
tastes, bases = @flavors.partition(&:taste?)
|
|
64
|
+
tastes.reverse_each + bases.reverse_each
|
|
65
|
+
end
|
|
54
66
|
end
|
|
55
67
|
end
|
|
56
68
|
end
|
|
@@ -24,9 +24,18 @@ module Metanorma
|
|
|
24
24
|
# resolves relative asset paths against and jails includes
|
|
25
25
|
# within; defaults to the process working directory).
|
|
26
26
|
# @return [String] Asciidoctor convert output.
|
|
27
|
+
# Enable STEM syntax handling (`stem:[...]`, `[stem]` blocks) for
|
|
28
|
+
# every compile, without deciding the STEM flavor on the
|
|
29
|
+
# document's behalf. The trailing `@` marks the attribute as a
|
|
30
|
+
# soft set: it applies only when the document itself does not
|
|
31
|
+
# carry a `:stem:` attribute entry. A hard set would clobber the
|
|
32
|
+
# document's `:stem: latexmath` with Asciidoctor's empty default,
|
|
33
|
+
# forcing every stem through the AsciiMath parser.
|
|
34
|
+
STEM_ENABLE_ATTR = "stem@".freeze
|
|
35
|
+
|
|
27
36
|
def process(file, filename, type, options = {})
|
|
28
37
|
require "asciidoctor"
|
|
29
|
-
attrs = ["nodoc",
|
|
38
|
+
attrs = ["nodoc", STEM_ENABLE_ATTR, "docfile=#{filename}",
|
|
30
39
|
"output_dir=#{options[:output_dir]}"]
|
|
31
40
|
# The converter reads novalid as a document ATTRIBUTE; the bare
|
|
32
41
|
# Asciidoctor option never reaches it, so --no-valid silently
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: metanorma-core
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.2.
|
|
4
|
+
version: 0.2.10
|
|
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-11-
|
|
11
|
+
date: 2026-11-24 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: asciidoctor
|