metanorma-plugin-glossarist 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: b06eede0539ad9fda202136bb7d97aded91a6e925536234e822bdff0a067996e
4
- data.tar.gz: 96981f754d34698da5288b12df8fe54719e9e40e15f96413a1cbad9f63962e4e
3
+ metadata.gz: c15949c9576065603f4a70e07d513df78d3042747d5506a4a80a0aaf23189b99
4
+ data.tar.gz: 7231ecb9af7c8dd43cc7ee9419d1a179ceaf468e6af248ac5ab183600afb6f27
5
5
  SHA512:
6
- metadata.gz: 9dd3c3ec6cd75a5aeb4f718e567374820ed074de9dd428919b7e3c9d038f95b116d61d2f29478c25e624aa35f593da0ca9e31fd280be43c9ea46e75cfdfce824
7
- data.tar.gz: 1ea5f7d523beecdb2a1c67f9282064b5791f537ca6f6743d17329aefab4492421b758ee4f3728332653f567cb92f1c0c4977010ecbce86c4f92d79328adb5701
6
+ metadata.gz: d0d74131f0d39fe1c75893814730551db56f6471bacbd5c18f85a53fb07c440da28d1d7fb70ab8e7cf47db63f2a92b099f866269ad46e5acec944dff9fed9808
7
+ data.tar.gz: 999be7b8d32c5204e0c7b822b4ae2536e4b7f4b327986ab86d635bd60b6d210b2556f23b9e71d1f1c940e303fe8f57eb940a13872e8941636aa4d665d1372248
data/README.adoc CHANGED
@@ -569,7 +569,9 @@ glossarist::render_bibliography_entry[{dataset-name}, {term}]
569
569
 
570
570
  Where,
571
571
 
572
- `{dataset-name}`:: The name of the dataset (e.g., `dataset`).
572
+ `{dataset-name}`:: The name of the dataset (e.g., `dataset`) or the path to the
573
+ Glossarist dataset relative to the master document
574
+ (e.g., `./path/to/glossarist-dataset`).
573
575
 
574
576
  `{term}`:: The term to render the bibliography for (e.g., `foo`).
575
577
 
@@ -617,7 +619,9 @@ glossarist::render_bibliography[{dataset-name}]
617
619
 
618
620
  Where,
619
621
 
620
- `{dataset-name}`:: The name of the dataset (e.g., `dataset`).
622
+ `{dataset-name}`:: The name of the dataset (e.g., `dataset`) or the path to the
623
+ Glossarist dataset relative to the master document
624
+ (e.g., `./path/to/glossarist-dataset`).
621
625
 
622
626
  [example]
623
627
  ====
@@ -6,11 +6,14 @@ require "liquid"
6
6
  require "asciidoctor/reader"
7
7
  require "glossarist"
8
8
  require "metanorma/plugin/glossarist/document"
9
+ require "metanorma/plugin/glossarist/liquid/custom_filters/filters"
9
10
 
10
11
  module Metanorma
11
12
  module Plugin
12
13
  module Glossarist
13
14
  class DatasetPreprocessor < Asciidoctor::Extensions::Preprocessor
15
+ include Metanorma::Plugin::Glossarist::Liquid::CustomFilters::Filters
16
+
14
17
  GLOSSARIST_DATASET_REGEX = /^:glossarist-dataset:\s*(.*?)$/m.freeze
15
18
  GLOSSARIST_IMPORT_REGEX = /^glossarist::import\[(.*?)\]$/m.freeze
16
19
  GLOSSARIST_RENDER_REGEX = /^glossarist::render\[(.*?)\]$/m.freeze
@@ -105,9 +108,9 @@ module Metanorma
105
108
  elsif match = current_line.match(GLOSSARIST_IMPORT_REGEX)
106
109
  process_import_tag(liquid_doc, match)
107
110
  elsif match = current_line.match(GLOSSARIST_BIBLIOGRAPHY_REGEX)
108
- process_bibliography(liquid_doc, match)
111
+ process_bibliography(document, liquid_doc, match)
109
112
  elsif match = current_line.match(GLOSSARIST_BIBLIOGRAPHY_ENTRY_REGEX)
110
- process_bibliography_entry(liquid_doc, match)
113
+ process_bibliography_entry(document, liquid_doc, match)
111
114
  elsif match = current_line.match(GLOSSARIST_BLOCK_REGEX)
112
115
  process_glossarist_block(document, liquid_doc, input_lines, match)
113
116
  else
@@ -199,32 +202,44 @@ module Metanorma
199
202
 
200
203
  def process_render_tag(liquid_doc, match)
201
204
  @seen_glossarist << "x"
