metanorma-plugin-glossarist 0.1.8 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- 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 -9
- data/lib/metanorma/plugin/glossarist/version.rb +1 -1
- data/metanorma-plugin-glossarist.gemspec +5 -3
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8f950715c1c6a808aa2b24e8cb855ef674799465bd7a57b1f04ac73d1e899a91
|
4
|
+
data.tar.gz: 4fb0bdfc76982a98749a03f8f89600cff06073fbe5a555d6ef2004d1fffda0b8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 02f4df920b7fb3b3b67f647764b49bbfa4f276bb6aa8c8c803c3f55227d257d4cd5bcd1b77a88996ce6d96d1d453626bf2ab088e75c8629520b8976ff7fecf9d
|
7
|
+
data.tar.gz: 5c1a118c591f17783f7f54f9c66c316c3dd60b9034b8a23b904c22335a338a61d526c73d68d0f16a1c43c7d0520ac5469f32fc5da049004141cc42241769d968
|
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
|
|
@@ -1,7 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require "asciidoctor"
|
4
|
-
require "pry"
|
5
4
|
|
6
5
|
require "liquid"
|
7
6
|
require "asciidoctor/reader"
|
@@ -65,7 +64,7 @@ module Metanorma
|
|
65
64
|
end
|
66
65
|
|
67
66
|
def process(document, reader)
|
68
|
-
input_lines = reader.
|
67
|
+
input_lines = reader.lines.to_enum
|
69
68
|
|
70
69
|
file_system = ::Liquid::LocalFileSystem.new(
|
71
70
|
relative_file_path(document, ""),
|
@@ -74,9 +73,8 @@ module Metanorma
|
|
74
73
|
@config[:file_system] = file_system
|
75
74
|
|
76
75
|
processed_doc = prepare_document(document, input_lines)
|
77
|
-
Asciidoctor::
|
78
|
-
|
79
|
-
)
|
76
|
+
Asciidoctor::PreprocessorReader.new(document,
|
77
|
+
processed_doc.to_s.split("\n"))
|
80
78
|
end
|
81
79
|
|
82
80
|
private
|
@@ -176,7 +174,7 @@ module Metanorma
|
|
176
174
|
liquid_doc.add_content(
|
177
175
|
dataset.concepts.map do |concept_name, _concept|
|
178
176
|
concept_template(context_name, concept_name)
|
179
|
-
end.join("\n")
|
177
|
+
end.join("\n"),
|
180
178
|
)
|
181
179
|
end
|
182
180
|
|
@@ -187,7 +185,7 @@ module Metanorma
|
|
187
185
|
liquid_doc.add_content(
|
188
186
|
dataset.concepts.map do |_concept_name, concept|
|
189
187
|
concept_bibliography(concept)
|
190
|
-
end.compact.sort.join("\n")
|
188
|
+
end.compact.sort.join("\n"),
|
191
189
|
)
|
192
190
|
end
|
193
191
|
|
@@ -196,7 +194,7 @@ module Metanorma
|
|
196
194
|
concept = @datasets[dataset_name][concept_name]
|
197
195
|
|
198
196
|
liquid_doc.add_content(
|
199
|
-
concept_bibliography(concept)
|
197
|
+
concept_bibliography(concept),
|
200
198
|
)
|
201
199
|
end
|
202
200
|
|
@@ -206,7 +204,7 @@ module Metanorma
|
|
206
204
|
|
207
205
|
next if @rendered_bibliographies[ref]
|
208
206
|
|
209
|
-
@rendered_bibliographies[ref] = ref.gsub(/[ \/:]/,
|
207
|
+
@rendered_bibliographies[ref] = ref.gsub(/[ \/:]/, "_")
|
210
208
|
"* [[[#{@rendered_bibliographies[ref]},#{ref}]]]"
|
211
209
|
end.compact.join("\n")
|
212
210
|
|
@@ -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.1
|
4
|
+
version: 0.2.1
|
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-05-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: asciidoctor
|
@@ -141,7 +141,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
141
141
|
- !ruby/object:Gem::Version
|
142
142
|
version: '0'
|
143
143
|
requirements: []
|
144
|
-
rubygems_version: 3.3.
|
144
|
+
rubygems_version: 3.3.27
|
145
145
|
signing_key:
|
146
146
|
specification_version: 4
|
147
147
|
summary: Metanorma plugin for glossarist
|