metanorma-plugin-glossarist 0.3.2 → 0.3.6
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/.gitignore +6 -6
- data/.rubocop_todo.yml +55 -246
- data/Gemfile +6 -5
- data/README.adoc +11 -1
- data/lib/metanorma/plugin/glossarist/bibliography_renderer.rb +54 -10
- data/lib/metanorma/plugin/glossarist/concept_filter.rb +22 -40
- data/lib/metanorma/plugin/glossarist/concept_path_resolver.rb +100 -0
- data/lib/metanorma/plugin/glossarist/dataset_preprocessor.rb +55 -84
- data/lib/metanorma/plugin/glossarist/dataset_registry.rb +98 -0
- data/lib/metanorma/plugin/glossarist/document.rb +8 -20
- data/lib/metanorma/plugin/glossarist/liquid/custom_blocks/with_glossarist_context.rb +47 -61
- data/lib/metanorma/plugin/glossarist/liquid/custom_filters/filters.rb +10 -4
- data/lib/metanorma/plugin/glossarist/liquid/custom_filters.rb +14 -0
- data/lib/metanorma/plugin/glossarist/liquid/drop_bracket_access.rb +36 -0
- data/lib/metanorma/plugin/glossarist/liquid/drops/localization_collection_drop.rb +47 -0
- data/lib/metanorma/plugin/glossarist/liquid/drops/managed_concept_data_drop.rb +29 -0
- data/lib/metanorma/plugin/glossarist/liquid/drops/managed_concept_drop.rb +45 -0
- data/lib/metanorma/plugin/glossarist/liquid/multiply_local_file_system.rb +1 -1
- data/lib/metanorma/plugin/glossarist/liquid.rb +26 -0
- data/lib/metanorma/plugin/glossarist/liquid_rendering.rb +26 -0
- data/lib/metanorma/plugin/glossarist/liquid_templates/_concept.liquid +51 -0
- data/lib/metanorma/plugin/glossarist/sanitize.rb +6 -4
- data/lib/metanorma/plugin/glossarist/template_renderer.rb +113 -0
- data/lib/metanorma/plugin/glossarist/version.rb +1 -1
- data/lib/metanorma-plugin-glossarist.rb +26 -7
- data/metanorma-plugin-glossarist.gemspec +1 -1
- metadata +21 -6
- data/lib/metanorma/plugin/glossarist/concept_renderer.rb +0 -91
- data/lib/metanorma/plugin/glossarist/concept_serializer.rb +0 -27
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Metanorma
|
|
4
|
+
module Plugin
|
|
5
|
+
module Glossarist
|
|
6
|
+
module Liquid
|
|
7
|
+
class LocalizationCollectionDrop < ::Liquid::Drop
|
|
8
|
+
include Enumerable
|
|
9
|
+
|
|
10
|
+
def initialize(collection)
|
|
11
|
+
super()
|
|
12
|
+
@collection = collection
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def liquid_method_missing(method)
|
|
16
|
+
l10n = @collection.find_by(:language_code, method.to_s)
|
|
17
|
+
l10n ? l10n.to_liquid : super
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def [](key)
|
|
21
|
+
liquid_method_missing(key.to_s)
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def key?(key)
|
|
25
|
+
!@collection.find_by(:language_code, key.to_s).nil?
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def size
|
|
29
|
+
@collection.size
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def each(&block)
|
|
33
|
+
@collection.each(&block)
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def first
|
|
37
|
+
@collection.first
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def last
|
|
41
|
+
@collection.last
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
end
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Metanorma
|
|
4
|
+
module Plugin
|
|
5
|
+
module Glossarist
|
|
6
|
+
module Liquid
|
|
7
|
+
class ManagedConceptDataDrop < ::Liquid::Drop
|
|
8
|
+
def initialize(concept_data)
|
|
9
|
+
super()
|
|
10
|
+
@concept_data = concept_data
|
|
11
|
+
@auto_drop = concept_data.to_liquid
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def localizations
|
|
15
|
+
@localizations ||= LocalizationCollectionDrop.new(@concept_data.localizations)
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def identifier
|
|
19
|
+
@concept_data.id
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def liquid_method_missing(method)
|
|
23
|
+
@auto_drop.invoke_drop(method)
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Metanorma
|
|
4
|
+
module Plugin
|
|
5
|
+
module Glossarist
|
|
6
|
+
module Liquid
|
|
7
|
+
class ManagedConceptDrop < ::Liquid::Drop
|
|
8
|
+
def initialize(concept)
|
|
9
|
+
super()
|
|
10
|
+
@concept = concept
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def data
|
|
14
|
+
@data ||= ManagedConceptDataDrop.new(@concept.data)
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def schema_version
|
|
18
|
+
@concept.schema_version
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def uuid
|
|
22
|
+
@concept.uuid
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def identifier
|
|
26
|
+
@concept.identifier
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def default_designation
|
|
30
|
+
@concept.default_designation
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def tags
|
|
34
|
+
@concept.data.tags
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def liquid_method_missing(method)
|
|
38
|
+
l10n = @concept.localization(method.to_s)
|
|
39
|
+
l10n ? l10n.to_liquid : super
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
end
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "liquid"
|
|
4
|
+
|
|
5
|
+
module Metanorma
|
|
6
|
+
module Plugin
|
|
7
|
+
module Glossarist
|
|
8
|
+
module Liquid
|
|
9
|
+
autoload :LocalFileSystem,
|
|
10
|
+
"metanorma/plugin/glossarist/liquid/multiply_local_file_system"
|
|
11
|
+
autoload :ManagedConceptDataDrop,
|
|
12
|
+
"metanorma/plugin/glossarist/liquid/drops/managed_concept_data_drop"
|
|
13
|
+
autoload :ManagedConceptDrop,
|
|
14
|
+
"metanorma/plugin/glossarist/liquid/drops/managed_concept_drop"
|
|
15
|
+
autoload :LocalizationCollectionDrop,
|
|
16
|
+
"metanorma/plugin/glossarist/liquid/drops/localization_collection_drop"
|
|
17
|
+
autoload :PolyfillIndexedAccess,
|
|
18
|
+
"metanorma/plugin/glossarist/liquid/drop_bracket_access"
|
|
19
|
+
autoload :WithGlossaristContext,
|
|
20
|
+
"metanorma/plugin/glossarist/liquid/custom_blocks/with_glossarist_context"
|
|
21
|
+
autoload :CustomFilters,
|
|
22
|
+
"metanorma/plugin/glossarist/liquid/custom_filters"
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "liquid"
|
|
4
|
+
|
|
5
|
+
module Metanorma
|
|
6
|
+
module Plugin
|
|
7
|
+
module Glossarist
|
|
8
|
+
module LiquidRendering
|
|
9
|
+
DEFAULT_PATTERNS = ["%s.liquid", "_%s.liquid"].freeze
|
|
10
|
+
DOCUMENT_PATTERNS = ["%s.liquid", "_%s.liquid", "_%s.adoc"].freeze
|
|
11
|
+
|
|
12
|
+
def self.render(content, include_paths:, patterns: DEFAULT_PATTERNS,
|
|
13
|
+
assigns: {}, registry: nil)
|
|
14
|
+
template = ::Liquid::Template.parse(content)
|
|
15
|
+
template.registers[:file_system] =
|
|
16
|
+
Liquid::LocalFileSystem.new(include_paths, patterns)
|
|
17
|
+
template.registers[:dataset_registry] = registry if registry
|
|
18
|
+
rendered = template.render(assigns)
|
|
19
|
+
raise template.errors.first.cause if template.errors.any?
|
|
20
|
+
|
|
21
|
+
rendered
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
{{ depth_marker }} {{ l10n.data.terms[0].designation }}
|
|
2
|
+
{%- for term in l10n.data.terms offset:1 %}
|
|
3
|
+
{%- if term.normative_status == "preferred" %}
|
|
4
|
+
preferred:[{{ term.designation }}]
|
|
5
|
+
{%- elsif term.normative_status == "admitted" %}
|
|
6
|
+
admitted:[{{ term.designation }}]
|
|
7
|
+
{%- elsif term.normative_status == "deprecated" %}
|
|
8
|
+
deprecated:[{{ term.designation }}]
|
|
9
|
+
{%- else %}
|
|
10
|
+
alt:[{{ term.designation }}]
|
|
11
|
+
{%- endif %}
|
|
12
|
+
{%- endfor %}
|
|
13
|
+
{% if l10n.data.domain %}
|
|
14
|
+
domain:[{{ l10n.data.domain }}]
|
|
15
|
+
|
|
16
|
+
{% endif %}
|
|
17
|
+
{% if l10n.data.definition.definitions[0] %}
|
|
18
|
+
{{ l10n.data.definition.definitions[0].content | sanitize_references }}
|
|
19
|
+
|
|
20
|
+
{% endif %}
|
|
21
|
+
{% for example in l10n.data.examples.definitions -%}
|
|
22
|
+
[example]
|
|
23
|
+
====
|
|
24
|
+
{{ example.content | sanitize_references }}
|
|
25
|
+
====
|
|
26
|
+
|
|
27
|
+
{% endfor %}
|
|
28
|
+
{% for note in l10n.data.notes.definitions -%}
|
|
29
|
+
[NOTE]
|
|
30
|
+
====
|
|
31
|
+
{{ note.content | sanitize_references }}
|
|
32
|
+
====
|
|
33
|
+
|
|
34
|
+
{% endfor %}
|
|
35
|
+
{% if l10n.data.annotations -%}
|
|
36
|
+
{% for annotation in l10n.data.annotations.definitions -%}
|
|
37
|
+
[NOTE]
|
|
38
|
+
====
|
|
39
|
+
{{ annotation.content | sanitize_references }}
|
|
40
|
+
====
|
|
41
|
+
|
|
42
|
+
{% endfor %}
|
|
43
|
+
{% endif %}
|
|
44
|
+
{% for source in l10n.data.sources.sources -%}
|
|
45
|
+
{% assign ref_text = source.origin.text | format_ref -%}
|
|
46
|
+
{% if ref_text != "" -%}
|
|
47
|
+
[.source]
|
|
48
|
+
<<{{ ref_text }}{% if source.origin.locality %},{{ source.origin.locality.type }}="{{ source.origin.locality.reference_from }}"{% elsif source.origin.original %},{{ source.origin.original }}{% endif %}>>{% if source.modification %}, {{ source.modification }}{% endif %}
|
|
49
|
+
|
|
50
|
+
{% endif %}
|
|
51
|
+
{% endfor %}
|
|
@@ -4,15 +4,17 @@ module Metanorma
|
|
|
4
4
|
module Plugin
|
|
5
5
|
module Glossarist
|
|
6
6
|
module Sanitize
|
|
7
|
-
REF_REGEX = /{{([^,{}]+),([^}]+?)}}(.*)$/
|
|
7
|
+
REF_REGEX = /{{(urn:[^,{}]+),([^}]+?)}}(.*)$/m
|
|
8
8
|
XREF_REGEX = /<<((?>[^,>\n]+))(?:,[^>\n]*)?>>/
|
|
9
9
|
|
|
10
10
|
def self.references(str)
|
|
11
11
|
return str unless str&.match?(REF_REGEX)
|
|
12
12
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
13
|
+
str.gsub(REF_REGEX) do
|
|
14
|
+
m = Regexp.last_match
|
|
15
|
+
urn = Metanorma::Utils.to_ncname(m[1]).gsub(":", "_")
|
|
16
|
+
"{{#{urn},#{m[2]}}}#{m[3]}"
|
|
17
|
+
end
|
|
16
18
|
end
|
|
17
19
|
|
|
18
20
|
def self.extract_xrefs(text)
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Metanorma
|
|
4
|
+
module Plugin
|
|
5
|
+
module Glossarist
|
|
6
|
+
class TemplateRenderer
|
|
7
|
+
TEMPLATES_DIR = File.join(File.dirname(__FILE__), "liquid_templates")
|
|
8
|
+
DEFAULT_TEMPLATE = File.join(TEMPLATES_DIR, "_concept.liquid")
|
|
9
|
+
|
|
10
|
+
def initialize(file_system:, lang: "eng")
|
|
11
|
+
@file_system = file_system
|
|
12
|
+
@lang = lang
|
|
13
|
+
@template_cache = {}
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def render_concepts(concepts, depth:, anchor_prefix: nil)
|
|
17
|
+
tree = build_concept_tree(concepts)
|
|
18
|
+
parts = tree.map { |c| render_tree_node(c, depth, anchor_prefix) }
|
|
19
|
+
normalize_whitespace(parts.join("\n\n"))
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def render_concept(concept, depth:, anchor_prefix: nil)
|
|
23
|
+
l10n = concept.localization(@lang)
|
|
24
|
+
context = {
|
|
25
|
+
"concept" => concept.to_liquid,
|
|
26
|
+
"l10n" => l10n&.to_liquid,
|
|
27
|
+
"depth_marker" => "=" * (depth + 1),
|
|
28
|
+
"anchor" => build_anchor(concept.data.id.to_s, anchor_prefix),
|
|
29
|
+
}
|
|
30
|
+
template_content = cached_template(concept)
|
|
31
|
+
rendered = render_template(template_content, context)
|
|
32
|
+
normalize_whitespace(rendered)
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
private
|
|
36
|
+
|
|
37
|
+
def cached_template(concept)
|
|
38
|
+
version = concept.schema_version
|
|
39
|
+
@template_cache[version] ||= begin
|
|
40
|
+
path = File.join(TEMPLATES_DIR, "_concept_#{version}.liquid")
|
|
41
|
+
File.exist?(path) ? File.read(path) : File.read(DEFAULT_TEMPLATE)
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def render_tree_node((concept, children), depth, anchor_prefix)
|
|
46
|
+
result = render_concept(concept, depth: depth,
|
|
47
|
+
anchor_prefix: anchor_prefix)
|
|
48
|
+
children.each do |child_node|
|
|
49
|
+
result += "\n" + render_tree_node(child_node, depth + 1,
|
|
50
|
+
anchor_prefix)
|
|
51
|
+
end
|
|
52
|
+
result
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def build_concept_tree(concepts)
|
|
56
|
+
concept_map = concepts.to_h { |c| [concept_id(c), c] }
|
|
57
|
+
children_of = Hash.new { |h, k| h[k] = [] }
|
|
58
|
+
roots = []
|
|
59
|
+
|
|
60
|
+
concepts.each do |c|
|
|
61
|
+
parent_id = find_parent_id(c)
|
|
62
|
+
if parent_id && concept_map[parent_id]
|
|
63
|
+
children_of[parent_id] << c
|
|
64
|
+
else
|
|
65
|
+
roots << c
|
|
66
|
+
end
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
build_tree_nodes(roots, children_of)
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
def build_tree_nodes(concepts, children_of)
|
|
73
|
+
concepts.map do |c|
|
|
74
|
+
[c, build_tree_nodes(children_of[concept_id(c)], children_of)]
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
def concept_id(concept)
|
|
79
|
+
concept.data.id.to_s
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
def find_parent_id(concept)
|
|
83
|
+
concept.data.related&.find { |r| r.type == "broader" }&.ref&.id&.to_s
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
def build_anchor(id, prefix)
|
|
87
|
+
anchor = prefix ? "#{prefix}#{id}" : id
|
|
88
|
+
if anchor.match?(/\A\d/)
|
|
89
|
+
anchor
|
|
90
|
+
else
|
|
91
|
+
Metanorma::Utils.to_ncname(anchor.gsub(
|
|
92
|
+
":", "_"
|
|
93
|
+
))
|
|
94
|
+
end
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
def render_template(content, assigns)
|
|
98
|
+
LiquidRendering.render(
|
|
99
|
+
content,
|
|
100
|
+
include_paths: [TEMPLATES_DIR, @file_system].compact,
|
|
101
|
+
assigns: assigns,
|
|
102
|
+
)
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
def normalize_whitespace(text)
|
|
106
|
+
text.gsub(/\n{3,}/, "\n\n")
|
|
107
|
+
.gsub(/([^\]\n])\n(={2,6} )/, "\\1\n\n\\2")
|
|
108
|
+
.strip
|
|
109
|
+
end
|
|
110
|
+
end
|
|
111
|
+
end
|
|
112
|
+
end
|
|
113
|
+
end
|
|
@@ -2,10 +2,29 @@
|
|
|
2
2
|
|
|
3
3
|
require "metanorma/plugin/glossarist/version"
|
|
4
4
|
require "metanorma-utils"
|
|
5
|
-
require "
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
5
|
+
require "glossarist"
|
|
6
|
+
|
|
7
|
+
module Metanorma
|
|
8
|
+
module Plugin
|
|
9
|
+
module Glossarist
|
|
10
|
+
autoload :BibliographyRenderer,
|
|
11
|
+
"metanorma/plugin/glossarist/bibliography_renderer"
|
|
12
|
+
autoload :ConceptFilter, "metanorma/plugin/glossarist/concept_filter"
|
|
13
|
+
autoload :ConceptPathResolver,
|
|
14
|
+
"metanorma/plugin/glossarist/concept_path_resolver"
|
|
15
|
+
autoload :DatasetPreprocessor,
|
|
16
|
+
"metanorma/plugin/glossarist/dataset_preprocessor"
|
|
17
|
+
autoload :DatasetRegistry, "metanorma/plugin/glossarist/dataset_registry"
|
|
18
|
+
autoload :Document, "metanorma/plugin/glossarist/document"
|
|
19
|
+
autoload :Liquid, "metanorma/plugin/glossarist/liquid"
|
|
20
|
+
autoload :LiquidRendering, "metanorma/plugin/glossarist/liquid_rendering"
|
|
21
|
+
autoload :Sanitize, "metanorma/plugin/glossarist/sanitize"
|
|
22
|
+
autoload :TemplateRenderer,
|
|
23
|
+
"metanorma/plugin/glossarist/template_renderer"
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
Metanorma::Plugin::Glossarist::Liquid::PolyfillIndexedAccess.apply!
|
|
29
|
+
Metanorma::Plugin::Glossarist::Liquid::WithGlossaristContext.register!
|
|
30
|
+
Metanorma::Plugin::Glossarist::Liquid::CustomFilters::Filters.register!
|
|
@@ -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.
|
|
29
|
+
spec.add_dependency "glossarist", "~> 2.8", ">= 2.8.7"
|
|
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.3.
|
|
4
|
+
version: 0.3.6
|
|
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-
|
|
11
|
+
date: 2026-06-09 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: asciidoctor
|
|
@@ -30,14 +30,20 @@ dependencies:
|
|
|
30
30
|
requirements:
|
|
31
31
|
- - "~>"
|
|
32
32
|
- !ruby/object:Gem::Version
|
|
33
|
-
version: 2.
|
|
33
|
+
version: '2.8'
|
|
34
|
+
- - ">="
|
|
35
|
+
- !ruby/object:Gem::Version
|
|
36
|
+
version: 2.8.7
|
|
34
37
|
type: :runtime
|
|
35
38
|
prerelease: false
|
|
36
39
|
version_requirements: !ruby/object:Gem::Requirement
|
|
37
40
|
requirements:
|
|
38
41
|
- - "~>"
|
|
39
42
|
- !ruby/object:Gem::Version
|
|
40
|
-
version: 2.
|
|
43
|
+
version: '2.8'
|
|
44
|
+
- - ">="
|
|
45
|
+
- !ruby/object:Gem::Version
|
|
46
|
+
version: 2.8.7
|
|
41
47
|
- !ruby/object:Gem::Dependency
|
|
42
48
|
name: liquid
|
|
43
49
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -90,14 +96,23 @@ files:
|
|
|
90
96
|
- lib/metanorma-plugin-glossarist.rb
|
|
91
97
|
- lib/metanorma/plugin/glossarist/bibliography_renderer.rb
|
|
92
98
|
- lib/metanorma/plugin/glossarist/concept_filter.rb
|
|
93
|
-
- lib/metanorma/plugin/glossarist/
|
|
94
|
-
- lib/metanorma/plugin/glossarist/concept_serializer.rb
|
|
99
|
+
- lib/metanorma/plugin/glossarist/concept_path_resolver.rb
|
|
95
100
|
- lib/metanorma/plugin/glossarist/dataset_preprocessor.rb
|
|
101
|
+
- lib/metanorma/plugin/glossarist/dataset_registry.rb
|
|
96
102
|
- lib/metanorma/plugin/glossarist/document.rb
|
|
103
|
+
- lib/metanorma/plugin/glossarist/liquid.rb
|
|
97
104
|
- lib/metanorma/plugin/glossarist/liquid/custom_blocks/with_glossarist_context.rb
|
|
105
|
+
- lib/metanorma/plugin/glossarist/liquid/custom_filters.rb
|
|
98
106
|
- lib/metanorma/plugin/glossarist/liquid/custom_filters/filters.rb
|
|
107
|
+
- lib/metanorma/plugin/glossarist/liquid/drop_bracket_access.rb
|
|
108
|
+
- lib/metanorma/plugin/glossarist/liquid/drops/localization_collection_drop.rb
|
|
109
|
+
- lib/metanorma/plugin/glossarist/liquid/drops/managed_concept_data_drop.rb
|
|
110
|
+
- lib/metanorma/plugin/glossarist/liquid/drops/managed_concept_drop.rb
|
|
99
111
|
- lib/metanorma/plugin/glossarist/liquid/multiply_local_file_system.rb
|
|
112
|
+
- lib/metanorma/plugin/glossarist/liquid_rendering.rb
|
|
113
|
+
- lib/metanorma/plugin/glossarist/liquid_templates/_concept.liquid
|
|
100
114
|
- lib/metanorma/plugin/glossarist/sanitize.rb
|
|
115
|
+
- lib/metanorma/plugin/glossarist/template_renderer.rb
|
|
101
116
|
- lib/metanorma/plugin/glossarist/version.rb
|
|
102
117
|
- metanorma-plugin-glossarist.gemspec
|
|
103
118
|
homepage: https://github.com/metanorma/metanorma-plugin-glossarist
|
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module Metanorma
|
|
4
|
-
module Plugin
|
|
5
|
-
module Glossarist
|
|
6
|
-
class ConceptRenderer
|
|
7
|
-
TERM_TYPES = %w[preferred admitted deprecated].freeze
|
|
8
|
-
|
|
9
|
-
def initialize(concept, depth:, anchor_prefix: nil)
|
|
10
|
-
@concept = concept
|
|
11
|
-
@depth = depth
|
|
12
|
-
@anchor_prefix = anchor_prefix
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
def render
|
|
16
|
-
sections = [concept_header]
|
|
17
|
-
sections << alt_terms_section
|
|
18
|
-
sections << definition_section
|
|
19
|
-
sections << examples_section
|
|
20
|
-
sections << notes_section
|
|
21
|
-
sections << sources_section
|
|
22
|
-
sections.compact.join("\n\n")
|
|
23
|
-
end
|
|
24
|
-
|
|
25
|
-
private
|
|
26
|
-
|
|
27
|
-
def eng_l10n
|
|
28
|
-
@eng_l10n ||= @concept.localization("eng")
|
|
29
|
-
end
|
|
30
|
-
|
|
31
|
-
def concept_header
|
|
32
|
-
"[[#{anchor_id}]]\n#{heading_line}"
|
|
33
|
-
end
|
|
34
|
-
|
|
35
|
-
def anchor_id
|
|
36
|
-
id = "#{@anchor_prefix}#{@concept.data.id}"
|
|
37
|
-
id.match?(/\A\d/) ? id : Metanorma::Utils.to_ncname(id.gsub(":", "_"))
|
|
38
|
-
end
|
|
39
|
-
|
|
40
|
-
def heading_line
|
|
41
|
-
"#{'=' * (@depth + 1)} #{term_designation}"
|
|
42
|
-
end
|
|
43
|
-
|
|
44
|
-
def term_designation
|
|
45
|
-
eng_l10n.terms.first&.designation.to_s
|
|
46
|
-
end
|
|
47
|
-
|
|
48
|
-
def alt_terms_section
|
|
49
|
-
terms = eng_l10n.terms[1..].map do |term|
|
|
50
|
-
type = TERM_TYPES.include?(term.normative_status) ? term.normative_status : "alt"
|
|
51
|
-
"#{type}:[#{term.designation}]"
|
|
52
|
-
end
|
|
53
|
-
terms.empty? ? nil : terms.join("\n")
|
|
54
|
-
end
|
|
55
|
-
|
|
56
|
-
def definition_section
|
|
57
|
-
content = eng_l10n.definition.first&.content
|
|
58
|
-
return nil unless content
|
|
59
|
-
|
|
60
|
-
Sanitize.references(content.to_s)
|
|
61
|
-
end
|
|
62
|
-
|
|
63
|
-
def examples_section
|
|
64
|
-
examples = eng_l10n.examples.map do |example|
|
|
65
|
-
"[example]\n#{Sanitize.references(example.content.to_s)}"
|
|
66
|
-
end
|
|
67
|
-
examples.empty? ? nil : examples.join("\n")
|
|
68
|
-
end
|
|
69
|
-
|
|
70
|
-
def notes_section
|
|
71
|
-
notes = eng_l10n.notes.map do |note|
|
|
72
|
-
"[NOTE]\n====\n#{Sanitize.references(note.content.to_s)}\n===="
|
|
73
|
-
end
|
|
74
|
-
notes.empty? ? nil : notes.join("\n")
|
|
75
|
-
end
|
|
76
|
-
|
|
77
|
-
def sources_section
|
|
78
|
-
sources = eng_l10n.sources.filter_map do |source|
|
|
79
|
-
next if source.origin&.text.nil? || source.origin.text.empty?
|
|
80
|
-
next unless source.origin.locality&.type == "clause"
|
|
81
|
-
|
|
82
|
-
ref = source.origin.text.gsub(%r{[ /:]}, "_")
|
|
83
|
-
clause = source.origin.locality.reference_from
|
|
84
|
-
"[.source]\n<<#{ref},#{clause}>>"
|
|
85
|
-
end
|
|
86
|
-
sources.empty? ? nil : sources.join("\n")
|
|
87
|
-
end
|
|
88
|
-
end
|
|
89
|
-
end
|
|
90
|
-
end
|
|
91
|
-
end
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module Metanorma
|
|
4
|
-
module Plugin
|
|
5
|
-
module Glossarist
|
|
6
|
-
class ConceptSerializer
|
|
7
|
-
def initialize(concept)
|
|
8
|
-
@concept = concept
|
|
9
|
-
end
|
|
10
|
-
|
|
11
|
-
def to_h
|
|
12
|
-
data = @concept.data.to_hash
|
|
13
|
-
data["localizations"] = localizations_hash unless @concept.localizations.empty?
|
|
14
|
-
{ "data" => data.compact }
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
private
|
|
18
|
-
|
|
19
|
-
def localizations_hash
|
|
20
|
-
@concept.localizations.to_h do |l10n|
|
|
21
|
-
[l10n.language_code, l10n.to_hash]
|
|
22
|
-
end
|
|
23
|
-
end
|
|
24
|
-
end
|
|
25
|
-
end
|
|
26
|
-
end
|
|
27
|
-
end
|