asciidoctor-json-value-loader 0.2.0 → 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/lib/asciidoctor-json-value-loader.rb +14 -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: 4b86d0a1e7e4af629f5c1dc606436e5d90e46e4cd127f58bdab01302449ca8cc
|
4
|
+
data.tar.gz: 6cf0cd4337d4ac231b8572e6e9fccd5e9ef1328b2fef6533a501de287e3aa497
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 792bdf653a388f8f72ebc08e1839e622bb58e8ecfd8f32fe44aa9215215f331574209ac8655a10cee3a9c18e16f95d8bab4b474875f564d1e1fac86cef757b78
|
7
|
+
data.tar.gz: aaf4bbcb76df06811218b4a38a29c7693dc783fcbfe7ab976731ec8fd1e6dc7d98744959b1521e530b32a1f91b4b0af8256436319ce843b81f9ab9da8ba85023
|
@@ -2,7 +2,14 @@ require 'asciidoctor'
|
|
2
2
|
require 'json'
|
3
3
|
require 'uri'
|
4
4
|
|
5
|
-
class
|
5
|
+
class JsonValueLoaderFilePathTreeProcessor < Asciidoctor::Extensions::TreeProcessor
|
6
|
+
def process(document)
|
7
|
+
document.set_attr('json-value-loader-target-file', document.attr('docfile'))
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
|
12
|
+
class JsonValueLoaderInlineMacro < Asciidoctor::Extensions::InlineMacroProcessor
|
6
13
|
include Asciidoctor::Logging
|
7
14
|
|
8
15
|
use_dsl
|
@@ -16,6 +23,8 @@ class JsonValueLoadInlineMacro < Asciidoctor::Extensions::InlineMacroProcessor
|
|
16
23
|
path, query = target.split(':', 2)
|
17
24
|
delimiter = attrs['delimiter']
|
18
25
|
|
26
|
+
dir = File.dirname(parent.document.attr('json-value-loader-target-file'))
|
27
|
+
|
19
28
|
query = query.split(delimiter).map do |q|
|
20
29
|
decoded = URI.decode_www_form_component(q)
|
21
30
|
if decoded.match(/^\d+$/) then
|
@@ -25,7 +34,8 @@ class JsonValueLoadInlineMacro < Asciidoctor::Extensions::InlineMacroProcessor
|
|
25
34
|
end
|
26
35
|
end
|
27
36
|
|
28
|
-
|
37
|
+
filepath = File.join(dir, path)
|
38
|
+
json = JSON.parse(File.open(File.join(dir, path), 'r:utf-8', &:read))
|
29
39
|
|
30
40
|
content = json.dig(*query)
|
31
41
|
parent.logger.warn "json-value-loader: #{target} has no value." if content.nil?
|
@@ -44,5 +54,6 @@ class JsonValueLoadInlineMacro < Asciidoctor::Extensions::InlineMacroProcessor
|
|
44
54
|
end
|
45
55
|
|
46
56
|
Asciidoctor::Extensions.register do
|
47
|
-
|
57
|
+
tree_processor JsonValueLoaderFilePathTreeProcessor
|
58
|
+
inline_macro JsonValueLoaderInlineMacro
|
48
59
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: asciidoctor-json-value-loader
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- msr1k
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-08-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: asciidoctor
|