jekyll_aspec 1.0.1 → 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c39d61a6498f5af8f4d8ed4e5845a9f5ad0fac87
4
- data.tar.gz: bdd6191dcd9382f9804ded987609672fb343b0ef
3
+ metadata.gz: 5c606a844a3e7cc86b1a1dc7d5734d331e56c125
4
+ data.tar.gz: eed7882c3018c18c4a8ed11fd5f69f64a0c92bcd
5
5
  SHA512:
6
- metadata.gz: b07a3e61eb8a373aea89fd6f526528dddd6875b671dfa8defd1cb9812f9ad7c4145be1bdd783ecc983e0d06ec9665cd6861bb5351c89556958776367d79fa5b7
7
- data.tar.gz: ba7f2af116019673c1a3c9f2876ca047ba8039e4b8e9e660456bb6b8d2a5599d57323b4628b0e7c4cdf501b8cf859172c0782a2668ee38281519628ce6557509
6
+ metadata.gz: 43fcafd2d451abc45f987b1123db14f83dd6fbb917187b850f27ae2dfd1537e84162f8c2dda14bd83a1292ae4cea12a3048dd015619c294ef2134e831c5b6531
7
+ data.tar.gz: ebd58cbb80e998e1d644d0e967b09ca5a953613f03eedb80b2de0de33bd842577a5af2553488cb3299ba2ea0dfc0917ec09d4bea167dd0b1c76a05be4c3cd5b6
data/.rubocop.yml ADDED
@@ -0,0 +1,3 @@
1
+ Metrics/LineLength:
2
+ # This will disable the rule completely, regardless what other options you put
3
+ Enabled: false
data/.travis.yml CHANGED
@@ -1,3 +1,3 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 2.3
3
+ - 2.3.0
data/Gemfile CHANGED
@@ -1,6 +1,6 @@
1
- source "https://rubygems.org"
1
+ source 'https://rubygems.org'
2
2
 
3
- git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
3
+ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
4
4
 
5
5
  # Specify your gem's dependencies in jekyll-aspec.gemspec
6
6
  gemspec
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- jekyll_aspec (1.0.1)
4
+ jekyll_aspec (1.0.2)
5
5
  asciidoctor (>= 1.5.0)
6
6
 
7
7
  GEM
data/README.md CHANGED
@@ -2,26 +2,26 @@
2
2
 
