metanorma-plugin-glossarist 0.2.2 → 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.
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.2
4
+ version: 0.2.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-11-18 00:00:00.000000000 Z
11
+ date: 2025-06-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: asciidoctor
@@ -30,14 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '2.0'
33
+ version: 2.3.6
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: '2.0'
40
+ version: 2.3.6
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: liquid
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -68,23 +68,22 @@ files:
68
68
  - CODE_OF_CONDUCT.md
69
69
  - Gemfile
70
70
  - LICENSE.txt
71
- - README.md
71
+ - README.adoc
72
72
  - Rakefile
73
73
  - bin/console
74
74
  - bin/setup
75
- - lib/liquid/custom_blocks/with_glossarist_context.rb
76
- - lib/liquid/custom_filters/filters.rb
77
- - lib/liquid/drops/concepts_drop.rb
78
75
  - lib/metanorma-plugin-glossarist.rb
79
76
  - lib/metanorma/plugin/glossarist/dataset_preprocessor.rb
80
77
  - lib/metanorma/plugin/glossarist/document.rb
78
+ - lib/metanorma/plugin/glossarist/liquid/custom_blocks/with_glossarist_context.rb
79
+ - lib/metanorma/plugin/glossarist/liquid/custom_filters/filters.rb
81
80
  - lib/metanorma/plugin/glossarist/version.rb
82
81
  - metanorma-plugin-glossarist.gemspec
83
82
  homepage: https://github.com/metanorma/metanorma-plugin-glossarist
84
83
  licenses:
85
84
  - BSD-2-Clause
86
85
  metadata: {}
87
- post_install_message:
86
+ post_install_message:
88
87
  rdoc_options: []
89
88
  require_paths:
90
89
  - lib
@@ -92,15 +91,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
92
91
  requirements:
93
92
  - - ">="
94
93
  - !ruby/object:Gem::Version
95
- version: '0'
94
+ version: 2.7.0
96
95
  required_rubygems_version: !ruby/object:Gem::Requirement
97
96
  requirements:
98
97
  - - ">="
99
98
  - !ruby/object:Gem::Version
100
99
  version: '0'
101
100
  requirements: []
102
- rubygems_version: 3.3.27
103
- signing_key:
101
+ rubygems_version: 3.5.22
102
+ signing_key:
104
103
  specification_version: 4
105
104
  summary: Metanorma plugin for glossarist
106
105
  test_files: []
