metanorma-plugin-glossarist 0.4.1 → 0.5.0
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/plugin/glossarist/dataset_preprocessor.rb +1 -1
- data/lib/metanorma/plugin/glossarist/dataset_registry.rb +19 -27
- data/lib/metanorma/plugin/glossarist/non_verbal_renderer.rb +34 -10
- data/lib/metanorma/plugin/glossarist/version.rb +1 -1
- data/metanorma-plugin-glossarist.gemspec +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 704ad16bc258aaa5af4a78ffdeac527254bf94ca24dfb26dac89e4233f4e625e
|
|
4
|
+
data.tar.gz: f073009599c27404eb2a7c59d1988892ed954bc70d42e8e7e41990b20b430c1a
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 2b7c0b15020b2be901c61bd6d79df81aae2ac2f76f50ac9f6cf49ed4035bb2df7089ac7d70ccec4998023fcb46539f1c902836eb6d62f4f17e6f5bc4ce238513
|
|
7
|
+
data.tar.gz: 2ac8b854afb2da6692690105c41a8b4a71c2cc69ce367b32a5ec199eaf2850223ade67dacf4b96e9b03512230409ae09772ee6f567e138ea91235d55559c90cc
|
|
@@ -290,7 +290,7 @@ module Metanorma
|
|
|
290
290
|
kind = :"#{match[1]}"
|
|
291
291
|
dataset_name = match[2].strip
|
|
292
292
|
collection = @registry.non_verbal_collection(dataset_name, kind)
|
|
293
|
-
return
|
|
293
|
+
return if collection.nil? || collection.empty?
|
|
294
294
|
|
|
295
295
|
renderer = NonVerbalRenderer.new(collections: { kind => collection })
|
|
296
296
|
rendered = renderer.render_kind(kind)
|
|
@@ -14,20 +14,16 @@ module Metanorma
|
|
|
14
14
|
BIBLIOGRAPHY_FILENAME = "bibliography.yaml"
|
|
15
15
|
REGISTER_FILENAME = "register.yaml"
|
|
16
16
|
|
|
17
|
-
#
|
|
18
|
-
#
|
|
19
|
-
#
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
tables: [::Glossarist::Collections::TableCollection, "tables"],
|
|
23
|
-
formulas: [::Glossarist::Collections::FormulaCollection, "formulas"],
|
|
24
|
-
}.freeze
|
|
17
|
+
# Non-verbal entity kinds exposed by GlossaryStore. Each kind
|
|
18
|
+
# matches a method on +GlossaryStore+ (+#figures+, +#tables+,
|
|
19
|
+
# +#formulas+) that returns an +Array<Figure|Table|Formula>+,
|
|
20
|
+
# lazily loaded from +{dataset_path}/{kind}/*.yaml+.
|
|
21
|
+
NON_VERBAL_KINDS = %i[figures tables formulas].freeze
|
|
25
22
|
|
|
26
23
|
def initialize
|
|
27
24
|
@stores = {}
|
|
28
25
|
@registers = {}
|
|
29
26
|
@bibliographies = {}
|
|
30
|
-
@non_verbal = {}
|
|
31
27
|
@context_paths = {}
|
|
32
28
|
end
|
|
33
29
|
|
|
@@ -90,35 +86,39 @@ module Metanorma
|
|
|
90
86
|
store_for(path).concepts
|
|
91
87
|
end
|
|
92
88
|
|
|
93
|
-
# Returns the
|
|
94
|
-
# (e.g.
|
|
95
|
-
#
|
|
89
|
+
# Returns the Array of dataset-level non-verbal entities of the
|
|
90
|
+
# given kind for a registered context (e.g. +Array<Glossarist::Figure>+),
|
|
91
|
+
# or +nil+ if the context isn't registered. Empty Array means the
|
|
92
|
+
# dataset has no +{kind}/+ subdirectory.
|
|
93
|
+
#
|
|
94
|
+
# +kind+ must be one of +NON_VERBAL_KINDS+. The kind symbol is the
|
|
95
|
+
# message sent to +GlossaryStore+ — adding a new kind requires both
|
|
96
|
+
# a GlossaryStore accessor and an entry here.
|
|
96
97
|
def non_verbal_collection(context_name, kind)
|
|
97
|
-
unless NON_VERBAL_KINDS.
|
|
98
|
+
unless NON_VERBAL_KINDS.include?(kind)
|
|
98
99
|
raise ArgumentError, "unknown non-verbal kind: #{kind.inspect}"
|
|
99
100
|
end
|
|
100
101
|
|
|
101
102
|
path = @context_paths[context_name]
|
|
102
103
|
return nil unless path
|
|
103
104
|
|
|
104
|
-
|
|
105
|
-
non_verbal_at(path, kind, subdir, collection_class)
|
|
105
|
+
store_for(path).public_send(kind)
|
|
106
106
|
end
|
|
107
107
|
|
|
108
|
-
NON_VERBAL_KINDS.
|
|
108
|
+
NON_VERBAL_KINDS.each do |kind|
|
|
109
109
|
define_method("#{kind}_for") do |context_name|
|
|
110
110
|
non_verbal_collection(context_name, kind)
|
|
111
111
|
end
|
|
112
112
|
end
|
|
113
113
|
|
|
114
114
|
# Returns all available non-verbal collections for a context as a
|
|
115
|
-
# hash keyed by kind symbol (e.g. +{ figures:
|
|
115
|
+
# hash keyed by kind symbol (e.g. +{ figures: Array<Figure> }+).
|
|
116
116
|
# Kinds whose subdirectory doesn't exist are omitted. Convenient
|
|
117
117
|
# for building a NonVerbalRenderer in one call.
|
|
118
118
|
def non_verbal_collections(context_name)
|
|
119
|
-
NON_VERBAL_KINDS.each_with_object({}) do |
|
|
119
|
+
NON_VERBAL_KINDS.each_with_object({}) do |kind, memo|
|
|
120
120
|
collection = non_verbal_collection(context_name, kind)
|
|
121
|
-
memo[kind] = collection if collection
|
|
121
|
+
memo[kind] = collection if collection && !collection.empty?
|
|
122
122
|
end
|
|
123
123
|
end
|
|
124
124
|
|
|
@@ -149,14 +149,6 @@ module Metanorma
|
|
|
149
149
|
end
|
|
150
150
|
end
|
|
151
151
|
|
|
152
|
-
def non_verbal_at(path, kind, subdir, collection_class)
|
|
153
|
-
dir = File.join(path, subdir)
|
|
154
|
-
return nil unless File.directory?(dir)
|
|
155
|
-
|
|
156
|
-
@non_verbal[path] ||= {}
|
|
157
|
-
@non_verbal[path][kind] ||= collection_class.from_directory(dir)
|
|
158
|
-
end
|
|
159
|
-
|
|
160
152
|
def relative_file_path(document, file_path)
|
|
161
153
|
return file_path if File.absolute_path?(file_path)
|
|
162
154
|
|
|
@@ -11,6 +11,12 @@ module Metanorma
|
|
|
11
11
|
# Per-kind formatting is delegated to a formatter class registered
|
|
12
12
|
# in +FORMATTERS+. Adding a new kind = adding one formatter class
|
|
13
13
|
# and one entry here; the dispatcher itself never changes shape.
|
|
14
|
+
#
|
|
15
|
+
# Collections are +Array<Figure|Table|Formula>+ as returned by
|
|
16
|
+
# +GlossaryStore#figures/#tables/#formulas+. Lookups by id
|
|
17
|
+
# (for concept→entity refs) use a lazily-built index that includes
|
|
18
|
+
# Figure subfigures, preserving the recursive +Figure#find_by_id+
|
|
19
|
+
# semantics of the previous Collection-based path.
|
|
14
20
|
class NonVerbalRenderer
|
|
15
21
|
FORMATTERS = {
|
|
16
22
|
figures: NonVerbalFormatters::Figure,
|
|
@@ -18,13 +24,14 @@ module Metanorma
|
|
|
18
24
|
formulas: NonVerbalFormatters::Formula,
|
|
19
25
|
}.freeze
|
|
20
26
|
|
|
21
|
-
# @param collections [Hash{Symbol =>
|
|
27
|
+
# @param collections [Hash{Symbol => Array<NonVerbalEntity>, nil}]
|
|
22
28
|
# one entry per non-verbal kind, e.g.
|
|
23
|
-
# `{ figures:
|
|
29
|
+
# `{ figures: Array<Glossarist::Figure>, ... }`.
|
|
24
30
|
# Missing or nil entries are silently skipped.
|
|
25
31
|
def initialize(collections:, lang: "eng")
|
|
26
32
|
@collections = collections
|
|
27
33
|
@lang = lang
|
|
34
|
+
@indices = {}
|
|
28
35
|
end
|
|
29
36
|
|
|
30
37
|
# Render every entity in the named collection.
|
|
@@ -32,11 +39,10 @@ module Metanorma
|
|
|
32
39
|
# @param kind [Symbol] key in FORMATTERS (e.g. +:figures+)
|
|
33
40
|
# @return [String] AsciiDoc blocks joined by blank lines, or ""
|
|
34
41
|
def render_kind(kind)
|
|
35
|
-
|
|
36
|
-
return "" if
|
|
42
|
+
entities = @collections[kind]
|
|
43
|
+
return "" if entities.nil? || entities.empty?
|
|
37
44
|
|
|
38
|
-
|
|
39
|
-
"#{entries.map { |e| format_one(kind, e) }.join("\n\n")}\n"
|
|
45
|
+
"#{entities.map { |e| format_one(kind, e) }.join("\n\n")}\n"
|
|
40
46
|
end
|
|
41
47
|
|
|
42
48
|
# Render the non-verbal entities referenced by a concept's
|
|
@@ -61,10 +67,7 @@ module Metanorma
|
|
|
61
67
|
private
|
|
62
68
|
|
|
63
69
|
def render_ref(kind, ref)
|
|
64
|
-
|
|
65
|
-
return nil unless collection
|
|
66
|
-
|
|
67
|
-
entity = collection.by_id(ref.entity_id)
|
|
70
|
+
entity = index_for(kind)[ref.entity_id]
|
|
68
71
|
return nil unless entity
|
|
69
72
|
|
|
70
73
|
format_one(kind, entity)
|
|
@@ -78,6 +81,27 @@ module Metanorma
|
|
|
78
81
|
refs = concept.data&.public_send(kind)
|
|
79
82
|
Array(refs)
|
|
80
83
|
end
|
|
84
|
+
|
|
85
|
+
# Lazily builds and caches a {id => entity} index for the named
|
|
86
|
+
# kind. Figures include their subfigures recursively; other kinds
|
|
87
|
+
# are flat by id. Returns {} for missing/empty collections so
|
|
88
|
+
# lookups naturally return nil.
|
|
89
|
+
def index_for(kind)
|
|
90
|
+
@indices[kind] ||= build_index(@collections[kind])
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
def build_index(entities)
|
|
94
|
+
return {} if entities.nil? || entities.empty?
|
|
95
|
+
|
|
96
|
+
entities.each_with_object({}) { |e, h| index_entity(h, e) }
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
def index_entity(index, entity)
|
|
100
|
+
index[entity.id] = entity
|
|
101
|
+
return unless entity.is_a?(::Glossarist::Figure)
|
|
102
|
+
|
|
103
|
+
Array(entity.subfigures).each { |sub| index_entity(index, sub) }
|
|
104
|
+
end
|
|
81
105
|
end
|
|
82
106
|
end
|
|
83
107
|
end
|
|
@@ -26,7 +26,7 @@ Gem::Specification.new do |spec|
|
|
|
26
26
|
spec.required_ruby_version = ">= 3.1.0"
|
|
27
27
|
|
|
28
28
|
spec.add_dependency "asciidoctor"
|
|
29
|
-
spec.add_dependency "glossarist", "~> 2.8", ">= 2.
|
|
29
|
+
spec.add_dependency "glossarist", "~> 2.8", ">= 2.11.1"
|
|
30
30
|
spec.add_dependency "liquid"
|
|
31
31
|
spec.add_dependency "metanorma-utils"
|
|
32
32
|
spec.metadata["rubygems_mfa_required"] = "true"
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: metanorma-plugin-glossarist
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.5.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Ribose Inc.
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2026-07-
|
|
11
|
+
date: 2026-07-08 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: asciidoctor
|
|
@@ -33,7 +33,7 @@ dependencies:
|
|
|
33
33
|
version: '2.8'
|
|
34
34
|
- - ">="
|
|
35
35
|
- !ruby/object:Gem::Version
|
|
36
|
-
version: 2.
|
|
36
|
+
version: 2.11.1
|
|
37
37
|
type: :runtime
|
|
38
38
|
prerelease: false
|
|
39
39
|
version_requirements: !ruby/object:Gem::Requirement
|
|
@@ -43,7 +43,7 @@ dependencies:
|
|
|
43
43
|
version: '2.8'
|
|
44
44
|
- - ">="
|
|
45
45
|
- !ruby/object:Gem::Version
|
|
46
|
-
version: 2.
|
|
46
|
+
version: 2.11.1
|
|
47
47
|
- !ruby/object:Gem::Dependency
|
|
48
48
|
name: liquid
|
|
49
49
|
requirement: !ruby/object:Gem::Requirement
|