aspec_rb 0.0.16 → 0.0.18

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: 81629ea54e2cfed1b38309c4f2cef083a4b174c199f801f2f43db23a1a8db1c0
4
- data.tar.gz: d97546374ffc196faa146acb0117d35f020250a39ce659f67aa5a5188af13f49
3
+ metadata.gz: 427cbb8b59cafd0a51f3253e03a53c29a9893699cb7607a95815cdb384d57d45
4
+ data.tar.gz: 25d2bcc8d6bcb9a528b153cdba5a6286ff47fa4adfafbf8f5a000859f61be18c
5
5
  SHA512:
6
- metadata.gz: 474bd5d638e8eebd902d3b8bc0dbd4aabc9bda65fc4667e1a8e1be1c5135d01e5f2abc880d16c3dce8c55481f4ed08f912cf8badda361c3f643ed81c9e15ae2f
7
- data.tar.gz: c6f33e16bdd177198faa7571ac6297eb2714fb560c2955ed37d301249552be52953fa37e4b4125f0fb39cbc078a799450f367aa4d44ffa95968dce05826bb381
6
+ metadata.gz: 70f61d330bcddef4927e4cc5c7d3ca1ef19757a3b49418e698ae40d3c671a3e1efa59e0bdfdc67476b4829fcaa6f406755963aa8f73b82a5d3d7bb8a097bc748
7
+ data.tar.gz: 3a7b1ffabfd31002e268abaa8bab909e46897794afc383bf094c0b3ec49fc13ebc90775993cb59433207a81d3391281f9e49282895bf8b7725cf4453a8cade54
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- aspec_rb (0.0.16)
4
+ aspec_rb (0.0.18)
5
5
  asciidoctor
6
6
 
7
7
  GEM
@@ -10,7 +10,7 @@ GEM
10
10
  asciidoctor (1.5.7.1)
11
11
  docile (1.3.1)
12
12
  json (2.1.0)
13
- power_assert (1.1.1)
13
+ power_assert (1.1.2)
14
14
  rake (12.3.1)
15
15
  simplecov (0.16.1)
16
16
  docile (~> 1.1)
@@ -7,5 +7,5 @@ module AspecRb
7
7
  # For this deploy config, see https://github.com/tcob/aspec_rb/blob/master/.travis.yml
8
8
  #
9
9
  # Manual release can be performed by running 'bundle install && rake release'
10
- VERSION = '0.0.16'
10
+ VERSION = '0.0.18'
11
11
  end
@@ -9,28 +9,29 @@ include ::Asciidoctor
9
9
  $srcdir = 'chapters'
10
10
 
11
11
  AnchorRx = /\[\[(?:|([\w+?_:][\w+?:.-]*)(?:, *(.+))?)\]\]/
12
+ ImageRx = /^(\.\S\w+)/
13
+ SectitleRx = /^(\=+\s+?\S+.+)/
14
+ XrefRx = /\<\<(?!Req)(.+?)\>\>/
12
15
 
13
16
  ni_includes, includes, doclinks, anchorfixes, intrachapter, interchapter, anchors, xrefs = Array.new(9) { [] }
14
17
 
15
- # Don't do this!
16
18
  adoc_files = Dir.glob("#{$srcdir}/**/*.adoc")
17
19
 
18
20
  indexincludes = Index.includes
19
21
 
20
- adoc_files.each do |filename|
21
- main = false
22
+ # Scan adoc files and store some arrays of xrefs and anchors
23
+ adoc_files.each do |filename, main=false|
22
24
  path = Sform.trim(filename)
23
25
  chapter = path.match(/.+?(?=\/)/).to_s
24
26
 
25
- # Add a switch if the current document is an include within the index.adoc
26
- indexincludes.each do |inc|
27
- main = true if inc == filename
28
- end
27
+ # If the current document is an include within the index.adoc
28
+ indexincludes.each { |inc| main = true if inc == filename }
29
29
 
30
30
  File.read(filename).each_line do |li|
31
31
  h1 = false
32
32
 