3
3
  [![Gem Version](https://badge.fury.io/rb/jekyll_aspec.svg)](https://badge.fury.io/rb/jekyll_aspec) [![Build Status](https://travis-ci.org/bsmith-n4/jekyll_aspec.svg?branch=master)](https://travis-ci.org/bsmith-n4/jekyll_aspec)
4
4
 
5
- A selection of Asciidoctor extensions designed to used to write some AsciiSpec with Jekyll.
5
+ A selection of Asciidoctor extensions for use with Jekyll and [jekyll-asciidoc](https://github.com/asciidoctor/jekyll-asciidoc).
6
6
 
7
7
  These extensions add custom blocks for Requirements and attempts to smartly handle inter-document auto-linking functionality.
8
8
 
9
9
  ## Motivation
10
10
 
11
11
  Jekyll is a very flexible and speedy tool for generating static HTML pages.
12
- The `jekyl-asciidoc` gem adds Asciidoctor functionality but it lacks a few features due to the way it handles multiple source files. As each `.adoc` file is consumed individually, we lose the ability to automatically format inter-document cross-references. This plugin is a group of extensions that performs some directory walking, stores the location of titles and anchors so that cross references in a Jekyll project are resolved automatically.
12
+ The [jekyll-asciidoc](https://github.com/asciidoctor/jekyll-asciidoc) gem adds Asciidoctor functionality but it lacks a few features due to the way it handles multiple source files. As each `.adoc` file is consumed individually, we lose the ability to automatically format inter-document cross-references. This plugin is a group of extensions that performs some directory walking, stores the location of titles and anchors so that cross references in a Jekyll project are resolved automatically.
13
13
 
14
14
  Additional features are
15
15
 
16
16
  * Custom block for ``TODO``s
17
17
  * Requirements Block with versioning
18
- * Requirements block macro that creates a Table of Contents of declared Requirements
18
+ * Requirements block macro that creates an appendix-style Table of Contents for Requirements
19
19
  * Inline Callout macro to arbitrarily add callouts
20
20
  * Inline Task macro to link to Jira tickets or Github Issues
21
21
  * Inline Repo Macro to link to specific files or lines on GitHub
22
22
  * A HTML postprocessor to correct some minor fixes and invalid tags created by Asciidoctor
23
23
 
24
- When these custom extensions are combined with other recommended gems such as `asciidoctor-bibtex` and `asciidoctor-latex`, you can achieve quite high quality, speedy HTML documentation for technical projects with the benefits of a Jekyll build. It's recommended to use the `html-proofer` gem which will validate all links created with these extensions.
24
+ When these custom extensions are combined with other recommended gems such as `asciidoctor-bibtex` and `asciidoctor-latex`, you can achieve quite high quality, speedy HTML documentation for technical projects with the benefits of a Jekyll build. It's recommended to use the [html-proofer](https://github.com/gjtorikian/html-proofer) gem which will validate all links created with these extensions.
25
25
 
26
26
  ## Installation
27
27
 
@@ -36,18 +36,18 @@ end
36
36
 
37
37
  Or install it yourself as:
38
38
 
39
- $ gem install jekyll_aspec
39
+ ```
40
+ $ gem install jekyll_aspec
41
+ ```
40
42
 
41
43
  ## Docs
42
44
 
43
- Yard documentation is generation automatically at http://www.rubydoc.info/gems/jekyll_aspec/
44
-
45
- Also refer to the `docs` directory for some basic documentation on extended Asciidoctor features.
45
+ Yard documentation is generation automatically at [RubyDoc.info](http://www.rubydoc.info/gems/jekyll_aspec/)
46
46
 
47
47
  ## Contributing
48
48
 
49
- This gem is under heavy initial development and there are still many kinks to work out. The areas to be improved upon include performance enhancements, proper handling of file IO / directory walking and, of course, documentation. Bug reports and pull requests are welcome on GitHub at https://github.com/bsmith-n4/jekyll_aspec.
49
+ This gem is under heavy initial development and there are still many kinks to work out. The areas to be improved upon include performance enhancements, proper handling of file IO / directory walking and, of course, documentation. Bug reports and pull requests are welcome on [GitHub](https://github.com/bsmith-n4/jekyll_aspec).
50
50
 
51
51
  ## License
52
52
 
53
- The gem is available as open source under the terms of the https://opensource.org/licenses/MIT[MIT License].
53
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile CHANGED
@@ -1,8 +1,15 @@
1
1
  require 'bundler/gem_tasks'
2
2
  require 'test/unit'
3
3
 
4
- task :default => :test
4
+ task default: :test
5
5
 
6
6
  task :test do
7
7
  ruby 'test/suite.rb'
8
+ ruby 'test/html_postprocessor.rb'
9
+ ruby 'test/convert_doc.rb'
10
+ end
11
+
12
+ task :rubocop do
13
+ sh 'rubocop'
14
+ sh 'htmlproofer test'
8
15
  end
data/bin/console CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- require "bundler/setup"
4
- require "jekyll-aspec"
3
+ require 'bundler/setup'
4
+ require 'jekyll-aspec'
5
5
 
6
6
  # You can add fixtures and/or initialization code here to make experimenting
7
7
  # with your gem easier. You can also use a different console, if you like.
@@ -10,5 +10,5 @@ require "jekyll-aspec"
10
10
  # require "pry"
11
11
  # Pry.start
12
12
 
13
- require "irb"
13
+ require 'irb'
14
14
  IRB.start(__FILE__)
data/jekyll_aspec.gemspec CHANGED
@@ -1,34 +1,34 @@
1
1
 
2
- lib = File.expand_path("../lib", __FILE__)
2
+ lib = File.expand_path('../lib', __FILE__)
3
3
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require "jekyll_aspec/version"
4
+ require 'jekyll_aspec/version'
5
5
 
6
6
  Gem::Specification.new do |spec|
7
- spec.name = "jekyll_aspec"
7
+ spec.name = 'jekyll_aspec'
8
8
  spec.version = JekyllAspec::VERSION
9
- spec.authors = ["bsmith-n4"]
10
- spec.email = ["brian.smith@numberfour.eu"]
9
+ spec.authors = ['bsmith-n4']
10
+ spec.email = ['brian.smith@numberfour.eu']
11
11
 
12
- spec.summary = %q{Asciidoctor extensions for use as a Jekyll plugin}
13
- spec.description = %q{This plugin is a group of Asciidoctor extensions that perform directory walking,
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
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/jekyll_aspec"
18
- spec.license = "MIT"
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/jekyll_aspec'
18
+ spec.license = 'MIT'
19
19
 
20
20
  # This gem will work with 2.0 or greater.
21
21
  spec.required_ruby_version = '>= 2.0'
22
22
 
23
- spec.files = `git ls-files -z`.split("\x0").reject do |f|
23
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
24
24
  f.match(%r{^(test|spec|features)/})
25
25
  end
26
- spec.bindir = "exe"
26
+ spec.bindir = 'exe'
27
27
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
28
- spec.require_paths = ["lib"]
28
+ spec.require_paths = ['lib']
29
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"
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
34
  end
@@ -1,23 +1,118 @@
1
1
  require 'asciidoctor/extensions'
2
2
  require 'pathname'
3
- require_relative 'utils/xref_helper'
4
3
 
5
4
  include ::Asciidoctor
6
5
 
7
- mismatches = Xrefs.list_xrefs
6
+ # Find all Adoc Files
7
+ adoc_files = Dir.glob('**/*.adoc')
8
8
  invoc = Dir.pwd
9
9
 
10
+ # Make some arrays available
11
+ titles = []
12
+ anchors = []
13
+ xrefs = []
14
+ mismatches = []
15
+
16
+ replacement = ''
17
+
18
+ def trim(s)
19
+ s.gsub!(/_docs\//, '')
20
+ s.gsub!(/(\.adoc|\.md|\.html)/, '')
21
+ end
22
+
23
+ def targetify(t)
24
+ # make all chars lowercase and substitute spaces with hyphens
25
+ t.downcase.gsub(/\s/, '-')
26
+ end
27
+
28
+ adoc_files.each do |file_name|
29
+ lc = 0
30
+
31
+ File.read(file_name).each_line do |li|
32
+ lc += 1
33
+
34
+ # Match all <<xrefs>> exluding Requirements
35
+ if li[/\<\<(?!Req)(.+?)\>\>/]
36
+
37
+ text = ''
38
+ target = ''
39
+ path = trim(file_name)
40
+ xref = li.chop.match(/\<\<(?!Req)(\S.+?)\>\>/i).captures[0].to_s
41
+
42
+ if xref[/,/]
43
+ target = xref.downcase.gsub(/,.+/, '').gsub(/\s/, '-')
44
+ text = xref.gsub(/.+,/, '').lstrip!
45
+ xref = xref.sub(/,.+/, '')
46
+ path = file_name
47
+ else
48
+ target = xref.downcase.gsub(/\s/, '-')
49
+ text = xref
50
+ end
51
+
52
+ item = [xref, path, file_name, text, target]
53
+ xrefs.push item
54
+
55
+ # Match .Titles and = Section Titles
56
+ elsif li[/(^(\.\S\w+)|^(\=+\s+?\S+.+))/]
57
+
58
+ # Add check if none found (captures nil)
59
+ title = li.chop.match(/(?!=+\s)(\S+.+?)$/i).captures[0]
60
+ title.sub!(/\.(?=\w+?)/, '') if title[/\.(?=\w+?)/]
61
+ path = trim(file_name)
62
+ item = [title, path, file_name]
63
+ titles.push item
64
+
65
+ # Match [[anchors]]
66
+ elsif li[/\[\[(?:|([\w+?_:][\w+?:.-]*)(?:, *(.+))?)\]\]/]
67
+
68
+ # Add check if none found (captures nil)
69
+ anchor = li.chop.match(/(?<=\[\[).+?(?=\]\])/).to_s
70
+
71
+ if anchor[/,/]
72
+ anchor = anchor.match(/(?<=\[\[)(?:|[\w+?_:][\w+?:.-]*)(?=,.+?\]\])/).to_s
73
+ text = anchor.sub(/.+?,/, '')
74
+ text = text.sub(/\]\]$/, '')
75
+ end
76
+ path = trim(file_name)
77
+ item = [anchor, path, file_name, text]
78
+ titles.push item
79
+
80
+ end
81
+ end
82
+ end
83
+
84
+ # Run through each xref and check for matching titles
85
+ xrefs.each do |xref, xpath, xfile, xtext, xtarget|
86
+ # check xrefs against titles
87
+ titles.each do |ttext, tpath, tfile, _tdisp|
88
+ # puts "checking #{ttext} against #{xref}"
89
+ next unless ttext == xref
90
+ # puts "MATCHED #{ttext} with #{xref}"
91
+
92
+ # If the paths are not the same (xref and title not the same document) do the following
93
+ next unless tpath != xpath
94
+ tpath = 'index' if tpath.to_s.empty?
95
+ # puts "Title \"#{ttext}\" in #{tfile} - mismatched xref \"#{xref}\" to different doc - #{xpath}"
96
+
97
+ xtform = targetify(xtarget)
98
+ detail = [xref, xtarget, xtext, xpath, xfile, ttext, tpath, tfile, xtform]
99
+ mismatches.push detail
100
+ end
101
+ end
102
+
10
103
  Extensions.register do
11
104
  preprocessor do
12
105
  process do |document, reader|
13
106
  fixes = []
14
107
  i = 0
15
108
 
16
- # TODO - remove unused elements (prepended with _) from the helper method in utils/xref_helper
109
+ # Block is loaded once per document!!!
110
+ # for each malformed xref
17
111
  mismatches.each do |_xref, _xtarget, xtext, _xpath, xfile, _ttext, _tpath, tfile, xtform|
112
+ # FIXME: This directory is empty in POSTS - breaks conversion
18
113
  docfile = document.attributes['docfile'].sub(/^#{invoc}\//, '')
19
- Xrefs.trim(docfile)
20
-
114
+ trim(docfile)
115
+
21
116
  next unless docfile.to_s == xfile
22
117
 
23
118
  # calculate the relative path between source and target
@@ -35,6 +130,8 @@ Extensions.register do
35
130
  if li[/\<\<(?!Req)(.+?)\>\>/]
36
131
 
37
132
  mismatches.each do |xref, xtarget, xtext, _xpath, _xfile, _ttext, _tpath, _tfile, _relpath|
133
+ # check if the line contains the original xref
134
+
38
135
  next unless li[/\<\<#{xref}(,.+)?\>\>/]
39
136
  fixes.each do |x|
40
137
  if x[/#{xtarget}/]
@@ -44,6 +141,7 @@ Extensions.register do
44
141
  end
45
142
  i += 1
46
143
  end
144
+
47
145
  else
48
146
  replacement = ''
49
147
  end
@@ -2,11 +2,10 @@ require 'asciidoctor/extensions'
2
2
 
3
3
  include ::Asciidoctor
4
4
 
5
- # Strip bogus tags generated by Asciidoctor
6
5
  Extensions.register do
7
6
  postprocessor do
8
7
  process do |document, output|
9
- output = output.gsub(/<\/p>/, '')
8
+ output = output.gsub(/<\/p>/, '') if document.basebackend? 'html'
10
9
  output
11
10
  end
12
11
  end
@@ -7,7 +7,7 @@ include ::Asciidoctor
7
7
  Asciidoctor::Extensions.register do
8
8
  inline_macro do
9
9
  named :call
10
- process do |parent, target, attrs|
10
+ process do |parent, target, _attrs|
11
11
  Asciidoctor::Inline.new(parent, :callout, target.to_i).convert
12
12
  end
13
13
  end
@@ -14,14 +14,17 @@ Extensions.register do
14
14
 
15
15
  process do |parent, target, attrs|
16
16
  pattern = parent.document.attr 'cwiki-pattern'
17
- if pattern.nil?
17
+
18
+ if pattern.nil?
18
19
  warn "asciidoctor: WARNING: Attribue 'cwiki-pattern' for inline repo macro not defined"
19
- pattern = "unknown"
20
+ pattern = 'unknown'
21
+ label = 'warning'
22
+ target = 'cwiki-pattern missing'
23
+ else
24
+ label = Labels.getstatus(attrs)
20
25
  end
21
- url = pattern % target
22
26
 
23
- label = Labels.getstatus(attrs)
24
- html = Context.format(attrs, target, url, label)
27
+ html = Context.format(attrs, target, pattern, label)
25
28
  (create_pass_block parent, html, attrs).render
26
29
  end
27
30
  end
@@ -2,12 +2,6 @@ require 'asciidoctor/extensions' unless RUBY_ENGINE == 'opal'
2
2
 
3
3
  include ::Asciidoctor
4
4
 
5
- url = ''
6
- file = ''
7
- line = ''
8
- formattedurl = ''
9
- text = ''
10
-
11
5
  # Link to a file on GitHub.
12
6
  #
13
7
  # repo:<repository>:<file>:<line>[]
@@ -15,7 +9,7 @@ text = ''
15
9
  # The target should be set using document attributes prefixed by 'repo_'.
16
10
  #
17
11
  # @example Attribute configuration
18
- # :repo_dockerfiles: www.github.com/exampleuser/dockerfiles/issues
12
+ # :repo_dockerfiles: www.github.com/exampleuser/dockerfiles/issues
19
13
  # @example Simple Use
20
14
  # repo:dockerfiles:ansible/Dockerfile_template[]
21
15
  # @example Link to repo and line number
@@ -29,7 +23,16 @@ Extensions.register do
29
23
  named :repo
30
24
 
31
25
  process do |parent, target, attrs|
26
+ html = ''
27
+ url = ''
28
+ file = ''
29
+ line = ''
30
+ formattedurl = ''
31
+ text = ''
32
+ arr = []
33
+
32
34
  # @todo fix handling of use within cells. This is done using the context.
35
+
33
36
  if parent.context.to_s == 'cell'
34
37
  warn %([Hell in a cell] cell with repo link must have 'asciidoc format')
35
38
  end
@@ -64,26 +67,29 @@ Extensions.register do
64
67
  parent.document.attributes.each do |key, value|
65
68
  next unless key[/^repo_/]
66
69
  pattern = key.sub(/^repo_/, '')
67
- if repo == pattern
68
- formattedurl = "#{value}/#{branch}/#{file}#{line}"
69
- else
70
- url = ''
71
- end
70
+ arr.push(pattern)
71
+ formattedurl = "#{value}/#{branch}/#{file}#{line}" if repo == pattern
72
72
  end
73
73
 
74
- if formattedurl.nil?
75
- warn "asciidoctor: WARNING: Attribue 'repo_...' for inline repo macro not defined"
76
- pattern = "unknown"
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>)
77
91
  end
78
92
 
79
- html = %(<a href=\"#{formattedurl}\" style=\"padding-right:2px;\">
80
- <span class=\"label label-#{label}\" style=\"font-weight: 400;
81
- font-size:smaller;\">
82
- <i class=\"fa fa-github fa-lg\"></i>
83
- #{text}
84
- </span>
85
- </a>)
86
-
87
93
  (create_pass_block parent, html, attrs).render
88
94
  end
89
95
  end