metanorma-plugin-glossarist 0.2.3 → 0.2.4
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/Gemfile +5 -1
- data/README.adoc +836 -0
- data/Rakefile +1 -1
- data/lib/metanorma/plugin/glossarist/dataset_preprocessor.rb +140 -70
- data/lib/metanorma/plugin/glossarist/document.rb +21 -2
- data/lib/metanorma/plugin/glossarist/liquid/custom_blocks/with_glossarist_context.rb +155 -0
- data/lib/metanorma/plugin/glossarist/liquid/custom_filters/filters.rb +43 -0
- data/lib/metanorma/plugin/glossarist/version.rb +1 -1
- data/metanorma-plugin-glossarist.gemspec +5 -2
- metadata +12 -13
- data/README.md +0 -495
- data/lib/liquid/custom_blocks/with_glossarist_context.rb +0 -52
- data/lib/liquid/custom_filters/filters.rb +0 -35
- data/lib/liquid/drops/concepts_drop.rb +0 -129
data/Rakefile
CHANGED
@@ -6,15 +6,6 @@ require "liquid"
|
|
6
6
|
require "asciidoctor/reader"
|
7
7
|
require "glossarist"
|
8
8
|
require "metanorma/plugin/glossarist/document"
|
9
|
-
require "liquid/custom_blocks/with_glossarist_context"
|
10
|
-
|
11
|
-
require "liquid/drops/concepts_drop"
|
12
|
-
require "liquid/custom_filters/filters"
|
13
|
-
|
14
|
-
Liquid::Template
|
15
|
-
.register_tag("with_glossarist_context",
|
16
|
-
Liquid::CustomBlocks::WithGlossaristContext)
|
17
|
-
Liquid::Template.register_filter(Liquid::CustomFilters::Filters)
|
18
9
|
|
19
10
|
module Metanorma
|
20
11
|
module Plugin
|
@@ -23,12 +14,10 @@ module Metanorma
|
|
23
14
|
GLOSSARIST_DATASET_REGEX = /^:glossarist-dataset:\s*(.*?)$/m.freeze
|
24
15
|
GLOSSARIST_IMPORT_REGEX = /^glossarist::import\[(.*?)\]$/m.freeze
|
25
16
|
GLOSSARIST_RENDER_REGEX = /^glossarist::render\[(.*?)\]$/m.freeze
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
GLOSSARIST_BIBLIOGRAPHY_REGEX = /^glossarist::render_bibliography\[(.*?)\]$/m.freeze
|
31
|
-
GLOSSARIST_BIBLIOGRAPHY_ENTRY_REGEX = /^glossarist::render_bibliography_entry\[(.*?)\]$/m.freeze
|
17
|
+
GLOSSARIST_BLOCK_REGEX = /^\[glossarist,(.+?),(.+?)\]/.freeze
|
18
|
+
GLOSSARIST_FILTER_BLOCK_REGEX = /^\[glossarist,(.+?),(filter=.+?),(.+?)\]/.freeze # rubocop:disable Layout/LineLength
|
19
|
+
GLOSSARIST_BIBLIOGRAPHY_REGEX = /^glossarist::render_bibliography\[(.*?)\]$/m.freeze # rubocop:disable Layout/LineLength
|
20
|
+
GLOSSARIST_BIBLIOGRAPHY_ENTRY_REGEX = /^glossarist::render_bibliography_entry\[(.*?)\]$/m.freeze # rubocop:disable Layout/LineLength
|
32
21
|
|
33
22
|
# Search document for the following blocks
|
34
23
|
# - :glossarist-dataset: dataset1:./dataset1;dataset2:./dataset2
|
@@ -83,14 +72,18 @@ module Metanorma
|
|
83
72
|
protected
|
84
73
|
|
85
74
|
def log(doc, text)
|
86
|
-
File.open("#{doc.attr('docfile')}.glossarist.log.txt",
|
75
|
+
File.open("#{doc.attr('docfile')}.glossarist.log.txt",
|
76
|
+
"w:UTF-8") do |f|
|
87
77
|
f.write(text)
|
88
78
|
end
|
89
79
|
end
|
90
80
|
|
91
81
|
private
|
92
82
|
|
93
|
-
def prepare_document(
|
83
|
+
def prepare_document( # rubocop:disable Metrics/MethodLength
|
84
|
+
document, input_lines, end_mark = nil,
|
85
|
+
skip_dataset: false
|
86
|
+
)
|
94
87
|
liquid_doc = Document.new
|
95
88
|
liquid_doc.file_system = @config[:file_system]
|
96
89
|
|
@@ -98,13 +91,19 @@ module Metanorma
|
|
98
91
|
current_line = input_lines.next
|
99
92
|
break if end_mark && current_line == end_mark
|
100
93
|
|
101
|
-
|
94
|
+
if !(
|
95
|
+
skip_dataset && current_line.start_with?(":glossarist-dataset:")
|
96
|
+
)
|
97
|
+
process_line(document, input_lines, current_line, liquid_doc)
|
98
|
+
end
|
102
99
|
end
|
103
100
|
|
104
101
|
liquid_doc
|
105
102
|
end
|
106
103
|
|
107
|
-
def process_line(
|
104
|
+
def process_line( # rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/MethodLength,Metrics/PerceivedComplexity
|
105
|
+
document, input_lines, current_line, liquid_doc
|
106
|
+
)
|
108
107
|
if match = current_line.match(GLOSSARIST_DATASET_REGEX)
|
109
108
|
process_dataset_tag(document, input_lines, liquid_doc, match)
|
110
109
|
elsif match = current_line.match(GLOSSARIST_RENDER_REGEX)
|
@@ -117,40 +116,44 @@ module Metanorma
|
|
117
116
|
process_bibliography_entry(liquid_doc, match)
|
118
117
|
elsif match = current_line.match(GLOSSARIST_FILTER_BLOCK_REGEX)
|
119
118
|
process_glossarist_block(document, liquid_doc, input_lines, match)
|
120
|
-
elsif match = current_line.match(GLOSSARIST_BLOCK_REGEX)
|
119
|
+
elsif match = current_line.match(GLOSSARIST_BLOCK_REGEX) # rubocop:disable Lint/DuplicateBranch
|
121
120
|
process_glossarist_block(document, liquid_doc, input_lines, match)
|
122
121
|
else
|
123
|
-
|
122
|
+
if /^==+ \S/.match?(current_line)
|
123
|
+
@title_depth[:value] =
|
124
|
+
current_line.sub(/ .*$/,
|
125
|
+
"").size
|
126
|
+
end
|
124
127
|
liquid_doc.add_content(current_line)
|
125
128
|
end
|
126
129
|
end
|
127
130
|
|
128
131
|
def process_dataset_tag(document, input_lines, liquid_doc, match)
|
129
132
|
@seen_glossarist << "x"
|
130
|
-
context_names = prepare_dataset_contexts(document, match[1])
|
133
|
+
@context_names = prepare_dataset_contexts(document, match[1])
|
131
134
|
|
132
135
|
dataset_section = <<~TEMPLATE
|
133
|
-
{% with_glossarist_context #{context_names} %}
|
134
136
|
#{prepare_document(document, input_lines)}
|
135
|
-
{% endwith_glossarist_context %}
|
136
137
|
TEMPLATE
|
137
138
|
|
138
139
|
liquid_doc.add_content(
|
139
140
|
dataset_section,
|
140
|
-
render:
|
141
|
+
render: false,
|
141
142
|
)
|
142
143
|
end
|
143
144
|
|
144
145
|
def process_glossarist_block(document, liquid_doc, input_lines, match)
|
145
146
|
@seen_glossarist << "x"
|
146
147
|
end_mark = input_lines.next
|
147
|
-
path = relative_file_path(document, match[1])
|
148
|
-
|
148
|
+
# path = relative_file_path(document, match[1])
|
149
149
|
glossarist_params = prepare_glossarist_block_params(document, match)
|
150
150
|
|
151
151
|
glossarist_section = <<~TEMPLATE.strip
|
152
152
|
{% with_glossarist_context #{glossarist_params} %}
|
153
|
-
#{prepare_document(
|
153
|
+
#{prepare_document(
|
154
|
+
document, input_lines, end_mark,
|
155
|
+
skip_dataset: true
|
156
|
+
)}
|
154
157
|
{% endwith_glossarist_context %}
|
155
158
|
TEMPLATE
|
156
159
|
|
@@ -161,7 +164,7 @@ module Metanorma
|
|
161
164
|
end
|
162
165
|
|
163
166
|
def prepare_glossarist_block_params(document, match)
|
164
|
-
path =
|
167
|
+
path = get_context_path(document, match[1])
|
165
168
|
|
166
169
|
if match[2].strip.start_with?("filter")
|
167
170
|
filters = match[2].split("=")[1..-1].join("=").strip
|
@@ -173,6 +176,22 @@ module Metanorma
|
|
173
176
|
end
|
174
177
|
end
|
175
178
|
|
179
|
+
def get_context_path(document, key) # rubocop:disable Metrics/MethodLength
|
180
|
+
context_path = nil
|
181
|
+
# try to get context_path from glossarist-dataset definition
|
182
|
+
if @context_names
|
183
|
+
context_names = @context_names.split(",").map(&:strip)
|
184
|
+
context_path = context_names.find do |context|
|
185
|
+
context_name, = context.split("=")
|
186
|
+
context_name == key
|
187
|
+
end
|
188
|
+
end
|
189
|
+
|
190
|
+
return context_path.split("=").last.strip if context_path
|
191
|
+
|
192
|
+
relative_file_path(document, key)
|
193
|
+
end
|
194
|
+
|
176
195
|
def process_render_tag(liquid_doc, match)
|
177
196
|
@seen_glossarist << "x"
|
178
197
|
context_name, concept_name = match[1].split(",")
|
@@ -182,13 +201,15 @@ module Metanorma
|
|
182
201
|
)
|
183
202
|
end
|
184
203
|
|
185
|
-
def process_import_tag(liquid_doc, match)
|
204
|
+
def process_import_tag(liquid_doc, match) # rubocop:disable Metrics/AbcSize
|
186
205
|
@seen_glossarist << "x"
|
187
206
|
context_name = match[1].strip
|
188
|
-
dataset = @datasets[context_name
|
207
|
+
dataset = @datasets[context_name]
|
189
208
|
|
190
209
|
liquid_doc.add_content(
|
191
|
-
dataset.
|
210
|
+
dataset.map do |concept|
|
211
|
+
concept_name = concept.data.localizations["eng"].data
|
212
|
+
.terms[0].designation
|
192
213
|
concept_template(context_name, concept_name)
|
193
214
|
end.join("\n"),
|
194
215
|
)
|
@@ -200,7 +221,7 @@ module Metanorma
|
|
200
221
|
dataset = @datasets[dataset_name]
|
201
222
|
|
202
223
|
liquid_doc.add_content(
|
203
|
-
dataset.
|
224
|
+
dataset.map do |concept|
|
204
225
|
concept_bibliography(concept)
|
205
226
|
end.compact.sort.join("\n"),
|
206
227
|
)
|
@@ -209,17 +230,18 @@ module Metanorma
|
|
209
230
|
def process_bibliography_entry(liquid_doc, match)
|
210
231
|
@seen_glossarist << "x"
|
211
232
|
dataset_name, concept_name = match[1].split(",").map(&:strip)
|
212
|
-
concept =
|
233
|
+
concept = get_concept(dataset_name, concept_name)
|
213
234
|
|
214
235
|
liquid_doc.add_content(
|
215
236
|
concept_bibliography(concept),
|
216
237
|
)
|
217
238
|
end
|
218
239
|
|
219
|
-
def concept_bibliography(concept)
|
220
|
-
|
221
|
-
ref = source["origin"]["ref"]
|
240
|
+
def concept_bibliography(concept) # rubocop:disable Metrics/AbcSize
|
241
|
+
sources = concept.data.localizations["eng"].data.sources
|
222
242
|
|
243
|
+
bibliography = sources.map do |source|
|
244
|
+
ref = source.origin.text
|
223
245
|
next if @rendered_bibliographies[ref] || ref.nil? || ref.empty?
|
224
246
|
|
225
247
|
@rendered_bibliographies[ref] = ref.gsub(/[ \/:]/, "_")
|
@@ -236,7 +258,7 @@ module Metanorma
|
|
236
258
|
|
237
259
|
dataset = ::Glossarist::ManagedConceptCollection.new
|
238
260
|
dataset.load_from_files(path)
|
239
|
-
@datasets[context_name] =
|
261
|
+
@datasets[context_name] = dataset.map(&:to_liquid)
|
240
262
|
|
241
263
|
"#{context_name}=#{path}"
|
242
264
|
end
|
@@ -255,10 +277,10 @@ module Metanorma
|
|
255
277
|
|
256
278
|
def concept_template(dataset_name, concept_name)
|
257
279
|
<<~CONCEPT_TEMPLATE
|
258
|
-
#{
|
280
|
+
#{'=' * (@title_depth[:value] + 1)} #{concept_title(dataset_name, concept_name)}
|
259
281
|
#{alt_terms(dataset_name, concept_name)}
|
260
282
|
|
261
|
-
|
283
|
+
#{concept_definition(dataset_name, concept_name)}
|
262
284
|
|
263
285
|
#{examples(dataset_name, concept_name)}
|
264
286
|
|
@@ -268,51 +290,99 @@ module Metanorma
|
|
268
290
|
CONCEPT_TEMPLATE
|
269
291
|
end
|
270
292
|
|
271
|
-
def
|
272
|
-
|
293
|
+
def get_concept(dataset_name, concept_name)
|
294
|
+
@datasets[dataset_name].find do |c|
|
295
|
+
c.data.localizations["eng"]
|
296
|
+
.data.terms[0]
|
297
|
+
.designation == concept_name
|
298
|
+
end
|
299
|
+
end
|
300
|
+
|
301
|
+
def concept_title(dataset_name, concept_name)
|
302
|
+
concept = get_concept(dataset_name, concept_name)
|
303
|
+
concept.data.localizations["eng"].data.terms[0].designation
|
304
|
+
end
|
305
|
+
|
306
|
+
def concept_definition(dataset_name, concept_name)
|
307
|
+
concept = get_concept(dataset_name, concept_name)
|
308
|
+
definition = concept.data.localizations["eng"].data
|
309
|
+
.definition[0].content
|
310
|
+
definition.to_s
|
311
|
+
end
|
312
|
+
|
313
|
+
def alt_terms(dataset_name, concept_name) # rubocop:disable Metrics/AbcSize,Metrics/MethodLength
|
314
|
+
concept = get_concept(dataset_name, concept_name)
|
273
315
|
term_types = %w[preferred admitted deprecated]
|
316
|
+
concept_terms = concept.data.localizations["eng"].data.terms
|
274
317
|
|
275
|
-
|
276
|
-
type = if term_types.include?(term
|
277
|
-
term
|
318
|
+
concept_terms[1..-1].map do |term|
|
319
|
+
type = if term_types.include?(term.normative_status)
|
320
|
+
term.normative_status
|
278
321
|
else
|
279
322
|
"alt"
|
280
323
|
end
|
281
|
-
"#{type}:[#{term
|
324
|
+
"#{type}:[#{term.designation}]"
|
282
325
|
end.join("\n")
|
283
326
|
end
|
284
327
|
|
285
|
-
def examples(dataset_name, concept_name)
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
328
|
+
def examples(dataset_name, concept_name) # rubocop:disable Metrics/AbcSize,Metrics/MethodLength
|
329
|
+
concept = get_concept(dataset_name, concept_name)
|
330
|
+
examples = concept.data.localizations["eng"].data.examples
|
331
|
+
result = []
|
332
|
+
|
333
|
+
examples.each do |example|
|
334
|
+
content = <<~EXAMPLE
|
335
|
+
[example]
|
336
|
+
#{example.content}
|
290
337
|
|
291
|
-
|
292
|
-
|
338
|
+
EXAMPLE
|
339
|
+
result << content
|
340
|
+
end
|
341
|
+
|
342
|
+
result.join("\n")
|
293
343
|
end
|
294
344
|
|
295
|
-
def notes(dataset_name, concept_name)
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
345
|
+
def notes(dataset_name, concept_name) # rubocop:disable Metrics/AbcSize,Metrics/MethodLength
|
346
|
+
concept = get_concept(dataset_name, concept_name)
|
347
|
+
notes = concept.data.localizations["eng"].data.notes
|
348
|
+
result = []
|
349
|
+
|
350
|
+
notes.each do |note|
|
351
|
+
content = <<~NOTE
|
352
|
+
[NOTE]
|
353
|
+
====
|
354
|
+
#{note.content}
|
355
|
+
====
|
302
356
|
|
303
|
-
|
304
|
-
|
357
|
+
NOTE
|
358
|
+
result << content
|
359
|
+
end
|
360
|
+
|
361
|
+
result.join("\n")
|
305
362
|
end
|
306
363
|
|
307
|
-
def sources(dataset_name, concept_name)
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
364
|
+
def sources(dataset_name, concept_name) # rubocop:disable Metrics/AbcSize,Metrics/MethodLength
|
365
|
+
concept = get_concept(dataset_name, concept_name)
|
366
|
+
sources = concept.data.localizations["eng"].data.sources
|
367
|
+
result = []
|
368
|
+
|
369
|
+
sources.each do |source|
|
370
|
+
if source.origin.text && source.origin.text != ""
|
371
|
+
source_origin_text = source.origin.text
|
372
|
+
.gsub(" ", "_")
|
373
|
+
.gsub("/", "_")
|
374
|
+
.gsub(":", "_")
|
375
|
+
source_content = "#{source_origin_text},#{source.origin.clause}"
|
376
|
+
content = <<~SOURCES
|
377
|
+
[.source]
|
378
|
+
<<#{source_content}>>
|
379
|
+
|
380
|
+
SOURCES
|
381
|
+
result << content
|
382
|
+
end
|
383
|
+
end
|
313
384
|
|
314
|
-
|
315
|
-
SOURCES
|
385
|
+
result.join("\n")
|
316
386
|
end
|
317
387
|
end
|
318
388
|
end
|
@@ -1,5 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require_relative "liquid/custom_blocks/with_glossarist_context"
|
4
|
+
require_relative "liquid/custom_filters/filters"
|
5
|
+
|
3
6
|
module Metanorma
|
4
7
|
module Plugin
|
5
8
|
module Glossarist
|
@@ -24,14 +27,30 @@ module Metanorma
|
|
24
27
|
end
|
25
28
|
|
26
29
|
def render_liquid(file_content)
|
27
|
-
template = Liquid::Template
|
30
|
+
template = ::Liquid::Template
|
31
|
+
.parse(file_content, environment: create_liquid_environment)
|
32
|
+
|
28
33
|
template.registers[:file_system] = file_system
|
29
|
-
rendered_template = template.render(strict_variables: false,
|
34
|
+
rendered_template = template.render(strict_variables: false,
|
35
|
+
error_mode: :warn)
|
30
36
|
|
31
37
|
return rendered_template unless template.errors.any?
|
32
38
|
|
33
39
|
raise template.errors.first.cause
|
34
40
|
end
|
41
|
+
|
42
|
+
def create_liquid_environment
|
43
|
+
::Liquid::Environment.new.tap do |liquid_env|
|
44
|
+
liquid_env.register_tag(
|
45
|
+
"with_glossarist_context",
|
46
|
+
::Metanorma::Plugin::Glossarist::Liquid::CustomBlocks::
|
47
|
+
WithGlossaristContext,
|
48
|
+
)
|
49
|
+
liquid_env.register_filter(
|
50
|
+
::Metanorma::Plugin::Glossarist::Liquid::CustomFilters::Filters,
|
51
|
+
)
|
52
|
+
end
|
53
|
+
end
|
35
54
|
end
|
36
55
|
end
|
37
56
|
end
|
@@ -0,0 +1,155 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "liquid"
|
4
|
+
|
5
|
+
module Metanorma
|
6
|
+
module Plugin
|
7
|
+
module Glossarist
|
8
|
+
module Liquid
|
9
|
+
module CustomBlocks
|
10
|
+
class WithGlossaristContext < ::Liquid::Block
|
11
|
+
def initialize(tag_name, markup, tokens) # rubocop:disable Metrics/AbcSize,Metrics/MethodLength
|
12
|
+
super
|
13
|
+
|
14
|
+
@contexts = []
|
15
|
+
@filters = {}
|
16
|
+
|
17
|
+
contexts, filters = markup.split(";", 2)
|
18
|
+
|
19
|
+
if filters && !filters.empty?
|
20
|
+
filters.strip.gsub(/^['"]|['"]$/,
|
21
|
+
"").split(";").each do |filter|
|
22
|
+
property, value = filter.split("=")
|
23
|
+
|
24
|
+
@filters[property] = value
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
contexts.split(",").each do |context|
|
29
|
+
context_name, file_path = context.split("=").map(&:strip)
|
30
|
+
|
31
|
+
@contexts << {
|
32
|
+
name: context_name,
|
33
|
+
file_path: file_path,
|
34
|
+
}
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def load_collection(folder_path)
|
39
|
+
@@collections ||= {}
|
40
|
+
|
41
|
+
return @@collections[folder_path] if @@collections[folder_path]
|
42
|
+
|
43
|
+
collection = ::Glossarist::ManagedConceptCollection.new
|
44
|
+
collection.load_from_files(folder_path)
|
45
|
+
@@collections[folder_path] = collection
|
46
|
+
end
|
47
|
+
|
48
|
+
def filter_collection(collection, filters)
|
49
|
+
return collection unless filters
|
50
|
+
|
51
|
+
concept_filters = filters.dup
|
52
|
+
lang_filter = concept_filters.delete("lang")
|
53
|
+
group_filter = concept_filters.delete("group")
|
54
|
+
sort_filter = concept_filters.delete("sort_by")
|
55
|
+
|
56
|
+
collection = apply_lang_filter(collection, lang_filter)
|
57
|
+
collection = apply_group_filter(collection, group_filter)
|
58
|
+
collection = apply_field_filter(collection, concept_filters)
|
59
|
+
apply_sort_filter(collection, sort_filter)
|
60
|
+
end
|
61
|
+
|
62
|
+
def apply_field_filter(collection, field_filter) # rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/MethodLength,Metrics/PerceivedComplexity
|
63
|
+
return collection if field_filter.nil? || field_filter.empty?
|
64
|
+
|
65
|
+
collection.select do |obj| # rubocop:disable Metrics/BlockLength
|
66
|
+
fields = field_filter.keys.first.split(".")
|
67
|
+
value = field_filter.values.first
|
68
|
+
start_with = false
|
69
|
+
|
70
|
+
# check if the last field is a start_with condition
|
71
|
+
if fields.last.start_with?("start_with(") &&
|
72
|
+
fields.last.include?(")")
|
73
|
+
start_with = true
|
74
|
+
# Extract content between first '(' and last ')'
|
75
|
+
f = fields.last
|
76
|
+
value = f[(f.index("(") + 1)...f.rindex(")")]
|
77
|
+
fields = fields[0..-2]
|
78
|
+
end
|
79
|
+
|
80
|
+
fields.each do |field|
|
81
|
+
# contain index (i.e. field['abc'] or field[1])
|
82
|
+
if field.include?("[")
|
83
|
+
field, index = field[0..-2].split("[")
|
84
|
+
|
85
|
+
index = if index.include?("'") || index.include?("\"")
|
86
|
+
index.gsub(/['"]/, "")
|
87
|
+
else
|
88
|
+
index.to_i
|
89
|
+
end
|
90
|
+
|
91
|
+
obj = obj.send(field.to_sym)[index]
|
92
|
+
else
|
93
|
+
obj = obj.send(field.to_sym)
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
# check if the object matches the value
|
98
|
+
if start_with
|
99
|
+
obj.start_with?(value)
|
100
|
+
else
|
101
|
+
obj == value
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
def apply_lang_filter(collection, lang_filter)
|
107
|
+
return collection unless lang_filter
|
108
|
+
|
109
|
+
collection.select do |concept|
|
110
|
+
concept.data.localizations.key?(lang_filter)
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
def apply_group_filter(collection, group_filter)
|
115
|
+
return collection unless group_filter
|
116
|
+
|
117
|
+
collection.select do |concept|
|
118
|
+
concept.data.groups.include?(group_filter)
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
def apply_sort_filter(collection, sort_filter)
|
123
|
+
return collection unless sort_filter
|
124
|
+
|
125
|
+
sort_filter = case sort_filter
|
126
|
+
when "term"
|
127
|
+
"default_designation"
|
128
|
+
else
|
129
|
+
sort_filter
|
130
|
+
end
|
131
|
+
|
132
|
+
collection.sort_by do |concept|
|
133
|
+
concept.send(sort_filter.to_sym)
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
def render(context)
|
138
|
+
@contexts.each do |local_context|
|
139
|
+
context_file = local_context[:file_path].strip
|
140
|
+
collection = load_collection(context_file)
|
141
|
+
|
142
|
+
filtered_collection = filter_collection(collection, @filters)
|
143
|
+
|
144
|
+
context[local_context[:name]] = filtered_collection
|
145
|
+
.map(&:to_liquid)
|
146
|
+
end
|
147
|
+
|
148
|
+
super
|
149
|
+
end
|
150
|
+
end
|
151
|
+
end
|
152
|
+
end
|
153
|
+
end
|
154
|
+
end
|
155
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Metanorma
|
4
|
+
module Plugin
|
5
|
+
module Glossarist
|
6
|
+
module Liquid
|
7
|
+
module CustomFilters
|
8
|
+
module Filters
|
9
|
+
def values(list)
|
10
|
+
list.values
|
11
|
+
end
|
12
|
+
|
13
|
+
def terminological_data(term)
|
14
|
+
result = []
|
15
|
+
|
16
|
+
result << "<#{term['usage_info']}>" if term["usage_info"]
|
17
|
+
result << extract_grammar_info(term)
|
18
|
+
result << term["geographical_area"]&.upcase
|
19
|
+
|
20
|
+
result.unshift(",") if result.compact.size.positive?
|
21
|
+
|
22
|
+
result.compact.join(" ")
|
23
|
+
end
|
24
|
+
|
25
|
+
def extract_grammar_info(term)
|
26
|
+
return unless term["grammar_info"]
|
27
|
+
|
28
|
+
grammar_info = []
|
29
|
+
|
30
|
+
term["grammar_info"].each do |info|
|
31
|
+
grammar_info << info["gender"]&.join(", ")
|
32
|
+
grammar_info << info["number"]&.join(", ")
|
33
|
+
grammar_info << extract_parts_of_speech(info)
|
34
|
+
end
|
35
|
+
|
36
|
+
grammar_info.join(" ")
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -13,7 +13,8 @@ Gem::Specification.new do |spec|
|
|
13
13
|
spec.license = "BSD-2-Clause"
|
14
14
|
|
15
15
|
# Specify which files should be added to the gem when it is released.
|
16
|
-
# The `git ls-files -z` loads the files in the RubyGem that have been added
|
16
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added
|
17
|
+
# into git.
|
17
18
|
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
18
19
|
`git ls-files -z`.split("\x0").reject do |f|
|
19
20
|
f.match(%r{^(test|spec|features)/})
|
@@ -23,7 +24,9 @@ Gem::Specification.new do |spec|
|
|
23
24
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
24
25
|
spec.require_paths = ["lib"]
|
25
26
|
|
27
|
+
spec.required_ruby_version = ">= 2.7.0" # rubocop:disable Gemspec/RequiredRubyVersion
|
28
|
+
|
26
29
|
spec.add_dependency "asciidoctor", "~> 2.0.0"
|
27
|
-
spec.add_dependency "glossarist", "~> 2.
|
30
|
+
spec.add_dependency "glossarist", "~> 2.3.6"
|
28
31
|
spec.add_dependency "liquid", "~> 5"
|
29
32
|
end
|