33
- if li[/\<\<(?!Req)(.+?)\>\>/]
33
+ # Look for xrefs
34
+ if li[XrefRx]
34
35
  # Handle multiple cross refs per line
35
36
  li.scan(/(?=\<\<(?!Req)(.+?)\>\>)/) do |xref|
36
37
  text = ''
@@ -50,20 +51,22 @@ adoc_files.each do |filename|
50
51
  xrefs.push([xref, path, filename, text, target, chapter])
51
52
  end
52
53
 
53
- elsif li[/^(\=+\s+?\S+.+)/]
54
+ # Section Titles
55
+ elsif li[SectitleRx]
54
56
  h1 = true if li[/^=\s+?\S+.+/]
55
57
  title = li.chop.match(/(?!=+\s)(\S+.+?)$/i).captures[0].strip
56
58
  title.sub!(/\.(?=\w+?)/, '') if title[/\.(?=\w+?)/]
57
59
  link = Sform.underscorify(title)
58
60
  anchors.push([title, path, filename, link, chapter, main, h1])
59
61
 
60
- # Handle images separately
61
- elsif li[/^(\.\S\w+)/]
62
+ # Images
63
+ elsif li[ImageRx]
62
64
  title = li.chop.match(/(?!=+\s)(\S+.+?)$/i).captures[0].strip
63
65
  title.sub!(/\.(?=\w+?)/, '') if title[/\.(?=\w+?)/]
64
66
  anchors.push([title, path, filename, title, chapter, main, h1])
65
67
 
66
- elsif li[/\[\[(?:|([\w+?_:][\w+?:.-]*)(?:, *(.+))?)\]\]/]
68
+ # Anchors
69
+ elsif li[AnchorRx]
67
70
  anchor = li.chop.match(/(?<=\[\[).+?(?=\]\])/).to_s
68
71
 
69
72
  if anchor[/,/]
@@ -76,36 +79,37 @@ adoc_files.each do |filename|
76
79
 
77
80
  anchors.push([anchor, path, filename, text, chapter, main, h1, true])
78
81
 
79
- # Match for sub includes
82
+ # Match for includes
80
83
  elsif li[IncludeDirectiveRx]
81
84
  child = li.match(/(?<=^include::).+?\.adoc(?=\[\])/).to_s
82
85
  child = child.sub(/^\{find\}/, '')
83
86
  childpath = "#{filename.sub(/[^\/]+?\.adoc/, '')}#{child}"
84
- includes.push([Sform.trim(filename), child, Sform.trim(childpath)])
87
+ trim_childpath = Sform.trim(childpath)
88
+ trim_parent = Sform.trim(filename)
89
+ includes.push([filename, child, childpath, trim_childpath, trim_parent])
85
90
 
86
91
  end
87
92
  end
88
93
  end
89
94
 
90
- # Create array of non-indexed includes
95
+ # Create array of non-index includes
91
96
  adoc_files.each do |filename|
92
- includes.each do |parent, child, childpath|
97
+ includes.each do |parent, child, childpath, trim_childpath, trim_parent|
93
98
  next unless childpath == filename
94
- ni_includes.push([parent, child, filename])
99
+ ni_includes.push([parent, child, filename, trim_childpath, trim_parent])
95
100
  end
96
101
  end
97
102
 
98
-
99
- # For each main include, store a target link
103
+ # For each "main" include, store a target link
104
+ # This is where the generated HTML for each chapter will live
100
105
  anchors.each do |_anchor, full, _filename, link, chapter, main, h1|
101
106
  next unless main && h1
