asciidoctor-yaml-value-loader 0.1.0
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 +7 -0
- data/lib/asciidoctor-yaml-value-loader.rb +61 -0
- metadata +60 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 69458be92ae0bfb03cb4a80c70430e2bbff050308251c1221d22afa1e62f6cbf
|
|
4
|
+
data.tar.gz: d7ed2a1d6a03c0bf57bd4916578ac77793df83d434b8d2c0fb015abe854d025f
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 63fba5036868bce46084d834e1ef1b65a8ce72d68619c3c8e231dbad483bf1acd5ef29885b8a31554382e9ac2aa917d2a6b187dfb7fa1b8a619bceeaaa359149
|
|
7
|
+
data.tar.gz: 52a178d594d1c6ea393d93e2fd28937465c37a62e7decf96cd106cad8e9b51d2fbfdf1ff4d9714b141b1a92b2e894ccbef58b9f61d644fa19055f328d1f48966
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
require 'asciidoctor'
|
|
2
|
+
require 'yaml'
|
|
3
|
+
require 'uri'
|
|
4
|
+
|
|
5
|
+
class YamlValueLoaderFilePathTreeProcessor < Asciidoctor::Extensions::TreeProcessor
|
|
6
|
+
def process(document)
|
|
7
|
+
document.set_attr('yaml-value-loader-target-file', document.attr('docfile'))
|
|
8
|
+
end
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class YamlValueLoaderInlineMacro < Asciidoctor::Extensions::InlineMacroProcessor
|
|
13
|
+
include Asciidoctor::Logging
|
|
14
|
+
|
|
15
|
+
use_dsl
|
|
16
|
+
|
|
17
|
+
named "yaml-value"
|
|
18
|
+
name_positional_attributes 'delimitter'
|
|
19
|
+
default_attrs 'delimiter' => '/'
|
|
20
|
+
|
|
21
|
+
def process parent, target, attrs
|
|
22
|
+
|
|
23
|
+
path, query = target.split(':', 2)
|
|
24
|
+
delimiter = attrs['delimiter']
|
|
25
|
+
|
|
26
|
+
dir = File.dirname(parent.document.attr('yaml-value-loader-target-file'))
|
|
27
|
+
|
|
28
|
+
query = query.split(delimiter).map do |q|
|
|
29
|
+
decoded = URI.decode_www_form_component(q)
|
|
30
|
+
if decoded.match(/^\d+$/) then
|
|
31
|
+
decoded.to_i
|
|
32
|
+
else
|
|
33
|
+
decoded
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
filepath = File.join(dir, path)
|
|
38
|
+
yaml = YAML.load(File.open(File.join(dir, path), 'r:utf-8', &:read))
|
|
39
|
+
|
|
40
|
+
p yaml
|
|
41
|
+
|
|
42
|
+
content = yaml.dig(*query)
|
|
43
|
+
parent.logger.warn "yaml-value-loader: #{target} has no value." if content.nil?
|
|
44
|
+
|
|
45
|
+
content = case content
|
|
46
|
+
when String
|
|
47
|
+
content
|
|
48
|
+
when Numeric
|
|
49
|
+
content.to_s
|
|
50
|
+
else
|
|
51
|
+
YAML.dump(content)
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
create_inline_pass parent, content, attributes: { 'subs' => :normal }
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
Asciidoctor::Extensions.register do
|
|
59
|
+
tree_processor YamlValueLoaderFilePathTreeProcessor
|
|
60
|
+
inline_macro YamlValueLoaderInlineMacro
|
|
61
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: asciidoctor-yaml-value-loader
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- msr1k
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2025-12-25 00:00:00.000000000 Z
|
|
12
|
+
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: asciidoctor
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - ">="
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: '0'
|
|
20
|
+
type: :runtime
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - ">="
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: '0'
|
|
27
|
+
description: |
|
|
28
|
+
Adds asciidoctor a funciton to load specific YAML value from YAML file
|
|
29
|
+
|
|
30
|
+
(See: https://github.com/msr1k/asciidoctor-yaml-value-loader)
|
|
31
|
+
email: msr0210@gmail.com
|
|
32
|
+
executables: []
|
|
33
|
+
extensions: []
|
|
34
|
+
extra_rdoc_files: []
|
|
35
|
+
files:
|
|
36
|
+
- lib/asciidoctor-yaml-value-loader.rb
|
|
37
|
+
homepage: https://github.com/msr1k/asciidoctor-yaml-value-loader
|
|
38
|
+
licenses:
|
|
39
|
+
- MIT
|
|
40
|
+
metadata: {}
|
|
41
|
+
post_install_message:
|
|
42
|
+
rdoc_options: []
|
|
43
|
+
require_paths:
|
|
44
|
+
- lib
|
|
45
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
46
|
+
requirements:
|
|
47
|
+
- - ">="
|
|
48
|
+
- !ruby/object:Gem::Version
|
|
49
|
+
version: '0'
|
|
50
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
51
|
+
requirements:
|
|
52
|
+
- - ">="
|
|
53
|
+
- !ruby/object:Gem::Version
|
|
54
|
+
version: '0'
|
|
55
|
+
requirements: []
|
|
56
|
+
rubygems_version: 3.5.22
|
|
57
|
+
signing_key:
|
|
58
|
+
specification_version: 4
|
|
59
|
+
summary: An asciidoctor extention to load specific YAML value.
|
|
60
|
+
test_files: []
|