202
- context_name, concept_name = match[1].split(",")
205
+ matches = match[1].split(",").map(&:strip)
206
+
207
+ context_name = matches[0]
208
+ concept_name = matches[1]
209
+ render_options = matches[2..-1]
203
210
 
204
211
  liquid_doc.add_content(
205
- concept_template(context_name.strip, concept_name.strip),
212
+ concept_template(context_name.strip, concept_name.strip,
213
+ render_options),
206
214
  )
207
215
  end
208
216
 
209
- def process_import_tag(liquid_doc, match) # rubocop:disable Metrics/AbcSize
217
+ def process_import_tag(liquid_doc, match) # rubocop:disable Metrics/AbcSize,Metrics/MethodLength
210
218
  @seen_glossarist << "x"
211
- context_name = match[1].strip
212
- dataset = @datasets[context_name]
219
+ matches = match[1].split(",").map(&:strip)
220
+ context_name = matches[0]
221
+ render_options = matches[1..-1]
222
+ dataset = @datasets[context_name.strip]
213
223
 
214
224
  liquid_doc.add_content(
215
225
  dataset.map do |concept|
216
226
  concept_name = concept.data.localizations["eng"].data
217
227
  .terms[0].designation
218
- concept_template(context_name, concept_name)
228
+ concept_template(context_name, concept_name, render_options)
219
229
  end.join("\n"),
220
230
  )
221
231
  end
222
232
 
223
- def process_bibliography(liquid_doc, match)
233
+ def process_bibliography(document, liquid_doc, match) # rubocop:disable Metrics/AbcSize,Metrics/MethodLength
224
234
  @seen_glossarist << "x"
225
235
  dataset_name = match[1].strip
226
236
  dataset = @datasets[dataset_name]
227
237
 
238
+ if dataset.nil? || @datasets.empty?
239
+ path = relative_file_path(document, dataset_name)
240
+ dataset = load_dataset_from_path(path)
241
+ end
242
+
228
243
  liquid_doc.add_content(
229
244
  dataset.map do |concept|
230
245
  concept_bibliography(concept)
@@ -232,11 +247,12 @@ module Metanorma
232
247
  )
233
248
  end
234
249
 
235
- def process_bibliography_entry(liquid_doc, match)
250
+ def process_bibliography_entry(document, liquid_doc, match)
236
251
  @seen_glossarist << "x"
237
252
  dataset_name, concept_name = match[1].split(",").map(&:strip)
238
- concept = get_concept(dataset_name, concept_name)
253
+ concept = get_concept(dataset_name, concept_name, document)
239
254
  bibliography = concept_bibliography(concept)
255
+
240
256
  if bibliography
241
257
  liquid_doc.add_content(bibliography)
242
258
  end
@@ -261,15 +277,19 @@ module Metanorma
261
277
  contexts.split(";").map do |context|
262
278
  context_name, file_path = context.split(":").map(&:strip)
263
279
  path = relative_file_path(document, file_path)
264
-
265
- dataset = ::Glossarist::ManagedConceptCollection.new
266
- dataset.load_from_files(path)
280
+ dataset = load_dataset_from_path(path)
267
281
  @datasets[context_name] = dataset.map(&:to_liquid)
268
282
 
269
283
  "#{context_name}=#{path}"
270
284
  end
271
285
  end
272
286
 
287
+ def load_dataset_from_path(path)
288
+ dataset = ::Glossarist::ManagedConceptCollection.new
289
+ dataset.load_from_files(path)
290
+ dataset
291
+ end
292
+
273
293
  def relative_file_path(document, file_path)
