rspec-documentation 0.0.4 → 0.0.6

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.
Files changed (34) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +2 -1
  3. data/Gemfile.lock +9 -4
  4. data/README.md +2 -0
  5. data/lib/rspec/documentation/version.rb +1 -1
  6. data/lib/rspec_documentation/configuration.rb +7 -0
  7. data/lib/rspec_documentation/formatters/ruby.rb +3 -1
  8. data/lib/rspec_documentation/formatters/xml.rb +30 -0
  9. data/lib/rspec_documentation/formatters.rb +1 -0
  10. data/lib/rspec_documentation/html_element.rb +2 -1
  11. data/lib/rspec_documentation/kramdown_html_converter.rb +14 -0
  12. data/lib/rspec_documentation/page_collection.rb +1 -1
  13. data/lib/rspec_documentation/parsed_document.rb +1 -1
  14. data/lib/rspec_documentation/rspec/failure.rb +8 -1
  15. data/lib/rspec_documentation/spec.rb +2 -3
  16. data/lib/rspec_documentation.rb +9 -0
  17. data/lib/templates/layout.css.erb +9 -0
  18. data/lib/templates/layout.html.erb +7 -0
  19. data/lib/templates/modal_spec.html.erb +1 -1
  20. data/lib/templates/tabbed_spec.html.erb +1 -1
  21. data/rspec-documentation/pages/000-Introduction.md +1 -1
  22. data/rspec-documentation/pages/030-Examples/{010-Basic.md → 010-Basic Usage.md } +1 -25
  23. data/rspec-documentation/pages/030-Examples/011-Multiple Expectations.md +23 -0
  24. data/rspec-documentation/pages/030-Examples/012-Regular it Blocks.md +23 -0
  25. data/rspec-documentation/pages/030-Examples/040-JSON.md +1 -1
  26. data/rspec-documentation/pages/030-Examples/050-YAML.md +1 -2
  27. data/rspec-documentation/pages/030-Examples/060-XML.md +25 -0
  28. data/rspec-documentation/pages/060-Configuration/020-Build Paths.md +2 -2
  29. data/rspec-documentation/pages/060-Configuration/040-Hooks.md +31 -0
  30. data/rspec-documentation/pages/070-Publishing.md +2 -2
  31. data/rspec-documentation/spec_helper.rb +2 -0
  32. data/rspec-documentation.gemspec +1 -0
  33. metadata +24 -4
  34. /data/rspec-documentation/pages/{000-Introduction/000-Quickstart.md → 001-Quickstart.md} +0 -0
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a33d3b35a6feaea6cdb730424eabca522ee5592f7e944b9c751713b12c3c35d5
4
- data.tar.gz: 90be4151f65ecb8e0e4a74f70c85cdae67df5d78ed31acd0cc2fa2c7da72a2f2
3
+ metadata.gz: 6eb4258635900a3617ddf6ab4cdfb7fe1d1cba62fbd8231f11437cf9b9734c6b
4
+ data.tar.gz: f5db6165cfd08d759765d4e50a0398bfdb0ab99dee84567fd535bd97cd30f0a4
5
5
  SHA512:
6
- metadata.gz: f357c76176c0f5cc9a2061a51dfa3fceb59f05d75fe5173ed211dee64e1e4c07bb6309448757f1172f7b79f4b80f0c55c8fca99ca430eb17bb2b1766390ca1de
7
- data.tar.gz: b5598da557e010fb880dd001297d5d7796f46b7f2f2e7bf39847eec33073402f852f14f8113474c3ba00f950ee5b53b20af2d259b584a0bd5fe23cac707591bb
6
+ metadata.gz: e25685a33fb2cc2bace75aa20c72f2b33407f2edec5a14840163cced2662fd852d3c87f8e4b31741b15825311365348f22cf5754b1850ddec1196bba64181a02
7
+ data.tar.gz: 3678422ca81bc09c5cd68db061b6a81746d21fb848824e229369721e727ac01f4fa4e517263ef9d47b8f1457f336d7dd6a0fdea0ee6ed63e498d62995f7c4102
data/Gemfile CHANGED
@@ -8,10 +8,11 @@ gemspec
8
8
  gem 'rake', '~> 13.0'
