asciidoctor-github-include 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/asciidoctor-github-include.rb +75 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a4d2ffec52b3127a3d790aa4d774b63c52da5a0e
|
4
|
+
data.tar.gz: 7014707480dd04c00ee818bee2811eb11ba6c0aa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1812c41bea943e09d963de7f4e6d802d1edc9845b4d6e2167e939db31fa443c27f23a17afae5cef7feaa6af15bc929548d3e301c68a2f59e3f1cabbe496be0ce
|
7
|
+
data.tar.gz: '0964b2877ce6fc1f5505846dfb4edc6440dcbdbb6fffb36afe9d4a0e12ce1cba7b37ded7313c33d3e586807c4e64d4b16767c0df0b921137737f991ae6f10cf2'
|
@@ -9,6 +9,15 @@ class GithubPrivateUriIncludeProcessor < Extensions::IncludeProcessor
|
|
9
9
|
end
|
10
10
|
|
11
11
|
def process doc, reader, target, attributes
|
12
|
+
|
13
|
+
tags = [attributes["tag"]] if attributes.key? "tag" unless attributes["tag"] == ""
|
14
|
+
tags = attributes["tags"].split(DataDelimiterRx) if attributes.key? "tags" unless attributes["tags"] == ""
|
15
|
+
lines = attributes["lines"] unless attributes["lines"] == ""
|
16
|
+
if lines && tags
|
17
|
+
warn %(asciidoctor: WARNING: Tag selection #{tags} in #{target} was ignored because line selection was specified.)
|
18
|
+
end
|
19
|
+
|
20
|
+
# Fetch the file to be included
|
12
21
|
begin
|
13
22
|
doc.attr('github-access-token').nil? ?
|
14
23
|
content = (open target).readlines :
|
@@ -16,13 +25,78 @@ class GithubPrivateUriIncludeProcessor < Extensions::IncludeProcessor
|
|
16
25
|
rescue
|
17
26
|
warn %(asciidoctor: WARNING: Failed to retrieve GitHub URI #{target}. Did you set :github-access-token:?)
|
18
27
|
content = "WARNING: Failed to retrieve GitHub URI link:#{target}[]"
|
28
|
+
return reader.push_include content, target, target, 1, attributes
|
19
29
|
end
|
30
|
+
|
31
|
+
# process the lines and tags attributes
|
32
|
+
content = process_line_selection(content, lines, target) if lines
|
33
|
+
content = process_tags(content, tags, target) if tags unless lines
|
34
|
+
|
35
|
+
# push the lines onto the reader and return it
|
20
36
|
reader.push_include content, target, target, 1, attributes
|
21
37
|
reader
|
22
38
|
end
|
39
|
+
|
40
|
+
# We need to process tags. This is a very naïve implementation to start with, and
|
41
|
+
# only supports the case where there is exactly one opening and closing instance
|
42
|
+
# of the tag in the file.
|
43
|
+
#
|
44
|
+
# text - the text to be processed, as an array of lines
|
45
|
+
# tags - an array of tags to get
|
46
|
+
# target - the URI of the object being fetched (only used to check the extension)
|
47
|
+
def process_tags text, tags, target
|
48
|
+
snipped_content = []
|
49
|
+
|
50
|
+
# Asciidoctor provides a map of (file extension) => (opening and closing tags for
|
51
|
+
# the file's circumfix comments). Use it to check for this case and get the right
|
52
|
+
# suffix if needed.
|
53
|
+
target_extension = target.slice (target.rindex '.'), target.length
|
54
|
+
if (circ_cmt = CIRCUMFIX_COMMENTS[target_extension])
|
55
|
+
circumfix_suffix = circ_cmt[:suffix]
|
56
|
+
end
|
57
|
+
|
58
|
+
tags.each do |tag|
|
59
|
+
if circumfix_suffix
|
60
|
+
tag_open = text.index{|line| line.chomp.end_with? %(tag::#{tag}[] #{circumfix_suffix})}
|
61
|
+
tag_close = text.index{|line| line.chomp.end_with? %(end::#{tag}[] #{circumfix_suffix})}
|
62
|
+
else
|
63
|
+
tag_open = text.index{|line| line.chomp.end_with? %(tag::#{tag}[])}
|
64
|
+
tag_close = text.index{|line| line.chomp.end_with? %(end::#{tag}[])}
|
65
|
+
end
|
66
|
+
if (!tag_open && !tag_close)
|
67
|
+
warn %(asciidoctor: WARNING: Tag #{tag} not found in included GitHub URI #{target}.)
|
68
|
+
elsif (!tag_open && tag_close)
|
69
|
+
warn %(asciidoctor: WARNING: Tag #{tag} not found in included GitHub URI #{target}, but end::[] tag was found.)
|
70
|
+
elsif (tag_open && !tag_close)
|
71
|
+
warn %(asciidoctor: WARNING: Closing tag for tag #{tag} not found in included GitHub URI #{target}.)
|
72
|
+
end
|
73
|
+
|
74
|
+
snipped_content += text[tag_open+1..tag_close-1] unless (!tag_open || !tag_close)
|
75
|
+
end
|
76
|
+
snipped_content
|
77
|
+
end
|
78
|
+
|
79
|
+
def process_line_selection text, lines, target
|
80
|
+
snipped_content = []
|
81
|
+
selected_lines = []
|
82
|
+
|
83
|
+
lines.split(DataDelimiterRx).each do |linedef|
|
84
|
+
if linedef.include?('..')
|
85
|
+
from, to = linedef.split('..', 2).map {|it| it.to_i }
|
86
|
+
to = text.length if to == -1 # -1 as a closing length means end of file
|
87
|
+
selected_lines.concat ::Range.new(from, to).to_a
|
88
|
+
else
|
89
|
+
selected_lines << linedef.to_i
|
90
|
+
end
|
91
|
+
end
|
92
|
+
selected_lines.sort.uniq.each do |i|
|
93
|
+
snipped_content << text[i-1]
|
94
|
+
end
|
95
|
+
snipped_content
|
96
|
+
end
|
97
|
+
|
23
98
|
end
|
24
99
|
|
25
100
|
Extensions.register do
|
26
101
|
include_processor GithubPrivateUriIncludeProcessor
|
27
102
|
end
|
28
|
-
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: asciidoctor-github-include
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jon Oster
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-11-
|
11
|
+
date: 2017-11-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: asciidoctor
|