asciidoctor-json-value-loader 0.1.2 → 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 +19 -6
- metadata +4 -3
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,19 +2,30 @@ 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
|
9
16
|
|
10
17
|
named "json-value"
|
11
|
-
name_positional_attributes '
|
18
|
+
name_positional_attributes 'delimitter'
|
19
|
+
default_attrs 'delimiter' => '/'
|
12
20
|
|
13
21
|
def process parent, target, attrs
|
14
22
|
|
15
|
-
path, query = target.split(':')
|
23
|
+
path, query = target.split(':', 2)
|
24
|
+
delimiter = attrs['delimiter']
|
25
|
+
|
26
|
+
dir = File.dirname(parent.document.attr('json-value-loader-target-file'))
|
16
27
|
|
17
|
-
query = query.split(
|
28
|
+
query = query.split(delimiter).map do |q|
|
18
29
|
decoded = URI.decode_www_form_component(q)
|
19
30
|
if decoded.match(/^\d+$/) then
|
20
31
|
decoded.to_i
|
@@ -23,7 +34,8 @@ class JsonValueLoadInlineMacro < Asciidoctor::Extensions::InlineMacroProcessor
|
|
23
34
|
end
|
24
35
|
end
|
25
36
|
|
26
|
-
|
37
|
+
filepath = File.join(dir, path)
|
38
|
+
json = JSON.parse(File.open(File.join(dir, path), 'r:utf-8', &:read))
|
27
39
|
|
28
40
|
content = json.dig(*query)
|
29
41
|
parent.logger.warn "json-value-loader: #{target} has no value." if content.nil?
|
@@ -42,5 +54,6 @@ class JsonValueLoadInlineMacro < Asciidoctor::Extensions::InlineMacroProcessor
|
|
42
54
|
end
|
43
55
|
|
44
56
|
Asciidoctor::Extensions.register do
|
45
|
-
|
57
|
+
tree_processor JsonValueLoaderFilePathTreeProcessor
|
58
|
+
inline_macro JsonValueLoaderInlineMacro
|
46
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.1
|
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
|
@@ -25,7 +25,8 @@ dependencies:
|
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
27
|
description: |
|
28
|
-
Adds asciidoctor a
|
28
|
+
Adds asciidoctor a funciton to load specific JSON value from JSON file
|
29
|
+
|
29
30
|
(See: https://github.com/msr1k/asciidoctor-json-value-loader)
|
30
31
|
email: msr0210@gmail.com
|
31
32
|
executables: []
|