9
9
 
10
10
  gem 'devpack', '~> 0.4.1'
11
+ gem 'nokogiri', '~> 1.15'
11
12
  gem 'rspec', '~> 3.0'
12
13
  gem 'rspec-file_fixtures', '~> 0.1.6'
13
14
  gem 'rspec-its', '~> 1.3'
14
- gem 'rubocop', '~> 1.51'
15
+ gem 'rubocop', '~> 1.52'
15
16
  gem 'rubocop-rake', '~> 0.6.0'
16
17
  gem 'rubocop-rspec', '~> 2.22'
17
18
  gem 'strong_versions', '~> 0.4.5'
data/Gemfile.lock CHANGED
@@ -1,10 +1,11 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rspec-documentation (0.0.4)
4
+ rspec-documentation (0.0.6)
5
5
  htmlbeautifier (~> 1.4)
6
6
  kramdown (~> 2.4)
7
7
  kramdown-parser-gfm (~> 1.1)
8
+ nokogiri (~> 1.15)
8
9
  paintbrush (~> 0.1.3)
9
10
  redcarpet (~> 3.6)
10
11
  rouge (~> 4.1)
@@ -25,11 +26,14 @@ GEM
25
26
  rexml
26
27
  kramdown-parser-gfm (1.1.0)
27
28
  kramdown (~> 2.0)
29
+ nokogiri (1.15.2-x86_64-linux)
30
+ racc (~> 1.4)
28
31
  paint (2.3.0)
29
32
  paintbrush (0.1.3)
30
33
  parallel (1.23.0)
31
34
  parser (3.2.2.1)
32
35
  ast (~> 2.4.1)
36
+ racc (1.6.2)
33
37
  rainbow (3.1.1)
34
38
  rake (13.0.6)
35
39
  redcarpet (3.6.0)
@@ -54,7 +58,7 @@ GEM
54
58
  diff-lcs (>= 1.2.0, < 2.0)
55
59
  rspec-support (~> 3.12.0)
56
60
  rspec-support (3.12.0)
57
- rubocop (1.51.0)
61
+ rubocop (1.52.0)
58
62
  json (~> 2.3)
59
63
  parallel (~> 1.10)
60
64
  parser (>= 3.2.0.0)
@@ -64,7 +68,7 @@ GEM
64
68
  rubocop-ast (>= 1.28.0, < 2.0)
65
69
  ruby-progressbar (~> 1.7)
66
70
  unicode-display_width (>= 2.4.0, < 3.0)
67
- rubocop-ast (1.28.1)
71
+ rubocop-ast (1.29.0)
68
72
  parser (>= 3.2.1.0)
69
73
  rubocop-capybara (2.18.0)
70
74
  rubocop (~> 1.41)
@@ -87,12 +91,13 @@ PLATFORMS
87
91
 
88
92
  DEPENDENCIES
89
93
  devpack (~> 0.4.1)
94
+ nokogiri (~> 1.15)
90
95
  rake (~> 13.0)
91
96
  rspec (~> 3.0)
92
97
  rspec-documentation!
93
98
  rspec-file_fixtures (~> 0.1.6)
94
99
  rspec-its (~> 1.3)
95
- rubocop (~> 1.51)
100
+ rubocop (~> 1.52)
96
101
  rubocop-rake (~> 0.6.0)
97
102
  rubocop-rspec (~> 2.22)
98
103
  strong_versions (~> 0.4.5)
