aspec_rb 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +3 -0
- data/.rubocop.yml +3 -0
- data/.travis.yml +5 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +26 -0
- data/README.md +40 -0
- data/Rakefile +13 -0
- data/aspec_rb.gemspec +34 -0
- data/bin/console +8 -0
- data/bin/setup +8 -0
- data/lib/aspec_rb/version.rb +6 -0
- data/lib/aspec_rb.rb +14 -0
- data/lib/extensions/autoxrefs.rb +183 -0
- data/lib/extensions/definition_block.rb +49 -0
- data/lib/extensions/inline_callout_macro.rb +14 -0
- data/lib/extensions/inline_cwiki_macro.rb +31 -0
- data/lib/extensions/inline_repo_macro.rb +96 -0
- data/lib/extensions/inline_task_macro.rb +47 -0
- data/lib/extensions/postprocessor.rb +18 -0
- data/lib/extensions/req_refs.rb +191 -0
- data/lib/extensions/requirement_appendix.rb +108 -0
- data/lib/extensions/requirement_block.rb +50 -0
- data/lib/extensions/todo_block.rb +16 -0
- data/lib/extensions/utils/block.rb +36 -0
- data/lib/extensions/utils/labels.rb +18 -0
- data/lib/extensions/utils/scanner.rb +20 -0
- data/lib/html_chunker.rb +107 -0
- data/lib/postprocessors/fulltext_search.rb +48 -0
- data/lib/postprocessors/generate_toc.rb +104 -0
- metadata +133 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 741aaa4767d93c78ccd621de29c2190284e0d457
|
4
|
+
data.tar.gz: 93a60ac6decd924abb523f2c18ed2f204094b6d9
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: f2901681e83dc0898d7fb8906aec1b8a4487960f5a6eeaf60b838eb1e2b9a25913b1def89179ba5b54630f4037f679b9da16c586fdd76760296aca2308af6c6e
|
7
|
+
data.tar.gz: 3f350489c1ad995e031c9f64a596cd552ecc6960961e7e9da6f787f749d566cd3a11b1d1b7a7d2158a5988dbe0db67bb0e83e513dd5e3eb6b3a707cf096e2a6b
|
data/.gitignore
ADDED
data/.rubocop.yml
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
aspec_rb (0.0.1)
|
5
|
+
asciidoctor (>= 1.5.0)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
asciidoctor (1.5.6.1)
|
11
|
+
power_assert (1.1.1)
|
12
|
+
rake (12.3.0)
|
13
|
+
test-unit (3.2.7)
|
14
|
+
power_assert
|
15
|
+
|
16
|
+
PLATFORMS
|
17
|
+
ruby
|
18
|
+
|
19
|
+
DEPENDENCIES
|
20
|
+
aspec_rb!
|
21
|
+
bundler (>= 1.15.4)
|
22
|
+
rake (>= 12.1.0)
|
23
|
+
test-unit (>= 3.2.6)
|
24
|
+
|
25
|
+
BUNDLED WITH
|
26
|
+
1.16.0
|
data/README.md
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
# aspec_rb
|
2
|
+
|
3
|
+
[![Build Status](https://travis-ci.org/bsmith-n4/aspec_rb.svg?branch=master)](https://travis-ci.org/bsmith-n4/aspec_rb)
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
```
|
8
|
+
gem install aspec_rb
|
9
|
+
```
|
10
|
+
|
11
|
+
## Usage
|
12
|
+
|
13
|
+
```
|
14
|
+
asciidoctor -r aspec_rb index.adoc
|
15
|
+
```
|
16
|
+
|
17
|
+
## Development
|
18
|
+
|
19
|
+
To build a local copy of the gem to the `pkg` directory:
|
20
|
+
|
21
|
+
```
|
22
|
+
rake build
|
23
|
+
```
|
24
|
+
|
25
|
+
To install from a local build:
|
26
|
+
|
27
|
+
```
|
28
|
+
gem install pkg/aspec_rb<version>.gem
|
29
|
+
```
|
30
|
+
|
31
|
+
To release a new version, edit the version number in `lib/aspec_rb/version.rb`, run bundle install to regenerate the `Gemfile.lock`.
|
32
|
+
To release this version, use `rake release` command, providing all has been committed. This command builds the gem to the pkg directory in preparation for a push to Rubygems.org.
|
33
|
+
|
34
|
+
### Testing
|
35
|
+
|
36
|
+
Tests can be run using rake:
|
37
|
+
|
38
|
+
```
|
39
|
+
rake test
|
40
|
+
```
|
data/Rakefile
ADDED
data/aspec_rb.gemspec
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'aspec_rb/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'aspec_rb'
|
8
|
+
spec.version = AspecRb::VERSION
|
9
|
+
spec.authors = ['bsmith-n4']
|
10
|
+
spec.email = ['brian.smith@numberfour.eu']
|
11
|
+
|
12
|
+
spec.summary = 'Asciidoctor extensions for use as a Jekyll plugin'
|
13
|
+
spec.description = 'This plugin is a group of Asciidoctor extensions that perform directory walking,
|
14
|
+
resolving the location of titles and anchors in all adoc files so that inter-document
|
15
|
+
cross-references in a Jekyll project are resolved automatically. Also included are some
|
16
|
+
custom macros and blocks that are useful for techinical writing.'
|
17
|
+
spec.homepage = 'https://github.com/bsmith-n4/aspec_rb'
|
18
|
+
spec.license = 'MIT'
|
19
|
+
|
20
|
+
# This gem will work with 2.0 or greater.
|
21
|
+
spec.required_ruby_version = '>= 2.0'
|
22
|
+
|
23
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
24
|
+
f.match(%r{^(test|spec|features)/})
|
25
|
+
end
|
26
|
+
spec.bindir = 'exe'
|
27
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
28
|
+
spec.require_paths = ['lib']
|
29
|
+
|
30
|
+
spec.add_development_dependency 'bundler', '>= 1.15.4'
|
31
|
+
spec.add_development_dependency 'rake', '>= 12.1.0'
|
32
|
+
spec.add_development_dependency 'test-unit', '>=3.2.6'
|
33
|
+
spec.add_runtime_dependency 'asciidoctor', '>= 1.5.0'
|
34
|
+
end
|
data/bin/console
ADDED
data/bin/setup
ADDED
data/lib/aspec_rb.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
require_relative 'extensions/autoxrefs'
|
2
|
+
require_relative 'extensions/definition_block'
|
3
|
+
require_relative 'extensions/inline_callout_macro'
|
4
|
+
require_relative 'extensions/inline_cwiki_macro'
|
5
|
+
require_relative 'extensions/inline_repo_macro'
|
6
|
+
require_relative 'extensions/inline_task_macro'
|
7
|
+
require_relative 'extensions/req_refs'
|
8
|
+
require_relative 'extensions/requirement_block'
|
9
|
+
require_relative 'extensions/todo_block'
|
10
|
+
require_relative 'html_chunker'
|
11
|
+
require 'asciidoctor-latex'
|
12
|
+
require 'asciidoctor-bibtex'
|
13
|
+
require_relative 'extensions/requirement_appendix'
|
14
|
+
require_relative 'extensions/postprocessor'
|
@@ -0,0 +1,183 @@
|
|
1
|
+
require 'asciidoctor/extensions'
|
2
|
+
require_relative 'utils/scanner'
|
3
|
+
|
4
|
+
include ::Asciidoctor
|
5
|
+
|
6
|
+
# Read from config file - do NOT hard code the srcdir
|
7
|
+
$srcdir = 'chapters'
|
8
|
+
invoc = Dir.pwd
|
9
|
+
|
10
|
+
AnchorRx = /\[\[(?:|([\w+?_:][\w+?:.-]*)(?:, *(.+))?)\]\]/
|
11
|
+
|
12
|
+
indexincludes, ni_includes, includes, doclinks, anchorfixes, intrachapter, interchapter, anchors, xrefs = Array.new(10) { [] }
|
13
|
+
|
14
|
+
adoc_files = Dir.glob("#{$srcdir}/**/*.adoc")
|
15
|
+
|
16
|
+
# From the index, create an array of the main chapters
|
17
|
+
File.read('index.adoc').each_line do |li|
|
18
|
+
if li[IncludeDirectiveRx]
|
19
|
+
doc = li.match(/(?<=^include::).+?\.adoc(?=\[\])/).to_s
|
20
|
+
doc = doc.sub(/^\{find\}/, '')
|
21
|
+
indexincludes.push(doc) unless doc == 'config'
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
adoc_files.each do |filename|
|
26
|
+
main = false
|
27
|
+
path = Sform.trim(filename)
|
28
|
+
chapter = path.match(/.+?(?=\/)/).to_s
|
29
|
+
|
30
|
+
# Add a switch if the current document is an include within the index.adoc
|
31
|
+
indexincludes.each do |inc|
|
32
|
+
main = true if inc == filename
|
33
|
+
end
|
34
|
+
|
35
|
+
File.read(filename).each_line do |li|
|
36
|
+
h1 = false
|
37
|
+
|
38
|
+
if li[/\<\<(?!Req)(.+?)\>\>/]
|
39
|
+
# Handle multiple cross refs per line
|
40
|
+
li.scan(/(?=\<\<(?!Req)(.+?)\>\>)/) do |xref|
|
41
|
+
text = ''
|
42
|
+
target = ''
|
43
|
+
xref = xref[0].to_s
|
44
|
+
target = xref.gsub(/\s/, '-')
|
45
|
+
|
46
|
+
if xref[/,/]
|
47
|
+
target = xref.gsub(/,.+/, '')
|
48
|
+
text = xref.gsub(/.+,/, '').lstrip
|
49
|
+
xref = xref.sub(/,.+/, '')
|
50
|
+
else
|
51
|
+
text = Sform.titleify(xref).strip
|
52
|
+
end
|
53
|
+
xrefs.push([xref, path, filename, text, target, chapter])
|
54
|
+
end
|
55
|
+
|
56
|
+
elsif li[/^(\=+\s+?\S+.+)/]
|
57
|
+
h1 = true if li[/^=\s+?\S+.+/]
|
58
|
+
title = li.chop.match(/(?!=+\s)(\S+.+?)$/i).captures[0].strip
|
59
|
+
title.sub!(/\.(?=\w+?)/, '') if title[/\.(?=\w+?)/]
|
60
|
+
link = Sform.underscorify(title)
|
61
|
+
anchors.push([title, path, filename, link, chapter, main, h1])
|
62
|
+
|
63
|
+
# Handle images separately
|
64
|
+
elsif li[/^(\.\S\w+)/]
|
65
|
+
title = li.chop.match(/(?!=+\s)(\S+.+?)$/i).captures[0].strip
|
66
|
+
title.sub!(/\.(?=\w+?)/, '') if title[/\.(?=\w+?)/]
|
67
|
+
anchors.push([title, path, filename, title, chapter, main, h1])
|
68
|
+
|
69
|
+
elsif li[/\[\[(?:|([\w+?_:][\w+?:.-]*)(?:, *(.+))?)\]\]/]
|
70
|
+
anchor = li.chop.match(/(?<=\[\[).+?(?=\]\])/).to_s
|
71
|
+
|
72
|
+
if anchor[/,/]
|
73
|
+
anchor = anchor.match(/(?<=\[\[)(?:|[\w+?_:][\w+?:.-]*)(?=,.+?\]\])/).to_s
|
74
|
+
text = anchor.sub(/.+?,/, '')
|
75
|
+
text = text.sub(/\]\]$/, '')
|
76
|
+
else
|
77
|
+
text = anchor
|
78
|
+
end
|
79
|
+
|
80
|
+
anchors.push([anchor, path, filename, text, chapter, main, h1, true])
|
81
|
+
|
82
|
+
# Match for sub includes
|
83
|
+
elsif li[IncludeDirectiveRx]
|
84
|
+
child = li.match(/(?<=^include::).+?\.adoc(?=\[\])/).to_s
|
85
|
+
child = child.sub(/^\{find\}/, '')
|
86
|
+
childpath = "#{filename.sub(/[^\/]+?\.adoc/, '')}#{child}"
|
87
|
+
includes.push([filename, child, childpath])
|
88
|
+
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
# Create array of non-indexed includes
|
94
|
+
adoc_files.each do |filename|
|
95
|
+
includes.each do |parent, child, childpath|
|
96
|
+
next unless childpath == filename
|
97
|
+
ni_includes.push([parent, child, filename])
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
# For each main include, store a target link
|
102
|
+
anchors.each do |_anchor, full, _filename, link, chapter, main, h1|
|
103
|
+
next unless main && h1
|
104
|
+
doc = full.gsub(/^#{chapter}\//, '')
|
105
|
+
doclinks.push([doc, link, chapter])
|
106
|
+
end
|
107
|
+
|
108
|
+
# If a section title has an overriding anchor on the previous line, perform the following fix
|
109
|
+
o_anchors = []
|
110
|
+
doclinks.delete_if do |doc, _link, mchapter|
|
111
|
+
topleveldoc = "#{$srcdir}/#{mchapter}/#{doc}.adoc"
|
112
|
+
lines = File.foreach(topleveldoc).first(10).join
|
113
|
+
next unless lines[/(?x)\[\[.+?\]\]\n=\s{1,}.+$/]
|
114
|
+
overriding_anchor = lines.match(/(?x)\[\[(.+?)\]\]\n=\s{1,}.+$/).captures[0].to_s
|
115
|
+
o_anchors.push([doc, overriding_anchor, mchapter])
|
116
|
+
true
|
117
|
+
end
|
118
|
+
|
119
|
+
doclinks += o_anchors
|
120
|
+
doclinks.uniq!
|
121
|
+
|
122
|
+
# Edit the array of Anchors to point to the parent document *if* it is included.
|
123
|
+
# TODO use a while loop, repeat until no changes made
|
124
|
+
tempanchors = []
|
125
|
+
3.times do
|
126
|
+
tempanchors.clear
|
127
|
+
|
128
|
+
# Loop through all includes, if the anchor is contained in an include,
|
129
|
+
# edit the anchors array to point to its parent instead
|
130
|
+
includes.each do |parent, _child, childpath|
|
131
|
+
anchors.delete_if do |anchor, path, filename, text, chapter, main, _h1|
|
132
|
+
next unless Sform.trim(childpath) == Sform.trim(filename)
|
133
|
+
tempanchors.push([anchor, path, Sform.trim(parent), text, chapter, main])
|
134
|
+
true
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
138
|
+
anchors += tempanchors
|
139
|
+
anchors.uniq!
|
140
|
+
end
|
141
|
+
|
142
|
+
tempanchors.clear
|
143
|
+
|
144
|
+
anchors.delete_if do |anchor, apath, trim_parent, parent, amain, achapter|
|
145
|
+
doclinks.each do |doc, link, dchapter|
|
146
|
+
next unless apath == "#{dchapter}/#{doc}" || trim_parent == "#{dchapter}/#{doc}"
|
147
|
+
tempanchors.push([anchor, apath, link, parent, amain, achapter])
|
148
|
+
true
|
149
|
+
end
|
150
|
+
end
|
151
|
+
|
152
|
+
anchors += tempanchors
|
153
|
+
anchors.uniq!
|
154
|
+
|
155
|
+
# For all requirements, check which chapter they should finally be in with includes catered for
|
156
|
+
# match with a main document name - should be a main chapter title
|
157
|
+
xrefs.each do |xref, xpath, _xfilename, xtext, _xtarget, _xchapter|
|
158
|
+
anchors.each do |anchor, apath, afilename, atext, _achapter, _amain, _h1|
|
159
|
+
next unless xref == anchor
|
160
|
+
# if in same chapter, dont link to other HTML file
|
161
|
+
afilename = '' if xpath == apath
|
162
|
+
xtext = Sform.titleify(xref) if xtext.empty?
|
163
|
+
afilename.sub!(/^_/, '') if afilename[/^_/]
|
164
|
+
fix = "#{afilename}##{atext},#{xtext}"
|
165
|
+
anchorfixes.push([anchor, fix, xref])
|
166
|
+
end
|
167
|
+
end
|
168
|
+
|
169
|
+
Extensions.register do
|
170
|
+
preprocessor do
|
171
|
+
process do |_document, reader|
|
172
|
+
Reader.new reader.readlines.map { |line|
|
173
|
+
if line[/\<\<(?!Req)(.+?)\>\>/]
|
174
|
+
anchorfixes.each do |original, fix|
|
175
|
+
next unless line[/\<\<#{original}(,.+?)?\>\>/]
|
176
|
+
line = line.sub(/\<\<#{original}(,.+?)?\>\>/, "icon:angle-double-up[] <<#{fix}>>")
|
177
|
+
end
|
178
|
+
end
|
179
|
+
line
|
180
|
+
}
|
181
|
+
end
|
182
|
+
end
|
183
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require 'asciidoctor/extensions' unless RUBY_ENGINE == 'opal'
|
2
|
+
|
3
|
+
include ::Asciidoctor
|
4
|
+
|
5
|
+
Extensions.register do
|
6
|
+
block do
|
7
|
+
named :def
|
8
|
+
on_contexts :open, :paragraph, :example, :listing, :sidebar, :pass
|
9
|
+
|
10
|
+
process do |parent, reader, attrs|
|
11
|
+
# Add pass characters here to prevent html character replacements for < > tags
|
12
|
+
pass = '+++'
|
13
|
+
attrs['name'] = 'definition'
|
14
|
+
attrs['caption'] = 'Definition: '
|
15
|
+
nl = ''
|
16
|
+
|
17
|
+
begin
|
18
|
+
# downcase the title and replace spaces with underscores.
|
19
|
+
# Also replacing special HTML entities:
|
20
|
+
# " = "
|
21
|
+
# & = &
|
22
|
+
downcased_title = attrs['title'].downcase.tr(' ', '_').gsub('"', '"')
|
23
|
+
san_title = attrs['title'].gsub(/&/, '&').delete('`').delete("'").delete('*')
|
24
|
+
rescue Exception => msg
|
25
|
+
puts msg
|
26
|
+
# If no title exists on the Def block, throw an exception
|
27
|
+
puts '[ERROR] Definition block title missing'
|
28
|
+
end
|
29
|
+
|
30
|
+
alt = %(
|
31
|
+
<div class=\"panel panel-primary\">
|
32
|
+
<div class=\"panel-heading\">
|
33
|
+
<h3 class=\"panel-title\">
|
34
|
+
<a class=\"anchor\" href=\"##{san_title}\"></a>
|
35
|
+
<a class=\"link\" href=\"##{san_title}\"><emphasis role=\"strong\">Definition: </emphasis> #{san_title} </a>
|
36
|
+
</h3>
|
37
|
+
</div>
|
38
|
+
<div class=\"panel-body\">)
|
39
|
+
|
40
|
+
close = '</div></div>'
|
41
|
+
|
42
|
+
# concatenate all generated lines and prepend before the original content
|
43
|
+
concat_lines = reader.lines.unshift(pass, alt, pass, nl)
|
44
|
+
concat_lines.push(nl, pass, close, pass)
|
45
|
+
|
46
|
+
create_block parent, :open, concat_lines, attrs, content_model: :compound
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'asciidoctor/extensions'
|
2
|
+
|
3
|
+
include ::Asciidoctor
|
4
|
+
|
5
|
+
# @example Basic Usage
|
6
|
+
# See call:1[] for details
|
7
|
+
Asciidoctor::Extensions.register do
|
8
|
+
inline_macro do
|
9
|
+
named :call
|
10
|
+
process do |parent, target, _attrs|
|
11
|
+
Asciidoctor::Inline.new(parent, :callout, target.to_i).convert
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'asciidoctor/extensions' unless RUBY_ENGINE == 'opal'
|
2
|
+
require_relative 'utils/labels'
|
3
|
+
require_relative 'utils/block'
|
4
|
+
|
5
|
+
include ::Asciidoctor
|
6
|
+
|
7
|
+
# @example Basic Usage
|
8
|
+
# See cwiki:topic[] for details
|
9
|
+
# @example Block Use
|
10
|
+
# Already documented. cwiki::topic[]
|
11
|
+
Extensions.register do
|
12
|
+
inline_macro do
|
13
|
+
named :cwiki
|
14
|
+
|
15
|
+
process do |parent, target, attrs|
|
16
|
+
pattern = parent.document.attr 'cwiki-pattern'
|
17
|
+
|
18
|
+
if pattern.nil?
|
19
|
+
warn "asciidoctor: WARNING: Attribue 'cwiki-pattern' for inline repo macro not defined"
|
20
|
+
pattern = 'unknown'
|
21
|
+
label = 'warning'
|
22
|
+
target = 'cwiki-pattern missing'
|
23
|
+
else
|
24
|
+
label = Labels.getstatus(attrs)
|
25
|
+
end
|
26
|
+
|
27
|
+
html = Context.format(attrs, target, pattern, label)
|
28
|
+
(create_pass_block parent, html, attrs).render
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,96 @@
|
|
1
|
+
require 'asciidoctor/extensions' unless RUBY_ENGINE == 'opal'
|
2
|
+
|
3
|
+
include ::Asciidoctor
|
4
|
+
|
5
|
+
# Link to a file on GitHub.
|
6
|
+
#
|
7
|
+
# repo:<repository>:<file>:<line>[]
|
8
|
+
#
|
9
|
+
# The target should be set using document attributes prefixed by 'repo_'.
|
10
|
+
#
|
11
|
+
# @example Attribute configuration
|
12
|
+
# :repo_dockerfiles: www.github.com/exampleuser/dockerfiles/issues
|
13
|
+
# @example Simple Use
|
14
|
+
# repo:dockerfiles:ansible/Dockerfile_template[]
|
15
|
+
# @example Link to repo and line number
|
16
|
+
# repo:dockerfiles:ansible/Dockerfile_template:2[]
|
17
|
+
# @example Link to repo, branch and line number
|
18
|
+
# repo:dockerfiles:ansible/Dockerfile_template:5[branch="AS_v0.0.10"]
|
19
|
+
# @example Link to repo and line number (alternate use)
|
20
|
+
# repo:dockerfiles:ansible/Dockerfile_template[line="5",branch="AS_v0.0.10"]
|
21
|
+
Extensions.register do
|
22
|
+
inline_macro do
|
23
|
+
named :repo
|
24
|
+
|
25
|
+
process do |parent, target, attrs|
|
26
|
+
html = ''
|
27
|
+
url = ''
|
28
|
+
file = ''
|
29
|
+
line = ''
|
30
|
+
formattedurl = ''
|
31
|
+
text = ''
|
32
|
+
arr = []
|
33
|
+
|
34
|
+
# @todo fix handling of use within cells. This is done using the context.
|
35
|
+
|
36
|
+
if parent.context.to_s == 'cell'
|
37
|
+
warn %([Hell in a cell] cell with repo link must have 'asciidoc format')
|
38
|
+
end
|
39
|
+
|
40
|
+
repo = target.match(/^.+?(?=:)/).to_s
|
41
|
+
file = target.match(/(?<=:).+/).to_s
|
42
|
+
|
43
|
+
text = file
|
44
|
+
text = file.gsub(%r{/.+\//}, '') if file[%r{/\//}]
|
45
|
+
|
46
|
+
if target[/(?<=:)\d+$/]
|
47
|
+
line = "#L#{target.match(/(?<=:)\d+?$/)}"
|
48
|
+
file = file.sub(/:\d+$/, '')
|
49
|
+
elsif attrs['line']
|
50
|
+
line = "#L#{attrs['line']}"
|
51
|
+
else
|
52
|
+
line = ''
|
53
|
+
end
|
54
|
+
|
55
|
+
if attrs['branch']
|
56
|
+
branch = "tree/#{attrs['branch']}"
|
57
|
+
text = "#{text} (#{branch})"
|
58
|
+
label = 'warning'
|
59
|
+
else
|
60
|
+
branch = 'blob/master'
|
61
|
+
label = 'info'
|
62
|
+
end
|
63
|
+
|
64
|
+
text = attrs['title'].to_s if attrs['title']
|
65
|
+
text.gsub!(/:(?=\d+$)/, ' line ') if text[/(?<=:)\d+$/]
|
66
|
+
|
67
|
+
parent.document.attributes.each do |key, value|
|
68
|
+
next unless key[/^repo_/]
|
69
|
+
pattern = key.sub(/^repo_/, '')
|
70
|
+
arr.push(pattern)
|
71
|
+
formattedurl = "#{value}/#{branch}/#{file}#{line}" if repo == pattern
|
72
|
+
end
|
73
|
+
|
74
|
+
if arr.include? repo
|
75
|
+
html = %(<a href=\"#{formattedurl}\" style=\"padding-right:2px;\">
|
76
|
+
<span class=\"label label-#{label}\" style=\"font-weight: 400;
|
77
|
+
font-size:smaller;\">
|
78
|
+
<i class=\"fa fa-github fa-lg\"></i>
|
79
|
+
#{text}
|
80
|
+
</span>
|
81
|
+
</a>)
|
82
|
+
else
|
83
|
+
warn "asciidoctor: WARNING: Inline Repo Macro missing config for '#{target}'"
|
84
|
+
html = %(<a href=\"#\" style=\"padding-right:2px;\">
|
85
|
+
<span class=\"label label-warning\" style=\"font-weight: 400;
|
86
|
+
font-size:smaller;\">
|
87
|
+
<i class=\"fa fa-github fa-lg\"></i>
|
88
|
+
Missing repo config for '#{target}'
|
89
|
+
</span>
|
90
|
+
</a>)
|
91
|
+
end
|
92
|
+
|
93
|
+
(create_pass_block parent, html, attrs).render
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'asciidoctor/extensions'
|
2
|
+
require_relative 'utils/labels'
|
3
|
+
require_relative 'utils/block'
|
4
|
+
|
5
|
+
include ::Asciidoctor
|
6
|
+
|
7
|
+
prefix = ''
|
8
|
+
|
9
|
+
# @example Basic Usage
|
10
|
+
# See task:101[] for details
|
11
|
+
# @example Block Use
|
12
|
+
# Already completed. task::101[]
|
13
|
+
# @example Configuration
|
14
|
+
# :task_def_OPR-: Jira;OPR Backlog;https://jira.myorg.eu/browse/OPR-{TASK_ID};images/icons/jira.png;OPR-{TASK_ID}
|
15
|
+
# :task_def_GH-: GitHub;Project GitHub Issues;https://github.organisation.com/MyOrg/repo/issues
|
16
|
+
Extensions.register do
|
17
|
+
inline_macro do
|
18
|
+
named :task
|
19
|
+
|
20
|
+
process do |parent, target, attrs|
|
21
|
+
pa = ''
|
22
|
+
dest = target.match(/\w+-/).to_s.downcase if target[/-/]
|
23
|
+
pattern = parent.document.attr 'task-pattern'
|
24
|
+
|
25
|
+
parent.document.attributes.each do |key, value|
|
26
|
+
next unless key[/^task_def_/]
|
27
|
+
prefix = key.sub(/^task_def_/, '')
|
28
|
+
if dest == prefix
|
29
|
+
type, tip, patt, icon, id = value.match(/^([^^]+)\;([^^]+)\;([^^]+)\;([^^]+)\;([^^]+)/).captures
|
30
|
+
patt.gsub!(/\/(\w+?-)?{.+?}/, '')
|
31
|
+
pattern = patt
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
if pattern.nil?
|
36
|
+
warn "asciidoctor: WARNING: Task pattern not defined for #{target.delete(':')}"
|
37
|
+
pattern = 'unknown'
|
38
|
+
end
|
39
|
+
|
40
|
+
url = pattern % target
|
41
|
+
|
42
|
+
label = Labels.getstatus(attrs)
|
43
|
+
html = Context.format(attrs, target, url, label)
|
44
|
+
(create_pass_block parent, html, attrs).render
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'asciidoctor/extensions'
|
2
|
+
|
3
|
+
include ::Asciidoctor
|
4
|
+
|
5
|
+
jquery = '<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>'
|
6
|
+
lt_gt = '(>>|<<)'
|
7
|
+
|
8
|
+
Extensions.register do
|
9
|
+
postprocessor do
|
10
|
+
process do |_document, output|
|
11
|
+
# asciidoctor-latex injects an old version of jquery, causing conflicts,
|
12
|
+
# see https://github.com/asciidoctor/asciidoctor-latex/blob/master/lib/asciidoctor/latex/inject_html.rb#L28
|
13
|
+
output = output.sub(/#{jquery}/, '') if output[/#{jquery}/]
|
14
|
+
# Remove angle brackets, add scrollspy for bootstrap, target nav.toc
|
15
|
+
output.gsub(/#{lt_gt}/, '').sub(/<body class="book">/, '<body data-spy="scroll" data-target="#toc">')
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|