asciidoctor-json-value-loader 0.2.0 → 0.2.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c1a49b45f4f5a1c0f95adb31f68d3869aced151c1f67be786cd0202384db8ae7
4
- data.tar.gz: c4d25c91934d260e13e95d1db516128f27f6555fc203b8cee8f270b3eb0e8905
3
+ metadata.gz: 4b86d0a1e7e4af629f5c1dc606436e5d90e46e4cd127f58bdab01302449ca8cc
4
+ data.tar.gz: 6cf0cd4337d4ac231b8572e6e9fccd5e9ef1328b2fef6533a501de287e3aa497
5
5
  SHA512:
6
- metadata.gz: 294a447855a7a7b5b2a0a8f418caf6263eccbe2fd394bc2cc24c3c2534ace4b193b6492b6691081c438362ee37a5e2df9e0c903c4eee9b9fd97ed8734fc2e40e
7
- data.tar.gz: 243db55aada57b92ed394ef7db42161766a12ede32ce76bd305956ea5392956b2d0427552d45b0ae6acc89c5be8e0dd29f2d20bbd4290e79d2f26a9cd5030b24
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 JsonValueLoadInlineMacro < Asciidoctor::Extensions::InlineMacroProcessor
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
- json = JSON.parse(File.open(path, 'r:utf-8', &:read))
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
- inline_macro JsonValueLoadInlineMacro
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.0
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-07-16 00:00:00.000000000 Z
11
+ date: 2024-08-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: asciidoctor