102
107
  doc = full.gsub(/^#{chapter}\//, '')
103
108
  doclinks.push([doc, link, chapter])
104
109
  end
105
110
 
106
- o_anchors = []
107
-
108
111
  # If a section title has an overriding anchor on the previous line, perform the following fix
112
+ o_anchors = []
109
113
  doclinks.delete_if do |doc, _link, mchapter|
110
114
  topleveldoc = "#{$srcdir}/#{mchapter}/#{doc}.adoc"
111
115
  lines = File.foreach(topleveldoc).first(10).join
@@ -118,25 +122,30 @@ end
118
122
  doclinks += o_anchors
119
123
  doclinks.uniq!
120
124
 
121
- # Edit the array of Anchors to point to the parent document *if* it is included.
122
- # TODO use a while loop, repeat until no changes made
125
+ # Edit the array of Anchors to point to the parent document if it is included.
123
126
  tempanchors = []
124
127
  3.times do
125
128
  tempanchors.clear
126
129
 
127
130
  # Loop through all includes, if the anchor is contained in an include,
128
131
  # edit the anchors array to point to its parent instead
129
- includes.each do |parent, _child, childpath|
132
+ includes.each do |parent, _child, childpath, trim_childpath, trim_parent|
130
133
  anchors.delete_if do |anchor, path, filename, text, chapter, main, _h1|
131
- next unless Sform.trim(childpath) == Sform.trim(filename)
132
- tempanchors.push([anchor, path, Sform.trim(parent), text, chapter, main])
134
+ # TODO - this is a huge bottleneck!
135
+ # remove string operations inside iterators!!!
136
+ next unless trim_childpath == Sform.trim(filename)
137
+ tempanchors.push([anchor, path, trim_parent, text, chapter, main])
133
138
  true
134
139
  end
135
140
  end
141
+
136
142
  anchors += tempanchors
137
143
  anchors.uniq!
144
+
138
145
  end
139
146
 
147
+ tempanchors.clear
148
+
140
149
  anchors.delete_if do |anchor, apath, trim_parent, parent, amain, achapter|
141
150
  doclinks.each do |doc, link, dchapter|
142
151
  next unless apath == "#{dchapter}/#{doc}" || trim_parent == "#{dchapter}/#{doc}"
@@ -145,31 +154,29 @@ anchors.delete_if do |anchor, apath, trim_parent, parent, amain, achapter|
145
154
  end
146
155
  end
147
156
 
148
-
149
- tempanchors.uniq!
150
157
  anchors += tempanchors
151
158
  anchors.uniq!
152
159
 
153
160
  # For all requirements, check which chapter they should finally be in with includes catered for
154
161
  # match with a main document name - should be a main chapter title
155
- xrefs.each do |xref, xpath, _xfilename, _xtext, xtarget, _xchapter|
162
+ xrefs.each do |xref, xpath, _xfilename, xtext, xtarget, _xchapter|
156
163
  anchors.each do |anchor, apath, afilename, atext, _achapter, _amain, _h1|
157
164
  next unless xref == anchor
158
165
  # if in same chapter, dont link to other HTML file
159
166
  afilename = '' if xpath == apath
160
167
  # xtext = xref if xtext.empty?
161
168
  afilename.sub!(/^_/, '') if afilename[/^_/]
162
- fix = "#{afilename}##{atext},#{_xtext}"
169
+ fix = "#{afilename}##{atext},#{xtext}"
163
170
  anchorfixes.push([anchor, fix, xref])
164
171
  end
165
172
  end
166
173
 
174
+ anchorfixes.uniq!
175
+
167
176
  Extensions.register do
168
177
  preprocessor do
169
178
  process do |_document, reader|
170
- # return reader if reader.eof?
171
-
172
- replacement_lines = reader.read_lines.map do |line|
179
+ Reader.new reader.readlines.map { |line|
173
180
  if line[/\<\<(?!Req)(.+?)\>\>/]
174
181
  anchorfixes.each do |original, fix|
175
182
  next unless line[/\<\<#{original}(,.+?)?\>\>/]
@@ -183,9 +190,7 @@ Extensions.register do
183
190
  2.times { line.sub!(/`/, '') }
184
191
  end
185
192
  line
186
- end
187
- reader.unshift_lines replacement_lines
188
- reader
193
+ }
189
194
  end
190
195
  end
191
196
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: aspec_rb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.16
4
+ version: 0.0.18
5
5
  platform: ruby
6
6
  authors:
7
7
  - tcob
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-06-11 00:00:00.000000000 Z
11
+ date: 2018-06-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler