metanorma-core 0.2.9 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ca8a43da82e11d899c6bf138d835c93e88f58f6d938fac155b1e6a8f40d15417
4
- data.tar.gz: 4a6ed27f23eb9e04c054fa012c477ef480fdb6bace05a1fec47b76d53a76c7fc
3
+ metadata.gz: 3c3f877f38dea9a1dd3cfd0fa9ecb05e2fb05ef7433e5c2ef6f7f9c861765db5
4
+ data.tar.gz: 13fa04ed6359681aa73e33737425fd266dd0d34512e1e1bfc36236688d17f103
5
5
  SHA512:
6
- metadata.gz: 39a68ba5fed73c32c349f305897037b06a8e5a5aafe0b8a98b44569dda07e77049252109b84a1156daf4f535bddc040829ce79014f9a3190cbf85697f767360e
7
- data.tar.gz: c861798c3b4d020ff06e332a5dbbcc990a0e9623c1e6adab47c515682bd8064bc83494e21e2b52efb1ecb297aae34e2ae781ff090a2fe9e1a312c751484b1713
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
- !!(document_class <= root)
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. Registered most-specific-last;
6
- # resolution walks most-specific-first so flavor gems (loaded after
7
- # the harness defaults) win, and taste entries fall through to their
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
- @flavors.reverse_each.find { |f| f.matches?(document.class) }
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
- @flavors.reverse_each.each do |flavor|
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
@@ -1,5 +1,5 @@
1
1
  module Metanorma
2
2
  module Core
3
- VERSION = "0.2.9".freeze
3
+ VERSION = "0.2.10".freeze
4
4
  end
5
5
  end
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.9
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-17 00:00:00.000000000 Z
11
+ date: 2026-11-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: asciidoctor