metanorma-plugin-glossarist 0.2.8 → 0.2.9
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/README.adoc +5 -2
- data/lib/metanorma/plugin/glossarist/dataset_preprocessor.rb +34 -30
- data/lib/metanorma/plugin/glossarist/document.rb +7 -4
- data/lib/metanorma/plugin/glossarist/liquid/custom_blocks/with_glossarist_context.rb +3 -4
- data/lib/metanorma/plugin/glossarist/liquid/multiply_local_file_system.rb +74 -0
- data/lib/metanorma/plugin/glossarist/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b06eede0539ad9fda202136bb7d97aded91a6e925536234e822bdff0a067996e
|
4
|
+
data.tar.gz: 96981f754d34698da5288b12df8fe54719e9e40e15f96413a1cbad9f63962e4e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9dd3c3ec6cd75a5aeb4f718e567374820ed074de9dd428919b7e3c9d038f95b116d61d2f29478c25e624aa35f593da0ca9e31fd280be43c9ea46e75cfdfce824
|
7
|
+
data.tar.gz: 1ea5f7d523beecdb2a1c67f9282064b5791f537ca6f6743d17329aefab4492421b758ee4f3728332653f567cb92f1c0c4977010ecbce86c4f92d79328adb5701
|
data/README.adoc
CHANGED
@@ -83,7 +83,7 @@ Syntax:
|
|
83
83
|
|
84
84
|
[source,adoc]
|
85
85
|
------
|
86
|
-
[glossarist,{dataset-path},{filters},{context}]
|
86
|
+
[glossarist,{dataset-path},{filter=filters},{template=path/to/template},{context}]
|
87
87
|
----
|
88
88
|
// Liquid template
|
89
89
|
----
|
@@ -96,9 +96,12 @@ Where,
|
|
96
96
|
|
97
97
|
`{context}`:: The context in which the dataset is being used (e.g., `concepts`).
|
98
98
|
|
99
|
-
`{filters}`:: (Optional) Filters to apply to the dataset prior to making the
|
99
|
+
`{filter=filters}`:: (Optional) Filters to apply to the dataset prior to making the
|
100
100
|
`context` available.
|
101
101
|
|
102
|
+
`{template=path/to/template}`:: (Optional) The path to a Liquid template folder
|
103
|
+
to use for rendering.
|
104
|
+
|
102
105
|
[example]
|
103
106
|
======
|
104
107
|
Given the following Glossarist block:
|
@@ -14,8 +14,7 @@ module Metanorma
|
|
14
14
|
GLOSSARIST_DATASET_REGEX = /^:glossarist-dataset:\s*(.*?)$/m.freeze
|
15
15
|
GLOSSARIST_IMPORT_REGEX = /^glossarist::import\[(.*?)\]$/m.freeze
|
16
16
|
GLOSSARIST_RENDER_REGEX = /^glossarist::render\[(.*?)\]$/m.freeze
|
17
|
-
GLOSSARIST_BLOCK_REGEX = /^\[glossarist,(.+?),(.+?)\]
|
18
|
-
GLOSSARIST_FILTER_BLOCK_REGEX = /^\[glossarist,(.+?),(filter=.+?),(.+?)\]/.freeze # rubocop:disable Layout/LineLength
|
17
|
+
GLOSSARIST_BLOCK_REGEX = /^\[glossarist,(.+?),(.+?)\]$/m.freeze
|
19
18
|
GLOSSARIST_BIBLIOGRAPHY_REGEX = /^glossarist::render_bibliography\[(.*?)\]$/m.freeze # rubocop:disable Layout/LineLength
|
20
19
|
GLOSSARIST_BIBLIOGRAPHY_ENTRY_REGEX = /^glossarist::render_bibliography_entry\[(.*?)\]$/m.freeze # rubocop:disable Layout/LineLength
|
21
20
|
|
@@ -57,13 +56,7 @@ module Metanorma
|
|
57
56
|
|
58
57
|
def process(document, reader)
|
59
58
|
input_lines = reader.lines.to_enum
|
60
|
-
|
61
|
-
file_system = ::Liquid::LocalFileSystem.new(
|
62
|
-
relative_file_path(document, ""),
|
63
|
-
)
|
64
|
-
|
65
|
-
@config[:file_system] = file_system
|
66
|
-
|
59
|
+
@config[:file_system] = relative_file_path(document, "")
|
67
60
|
processed_doc = prepare_document(document, input_lines)
|
68
61
|
log(document, processed_doc.to_s) unless @seen_glossarist.empty?
|
69
62
|
Asciidoctor::PreprocessorReader.new(document,
|
@@ -115,15 +108,11 @@ module Metanorma
|
|
115
108
|
process_bibliography(liquid_doc, match)
|
116
109
|
elsif match = current_line.match(GLOSSARIST_BIBLIOGRAPHY_ENTRY_REGEX)
|
117
110
|
process_bibliography_entry(liquid_doc, match)
|
118
|
-
elsif match = current_line.match(
|
119
|
-
process_glossarist_block(document, liquid_doc, input_lines, match)
|
120
|
-
elsif match = current_line.match(GLOSSARIST_BLOCK_REGEX) # rubocop:disable Lint/DuplicateBranch
|
111
|
+
elsif match = current_line.match(GLOSSARIST_BLOCK_REGEX)
|
121
112
|
process_glossarist_block(document, liquid_doc, input_lines, match)
|
122
113
|
else
|
123
114
|
if /^==+ \S/.match?(current_line)
|
124
|
-
@title_depth[:value] =
|
125
|
-
current_line.sub(/ .*$/,
|
126
|
-
"").size
|
115
|
+
@title_depth[:value] = current_line.sub(/ .*$/, "").size
|
127
116
|
end
|
128
117
|
liquid_doc.add_content(current_line)
|
129
118
|
end
|
@@ -146,9 +135,9 @@ module Metanorma
|
|
146
135
|
def process_glossarist_block(document, liquid_doc, input_lines, match)
|
147
136
|
@seen_glossarist << "x"
|
148
137
|
end_mark = input_lines.next
|
149
|
-
# path = relative_file_path(document, match[1])
|
150
|
-
glossarist_params = prepare_glossarist_block_params(document, match)
|
151
138
|
|
139
|
+
glossarist_params, template =
|
140
|
+
prepare_glossarist_block_params(document, match)
|
152
141
|
glossarist_section = <<~TEMPLATE.strip
|
153
142
|
{% with_glossarist_context #{glossarist_params} %}
|
154
143
|
#{prepare_document(
|
@@ -158,23 +147,38 @@ module Metanorma
|
|
158
147
|
{% endwith_glossarist_context %}
|
159
148
|
TEMPLATE
|
160
149
|
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
)
|
150
|
+
options = { render: true }
|
151
|
+
options[:template] = template if template
|
152
|
+
|
153
|
+
liquid_doc.add_content(glossarist_section, options)
|
165
154
|
end
|
166
155
|
|
167
|
-
def prepare_glossarist_block_params(document, match)
|
156
|
+
def prepare_glossarist_block_params(document, match) # rubocop:disable Metrics/AbcSize,Metrics/MethodLength
|
168
157
|
path = get_context_path(document, match[1])
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
158
|
+
matched_arr = match[2].split(",").map(&:strip)
|
159
|
+
# get the last element as context name
|
160
|
+
context_name = matched_arr.last
|
161
|
+
|
162
|
+
glossarist_block_params = []
|
163
|
+
glossarist_block_params << "#{context_name}=#{path}"
|
164
|
+
|
165
|
+
template = nil
|
166
|
+
if matched_arr.size > 1
|
167
|
+
filters_or_template = matched_arr[0..-2]
|
168
|
+
filters_or_template.each do |item|
|
169
|
+
if item.start_with?("filter=")
|
170
|
+
filters = item.gsub(/^filter=/, "").strip
|
171
|
+
glossarist_block_params << filters
|
172
|
+
elsif item.start_with?("template=")
|
173
|
+
template = relative_file_path(
|
174
|
+
document,
|
175
|
+
item.gsub(/^template=/, "").strip,
|
176
|
+
)
|
177
|
+
end
|
178
|
+
end
|
177
179
|
end
|
180
|
+
|
181
|
+
[glossarist_block_params.join(";"), template]
|
178
182
|
end
|
179
183
|
|
180
184
|
def get_context_path(document, key) # rubocop:disable Metrics/MethodLength
|
@@ -2,6 +2,7 @@
|
|
2
2
|
|
3
3
|
require_relative "liquid/custom_blocks/with_glossarist_context"
|
4
4
|
require_relative "liquid/custom_filters/filters"
|
5
|
+
require_relative "liquid/multiply_local_file_system"
|
5
6
|
|
6
7
|
module Metanorma
|
7
8
|
module Plugin
|
@@ -16,7 +17,7 @@ module Metanorma
|
|
16
17
|
|
17
18
|
def add_content(content, options = {})
|
18
19
|
@content << if options[:render]
|
19
|
-
render_liquid(content)
|
20
|
+
render_liquid(content, options)
|
20
21
|
else
|
21
22
|
content
|
22
23
|
end
|
@@ -26,11 +27,13 @@ module Metanorma
|
|
26
27
|
@content.compact.join("\n")
|
27
28
|
end
|
28
29
|
|
29
|
-
def render_liquid(file_content)
|
30
|
+
def render_liquid(file_content, options = {}) # rubocop:disable Metrics/AbcSize
|
31
|
+
include_paths = [file_system, options[:template]].compact
|
30
32
|
template = ::Liquid::Template
|
31
33
|
.parse(file_content, environment: create_liquid_environment)
|
32
|
-
|
33
|
-
|
34
|
+
template.registers[:file_system] = ::Metanorma::Plugin::Glossarist::Liquid::LocalFileSystem.new(
|
35
|
+
include_paths, ["%s.liquid", "_%s.liquid", "_%s.adoc"]
|
36
|
+
)
|
34
37
|
rendered_template = template.render(strict_variables: false,
|
35
38
|
error_mode: :warn)
|
36
39
|
|
@@ -14,13 +14,12 @@ module Metanorma
|
|
14
14
|
@contexts = []
|
15
15
|
@filters = {}
|
16
16
|
|
17
|
-
contexts, filters = markup.split(";", 2)
|
17
|
+
contexts, filters = markup.strip.split(";", 2)
|
18
18
|
|
19
19
|
if filters && !filters.empty?
|
20
|
-
filters.strip.gsub(/^['"]|['"]$/,
|
21
|
-
|
20
|
+
filters = filters.strip.gsub(/^['"]|['"]$/, "").split(";")
|
21
|
+
filters.each do |filter|
|
22
22
|
property, value = filter.split("=")
|
23
|
-
|
24
23
|
@filters[property] = value
|
25
24
|
end
|
26
25
|
end
|
@@ -0,0 +1,74 @@
|
|
1
|
+
module Metanorma
|
2
|
+
module Plugin
|
3
|
+
module Glossarist
|
4
|
+
module Liquid
|
5
|
+
class LocalFileSystem
|
6
|
+
attr_accessor :roots, :patterns
|
7
|
+
|
8
|
+
def initialize(roots, patterns = ["_%s.liquid"])
|
9
|
+
@roots = roots
|
10
|
+
@patterns = patterns
|
11
|
+
end
|
12
|
+
|
13
|
+
def read_template_file(template_path)
|
14
|
+
full_path = full_path(template_path)
|
15
|
+
|
16
|
+
unless File.exist?(full_path)
|
17
|
+
raise FileSystemError, "No such template '#{template_path}'"
|
18
|
+
end
|
19
|
+
|
20
|
+
File.read(full_path)
|
21
|
+
end
|
22
|
+
|
23
|
+
def full_path(template_path) # rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/MethodLength,Metrics/PerceivedComplexity
|
24
|
+
unless %r{\A[^./][a-zA-Z0-9_/]+\z}.match?(template_path)
|
25
|
+
raise ::Liquid::FileSystemError,
|
26
|
+
"Illegal template name '#{template_path}'"
|
27
|
+
end
|
28
|
+
|
29
|
+
result_path = if template_path.include?("/")
|
30
|
+
roots
|
31
|
+
.map do |root|
|
32
|
+
patterns.map do |pattern|
|
33
|
+
File.join(
|
34
|
+
root,
|
35
|
+
File.dirname(template_path),
|
36
|
+
pattern % File.basename(template_path),
|
37
|
+
)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
.flatten
|
41
|
+
.find { |path| File.file?(path) }
|
42
|
+
else
|
43
|
+
roots
|
44
|
+
.map do |root|
|
45
|
+
patterns.map do |pattern|
|
46
|
+
File.join(root, pattern % template_path)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
.flatten
|
50
|
+
.find { |path| File.file?(path) }
|
51
|
+
end
|
52
|
+
|
53
|
+
if result_path.nil?
|
54
|
+
raise ::Liquid::FileSystemError,
|
55
|
+
"No documents in template path: " \
|
56
|
+
" #{File.expand_path(template_path)}"
|
57
|
+
end
|
58
|
+
|
59
|
+
unless roots.any? do |root|
|
60
|
+
File.expand_path(result_path).start_with?(
|
61
|
+
File.expand_path(root),
|
62
|
+
)
|
63
|
+
end
|
64
|
+
raise ::Liquid::FileSystemError,
|
65
|
+
"Illegal template path '#{File.expand_path(result_path)}'"
|
66
|
+
end
|
67
|
+
|
68
|
+
result_path
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
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.
|
4
|
+
version: 0.2.9
|
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-
|
11
|
+
date: 2025-07-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: asciidoctor
|
@@ -77,6 +77,7 @@ files:
|
|
77
77
|
- lib/metanorma/plugin/glossarist/document.rb
|
78
78
|
- lib/metanorma/plugin/glossarist/liquid/custom_blocks/with_glossarist_context.rb
|
79
79
|
- lib/metanorma/plugin/glossarist/liquid/custom_filters/filters.rb
|
80
|
+
- lib/metanorma/plugin/glossarist/liquid/multiply_local_file_system.rb
|
80
81
|
- lib/metanorma/plugin/glossarist/version.rb
|
81
82
|
- metanorma-plugin-glossarist.gemspec
|
82
83
|
homepage: https://github.com/metanorma/metanorma-plugin-glossarist
|