data/README.md DELETED
@@ -1,495 +0,0 @@
1
- # Metanorma::Plugin::Glossarist
2
-
3
- Metanorma plugin that allows you to access data from the glossarist dataset inside a Metanorma document.
4
-
5
- ## Installation
6
-
7
- Add this line to your application's Gemfile:
8
-
9
- ```ruby
10
- gem 'metanorma-plugin-glossarist'
11
- ```
12
-
13
- And then execute:
14
-
15
- $ bundle install
16
-
17
- Or install it yourself as:
18
-
19
- $ gem install metanorma-plugin-glossarist
20
-
21
- ## Usage
22
-
23
- In order to use the macros in Metanorma, add the gem gem `metanorma-plugin-glossarist` in your Gemfile.
24
-
25
- ## Available Macros
26
-
27
- Currently, there are 6 macros available for this plugin and all of them support all [Liquid syntax expressions](https://shopify.github.io/liquid/basics/introduction/), including:
28
-
29
- - Loading Dataset
30
- - `:glossarist-dataset: <dataset name>:<dataset path>`
31
- - `[glossarist,<dataset path>, [filters], <dataset name>]`
32
- - Rendering a single term from loaded dataset `glossarist::render[<dataset name>, <term>]`
33
- - Rendering all terms from loaded dataset `glossarist::import[<dataset name>]`
34
- - Rendering bibliography for a single term in the dataset `glossarist::render_bibliography_entry[<dataset name>, <term>]`
35
- - Rendering bibliography for all terms in the dataset`glossarist::render_bibliography[<dataset name>]`
36
-
37
- ### Loading Dataset
38
-
39
- There are 2 ways of loading a dataset
40
- 1. Global syntax `:glossarist-dataset: <dataset name>:<dataset path>`
41
- 2. Block syntax `[glossarist,<dataset path>, [filters], <dataset name>]`
42
-
43
- ### Global syntax `:glossarist-dataset: <dataset name>:<dataset path>`
44
-
45
- This will load the glossarist data from `<dataset path>` into `<dataset name>` which can be used anywhere in the document after this line.
46
-
47
- #### Example
48
-
49
- Suppose we have a term named `foobar` in our dataset with the definition `The term foobar is used as metasyntactic variables and placeholder names in computer programming`
50
-
51
- ```adoc
52
- :glossarist-dataset: dataset:./path/to/glossarist-dataset
53
-
54
- === Section 1
55
- {{ dataset['foobar']['eng'].definition[0].content }}
56
- ```
57
-
58
- this will output
59
-
60
- ```adoc
61
- === Section 1
62
- The term foobar is used as metasyntactic variables and placeholder names in computer programming
63
- ```
64
-
65
- ### Block syntax`[glossarist,<dataset path>, [filters], <dataset name>]`
66
-
67
- This will load the glossarist data from `<dataset path>` into `<dataset name>` which can be used in the given block. Filters are optional and can be used to filter and/or sort the loaded concepts from the glossarist dataset multiple filters can be added by separating them with a semicolon `;`. Filter can be added by adding `filter='<filters to apply>;<another filter>'`
68
-
69
- Available filters are:
70
- - `sort_by:<field name>`: will sort the dataset in ascending order of the given field values e.g `sort_by:term` will sort concepts in ascending order based on the term.
71
- - `<field name>:<values>`: will only load a concept if the value of the given field name is equal to the given value e.g `group=foo` will only load a concept if it has a group named `foo` or `lang=ara` will only load Arabic translations for all concepts.
72
-
73
- #### Example
74
-
75
- Suppose we have the following terms in our dataset
76
-
77
- | Name | Definition | Groups |
78
- | ----- | ----- | ----- |
79
- | foo | The term foo is used as metasyntactic variables and placeholder names in computer programming | foo |
80
- | bar | The term bar is used as metasyntactic variables and placeholder names in computer programming | foo, bar |
81
- | baz | The term baz is used as metasyntactic variables and placeholder names in computer programming | baz |
82
-
83
- ```adoc
84
- === Definitions
85
- [glossarist, /path/to/glossarist-dataset, dataset]
86
- ----
87
- {%- for concept in dataset -%}
88
- ==== {{ concept.term }}
89
-
90
- {{ concept.eng.definition[0].content }}
91
- {%- endfor -%}
92
- ----
93
- ```
94
-
95
- this will output
96
-
97
- ```adoc
98
- === Section 1
99
-
100
- ==== foo
101
-
102
- The term foo is used as metasyntactic variables and placeholder names in computer programming
103
-
104
- ==== bar
105
-
106
- The term bar is used as metasyntactic variables and placeholder names in computer programming
107
-
108
- ==== baz
109
-
110
- The term baz is used as metasyntactic variables and placeholder names in computer programming
111
- ```
112
-
113
- Applying sorting and filtering by group
114
-
115
- ```adoc
116
- === Definitions
117
- [glossarist, /path/to/glossarist-dataset, filter='group=foo;sort_by=term', dataset]
118
- ----
119
- {%- for concept in dataset -%}
120
- ==== {{ concept.term }}
121
-
122
- {{ concept.eng.definition[0].content }}
123
- {%- endfor -%}
124
- ----
125
- ```
126
-
127
- this will output
128
-
129
- ```adoc
130
- === Section 1
131
-
132
- ==== bar
133
-
134
- The term bar is used as metasyntactic variables and placeholder names in computer programming
135
-
136
- ==== foo
137
-
138
- The term foo is used as metasyntactic variables and placeholder names in computer programming
139
- ```
140
-
141
- The full concept model (a concept can have multiple localized concepts) is available through the block as follows:
142
-
143
- ```ruby
144
- {
145
- # UUIDs for localized concept mappings
146
- "localized_concepts" => {
147
- "eng" => "<uuid>", # English concept UUID
148
- "fre" => "<uuid>" # French concept UUID
149
- },
150
-
151
- # Main concept term
152
- "term" => "<string>",
153
-
154
- # Language-specific content (structure repeated for each language code)
155
- "<language_code>" => {
156
- "dates" => [], # Array of relevant dates
157
- "definition" => [ # Array of definition objects
158
- {
159
- "content" => "<string>" # Definition text
160
- }
161
- ],
162
- "examples" => [], # Array of example objects
163
- "id" => "<string>", # Concept ID
164
-
165
- "notes" => [ # Array of note objects
166
- {
167
- "content" => "<string>" # Note text
168
- }
169
- ],
170
-
171
- "sources" => [ # Array of source objects
172
- {
173
- "origin" => {
174
- "ref" => "<string>" # Reference citation
175
- },
176
- "type" => "<string>", # Source type (e.g. "lineage")
177
- "status" => "<string>" # Status (e.g. "identical")
178
- }
179
- ],
180
-
181
- "terms" => [ # Array of term objects
182
- {
183
- "type" => "<string>", # Term type (e.g. "expression")
184
- "normative_status" => "<string>", # Status (e.g. "preferred")
185
- "designation" => "<string>", # Term text
186
- "grammar_info" => [ # Array of grammar objects
187
- {
188
- "preposition" => boolean,
189
- "participle" => boolean,
190
- "adj" => boolean,
191
- "verb" => boolean,
192
- "adverb" => boolean,
193
- "noun" => boolean,
194
- "gender" => ["<string>"], # Array of grammatical genders
195
- "number" => ["<string>"] # Array of grammatical numbers
196
- }
197
- ]
198
- }
199
- ],
200
-
201
- "language_code" => "<string>" # ISO language code
202
- }
203
- }
204
- ```
205
-
206
- The language codes used are ISO 639-* 3-character codes, as described in the
207
- [Glossarist Concept model](https://github.com/glossarist/concept-model).
208
-
209
- An example of the full model (from ISO/IEC 2382:2015):
210
-
211
- ```ruby
212
- {
213
- "localized_concepts" => {
214
- "eng" => "01134f51-b88c-5214-8909-5d271ea619cf",
215
- "fre" => "f290a3af-f1b3-527a-9045-a2dfcc0caf5a"
216
- },
217
- "term" => "concept description",
218
- "eng" => {
219
- "dates" => [],
220
- "definition" => [
221
- {
222
- "content" => "data structure describing the class of all known instances of a concept"
223
- }
224
- ],
225
- "examples" => [],
226
- "id" => "2122978",
227
- "notes" => [
228
- {
229
- "content" => "concept description: term and definition standardized by ISO/IEC [ISO/IEC 2382-31:1997]."
230
- },
231
- {
232
- "content" => "31.02.02 (2382)"
233
- }
234
- ],
235
- "sources" => [
236
- {
237
- "origin" => {
238
- "ref" => "ISO/IEC 2382-31:1997"
239
- },
240
- "type" => "lineage",
241
- "status" => "identical"
242
- },
243
- {
244
- "origin" => {
245
- "ref" => "Ranger, Natalie * 2006 * Bureau de la traduction / Translation Bureau * Services linguistiques / Linguistic Services * Bur. dir. Centre de traduction et de terminologie / Dir's Office Translation and Terminology Centre * Div. Citoyenneté et Protection civile / Citizen. & Emergency preparedness Div. * Normalisation terminologique / Terminology Standardization"
246
- },
247
- "type" => "lineage",
248
- "status" => "identical"
249
- }
250
- ],
251
- "terms" => [
252
- {
253
- "type" => "expression",
254
- "normative_status" => "preferred",
255
- "designation" => "concept description",
256
- "grammar_info" => [
257
- {
258
- "preposition" => false,
259
- "participle" => false,
260
- "adj" => false,
261
- "verb" => false,
262
- "adverb" => false,
263
- "noun" => false,
264
- "gender" => [],
265
- "number" => ["singular"]
266
- }
267
- ]
268
- }
269
- ],
270
- "language_code" => "eng"
271
- },
272
- "fre" => {
273
- "dates" => [],
274
- "definition" => [
275
- {
276
- "content" => "structure de données qui décrit la classe des instances connues d'un concept"
277
- }
278
- ],
279
- "examples" => [],
280
- "id" => "2122978",
281
- "notes" => [
282
- {
283
- "content" => "description de concept : terme et définition normalisés par l'ISO/CEI [ISO/IEC 2382-31:1997]."
284
- },
285
- {
286
- "content" => "31.02.02 (2382)"
287
- }
288
- ],
289
- "sources" => [
290
- {
291
- "origin" => {
292
- "ref" => "ISO/IEC 2382-31:1997"
293
- },
294
- "type" => "lineage",
295
- "status" => "identical"
296
- },
297
- {
298
- "origin" => {
299
- "ref" => "Ranger, Natalie * 2006 * Bureau de la traduction / Translation Bureau * Services linguistiques / Linguistic Services * Bur. dir. Centre de traduction et de terminologie / Dir's Office Translation and Terminology Centre * Div. Citoyenneté et Protection civile / Citizen. & Emergency preparedness Div. * Normalisation terminologique / Terminology Standardization"
300
- },
301
- "type" => "lineage",
302
- "status" => "identical"
303
- }
304
- ],
305
- "terms" => [
306
- {
307
- "type" => "expression",
308
- "normative_status" => "preferred",
309
- "designation" => "description de concept",
310
- "grammar_info" => [
311
- {
312
- "preposition" => false,
313
- "participle" => false,
314
- "adj" => false,
315
- "verb" => false,
316
- "adverb" => false,
317
- "noun" => false,
318
- "gender" => ["f"],
319
- "number" => ["singular"]
320
- }
321
- ]
322
- }
323
- ],
324
- "language_code" => "fre"
325
- }
326
- }
327
- ```
328
-
329
- ### Rendering a single term from loaded dataset
330
-
331
- This can be used to render a single concept from the loaded dataset. See [Loading Dataset](#loading-dataset) to load a dataset.
332
- This will use the [default template for rendering concepts](#default-template-for-rendering-concepts)
333
-
334
- #### Syntax
335
-
336
- `glossarist::render[<dataset name>, <term>]`
337
-
338
- #### Example
339
-
340
- Suppose we have a term named `foobar` in our dataset with the definition `The term foobar is used as metasyntactic variables and placeholder names in computer programming`
341
-
342
- ```adoc
343
- :glossarist-dataset: dataset:./path/to/glossarist-dataset
344
-
345
- === Section
346
- glossarist::render[dataset, foobar]
347
- ```
348
-
349
- then the output will be
350
-
351
- ```adoc
352
- === Section
353
- ==== entity
354
- concrete or abstract thing that exists, did exist, or can possibly exist, including associations among these things
355
- ```
356
-
357
- ### Rendering all terms from loaded dataset
358
-
359
- This will render all the concepts from the [loaded dataset](#loading-dataset) using [default template for rendering concepts](#default-template-for-rendering-concepts)
360
-
361
- #### Syntax
362
-
363
- `glossarist::import[<dataset name>]`
364
-
365
-
366
- ### Rendering bibliography for a single term in the dataset
367
-
368
- This will render a bibliography for a single term in the [loaded dataset](#loading-dataset) using the [default template for bibliography](#default-template-for-bibliography)
369
-
370
- #### Syntax
371
-
372
- `glossarist::render_bibliography_entry[<dataset name>, <term>]`
373
-
374
- #### Example
375
-
376
- Suppose we have a concept `foo` with the ref `ISO/TS 14812:2022`, then we can render the bibliography for this like
377
-
378
- ```adoc
379
- :glossarist-dataset: dataset:./path/to/glossarist-dataset
380
-
381
- glossarist::render_bibliography_entry[dataset, foo]
382
- ```
383
-
384
- then the output will be
385
-
386
- ```adoc
387
- * [[[ISO_TS_14812_2022,ISO/TS 14812:2022]]]
388
- ```
389
-
390
- ### Rendering bibliography for all terms in the dataset
391
-
392
- This will render all the bibliographies for the given dataset
393
-
394
- #### Syntax
395
-
396
- `glossarist::render_bibliography[<dataset name>]`
397
-
398
- #### Example
399
-
400
- Suppose we have following concepts in dataset
401
-
402
- - `foo` with ref `ISO/TS 14812:2022`
403
- - `bar` with ref `ISO/TS 14812:2023`
404
-
405
- then we can render the bibliography for this like
406
-
407
- ```adoc
408
- :glossarist-dataset: dataset:./path/to/glossarist-dataset
409
-
410
- glossarist::render_bibliography[dataset]
411
- ```
412
-
413
- then the output will be
414
-
415
- ```adoc
416
- * [[[ISO_TS_14812_2022,ISO/TS 14812:2022]]]
417
- * [[[ISO_TS_14812_2023,ISO/TS 14812:2023]]]
418
- ```
419
-
420
-
421
- ### Default template for rendering concepts
422
-
423
- ```adoc
424
- ==== {{ concept.term }}
425
- <type>:[designation for the type]
426
-
427
- {{ dataset[<concept name>]['eng'].definition[0].content }}
428
-
429
- {% for example in <dataset name>[<concept name>]['eng'].examples %}
430
- [example]
431
- {{ example.content }}
432
-
433
- {% endfor %}
434
-
435
- {% for note in <dataset name>[<concept name>]['eng'].notes %}
436
- [NOTE]
437
- ====
438
- {{ note.content }}
439
- ====
440
-
441
- {% endfor %}
442
-
443
- {% for source in <dataset name>[<concept name>]['eng'].sources %}
444
- [.source]
445
- <<{{ source.origin.ref | replace: ' ', '_' | replace: '/', '_' | replace: ':', '_' }},{{ source.origin.clause }}>>
446
-
447
- {% endfor %}
448
- ```
449
-
450
- #### Example
451
-
452
- ```adoc
453
- ==== foobar
454
- admitted:[E]
455
-
456
- The term foobar is used as metasyntactic variables and placeholder names in computer programming
457
-
458
- [example]
459
- example for the term
460
-
461
- [NOTE]
462
- ====
463
- note for the term
464
- ====
465
-
466
- [.source]
467
- <<ISO_TS_14812_2022,foo_bar_id>>
468
- ```
469
-
470
- ### Default template for bibliography
471
-
472
- ```adoc
473
- * [[[{{ source.origin.ref | replace: ' ', '_' | replace: '/', '_' | replace: ':', '_' }},{{ source.origin.clause }},{{source.origin.ref}}]]]
474
- ```
475
-
476
-
477
- ## Development
478
-
479
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
480
-
481
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
482
-
483
- ## Contributing
484
-
485
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/metanorma-plugin-glossarist. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/metanorma-plugin-glossarist/blob/master/CODE_OF_CONDUCT.md).
486
-
487
-
488
- ## License
489
-
490
- The gem is available as open source under the terms of the
491
- [2-Clause BSD License](https://opensource.org/licenses/BSD-2-Clause).
492
-
493
- ## Code of Conduct
494
-
495
- Everyone interacting in the Metanorma::Plugin::Glossarist project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/metanorma-plugin-glossarist/blob/master/CODE_OF_CONDUCT.md).
@@ -1,52 +0,0 @@
1
- module Liquid
2
- module CustomBlocks
3
- class WithGlossaristContext < Block
4
- def initialize(tag_name, markup, tokens)
5
- super
6
-
7
- @contexts = []
8
- @filters = {}
9
-
10
- contexts, filters = markup.split(";", 2)
11
-
12
- if filters && !filters.empty?
13
- filters.strip.gsub(/^['"]|['"]$/, "").split(";").each do |filter|
14
- property, value = filter.split("=")
15
-
16
- @filters[property] = value
17
- end
18
- end
19
-
20
- contexts.split(",").each do |context|
21
- context_name, file_path = context.split("=").map(&:strip)
22
-
23
- @contexts << {
24
- name: context_name,
25
- file_path: file_path,
26
- }
27
- end
28
- end
29
-
30
- def load_collection(folder_path)
31
- @@collections ||= {}
32
-
33
- return @@collections[folder_path] if @@collections[folder_path]
34
-
35
- collection = ::Glossarist::ManagedConceptCollection.new
36
- collection.load_from_files(folder_path)
37
- @@collections[folder_path] = collection
38
- end
39
-
40
- def render(context)
41
- @contexts.each do |local_context|
42
- context_file = local_context[:file_path].strip
43
- collection = load_collection(context_file)
44
-
45
- context[local_context[:name]] = Liquid::Drops::ConceptsDrop.new(collection, @filters)
46
- end
47
-
48
- super
49
- end
50
- end
51
- end
52
- end
@@ -1,35 +0,0 @@
1
- module Liquid
2
- module CustomFilters
3
- module Filters
4
- def values(list)
5
- list.values
6
- end
7
-
8
- def terminological_data(term)
9
- result = []
10
-
11
- result << "&lt;#{term['usage_info']}&gt;" if term["usage_info"]
12
- result << extract_grammar_info(term)
13
- result << term["geographical_area"]&.upcase
14
-
15
- result.unshift(",") if result.compact.size.positive?
16
-
17
- result.compact.join(" ")
18
- end
19
-
20
- def extract_grammar_info(term)
21
- return unless term["grammar_info"]
22
-
23
- grammar_info = []
24
-
25
- term["grammar_info"].each do |info|
26
- grammar_info << info["gender"]&.join(", ")
27
- grammar_info << info["number"]&.join(", ")
28
- grammar_info << extract_parts_of_speech(info)
29
- end
30
-
31
- grammar_info.join(" ")
32
- end
33
- end
34
- end
35
- end