metanorma-plugin-glossarist 0.1.7 → 0.1.8
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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 12c432cfc7a1397fe5a88e961db51aa103712a0a81bc1eca871e073774c60fbe
|
4
|
+
data.tar.gz: a8d24f1c847b536dae718dc96ba559a8f5e83f8213c6a9490b3f173a3b88e881
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7acd13849a68c375d9113a8a93dc4abe55df7d6c9a72f3aeb1fbd10f0b3c8e746c2f06f203fe85718f6e5306132211fac8fea044fe346350e9abd6914958ce4e
|
7
|
+
data.tar.gz: 4dd925541b2181f9301b838eb1c4b5c2a52b7e7e458334b25956c18ee1511b10d4c18f0b58680e6ab8087323978851d8f3ed2afee7241fc089fb38e22ae62abd
|
@@ -3,9 +3,9 @@
|
|
3
3
|
module Liquid
|
4
4
|
module Drops
|
5
5
|
class ConceptsDrop < Liquid::Drop
|
6
|
-
|
7
|
-
NON_LANGUAGE_FIELDS = %w[term termid groups].freeze
|
6
|
+
NON_LANGUAGE_FIELDS = %w[identifier localized_concepts groups term].freeze
|
8
7
|
|
8
|
+
# rubocop:disable Lint/MissingSuper
|
9
9
|
def initialize(managed_concept_collection, filters = {})
|
10
10
|
@concepts_collection = managed_concept_collection
|
11
11
|
@concepts_map = {}
|
@@ -36,35 +36,21 @@ module Liquid
|
|
36
36
|
sort_filter = concept_filters.delete('sort_by')
|
37
37
|
group_filter = concept_filters.delete('group')
|
38
38
|
|
39
|
-
concepts = concepts_collection.
|
40
|
-
filtered_concept = concept.
|
41
|
-
filtered_concept
|
42
|
-
next if NON_LANGUAGE_FIELDS.include?(field)
|
43
|
-
|
44
|
-
unless allowed_language?(field, language_filter)
|
45
|
-
filtered_concept.delete(field)
|
46
|
-
next
|
47
|
-
end
|
39
|
+
concepts = concepts_collection.map do |concept|
|
40
|
+
filtered_concept = concept.to_h["data"]
|
41
|
+
filtered_concept["term"] = concept.default_designation
|
48
42
|
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
unless filtered_concept.dig(*fields).start_with?(value)
|
56
|
-
filtered_concept.delete(field)
|
57
|
-
end
|
58
|
-
elsif filtered_concept.dig(*fields) != value
|
59
|
-
filtered_concept.delete(field)
|
60
|
-
end
|
61
|
-
end
|
62
|
-
end
|
43
|
+
filtered_concept = filtered_concept.merge(
|
44
|
+
extract_localized_concepts(
|
45
|
+
concept,
|
46
|
+
language_filter,
|
47
|
+
),
|
48
|
+
)
|
63
49
|
|
64
|
-
if filtered_concept
|
65
|
-
nil
|
66
|
-
else
|
50
|
+
if retain_concept?(filtered_concept, concept_filters)
|
67
51
|
filtered_concept
|
52
|
+
else
|
53
|
+
nil
|
68
54
|
end
|
69
55
|
end.compact
|
70
56
|
|
@@ -72,6 +58,41 @@ module Liquid
|
|
72
58
|
apply_sort_filter(concepts, sort_filter)
|
73
59
|
end
|
74
60
|
|
61
|
+
def extract_localized_concepts(concept, languages)
|
62
|
+
localized_concepts = {}
|
63
|
+
|
64
|
+
if !languages || languages.empty?
|
65
|
+
concept.localized_concepts.each do |lang, localized_concept_uuid|
|
66
|
+
localized_concepts[lang] = concept.localizations[lang].to_h["data"]
|
67
|
+
end
|
68
|
+
else
|
69
|
+
languages.split(",").each do |lang|
|
70
|
+
localization = concept.localizations[lang]&.to_h&.dig("data")
|
71
|
+
localized_concepts[lang] = localization if localization
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
localized_concepts
|
76
|
+
end
|
77
|
+
|
78
|
+
def retain_concept?(filtered_concept, concept_filters)
|
79
|
+
concept_filters.each do |name, value|
|
80
|
+
fields = extract_nested_field_names(name)
|
81
|
+
if fields.last.start_with?("start_with")
|
82
|
+
value = fields.last.gsub(/start_with\(([^\)]*)\)/, '\1')
|
83
|
+
fields = fields[0..-2]
|
84
|
+
|
85
|
+
unless filtered_concept.dig(*fields).start_with?(value)
|
86
|
+
return false
|
87
|
+
end
|
88
|
+
elsif filtered_concept.dig(*fields) != value
|
89
|
+
return false
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
filtered_concept.keys & NON_LANGUAGE_FIELDS != filtered_concept.keys
|
94
|
+
end
|
95
|
+
|
75
96
|
def apply_sort_filter(concepts, sort_by)
|
76
97
|
return concepts unless sort_by
|
77
98
|
|
@@ -22,7 +22,7 @@ Gem::Specification.new do |spec|
|
|
22
22
|
spec.require_paths = ["lib"]
|
23
23
|
|
24
24
|
spec.add_dependency "asciidoctor", "~> 2.0.0"
|
25
|
-
spec.add_dependency "glossarist"
|
25
|
+
spec.add_dependency "glossarist", "~> 2.0.1"
|
26
26
|
spec.add_dependency "liquid", "~> 5"
|
27
27
|
|
28
28
|
spec.add_development_dependency "pry"
|
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.1.
|
4
|
+
version: 0.1.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ribose Inc.
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-11-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: asciidoctor
|
@@ -28,16 +28,16 @@ dependencies:
|
|
28
28
|
name: glossarist
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - "
|
31
|
+
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
33
|
+
version: 2.0.1
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - "
|
38
|
+
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version:
|
40
|
+
version: 2.0.1
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: liquid
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|