metanorma-core 0.2.9 → 0.2.11
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/isodoc.rb +2 -2
- data/lib/metanorma/core/version.rb +1 -1
- data/lib/metanorma/input/asciidoc.rb +0 -2
- 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: 9b0a6419158f5678642209d4750a31c175be241b60932e1d77b5f76366ec2f2f
|
|
4
|
+
data.tar.gz: '038f6b96369f5c355755efd41c2488d6402b33cb766e0473bff28acae4c4c74a'
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 9d3482e2fc06e7c8d053fe290c87e293bfff097a9b9c3a575be490c82898dde96e909e8aeb530e673efffafe2db904b9fc1089f489ae96834ce7b1cc6983a097
|
|
7
|
+
data.tar.gz: e6228a20b2b4237f224bfee6857b8bb7ac1e2a1ae90fccef6346f9740d91c5e65a02f896ef18a0cb1b8b18755fed4036277957ee6d2831fec1d3f049b0849177
|
|
@@ -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
|
|
@@ -51,7 +51,7 @@ module Metanorma
|
|
|
51
51
|
# region-specific overrides.
|
|
52
52
|
# @param i18nyaml [Hash, String, nil] Either a parsed i18n hash or
|
|
53
53
|
# a path to a YAML file. Forwarded to +init_i18n+.
|
|
54
|
-
# @param xml [
|
|
54
|
+
# @param xml [Moxml::Node, nil] If supplied, +converter.info+
|
|
55
55
|
# is invoked against it so document-level metadata can be primed.
|
|
56
56
|
# @param localdir [String, nil] If supplied, wired into both
|
|
57
57
|
# +converter.meta+ and +converter.xrefs.klass+ so file lookups
|
|
@@ -112,7 +112,7 @@ module Metanorma
|
|
|
112
112
|
# @param locale [String, nil] optional BCP-47 locale tag.
|
|
113
113
|
# @param i18nyaml [Hash, String, nil] either a parsed i18n hash or
|
|
114
114
|
# a path to a YAML file. Forwarded to +init_i18n+.
|
|
115
|
-
# @param xml [
|
|
115
|
+
# @param xml [Moxml::Node, nil] if supplied, +converter.info+
|
|
116
116
|
# is invoked against it for metadata priming.
|
|
117
117
|
# @param localdir [String, nil] wired into +converter.meta+ and
|
|
118
118
|
# +converter.xrefs.klass+ for relative file-lookup resolution.
|
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.11
|
|
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-26 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: asciidoctor
|