274
294
  docfile_directory = File.dirname(
275
295
  document.attributes["docfile"] || ".",
@@ -279,9 +299,13 @@ module Metanorma
279
299
  .system_path(file_path, docfile_directory)
280
300
  end
281
301
 
282
- def concept_template(dataset_name, concept_name)
302
+ def concept_template(dataset_name, concept_name, options = [])
303
+ options = options_to_hash(options)
304
+
283
305
  <<~CONCEPT_TEMPLATE
306
+ [[#{identifier(dataset_name, concept_name, options)}]]
284
307
  #{'=' * (@title_depth[:value] + 1)} #{concept_title(dataset_name, concept_name)}
308
+
285
309
  #{alt_terms(dataset_name, concept_name)}
286
310
 
287
311
  #{concept_definition(dataset_name, concept_name)}
@@ -294,14 +318,38 @@ module Metanorma
294
318
  CONCEPT_TEMPLATE
295
319
  end
296
320
 
297
- def get_concept(dataset_name, concept_name)
298
- @datasets[dataset_name].find do |c|
321
+ def get_concept(dataset_name, concept_name, document = nil)
322
+ dataset = @datasets[dataset_name]
323
+
324
+ if document && dataset.nil?
325
+ path = relative_file_path(document, dataset_name)
326
+ dataset = load_dataset_from_path(path)
327
+ end
328
+
329
+ dataset.find do |c|
299
330
  c.data.localizations["eng"]
300
331
  .data.terms[0]
301
332
  .designation == concept_name
302
333
  end
303
334
  end
304
335
 
336
+ def identifier(dataset_name, concept_name, options = {})
337
+ prefix = options["anchor-prefix"].to_s if options["anchor-prefix"]
338
+ concept = get_concept(dataset_name, concept_name)
339
+
340
+ id = "#{prefix}#{concept.data.id}"
341
+ # id starts with digits 0-9
342
+ return id if id.start_with?(/[0-9]/)
343
+
344
+ Metanorma::Utils.to_ncname(id.gsub(":", "_"))
345
+ end
346
+
347
+ def options_to_hash(options_arr)
348
+ return {} if !options_arr || options_arr.empty?
349
+
350
+ options_arr.map { |option| option.split("=") }.to_h
351
+ end
352
+
305
353
  def concept_title(dataset_name, concept_name)
306
354
  concept = get_concept(dataset_name, concept_name)
307
355
  concept.data.localizations["eng"].data.terms[0].designation
@@ -311,7 +359,7 @@ module Metanorma
311
359
  concept = get_concept(dataset_name, concept_name)
312
360
  definition = concept.data.localizations["eng"].data
313
361
  .definition[0].content
314
- definition.to_s
362
+ sanitize_references(definition.to_s)
315
363
  end
316
364
 
317
365
  def alt_terms(dataset_name, concept_name) # rubocop:disable Metrics/AbcSize,Metrics/MethodLength
@@ -337,7 +385,7 @@ module Metanorma
337
385
  examples.each do |example|
338
386
  content = <<~EXAMPLE
339
387
  [example]
340
- #{example.content}
388
+ #{sanitize_references(example.content)}
341
389
 
342
390
  EXAMPLE
343
391
  result << content
@@ -355,7 +403,7 @@ module Metanorma
355
403
  content = <<~NOTE
356
404
  [NOTE]
357
405
  ====
358
- #{note.content}
406
+ #{sanitize_references(note.content)}
359
407
  ====
360
408
 
361
409
  NOTE
@@ -6,10 +6,21 @@ module Metanorma
6
6
  module Liquid
7
7
  module CustomFilters
8
8
  module Filters
9
+ REF_REGEX = /{{([^,]{1,500}),([^\}]{1,500})}}(.*?)$/s.freeze
10
+
9
11
  def values(list)
10
12
  list.values
11
13
  end
12
14
 
15
+ def sanitize_references(str)
16
+ return str unless str.match?(REF_REGEX)
17
+
18
+ matched_str = str.match(REF_REGEX)
19
+ urn = Metanorma::Utils.to_ncname(matched_str[1]).gsub(":", "_")
20
+
21
+ "{{#{urn},#{matched_str[2]}}}#{matched_str[3]}"
22
+ end
23
+
13
24
  def terminological_data(term)
14
25
  result = []
15
26
 
@@ -1,7 +1,7 @@
1
1
  module Metanorma
2
2
  module Plugin
3
3
  module Glossarist
4
- VERSION = "0.2.9".freeze
4
+ VERSION = "0.2.10".freeze
5
5
  end
6
6
  end
7
7
  end
@@ -1,6 +1,7 @@
1
1
  require "metanorma/plugin/glossarist/version"
2
2
  require "metanorma/plugin/glossarist/document"
3
3
  require "metanorma/plugin/glossarist/dataset_preprocessor"
4
+ require "metanorma-utils"
4
5
 
5
6
  module Metanorma
6
7
  module Plugin
@@ -29,4 +29,5 @@ Gem::Specification.new do |spec|
29
29
  spec.add_dependency "asciidoctor"
30
30
  spec.add_dependency "glossarist", "~> 2.3.7"
31
31
  spec.add_dependency "liquid"
32
+ spec.add_dependency "metanorma-utils", "~> 1.10"
32
33
  end
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.2.9
4
+ version: 0.2.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2025-07-17 00:00:00.000000000 Z
11
+ date: 2025-10-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: asciidoctor
@@ -52,6 +52,20 @@ dependencies:
52
52
  - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: metanorma-utils
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.10'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.10'
55
69
  description: Metanorma plugin for glossarist
56
70
  email:
57
71
  - open.source@ribose.com