data/README.md CHANGED
@@ -24,4 +24,6 @@ it { is_expected.to eql 'my subject' }
24
24
  ```
25
25
  ````
26
26
 
27
+ ## Documentation
28
+
27
29
  View the [full documentation](https://docs.bob.frl/rspec-documentation) (built using Rspec Documentation!) for detailed usage instructions.
@@ -2,6 +2,6 @@
2
2
 
3
3
  module RSpec
4
4
  module Documentation
5
- VERSION = '0.0.4'
5
+ VERSION = '0.0.6'
6
6
  end
7
7
  end
@@ -3,8 +3,11 @@
3
3
  module RSpecDocumentation
4
4
  # Configures the rspec-documentation gem, allows setting a context that makes values available to each example.
5
5
  class Configuration
6
+ attr_reader :hooks
7
+
6
8
  def initialize
7
9
  @context_defined = false
10
+ @hooks = {}
8
11
  end
9
12
 
10
13
  def context_defined?
@@ -24,5 +27,9 @@ module RSpecDocumentation
24
27
  @context_defined = true
25
28
  ::RSpec.shared_context('__rspec_documentation', &block)
26
29
  end
30
+
31
+ def hook(name, &block)
32
+ hooks[name] = block
33
+ end
27
34
  end
28
35
  end
@@ -16,7 +16,9 @@ module RSpecDocumentation
16
16
  def rendered_output
17
17
  formatter = Rouge::Formatters::HTML.new
18
18
  lexer = Rouge::Lexers::Ruby.new
19
- formatter.format(lexer.lex(subject.inspect))
19
+ io = StringIO.new
20
+ PP.pp(subject, io)
21
+ formatter.format(lexer.lex(io.string))
20
22
  end
21
23
 
22
24
  def render_raw?
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RSpecDocumentation
4
+ module Formatters
5
+ # Produces prettified XML to from an RSpec `subject` value.
6
+ class Xml
7
+ def initialize(subject:)
8
+ @subject = subject
9
+ end
10
+
11
+ def prettified_output
12
+ nil
13
+ end
14
+
15
+ def rendered_output
16
+ formatter = Rouge::Formatters::HTML.new
17
+ lexer = Rouge::Lexers::XML.new
18
+ formatter.format(lexer.lex(Nokogiri::XML.parse(subject).to_xml))
19
+ end
20
+
21
+ def render_raw?
22
+ false
23
+ end
24
+
25
+ private
26
+
27
+ attr_reader :subject
28
+ end
29
+ end
30
+ end
@@ -5,6 +5,7 @@ require_relative 'formatters/html'
5
5
  require_relative 'formatters/ansi'
6
6
  require_relative 'formatters/json'
7
7
  require_relative 'formatters/yaml'
8
+ require_relative 'formatters/xml'
8
9
 
9
10
  module RSpecDocumentation
10
11
  # Provides a set of formatters for rendering the value of a `subject` in an RSpec example into
@@ -47,7 +47,8 @@ module RSpecDocumentation
47
47
  html: Formatters::Html,
48
48
  ansi: Formatters::Ansi,
49
49
  json: Formatters::Json,
50
- yaml: Formatters::Yaml
50
+ yaml: Formatters::Yaml,
51
+ xml: Formatters::Xml
51
52
  }.fetch(spec.format, Formatters::Ruby).new(subject: spec.subject)
52
53
  end
53
54
 
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Kramdown
4
+ module Converter
5
+ # Custom HTML converter for kramdown. Invoked with `Kramdown::Document#to_html_rspec_documentation`.
6
+ # Applies a custom CSS class to Markdown tables when rendered to HTML.
7
+ class HtmlRspecDocumentation < Converter::Html
8
+ def convert_table(element, indent)
9
+ element.attr['class'] ||= 'rspec-documentation-table table'
10
+ super
11
+ end
12
+ end
13
+ end
14
+ end
@@ -7,7 +7,7 @@ module RSpecDocumentation
7
7
  attr_reader :failures, :page_paths
8
8
 
9
9
  def initialize(page_paths:)
10
- @page_paths = page_paths.sort
10
+ @page_paths = page_paths.sort_by(&:to_s)
11
11
  @buffer = {}
12
12
  @failures = []
13
13
  end
@@ -12,7 +12,7 @@ module RSpecDocumentation
12
12
  end
13
13
 
14
14
  def html
15
- document.to_html
15
+ document.to_html_rspec_documentation
16
16
  end
