metanorma-plugin-glossarist 0.1.8 → 0.2.0
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 +6 -1
- data/README.md +266 -4
- data/lib/liquid/drops/concepts_drop.rb +12 -17
- data/lib/metanorma/plugin/glossarist/dataset_preprocessor.rb +7 -8
- data/lib/metanorma/plugin/glossarist/version.rb +1 -1
- data/metanorma-plugin-glossarist.gemspec +5 -3
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a817c5969de17ce761956773dce8a9aeb2dee7e2c1bde5f3970783438dd008a1
|
4
|
+
data.tar.gz: 2cbc4ca6b683be306731443ab4ca1d8930b97a2bad8a1c0588d8c12d54b27d80
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5f37a8fd2db74f26be2868893eeac5ad65f5014e15f7748ff21975747c864f5d52d14a66bd1263d3be1a608a6032564b2db2a13045222a642a1308a7ad7d5637
|
7
|
+
data.tar.gz: c9b4b823a8e9ba4167d37b7f4d8a4d3c51c27af9cb5d411b35d3690dce50206ef1b682ccbe7bd0cb03fed06a1d977252cb3bc24222ccd570a909196f64c015a5
|
data/Gemfile
CHANGED
@@ -1,4 +1,9 @@
|
|
1
|
+
Encoding.default_external = Encoding::UTF_8
|
2
|
+
Encoding.default_internal = Encoding::UTF_8
|
3
|
+
|
1
4
|
source "https://rubygems.org"
|
5
|
+
git_source(:github) { |repo| "https://github.com/#{repo}" }
|
2
6
|
|
3
|
-
# Specify your gem's dependencies in metanorma-plugin-glossarist.gemspec
|
4
7
|
gemspec
|
8
|
+
|
9
|
+
eval_gemfile("Gemfile.devel") rescue nil
|
data/README.md
CHANGED
@@ -1,8 +1,6 @@
|
|
1
1
|
# Metanorma::Plugin::Glossarist
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
TODO: Delete this and the text above, and describe your gem
|
3
|
+
Metanorma plugin that allows you to access data from the glossarist dataset inside a Metanorma document.
|
6
4
|
|
7
5
|
## Installation
|
8
6
|
|
@@ -22,7 +20,271 @@ Or install it yourself as:
|
|
22
20
|
|
23
21
|
## Usage
|
24
22
|
|
25
|
-
|
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
|
+
### Rendering a single term from loaded dataset
|
142
|
+
|
143
|
+
This can be used to render a single concept from the loaded dataset. See [Loading Dataset](#loading-dataset) to load a dataset.
|
144
|
+
This will use the [default template for rendering concepts](#default-template-for-rendering-concepts)
|
145
|
+
|
146
|
+
#### Syntax
|
147
|
+
|
148
|
+
`glossarist::render[<dataset name>, <term>]`
|
149
|
+
|
150
|
+
#### Example
|
151
|
+
|
152
|
+
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`
|
153
|
+
|
154
|
+
```adoc
|
155
|
+
:glossarist-dataset: dataset:./path/to/glossarist-dataset
|
156
|
+
|
157
|
+
=== Section
|
158
|
+
glossarist::render[dataset, foobar]
|
159
|
+
```
|
160
|
+
|
161
|
+
then the output will be
|
162
|
+
|
163
|
+
```adoc
|
164
|
+
=== Section
|
165
|
+
==== entity
|
166
|
+
concrete or abstract thing that exists, did exist, or can possibly exist, including associations among these things
|
167
|
+
```
|
168
|
+
|
169
|
+
### Rendering all terms from loaded dataset
|
170
|
+
|
171
|
+
This will render all the concepts from the [loaded dataset](#loading-dataset) using [default template for rendering concepts](#default-template-for-rendering-concepts)
|
172
|
+
|
173
|
+
#### Syntax
|
174
|
+
|
175
|
+
`glossarist::import[<dataset name>]`
|
176
|
+
|
177
|
+
|
178
|
+
### Rendering bibliography for a single term in the dataset
|
179
|
+
|
180
|
+
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)
|
181
|
+
|
182
|
+
#### Syntax
|
183
|
+
|
184
|
+
`glossarist::render_bibliography_entry[<dataset name>, <term>]`
|
185
|
+
|
186
|
+
#### Example
|
187
|
+
|
188
|
+
Suppose we have a concept `foo` with the ref `ISO/TS 14812:2022`, then we can render the bibliography for this like
|
189
|
+
|
190
|
+
```adoc
|
191
|
+
:glossarist-dataset: dataset:./path/to/glossarist-dataset
|
192
|
+
|
193
|
+
glossarist::render_bibliography_entry[dataset, foo]
|
194
|
+
```
|
195
|
+
|
196
|
+
then the output will be
|
197
|
+
|
198
|
+
```adoc
|
199
|
+
* [[[ISO_TS_14812_2022,ISO/TS 14812:2022]]]
|
200
|
+
```
|
201
|
+
|
202
|
+
### Rendering bibliography for all terms in the dataset
|
203
|
+
|
204
|
+
This will render all the bibliographies for the given dataset
|
205
|
+
|
206
|
+
#### Syntax
|
207
|
+
|
208
|
+
`glossarist::render_bibliography[<dataset name>]`
|
209
|
+
|
210
|
+
#### Example
|
211
|
+
|
212
|
+
Suppose we have following concepts in dataset
|
213
|
+
|
214
|
+
- `foo` with ref `ISO/TS 14812:2022`
|
215
|
+
- `bar` with ref `ISO/TS 14812:2023`
|
216
|
+
|
217
|
+
then we can render the bibliography for this like
|
218
|
+
|
219
|
+
```adoc
|
220
|
+
:glossarist-dataset: dataset:./path/to/glossarist-dataset
|
221
|
+
|
222
|
+
glossarist::render_bibliography[dataset]
|
223
|
+
```
|
224
|
+
|
225
|
+
then the output will be
|
226
|
+
|
227
|
+
```adoc
|
228
|
+
* [[[ISO_TS_14812_2022,ISO/TS 14812:2022]]]
|
229
|
+
* [[[ISO_TS_14812_2023,ISO/TS 14812:2023]]]
|
230
|
+
```
|
231
|
+
|
232
|
+
|
233
|
+
### Default template for rendering concepts
|
234
|
+
|
235
|
+
```adoc
|
236
|
+
==== {{ concept.term }}
|
237
|
+
<type>:[designation for the type]
|
238
|
+
|
239
|
+
{{ dataset[<concept name>]['eng'].definition[0].content }}
|
240
|
+
|
241
|
+
{% for example in <dataset name>[<concept name>]['eng'].examples %}
|
242
|
+
[example]
|
243
|
+
{{ example.content }}
|
244
|
+
|
245
|
+
{% endfor %}
|
246
|
+
|
247
|
+
{% for note in <dataset name>[<concept name>]['eng'].notes %}
|
248
|
+
[NOTE]
|
249
|
+
====
|
250
|
+
{{ note.content }}
|
251
|
+
====
|
252
|
+
|
253
|
+
{% endfor %}
|
254
|
+
|
255
|
+
{% for source in <dataset name>[<concept name>]['eng'].sources %}
|
256
|
+
[.source]
|
257
|
+
<<{{ source.origin.ref | replace: ' ', '_' | replace: '/', '_' | replace: ':', '_' }},{{ source.origin.clause }}>>
|
258
|
+
|
259
|
+
{% endfor %}
|
260
|
+
```
|
261
|
+
|
262
|
+
#### Example
|
263
|
+
|
264
|
+
```adoc
|
265
|
+
==== foobar
|
266
|
+
admitted:[E]
|
267
|
+
|
268
|
+
The term foobar is used as metasyntactic variables and placeholder names in computer programming
|
269
|
+
|
270
|
+
[example]
|
271
|
+
example for the term
|
272
|
+
|
273
|
+
[NOTE]
|
274
|
+
====
|
275
|
+
note for the term
|
276
|
+
====
|
277
|
+
|
278
|
+
[.source]
|
279
|
+
<<ISO_TS_14812_2022,foo_bar_id>>
|
280
|
+
```
|
281
|
+
|
282
|
+
### Default template for bibliography
|
283
|
+
|
284
|
+
```adoc
|
285
|
+
* [[[{{ source.origin.ref | replace: ' ', '_' | replace: '/', '_' | replace: ':', '_' }},{{ source.origin.clause }},{{source.origin.ref}}]]]
|
286
|
+
```
|
287
|
+
|
26
288
|
|
27
289
|
## Development
|
28
290
|
|
@@ -32,25 +32,20 @@ module Liquid
|
|
32
32
|
|
33
33
|
def filtered_concepts(concepts_collection, filters)
|
34
34
|
concept_filters = filters.dup
|
35
|
-
language_filter = concept_filters.delete(
|
36
|
-
sort_filter = concept_filters.delete(
|
37
|
-
group_filter = concept_filters.delete(
|
35
|
+
language_filter = concept_filters.delete("lang")
|
36
|
+
sort_filter = concept_filters.delete("sort_by")
|
37
|
+
group_filter = concept_filters.delete("group")
|
38
38
|
|
39
39
|
concepts = concepts_collection.map do |concept|
|
40
40
|
filtered_concept = concept.to_h["data"]
|
41
41
|
filtered_concept["term"] = concept.default_designation
|
42
42
|
|
43
43
|
filtered_concept = filtered_concept.merge(
|
44
|
-
extract_localized_concepts(
|
45
|
-
concept,
|
46
|
-
language_filter,
|
47
|
-
),
|
44
|
+
extract_localized_concepts(concept, language_filter),
|
48
45
|
)
|
49
46
|
|
50
47
|
if retain_concept?(filtered_concept, concept_filters)
|
51
48
|
filtered_concept
|
52
|
-
else
|
53
|
-
nil
|
54
49
|
end
|
55
50
|
end.compact
|
56
51
|
|
@@ -62,13 +57,13 @@ module Liquid
|
|
62
57
|
localized_concepts = {}
|
63
58
|
|
64
59
|
if !languages || languages.empty?
|
65
|
-
concept.localized_concepts.each do |lang,
|
60
|
+
concept.localized_concepts.each do |lang, _localized_concept_uuid|
|
66
61
|
localized_concepts[lang] = concept.localizations[lang].to_h["data"]
|
67
62
|
end
|
68
63
|
else
|
69
64
|
languages.split(",").each do |lang|
|
70
|
-
localization = concept.localizations[lang]&.to_h&.dig("data")
|
71
|
-
|
65
|
+
localization = concept.localizations[lang]&.to_h&.dig("data") and
|
66
|
+
localized_concepts[lang] = localization
|
72
67
|
end
|
73
68
|
end
|
74
69
|
|
@@ -81,10 +76,8 @@ module Liquid
|
|
81
76
|
if fields.last.start_with?("start_with")
|
82
77
|
value = fields.last.gsub(/start_with\(([^\)]*)\)/, '\1')
|
83
78
|
fields = fields[0..-2]
|
84
|
-
|
85
|
-
unless filtered_concept.dig(*fields).start_with?(value)
|
79
|
+
filtered_concept.dig(*fields).start_with?(value) or
|
86
80
|
return false
|
87
|
-
end
|
88
81
|
elsif filtered_concept.dig(*fields) != value
|
89
82
|
return false
|
90
83
|
end
|
@@ -96,7 +89,9 @@ module Liquid
|
|
96
89
|
def apply_sort_filter(concepts, sort_by)
|
97
90
|
return concepts unless sort_by
|
98
91
|
|
99
|
-
concepts.sort_by
|
92
|
+
concepts.sort_by do |concept|
|
93
|
+
concept.dig(*extract_nested_field_names(sort_by))
|
94
|
+
end
|
100
95
|
end
|
101
96
|
|
102
97
|
def apply_group_filter(concepts, groups)
|
@@ -113,7 +108,7 @@ module Liquid
|
|
113
108
|
name.split(".").map do |field|
|
114
109
|
field_name = field.strip
|
115
110
|
|
116
|
-
|
111
|
+
/^\d+$/.match?(field_name) ? field_name.to_i : field_name
|
117
112
|
end
|
118
113
|
end
|
119
114
|
|
@@ -65,7 +65,7 @@ module Metanorma
|
|
65
65
|
end
|
66
66
|
|
67
67
|
def process(document, reader)
|
68
|
-
input_lines = reader.
|
68
|
+
input_lines = reader.lines.to_enum
|
69
69
|
|
70
70
|
file_system = ::Liquid::LocalFileSystem.new(
|
71
71
|
relative_file_path(document, ""),
|
@@ -74,9 +74,8 @@ module Metanorma
|
|
74
74
|
@config[:file_system] = file_system
|
75
75
|
|
76
76
|
processed_doc = prepare_document(document, input_lines)
|
77
|
-
Asciidoctor::
|
78
|
-
|
79
|
-
)
|
77
|
+
Asciidoctor::PreprocessorReader.new(document,
|
78
|
+
processed_doc.to_s.split("\n"))
|
80
79
|
end
|
81
80
|
|
82
81
|
private
|
@@ -176,7 +175,7 @@ module Metanorma
|
|
176
175
|
liquid_doc.add_content(
|
177
176
|
dataset.concepts.map do |concept_name, _concept|
|
178
177
|
concept_template(context_name, concept_name)
|
179
|
-
end.join("\n")
|
178
|
+
end.join("\n"),
|
180
179
|
)
|
181
180
|
end
|
182
181
|
|
@@ -187,7 +186,7 @@ module Metanorma
|
|
187
186
|
liquid_doc.add_content(
|
188
187
|
dataset.concepts.map do |_concept_name, concept|
|
189
188
|
concept_bibliography(concept)
|
190
|
-
end.compact.sort.join("\n")
|
189
|
+
end.compact.sort.join("\n"),
|
191
190
|
)
|
192
191
|
end
|
193
192
|
|
@@ -196,7 +195,7 @@ module Metanorma
|
|
196
195
|
concept = @datasets[dataset_name][concept_name]
|
197
196
|
|
198
197
|
liquid_doc.add_content(
|
199
|
-
concept_bibliography(concept)
|
198
|
+
concept_bibliography(concept),
|
200
199
|
)
|
201
200
|
end
|
202
201
|
|
@@ -206,7 +205,7 @@ module Metanorma
|
|
206
205
|
|
207
206
|
next if @rendered_bibliographies[ref]
|
208
207
|
|
209
|
-
@rendered_bibliographies[ref] = ref.gsub(/[ \/:]/,
|
208
|
+
@rendered_bibliographies[ref] = ref.gsub(/[ \/:]/, "_")
|
210
209
|
"* [[[#{@rendered_bibliographies[ref]},#{ref}]]]"
|
211
210
|
end.compact.join("\n")
|
212
211
|
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require_relative
|
1
|
+
require_relative "lib/metanorma/plugin/glossarist/version"
|
2
2
|
|
3
3
|
Gem::Specification.new do |spec|
|
4
4
|
spec.name = "metanorma-plugin-glossarist"
|
@@ -14,8 +14,10 @@ Gem::Specification.new do |spec|
|
|
14
14
|
|
15
15
|
# Specify which files should be added to the gem when it is released.
|
16
16
|
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
17
|
-
spec.files = Dir.chdir(File.expand_path(
|
18
|
-
`git ls-files -z`.split("\x0").reject
|
17
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
18
|
+
`git ls-files -z`.split("\x0").reject do |f|
|
19
|
+
f.match(%r{^(test|spec|features)/})
|
20
|
+
end
|
19
21
|
end
|
20
22
|
spec.bindir = "exe"
|
21
23
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
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.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ribose Inc.
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-03-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: asciidoctor
|