govuk_tech_docs 2.0.13 → 2.2.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.

Potentially problematic release.


This version of govuk_tech_docs might be problematic. Click here for more details.

Files changed (31) hide show
  1. checksums.yaml +4 -4
  2. data/.github/pull_request_template.md +1 -0
  3. data/.ruby-version +1 -1
  4. data/.travis.yml +3 -0
  5. data/CHANGELOG.md +54 -1
  6. data/README.md +15 -22
  7. data/example/.ruby-version +1 -1
  8. data/example/source/index.html.md.erb +1 -0
  9. data/example/source/prevent-index-page.html.md +10 -0
  10. data/govuk_tech_docs.gemspec +1 -7
  11. data/lib/assets/javascripts/_modules/search.js +13 -2
  12. data/lib/assets/javascripts/_modules/table-of-contents.js +9 -14
  13. data/lib/assets/stylesheets/modules/_page-review.scss +3 -5
  14. data/lib/assets/stylesheets/modules/_search.scss +47 -9
  15. data/lib/assets/stylesheets/modules/_technical-documentation.scss +11 -2
  16. data/lib/assets/stylesheets/modules/_toc.scss +12 -2
  17. data/lib/govuk_tech_docs/api_reference/api_reference_extension.rb +0 -1
  18. data/lib/govuk_tech_docs/api_reference/api_reference_renderer.rb +70 -186
  19. data/lib/govuk_tech_docs/api_reference/templates/api_reference_full.html.erb +3 -2
  20. data/lib/govuk_tech_docs/api_reference/templates/operation.html.erb +1 -1
  21. data/lib/govuk_tech_docs/api_reference/templates/parameters.html.erb +1 -1
  22. data/lib/govuk_tech_docs/api_reference/templates/responses.html.erb +1 -1
  23. data/lib/govuk_tech_docs/api_reference/templates/schema.html.erb +12 -12
  24. data/lib/govuk_tech_docs/meta_tags.rb +27 -8
  25. data/lib/govuk_tech_docs/tech_docs_html_renderer.rb +75 -1
  26. data/lib/govuk_tech_docs/version.rb +1 -1
  27. data/lib/source/images/search-button.png +0 -0
  28. data/lib/source/layouts/_search.erb +10 -4
  29. data/lib/source/layouts/core.erb +7 -10
  30. data/package-lock.json +3 -3
  31. metadata +7 -74
@@ -9,7 +9,7 @@
9
9
  <tr>
10
10
  <td><%= key %></td>
11
11
  <td>
12
- <%= markdown(response.description) %>
12
+ <%= response.description_html %>
13
13
  <% if response.content['application/json']
14
14
  if response.content['application/json']["example"]
15
15
  request_body = json_prettyprint(response.content['application/json']["example"])
@@ -1,26 +1,26 @@
1
1
  <h3 id="<%= id = 'schema-' + title; id.parameterize %>"><%= title %></h3>
2
- <%= markdown(schema.description) %>
2
+ <%= schema.description_html %>
3
3
  <% if properties.any? %>
4
- <table>
4
+ <table class='<%= id.parameterize %>'>
5
5
  <thead>
6
6
  <tr><th>Name</th><th>Type</th><th>Required</th><th>Description</th><th>Schema</th></tr>
7
7
  </thead>
8
8
  <tbody>
9
- <% properties.each do |property| %>
9
+ <% properties.each do |property_name, property_attributes| %>
10
10
  <tr>
11
- <td><%= property[0] %></td>
12
- <td><%= property[1].type %></td>
13
- <td><%= property[1].required.present? %></td>
14
- <td><%= markdown(property[1].description) %></td>
11
+ <td><%= property_name %></td>
12
+ <td><%= property_attributes.type %></td>
13
+ <td><%= schema.requires?(property_name) %></td>
14
+ <td><%= property_attributes.description_html %></td>
15
15
  <td>
16
16
  <%=
17
- schema = property[1]
17
+ linked_schema = property_attributes
18
18
  # If property is an array, check the items property for a reference.
19
- if property[1].type == 'array'
20
- schema = property[1]['items']
19
+ if property_attributes.type == 'array'
20
+ linked_schema = property_attributes['items']
21
21
  end