17
17
 
18
18
  def execute_and_substitute_examples!
@@ -14,7 +14,7 @@ module RSpecDocumentation
14
14
  end
15
15
 
16
16
  def message
17
- "\n#{formatted_header}\n\n#{formatted_source}\n\n#{formatted_cause}\n\n"
17
+ "\n#{formatted_header}\n\n#{formatted_source}\n\n#{formatted_cause}\n\n#{formatted_backtrace}\n\n"
18
18
  end
19
19
 
20
20
  private
@@ -37,6 +37,13 @@ module RSpecDocumentation
37
37
  paintbrush { red indented(without_anonymous_group_text(cause.message)) }
38
38
  end
39
39
 
40
+ def formatted_backtrace
41
+ cause.backtrace
42
+ .take_while { |line| line.start_with?(Dir.pwd) }
43
+ .map { |line| paintbrush { red " #{line.sub("#{Dir.pwd}/", '')}" } }
44
+ .join("\n")
45
+ end
46
+
40
47
  def indented(text)
41
48
  text.split("\n").map { |line| " #{line}" }.join("\n")
42
49
  end
@@ -24,7 +24,6 @@ module RSpecDocumentation
24
24
  def subject
25
25
  raise Error, "Code block did not define an example (e.g. with `it`).\n#{spec}" if examples.empty?
26
26
  raise Error, "Code block did not define a subject:\n#{spec}" if subjects.empty?
27
- raise Error, "Cannot define more than one example per code block:\n#{spec}" if subjects.size > 1
28
27
 
29
28
  subjects.last
30
29
  end
@@ -72,9 +71,9 @@ module RSpecDocumentation
72
71
  def example_group
73
72
  # rubocop:disable Style/DocumentDynamicEvalDefinition, Security/Eval
74
73
  @example_group ||= binding.eval(
75
- <<-SPEC, __FILE__, __LINE__.to_i
74
+ <<-SPEC, path.to_s, location
76
75
  ::RSpec::Core::ExampleGroup.describe do
77
- after { RSpecDocumentation::Spec.subjects << subject }
76
+ after { RSpecDocumentation::Spec.subjects << subject if RSpecDocumentation::Spec.subjects.empty? }
78
77
  include_context '__rspec_documentation' do
79
78
  #{spec}
80
79
  end
@@ -17,6 +17,8 @@ require 'json'
17
17
  require 'yaml'
18
18
  require 'date'
19
19
  require 'time'
20
+ require 'pp' # rubocop:disable Lint/RedundantRequireStatement
21
+ require 'stringio'
20
22
 
21
23
  require_relative 'rspec_documentation/rspec'
22
24
  require_relative 'rspec_documentation/util'
@@ -35,12 +37,15 @@ require_relative 'rspec_documentation/documentation'
35
37
  require_relative 'rspec_documentation/page_collection'
36
38
  require_relative 'rspec_documentation/page_tree'
37
39
  require_relative 'rspec_documentation/page_tree_element'
40
+ require_relative 'rspec_documentation/kramdown_html_converter'
38
41
 
39
42
  # Internal module used by RSpec::Documentation to run examples and write output into an HTML document.
40
43
  module RSpecDocumentation
41
44
  class Error < StandardError; end
42
45
  class MissingFileError < Error; end
43
46
 
47
+ @hooks = {}
48
+
44
49
  def self.root
45
50
  Pathname.new(File.dirname(__dir__))
46
51
  end
@@ -56,6 +61,10 @@ module RSpecDocumentation
56
61
  ERB.new(root.join('lib/templates/themes', "#{name}.css").read).result(binding)
57
62
  end
58
63
 
64
+ def self.hook(name)
65
+ configuration.hooks.fetch(name, nil)&.call
66
+ end
67
+
59
68
  def self.context
60
69
  yield configuration.context if block_given?
61
70
  configuration.context
@@ -45,6 +45,15 @@ body {
45
45
  background-color: #fff;
46
46
  }
47
47
 
48
+ table.rspec-documentation-table td, table.rspec-documentation-table th {
49
+ border: 1px solid #cdcdcd;
50
+ padding: 0.5rem 1rem;
51
+ }
52
+
53
+ [data-bs-theme="dark"] table.rspec-documentation-table td, [data-bs-theme="dark"] table.rspec-documentation-table th {
54
+ border: 1px solid #4e4e4e;
55
+ }
56
+
48
57
  [data-bs-theme="dark"] .header-wrapper {
49
58
  background-color: #212121;
50
59
  }
@@ -2,6 +2,7 @@
2
2
  <head>
3
3
  <meta charset="utf-8" />
4
4
  <%= RSpecDocumentation.template(:stylesheet_links).result(binding) %>
5
+ <%= RSpecDocumentation.hook(:after_head) %>
5
6
  </head>
6
7
 
7
8
  <body>
@@ -10,6 +11,8 @@
10
11
  <%= header %>
11
12
  </div>
12
13
 
14
+ <%= RSpecDocumentation.hook(:after_header) %>
15
+
13
16
  <div class="row flex-nowrap">
14
17
  <div class="col-sm-2 fs-6 mt-1 ms-3 me-3">
15
18
  <ol class="page-tree hidden position-fixed">
@@ -19,9 +22,13 @@
19
22
  </ol>
20
23
  </div>
21
24
 
25
+ <%= RSpecDocumentation.hook(:before_content) %>
26
+
22
27
  <div class="col content" style="max-width: 80%">
23
28
  <%= html %>
29
+ <%= RSpecDocumentation.hook(:after_content) %>
24
30
  <%= footer %>
31
+ <%= RSpecDocumentation.hook(:after_footer) %>
25
32
  </div>
26
33
  </div>
27
34
  </div>
@@ -33,7 +33,7 @@
33
33
  <h5>Rendered Output</h5>
34
34
  <% end %>
35
35
  <hr/>
36
- <div class="p-3 mb-5 <%= render_raw? ? nil : 'code highlight' %>">
36
+ <div class="p-3 mb-5 border <%= render_raw? ? nil : 'code highlight' %>">
37
37
  <%= rendered_output %>
38
38
  </div>
39
39
  </div>
@@ -73,7 +73,7 @@
73
73
  id="rendered-<%= element_id %>"
74
74
  role="tabpanel"
75
75
  aria-labelledby="rendered-<%= element_id %>-tab">
76
- <div class="p-3 mb-5 mt-3 <%= render_raw? ? nil : 'code highlight' %>">
76
+ <div class="p-3 mb-5 border mt-3 <%= render_raw? ? nil : 'code highlight' %>">
77
77
  <%= rendered_output %>
78
78
  </div>
79
79
  </div>
@@ -18,6 +18,6 @@ it { is_expected.to eql 'my subject' }
18
18
  ```
19
19
  ````
20
20
 
21
- See the [Quickstart](introduction/quickstart.html) setup guide to build your first _RSpec Documentation_ project.
21
+ See the [Quickstart](quickstart.html) setup guide to build your first _RSpec Documentation_ project.
22
22
 
23
23
  Browse the [Examples](examples.html) to get a better idea of the typical usage patterns.
@@ -6,7 +6,7 @@ This example uses a regular ```` ```rspec ```` code block.
6
6
 
7
7
  The spec defines a `subject`, a simple comparison is made on its value to satisfy the test, and the value of `subject` is viewable on the _Output_ tab.
8
8
 
9
- Any _RSpec_ test is valid, including one-liner syntax like this:
9
+ Any _RSpec_ test that defines a `subject` is valid, including one-liner syntax like this:
10
10
 
11
11
  ### Markdown
12
12
 
@@ -25,27 +25,3 @@ subject { 'my value' }
25
25
 
26
26
  it { is_expected.to eql 'my value' }
27
27
  ```
28
-
29
- ## Regular `it` blocks
30
-
31
- ### Markdown
32
-
33
- ````markdown
34
- ```rspec
35
- subject { 'my value' }
36
-
37
- it 'contains some expected text' do
38
- expect(subject).to eql 'my value'
39
- end
40
- ```
41
- ````
42
-
43
- ### Output
44
-
45
- ```rspec
46
- subject { 'my other value' }
47
-
48
- it 'contains some expected text' do
49
- expect(subject).to include 'other value'
50
- end
51
- ```
@@ -0,0 +1,23 @@
1
+ # Multiple Expectations
2
+
3
+ Add as many expectations as you like:
4
+
5
+ ## Markdown
6
+
7
+ ````markdown
8
+ ```rspec
9
+ subject { 'my value' }
10
+
11
+ it { is_expected.to eql 'my value' }
12
+ it { is_expected.to be_a String }
13
+ ```
14
+ ````
15
+
16
+ ## Output
17
+
18
+ ```rspec
19
+ subject { 'my value' }
20
+
21
+ it { is_expected.to eql 'my value' }
22
+ it { is_expected.to be_a String }
23
+ ```
@@ -0,0 +1,23 @@
1
+ ## Regular `it` blocks
2
+
3
+ ### Markdown
4
+
5
+ ````markdown
6
+ ```rspec
7
+ subject { 'my other value' }
8
+
9
+ it 'contains some expected text' do
10
+ expect(subject).to eql 'other value'
11
+ end
12
+ ```
13
+ ````
14
+
15
+ ### Output
16
+
17
+ ```rspec
18
+ subject { 'my other value' }
19
+
20
+ it 'contains some expected text' do
21
+ expect(subject).to include 'other value'
22
+ end
23
+ ```
@@ -1,6 +1,6 @@
1
1
  # JSON
2
2
 
3
- If your code outputs _JSON_, use the ```` ```rspec:json``` ```` formatter to prettify your _JSON_ output. Note that your code must produce a raw _JSON_ string in order to use this formatter, it does not convert _Ruby_ objects into _JSON_.
3
+ If your code outputs _JSON_, use the ```` ```rspec:json ```` formatter to prettify your _JSON_ output. Note that your code must produce a raw _JSON_ string in order to use this formatter, it does not convert _Ruby_ objects into _JSON_.
4
4
 
5
5
  ## Markdown
6
6
 
@@ -1,7 +1,6 @@
1
1
  # YAML
2
2
 
3
-
4
- If your code outputs _YAML_, use the ```` ```rspec:yaml``` ```` formatter to prettify your _YAML_ output. Note that your code must produce a raw _YAML_ string in order to use this formatter, it does not convert _Ruby_ objects into _YAML_.
3
+ If your code outputs _YAML_, use the ```` ```rspec:yaml ```` formatter to prettify your _YAML_ output. Note that your code must produce a raw _YAML_ string in order to use this formatter, it does not convert _Ruby_ objects into _YAML_.
5
4
 
6
5
  ## Markdown
7
6
 
@@ -0,0 +1,25 @@
1
+ # XML
2
+
3
+ If your code outputs _XML_, use the ```` ```rspec:xml ```` formatter to prettify your _XML_ output. Note that your code must produce a raw _XML_ string in order to use this formatter, it does not convert _Ruby_ objects into _XML_.
4
+
5
+ ## Markdown
6
+
7
+ ````markdown
8
+ ```rspec:xml
9
+ subject { '<?xml version="1.0" encoding="UTF-8"?><foo><bar>baz</bar></foo>' }
10
+
11
+ it 'has expected key/value' do
12
+ expect(Nokogiri::XML.parse(subject).xpath('//foo/bar').text).to eql 'baz'
13
+ end
14
+ ```
15
+ ````
16
+
17
+ ## Output
18
+
19
+ ```rspec:xml
20
+ subject { '<?xml version="1.0" encoding="UTF-8"?><foo><bar>baz</bar></foo>' }
21
+
22
+ it 'has expected key/value' do
23
+ expect(Nokogiri::XML.parse(subject).xpath('//foo/bar').text).to eql 'baz'
24
+ end
25
+ ```
@@ -15,7 +15,7 @@ $ RSPEC_DOCUMENTATION_BUNDLE_PATH=/tmp/my-documentation-bundle/ rspec-documentat
15
15
 
16
16
  Created 13 pages.
17
17
 
18
- View your documentation here: /tmp/my-documentation-bundle/introduction.html
18
+ View your documentation here: /tmp/my-documentation-bundle/index.html
19
19
  ```
20
20
 
21
21
  ## `RSPEC_DOCUMENTATION_URL_ROOT`
@@ -29,5 +29,5 @@ $ RSPEC_DOCUMENTATION_URL_ROOT=/rspec-documentation rspec-documentation
29
29
 
30
30
  Created 13 pages.
31
31
 
32
- View your documentation here: /home/bob/dev/rspec-documentation/rspec-documentation/bundle/introduction.html
32
+ View your documentation here: /home/bob/dev/rspec-documentation/rspec-documentation/bundle/index.html
33
33
  ```
@@ -0,0 +1,31 @@
1
+ # Hooks
2
+
3
+ _RSpec::Documentation_ provides hooks for inserting content into various places rendered _HTML_ documents for each page of your documentation.
4
+
5
+ To configure hooks, add the following to `rspec-documentation/spec_helper.rb`:
6
+
7
+ ```ruby
8
+ RSpec::Documentation.configure do |config|
9
+ config.hook(:after_head) { '<style>h1 { font-size: 10rem; }</style>' }
10
+ end
11
+ ```
12
+
13
+ In practice you will most likely load content from a file using `File.read` or similar. You are free to store supplementary content anywhere in your project, e.g. you may want to create `rspec-documentation/assets` and create a hook such as:
14
+
15
+ ```ruby
16
+ RSpec::Documentation.configure do |config|
17
+ config.hook(:after_head) do
18
+ "<script>#{File.read('rspec-documentation/assets/fontawesome.js')}</script>"
19
+ end
20
+ end
21
+ ```
22
+
23
+ ## Available Hooks
24
+
25
+ | Hook | Description |
26
+ |-|-|
27
+ | `after_head` | Inserts content immediately before the closing `</head>` tag, after the default head content. Use this to override any styling or add `<script>` and `<link>` tags. |
28
+ | `after_header` | Inserts content immediately after the main document header. Use this to insert custom content underneath the header for each page. |
29
+ | `before_content` | Inserts content immediately before the main document content, between the navigation tree and each rendered documentation page. |
30
+ | `after_content` | Inserts content immediately after the main documentation content, before the footer. |
31
+ | `after_footer` | Inserts content immediately below the footer. |
@@ -8,6 +8,6 @@ $ RSPEC_DOCUMENTATION_URL_ROOT='/rspec-documentation' rspec-documentation
8
8
  $ rsync --delete -r rspec-documentation/bundle/ docs01.bob.frl:/mnt/docs/rspec-documentation/
9
9
  ```
10
10
 
11
- This command was used to publish this documentation to an _AWS EC2_ instance which is serving the content that you are reading now. You are welcome to view the [Terraform code](https://github.com/bobf/docs.bob.frl-terraform) that manages this infrastructure.
11
+ This command was used to publish the documentation you are currently reading to an _AWS EC2_ instance which is serving the content that you are reading now. You are welcome to view the [Terraform code](https://github.com/bobf/docs.bob.frl-terraform) that manages this infrastructure.
12
12
 
13
- You can use any web host you like to serve this documentation since the build output is exclusively static _HTML_ plus a _Javascript_ and _CSS_ bundle. [Surge](https://surge.sh) is a good place to start if you are looking for a simple _CDN_ to get started with.
13
+ You can use any web host you like to serve this documentation since the build output is exclusively static _HTML_ plus a self-contained _Javascript_ and _CSS_ bundle. [Surge](https://surge.sh) is a good place to start if you are looking for a simple _CDN_ to get started with.
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'nokogiri'
4
+
3
5
  RSpec::Documentation.configure do |config|
4
6
  config.context do
5
7
  let(:foo) { 'baz' }
@@ -31,6 +31,7 @@ Gem::Specification.new do |spec|
31
31
  spec.add_runtime_dependency 'htmlbeautifier', '~> 1.4'
32
32
  spec.add_runtime_dependency 'kramdown', '~> 2.4'
33
33
  spec.add_runtime_dependency 'kramdown-parser-gfm', '~> 1.1'
34
+ spec.add_runtime_dependency 'nokogiri', '~> 1.15'
34
35
  spec.add_runtime_dependency 'paintbrush', '~> 0.1.3'
35
36
  spec.add_runtime_dependency 'redcarpet', '~> 3.6'
36
37
  spec.add_runtime_dependency 'rouge', '~> 4.1'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rspec-documentation
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bob Farrell
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-06-04 00:00:00.000000000 Z
11
+ date: 2023-06-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: htmlbeautifier
@@ -52,6 +52,20 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '1.1'
55
+ - !ruby/object:Gem::Dependency
56
+ name: nokogiri
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.15'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.15'
55
69
  - !ruby/object:Gem::Dependency
56
70
  name: paintbrush
57
71
  requirement: !ruby/object:Gem::Requirement
@@ -136,9 +150,11 @@ files:
136
150
  - lib/rspec_documentation/formatters/html.rb
137
151
  - lib/rspec_documentation/formatters/json.rb
138
152
  - lib/rspec_documentation/formatters/ruby.rb
153
+ - lib/rspec_documentation/formatters/xml.rb
139
154
  - lib/rspec_documentation/formatters/yaml.rb
140
155
  - lib/rspec_documentation/html_element.rb
141
156
  - lib/rspec_documentation/javascript_bundle.rb
157
+ - lib/rspec_documentation/kramdown_html_converter.rb
142
158
  - lib/rspec_documentation/markdown_renderer.rb
143
159
  - lib/rspec_documentation/page_collection.rb
144
160
  - lib/rspec_documentation/page_tree.rb
@@ -196,23 +212,27 @@ files:
196
212
  - rspec-documentation-0.1.0.gem
197
213
  - rspec-documentation.gemspec
198
214
  - rspec-documentation/pages/000-Introduction.md
199
- - rspec-documentation/pages/000-Introduction/000-Quickstart.md
215
+ - rspec-documentation/pages/001-Quickstart.md
200
216
  - rspec-documentation/pages/010-File System.md
201
217
  - rspec-documentation/pages/010-File System/000-Ordering.md
202
218
  - rspec-documentation/pages/010-File System/010-Documentation Bundle.md
203
219
  - rspec-documentation/pages/020-Running Tests.md
204
220
  - rspec-documentation/pages/030-Examples.md
205
- - rspec-documentation/pages/030-Examples/010-Basic.md
221
+ - rspec-documentation/pages/030-Examples/010-Basic Usage.md
222
+ - rspec-documentation/pages/030-Examples/011-Multiple Expectations.md
223
+ - rspec-documentation/pages/030-Examples/012-Regular it Blocks.md
206
224
  - rspec-documentation/pages/030-Examples/020-HTML.md
207
225
  - rspec-documentation/pages/030-Examples/030-ANSI.md
208
226
  - rspec-documentation/pages/030-Examples/040-JSON.md
209
227
  - rspec-documentation/pages/030-Examples/050-YAML.md
228
+ - rspec-documentation/pages/030-Examples/060-XML.md
210
229
  - rspec-documentation/pages/040-Spec Helper.md
211
230
  - rspec-documentation/pages/050-Linking.md
212
231
  - rspec-documentation/pages/060-Configuration.md
213
232
  - rspec-documentation/pages/060-Configuration/010-Context.md
214
233
  - rspec-documentation/pages/060-Configuration/020-Build Paths.md
215
234
  - rspec-documentation/pages/060-Configuration/030-Attribution.md
235
+ - rspec-documentation/pages/060-Configuration/040-Hooks.md
216
236
  - rspec-documentation/pages/070-Publishing.md
217
237
  - rspec-documentation/pages/500-License.md
218
238
  - rspec-documentation/spec_helper.rb