jekyll_aspec 1.0.1 → 1.0.2

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.
@@ -1,122 +0,0 @@
1
- # Helper methods for common xref processing.
2
- #
3
- module Xrefs
4
- # Trims a path of a given source document to exclude the docs directory
5
- # and file extension. This is used to calculate the target directory
6
- # of generated HTML files given default permalink settings.
7
- #
8
- # @param path [String] the path of the source document relative to the project root
9
- # @return [String] the formatted path
10
- def self.trim(path)
11
- trimmed = path.gsub(/_docs\//, '')
12
- trimmed.gsub(/(\.adoc|\.md|\.html)/, '')
13
- end
14
-
15
- # Formats a string to be permalink-friendly. This simply
16
- # downcases the string an substitutes spaces with hyphens. This is
17
- # typically used for section titles and document titles to generate
18
- # a cross-reference to an anchor.
19
- #
20
- # @param path [String] the path of the source document relative to the project root
21
- # @return [String] the formatted path
22
- def self.targetify(path)
23
- path.downcase.gsub(/\s/, '-')
24
- end
25
-
26
- # Recursively globs all files with the .adoc extension and matches cross-references,
27
- # section titles and anchors. Cross-references to Requirements are excluded and handled
28
- # in their own processor as they are a special case (i.e., there is no built-in support).
29
- #
30
- # @return [String] the formatted path
31
- def self.list_xrefs
32
-
33
- # @todo Maybe don't do this. Find a better way to process
34
- # all .adoc files before extensions are loaded.
35
- adoc_files = Dir.glob('**/*.adoc')
36
-
37
- # Make some arrays available
38
- titles = []
39
- anchors = []
40
- xrefs = []
41
- mismatches = []
42
-
43
- replacement = ''
44
-
45
- adoc_files.each do |file_name|
46
- lc = 0
47
-
48
- File.read(file_name).each_line do |li|
49
- lc += 1
50
-
51
- # @note Matches all <<xrefs>> except Requirements
52
- if li[/\<\<(?!Req)(.+?)\>\>/]
53
-
54
- text = ''
55
- target = ''
56
- path = trim(file_name)
57
- xref = li.chop.match(/\<\<(?!Req)(\S.+?)\>\>/i).captures[0].to_s
58
-
59
- # @note Checks if the xref has display text, i.e. '<<title-1,Lovely Display Text>>'
60
- if xref[/,/]
61
- # @todo Use helper methods.
62
- target = xref.downcase.gsub(/,.+/, '').gsub(/\s/, '-')
63
- text = xref.gsub(/.+,/, '').lstrip!
64
- xref = xref.sub(/,.+/, '')
65
- path = file_name
66
- else
67
- # @todo Use helper methods.
68
- target = xref.downcase.gsub(/\s/, '-')
69
- text = xref
70
- end
71
-
72
- item = [xref, path, file_name, text, target]
73
- xrefs.push item
74
-
75
- # Match .Titles and = Section Titles
76
- elsif li[/(^(\.\S\w+)|^(\=+\s+?\S+.+))/]
77
-
78
- # Add check if none found (captures nil)
79
- title = li.chop.match(/(?!=+\s)(\S+.+?)$/i).captures[0]
80
- title.sub(/\.(?=\w+?)/, '') if title[/\.(?=\w+?)/]
81
- path = trim(file_name)
82
- item = [title, path, file_name]
83
- titles.push item
84
-
85
- # Match [[anchors]]
86
- elsif li[/\[\[.+?\]\]/]
87
-
88
- # Add check if none found (captures nil)
89
- anchor = li.chop.match(/(?<=\[\[).+?(?=\]\])/).to_s
90
-
91
- if anchor[/,/]
92
- anchor = anchor.match(/(?<=\[\[)(?:|[\w+?_:][\w+?:.-]*)(?=,.+?\]\])/).to_s
93
- text = anchor.sub(/.+?,/, '')
94
- text = text.sub(/\]\]$/, '')
95
- end
96
-
97
- path = trim(file_name)
98
- item = [anchor, path, file_name, text]
99
- # for the moment, just handle anchors similar to titles
100
- titles.push item
101
-
102
- end
103
- end
104
- end
105
-
106
- # Run through each xref and check for matching titles
107
- xrefs.each do |xref, xpath, xfile, xtext, xtarget|
108
- # check xrefs against titles
109
- titles.each do |ttext, tpath, tfile, _tdisp|
110
-
111
- next unless ttext == xref
112
- tpath = 'index' if tpath.to_s.empty?
113
- # If the paths are not the same (xref and title not the same document) do the following
114
- next unless tpath != xpath
115
-
116
- xtform = targetify(xtarget)
117
- detail = [xref, xtarget, xtext, xpath, xfile, ttext, tpath, tfile, xtform]
118
- mismatches.push detail
119
- end
120
- end
121
- end
122
- end