22
- # Only print a link if it's a referenced object.
23
- get_schema_link(schema) if schema.node_context.referenced_by.to_s.include? '#/components/schemas' and !schema.node_context.source_location.to_s.include? '/properties/' %>
22
+ # Only print a link if it's a named schema
23
+ get_schema_link(linked_schema) if linked_schema.name %>
24
24
  </td>
25
25
  </tr>
26
26
  <% end %>
@@ -8,12 +8,8 @@ module GovukTechDocs
8
8
  def tags
9
9
  all_tags = {
10
10
  "description" => page_description,
11
- "og:description" => page_description,
12
- "og:image" => page_image,
13
- "og:site_name" => site_name,
14
- "og:title" => page_title,
15
- "og:type" => "object",
16
- "og:url" => canonical_url,
11
+ "google-site-verification" => google_site_verification,
12
+ "robots" => robots,
17
13
  "twitter:card" => "summary",
18
14
  "twitter:domain" => URI.parse(host).host,
19
15
  "twitter:image" => page_image,
@@ -24,6 +20,21 @@ module GovukTechDocs
24
20
  Hash[all_tags.select { |_k, v| v }]
25
21
  end
26
22
 
23
+ # OpenGraph uses the non-standard property attribute instead of name, so we
24
+ # return these separately so we can output them correctly.
25
+ def opengraph_tags
26
+ all_opengraph_tags = {
27
+ "og:description" => page_description,
28
+ "og:image" => page_image,
29
+ "og:site_name" => site_name,
30
+ "og:title" => page_title,
31
+ "og:type" => "object",
32
+ "og:url" => canonical_url,
33
+ }
34
+
35
+ Hash[all_opengraph_tags.select { |_k, v| v }]
36
+ end
37
+
27
38
  def browser_title
28
39
  [page_title, site_name].select(&:present?).uniq.join(" - ")
29
40
  end
@@ -45,11 +56,19 @@ module GovukTechDocs
45
56
  end
46
57
 
47
58
  def page_description
48
- locals[:description] || frontmatter.description
59
+ locals[:description] || frontmatter[:description]
49
60
  end
50
61
 
51
62
  def page_title
52
- locals[:title] || frontmatter.title
63
+ locals[:title] || frontmatter[:title]
64
+ end
65
+
66
+ def robots
67
+ "noindex" if config[:tech_docs][:prevent_indexing] || frontmatter[:prevent_indexing]
68
+ end
69
+
70
+ def google_site_verification
71
+ config[:tech_docs][:google_site_verification]
53
72
  end
54
73
 
55
74
  def host
@@ -20,7 +20,7 @@ module GovukTechDocs
20
20
  end
21
21
 
22
22
  def image(link, *args)
23
- %(<a href="#{link}" target="_blank" rel="noopener noreferrer">#{super}</a>)
23
+ %(<a href="#{link}" rel="noopener noreferrer">#{super}</a>)
24
24
  end
25
25
 
26
26
  def table(header, body)
@@ -30,5 +30,79 @@ module GovukTechDocs
30
30
  </table>
31
31
  </div>)
32
32
  end
33
+
34
+ def table_row(body)
35
+ # Post-processing the table_cell HTML to implement row headings.
36
+ #
37
+ # Doing this in table_row instead of table_cell is a hack.
38
+ #
39
+ # Ideally, we'd use the table_cell callback like:
40
+ #
41
+ # def table_cell(content, alignment, header)
42
+ # if header
43
+ # "<th>#{content}</th>"
44
+ # elsif content.start_with? "# "
45
+ # "<th scope="row">#{content.sub(/^# /, "")}</th>"
46
+ # else
47
+ # "<td>#{content}</td>"
48
+ # end
49
+ # end
50
+ #
51
+ # Sadly, Redcarpet's table_cell callback doesn't allow you to distinguish
52
+ # table cells and table headings until https://github.com/vmg/redcarpet/commit/27dfb2a738a23aadd286ac9e7ecd61c4545d29de
53
+ # (which is not yet released). This means we can't use the table_cell callback
54
+ # without breaking column headers, so we're having to hack it in table_row.
55
+
56
+ fragment = Nokogiri::HTML::DocumentFragment.parse(body)
57
+ fragment.children.each do |cell|
58
+ next unless cell.name == "td"
59
+ next if cell.children.empty?
60
+
61
+ first_child = cell.children.first
62
+ next unless first_child.text?
63
+
64
+ leading_text = first_child.content
65
+ next unless leading_text.start_with?("#")
66
+
67
+ cell.name = "th"
68
+ cell["scope"] = "row"
69
+ first_child.content = leading_text.sub(/# */, "")
70
+ end
71
+
72
+ tr = Nokogiri::XML::Node.new "tr", fragment
73
+ tr.children = fragment.children
74
+
75
+ tr.to_html
76
+ end
77
+
78
+ def block_code(text, lang)
79
+ if defined?(super)
80
+ # Post-processing the block_code HTML to implement tabbable code blocks.
81
+ #
82
+ # Middleman monkey patches the Middleman::Renderers::MiddlemanRedcarpetHTML
83
+ # to include Middleman::Syntax::RedcarpetCodeRenderer. This defines its own
84
+ # version of `block_code(text, lang)` which we can call with `super`.
85
+
86
+ fragment = Nokogiri::HTML::DocumentFragment.parse(super)
87
+ fragment.traverse do |element|
88
+ if element.name == "pre" && element["tabindex"].nil?
89
+ element["tabindex"] = "0"
90
+ end
91
+ end
92
+ fragment.to_html
93
+ else
94
+ # If syntax highlighting with redcarpet isn't enabled, super will not
95
+ # be `defined?`, so we can jump straight to rendering HTML ourselves.
96
+
97
+ fragment = Nokogiri::HTML::DocumentFragment.parse("")
98
+ pre = Nokogiri::XML::Node.new "pre", fragment
99
+ pre["tabindex"] = "0"
100
+ code = Nokogiri::XML::Node.new "code", fragment
101
+ code["class"] = lang
102
+ code.content = text
103
+ pre.add_child code
104
+ pre.to_html
105
+ end
106
+ end
33
107
  end
34
108
  end
@@ -1,3 +1,3 @@
1
1
  module GovukTechDocs
2
- VERSION = "2.0.13".freeze
2
+ VERSION = "2.2.2".freeze
3
3
  end
Binary file
@@ -1,16 +1,22 @@
1
1
  <% if config[:tech_docs][:enable_search] %>
2
2
  <div class="search" data-module="search">
3
- <form action="https://www.google.co.uk/search" method="get" role="search">
3
+ <form action="https://www.google.co.uk/search" method="get" role="search" class="search__form govuk-!-margin-bottom-4">
4
4
  <input type="hidden" name="as_sitesearch" value="<%= config[:tech_docs][:host] %>"/>
5
- <label class="govuk-label search__label" for="search">
5
+ <label class="govuk-label search__label" for="search" aria-hidden="true">
6
6
  Search (via Google)
7
7
  </label>
8
- <input class="govuk-input govuk-!-margin-bottom-4" id="search" name="q" type="text" aria-controls="search-results" placeholder="Search">
8
+ <input
9
+ type="text"
10
+ id="search" name="q"
11
+ class="govuk-input govuk-!-margin-bottom-0 search__input"
12
+ aria-controls="search-results"
13
+ placeholder="Search">
14
+ <button type="submit" class="search__button">Search</button>
9
15
  </form>
10
16
  <div id="search-results" class="search-results" aria-hidden="true" role="dialog" aria-labelledby="search-results-title">
11
17
  <div class="search-results__inner">
12
18
  <button class="search-results__close">Close<span class="search-results__close-label"> search results</span></button>
13
- <h2 id="search-results-title" class="search-results__title" aria-live="polite">Results</h2>
19
+ <h2 id="search-results-title" class="search-results__title" aria-live="assertive" role="alert">Results</h2>
14
20
  <div class="search-results__content"></div>
15
21
  </div>
16
22
  </div>
@@ -4,9 +4,6 @@
4
4
  <meta content="IE=edge" http-equiv="X-UA-Compatible">
5
5
  <meta charset="utf-8">
6
6
  <meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover">
7
- <% if config[:tech_docs][:prevent_indexing] %>
8
- <meta name="robots" content="noindex">
9
- <% end %>
10
7
 
11
8
  <title><%= meta_tags.browser_title %></title>
12
9
 
@@ -14,11 +11,11 @@
14
11
 
15
12
  <link rel="canonical" href="<%= meta_tags.canonical_url %>">
16
13
 
17
- <% if config[:tech_docs][:google_site_verification] %>
18
- <meta name="google-site-verification" content="<%= config[:tech_docs][:google_site_verification] %>" />
14
+ <% meta_tags.tags.each do |name, content| %>
15
+ <%= tag :meta, name: name, content: content %>
19
16
  <% end %>
20
17
 
21
- <% meta_tags.tags.each do |property, content| %>
18
+ <% meta_tags.opengraph_tags.each do |property, content| %>
22
19
  <%= tag :meta, property: property, content: content %>
23
20
  <% end %>
24
21
 
@@ -37,18 +34,18 @@
37
34
 
38
35
  <% if content_for? :sidebar %>
39
36
  <div id="toc-heading" class="toc-show fixedsticky">
40
- <a href="#toc" class="toc-show__label js-toc-show" aria-controls="toc">
37
+ <button type="button" class="toc-show__label js-toc-show" aria-controls="toc">
41
38
  Table of contents <span class="toc-show__icon"></span>
42
- </a>
39
+ </button>
43
40
  </div>
44
41
  <% end %>
45
42
 
46
43
  <div class="app-pane__body"<%= " data-module=\"#{yield_content(:toc_module)}\"" if content_for? :toc_module %>>
47
44
  <% if content_for? :sidebar %>
48
45
  <div class="app-pane__toc">
49
- <div class="toc" data-module="table-of-contents">
46
+ <div class="toc" data-module="table-of-contents" tabindex="-1" aria-label="Table of contents" role="dialog">
50
47
  <%= partial "layouts/search" %>
51
- <a href="#" class="toc__close js-toc-close" aria-controls="toc" aria-label="Hide table of contents"></a>
48
+ <button type="button" class="toc__close js-toc-close" aria-controls="toc" aria-label="Hide table of contents"></button>
52
49
  <nav id="toc" class="js-toc-list toc__list" aria-labelledby="toc-heading"<%= " data-module=\"collapsible-navigation\"" if config[:tech_docs][:collapsible_nav] %>>
53
50
  <%= yield_content :sidebar %>
54
51
  </nav>
data/package-lock.json CHANGED
@@ -1108,9 +1108,9 @@
1108
1108
  }
1109
1109
  },
1110
1110
  "lodash": {
1111
- "version": "4.17.15",
1112
- "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.15.tgz",
1113
- "integrity": "sha512-8xOcRHvCjnocdS5cpwXQXVzmmh5e5+saE2QGoeQmbKmRS6J3VQppPOIt0MnmE+4xlZoumy0GPG0D0MVIQbNA1A==",
1111
+ "version": "4.17.19",
1112
+ "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.19.tgz",
1113
+ "integrity": "sha512-JNvd8XER9GQX0v2qJgsaN/mzFCNA5BRe/j8JN9d+tWyGLSodKQHKFicdwNYzWwI3wjRnaKPsGj1XkBjx/F96DQ==",
1114
1114
  "dev": true
1115
1115
  },
1116
1116
  "loose-envify": {
metadata CHANGED
@@ -1,29 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: govuk_tech_docs
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.13
4
+ version: 2.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Government Digital Service
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-07-28 00:00:00.000000000 Z
11
+ date: 2021-03-25 00:00:00.000000000 Z
12
12
  dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: activesupport
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - ">="
18
- - !ruby/object:Gem::Version
19
- version: '0'
20
- type: :runtime
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - ">="
25
- - !ruby/object:Gem::Version
26
- version: '0'
27
13
  - !ruby/object:Gem::Dependency
28
14
  name: chronic
29
15
  requirement: !ruby/object:Gem::Requirement
@@ -156,28 +142,14 @@ dependencies:
156
142
  requirements:
157
143
  - - "~>"
158
144
  - !ruby/object:Gem::Version
159
- version: 0.5.0
145
+ version: 0.9.0
160
146
  type: :runtime
161
147
  prerelease: false
162
148
  version_requirements: !ruby/object:Gem::Requirement
163
149
  requirements:
164
150
  - - "~>"
165
151
  - !ruby/object:Gem::Version
166
- version: 0.5.0
167
- - !ruby/object:Gem::Dependency
168
- name: pry
169
- requirement: !ruby/object:Gem::Requirement
170
- requirements:
171
- - - ">="
172
- - !ruby/object:Gem::Version
173
- version: '0'
174
- type: :runtime
175
- prerelease: false
176
- version_requirements: !ruby/object:Gem::Requirement
177
- requirements:
178
- - - ">="
179
- - !ruby/object:Gem::Version
180
- version: '0'
152
+ version: 0.9.0
181
153
  - !ruby/object:Gem::Dependency
182
154
  name: redcarpet
183
155
  requirement: !ruby/object:Gem::Requirement
@@ -192,48 +164,6 @@ dependencies:
192
164
  - - "~>"
193
165
  - !ruby/object:Gem::Version
194
166
  version: 3.5.0
195
- - !ruby/object:Gem::Dependency
196
- name: sass
197
- requirement: !ruby/object:Gem::Requirement
198
- requirements:
199
- - - ">="
200
- - !ruby/object:Gem::Version
201
- version: '0'
202
- type: :runtime
203
- prerelease: false
204
- version_requirements: !ruby/object:Gem::Requirement
205
- requirements:
206
- - - ">="
207
- - !ruby/object:Gem::Version
208
- version: '0'
209
- - !ruby/object:Gem::Dependency
210
- name: sprockets
211
- requirement: !ruby/object:Gem::Requirement
212
- requirements:
213
- - - "~>"
214
- - !ruby/object:Gem::Version
215
- version: 4.0.0
216
- type: :runtime
217
- prerelease: false
218
- version_requirements: !ruby/object:Gem::Requirement
219
- requirements:
220
- - - "~>"
221
- - !ruby/object:Gem::Version
222
- version: 4.0.0
223
- - !ruby/object:Gem::Dependency
224
- name: bundler
225
- requirement: !ruby/object:Gem::Requirement
226
- requirements:
227
- - - "~>"
228
- - !ruby/object:Gem::Version
229
- version: 2.1.4
230
- type: :development
231
- prerelease: false
232
- version_requirements: !ruby/object:Gem::Requirement
233
- requirements:
234
- - - "~>"
235
- - !ruby/object:Gem::Version
236
- version: 2.1.4
237
167
  - !ruby/object:Gem::Dependency
238
168
  name: byebug
239
169
  requirement: !ruby/object:Gem::Requirement
@@ -327,6 +257,7 @@ extensions: []
327
257
  extra_rdoc_files: []
328
258
  files:
329
259
  - ".editorconfig"
260
+ - ".github/pull_request_template.md"
330
261
  - ".gitignore"
331
262
  - ".nvmrc"
332
263
  - ".rspec"
@@ -363,6 +294,7 @@ files:
363
294
  - example/source/nested-page/index.html.md
364
295
  - example/source/not-expired-page.html.md
365
296
  - example/source/pets.yml
297
+ - example/source/prevent-index-page.html.md
366
298
  - example/source/stylesheets/print.css.scss
367
299
  - example/source/stylesheets/screen-old-ie.css.scss
368
300
  - example/source/stylesheets/screen.css.scss
@@ -432,6 +364,7 @@ files:
432
364
  - lib/source/images/govuk-icn-close@2x.png
433
365
  - lib/source/images/govuk-icn-numbered-list.png
434
366
  - lib/source/images/govuk-icn-numbered-list@2x.png
367
+ - lib/source/images/search-button.png
435
368
  - lib/source/images/search-result-caret.svg
436
369
  - lib/source/layouts/_analytics.erb
437
370
  - lib/source/layouts/_footer.erb