govuk_tech_docs 2.2.0 → 2.4.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


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

Files changed (148) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/.nvmrc +1 -1
  4. data/.travis.yml +2 -0
  5. data/CHANGELOG.md +26 -1
  6. data/govuk_tech_docs.gemspec +3 -8
  7. data/lib/assets/javascripts/_modules/collapsible-navigation.js +7 -7
  8. data/lib/assets/javascripts/_modules/in-page-navigation.js +2 -4
  9. data/lib/assets/stylesheets/_govuk_tech_docs.scss +9 -10
  10. data/lib/assets/stylesheets/modules/_search.scss +8 -25
  11. data/lib/assets/stylesheets/modules/_technical-documentation.scss +1 -1
  12. data/lib/assets/stylesheets/modules/_toc.scss +11 -11
  13. data/lib/govuk_tech_docs/api_reference/api_reference_extension.rb +0 -1
  14. data/lib/govuk_tech_docs/api_reference/api_reference_renderer.rb +70 -186
  15. data/lib/govuk_tech_docs/api_reference/templates/api_reference_full.html.erb +3 -2
  16. data/lib/govuk_tech_docs/api_reference/templates/operation.html.erb +1 -1
  17. data/lib/govuk_tech_docs/api_reference/templates/parameters.html.erb +1 -1
  18. data/lib/govuk_tech_docs/api_reference/templates/responses.html.erb +1 -1
  19. data/lib/govuk_tech_docs/api_reference/templates/schema.html.erb +12 -12
  20. data/lib/govuk_tech_docs/table_of_contents/heading.rb +5 -1
  21. data/lib/govuk_tech_docs/table_of_contents/heading_tree_renderer.rb +2 -2
  22. data/lib/govuk_tech_docs/table_of_contents/helpers.rb +6 -3
  23. data/lib/govuk_tech_docs/tech_docs_html_renderer.rb +1 -1
  24. data/lib/govuk_tech_docs/version.rb +1 -1
  25. data/lib/source/layouts/_header.erb +6 -2
  26. data/lib/source/layouts/_search.erb +1 -1
  27. data/node_modules/govuk-frontend/govuk/_base.scss +3 -0
  28. data/node_modules/govuk-frontend/govuk/all.js +306 -94
  29. data/node_modules/govuk-frontend/govuk/all.scss +1 -3
  30. data/node_modules/govuk-frontend/govuk/components/_all.scss +33 -29
  31. data/node_modules/govuk-frontend/govuk/components/accordion/_accordion.scss +2 -208
  32. data/node_modules/govuk-frontend/govuk/components/accordion/_index.scss +197 -0
  33. data/node_modules/govuk-frontend/govuk/components/accordion/accordion.js +1 -1
  34. data/node_modules/govuk-frontend/govuk/components/back-link/_back-link.scss +2 -65
  35. data/node_modules/govuk-frontend/govuk/components/back-link/_index.scss +99 -0
  36. data/node_modules/govuk-frontend/govuk/components/breadcrumbs/_breadcrumbs.scss +2 -118
  37. data/node_modules/govuk-frontend/govuk/components/breadcrumbs/_index.scss +138 -0
  38. data/node_modules/govuk-frontend/govuk/components/button/_button.scss +2 -284
  39. data/node_modules/govuk-frontend/govuk/components/button/_index.scss +288 -0
  40. data/node_modules/govuk-frontend/govuk/components/character-count/_character-count.scss +2 -31
  41. data/node_modules/govuk-frontend/govuk/components/character-count/_index.scss +25 -0
  42. data/node_modules/govuk-frontend/govuk/components/character-count/character-count.js +17 -9
  43. data/node_modules/govuk-frontend/govuk/components/checkboxes/_checkboxes.scss +2 -308
  44. data/node_modules/govuk-frontend/govuk/components/checkboxes/_index.scss +320 -0
  45. data/node_modules/govuk-frontend/govuk/components/checkboxes/checkboxes.js +129 -24
  46. data/node_modules/govuk-frontend/govuk/components/cookie-banner/_cookie-banner.scss +2 -0
  47. data/node_modules/govuk-frontend/govuk/components/cookie-banner/_index.scss +51 -0
  48. data/node_modules/govuk-frontend/govuk/components/date-input/_date-input.scss +2 -30
  49. data/node_modules/govuk-frontend/govuk/components/date-input/_index.scss +26 -0
  50. data/node_modules/govuk-frontend/govuk/components/details/_details.scss +2 -88
  51. data/node_modules/govuk-frontend/govuk/components/details/_index.scss +87 -0
  52. data/node_modules/govuk-frontend/govuk/components/error-message/_error-message.scss +2 -15
  53. data/node_modules/govuk-frontend/govuk/components/error-message/_index.scss +11 -0
  54. data/node_modules/govuk-frontend/govuk/components/error-summary/_error-summary.scss +2 -59
  55. data/node_modules/govuk-frontend/govuk/components/error-summary/_index.scss +43 -0
  56. data/node_modules/govuk-frontend/govuk/components/fieldset/_fieldset.scss +2 -68
  57. data/node_modules/govuk-frontend/govuk/components/fieldset/_index.scss +64 -0
  58. data/node_modules/govuk-frontend/govuk/components/file-upload/_file-upload.scss +2 -81
  59. data/node_modules/govuk-frontend/govuk/components/file-upload/_index.scss +49 -0
  60. data/node_modules/govuk-frontend/govuk/components/footer/_footer.scss +2 -244
  61. data/node_modules/govuk-frontend/govuk/components/footer/_index.scss +241 -0
  62. data/node_modules/govuk-frontend/govuk/components/header/_header.scss +2 -318
  63. data/node_modules/govuk-frontend/govuk/components/header/_index.scss +331 -0
  64. data/node_modules/govuk-frontend/govuk/components/header/header.js +665 -316
  65. data/node_modules/govuk-frontend/govuk/components/hint/_hint.scss +2 -50
  66. data/node_modules/govuk-frontend/govuk/components/hint/_index.scss +44 -0
  67. data/node_modules/govuk-frontend/govuk/components/input/_index.scss +191 -0
  68. data/node_modules/govuk-frontend/govuk/components/input/_input.scss +2 -103
  69. data/node_modules/govuk-frontend/govuk/components/inset-text/_index.scss +24 -0
  70. data/node_modules/govuk-frontend/govuk/components/inset-text/_inset-text.scss +2 -28
  71. data/node_modules/govuk-frontend/govuk/components/label/_index.scss +41 -0
  72. data/node_modules/govuk-frontend/govuk/components/label/_label.scss +2 -45
  73. data/node_modules/govuk-frontend/govuk/components/notification-banner/_index.scss +89 -0
  74. data/node_modules/govuk-frontend/govuk/components/notification-banner/_notification-banner.scss +2 -0
  75. data/node_modules/govuk-frontend/govuk/components/notification-banner/notification-banner.js +61 -0
  76. data/node_modules/govuk-frontend/govuk/components/panel/_index.scss +44 -0
  77. data/node_modules/govuk-frontend/govuk/components/panel/_panel.scss +2 -44
  78. data/node_modules/govuk-frontend/govuk/components/phase-banner/_index.scss +27 -0
  79. data/node_modules/govuk-frontend/govuk/components/phase-banner/_phase-banner.scss +2 -31
  80. data/node_modules/govuk-frontend/govuk/components/radios/_index.scss +342 -0
  81. data/node_modules/govuk-frontend/govuk/components/radios/_radios.scss +2 -346
  82. data/node_modules/govuk-frontend/govuk/components/radios/radios.js +76 -28
  83. data/node_modules/govuk-frontend/govuk/components/select/_index.scss +49 -0
  84. data/node_modules/govuk-frontend/govuk/components/select/_select.scss +2 -57
  85. data/node_modules/govuk-frontend/govuk/components/skip-link/_index.scss +36 -0
  86. data/node_modules/govuk-frontend/govuk/components/skip-link/_skip-link.scss +2 -37
  87. data/node_modules/govuk-frontend/govuk/components/summary-list/_index.scss +145 -0
  88. data/node_modules/govuk-frontend/govuk/components/summary-list/_summary-list.scss +2 -157
  89. data/node_modules/govuk-frontend/govuk/components/table/_index.scss +71 -0
  90. data/node_modules/govuk-frontend/govuk/components/table/_table.scss +2 -54
  91. data/node_modules/govuk-frontend/govuk/components/tabs/_index.scss +130 -0
  92. data/node_modules/govuk-frontend/govuk/components/tabs/_tabs.scss +2 -142
  93. data/node_modules/govuk-frontend/govuk/components/tag/_index.scss +86 -0
  94. data/node_modules/govuk-frontend/govuk/components/tag/_tag.scss +2 -91
  95. data/node_modules/govuk-frontend/govuk/components/textarea/_index.scss +47 -0
  96. data/node_modules/govuk-frontend/govuk/components/textarea/_textarea.scss +2 -55
  97. data/node_modules/govuk-frontend/govuk/components/warning-text/_index.scss +66 -0
  98. data/node_modules/govuk-frontend/govuk/components/warning-text/_warning-text.scss +2 -60
  99. data/node_modules/govuk-frontend/govuk/core/_global-styles.scss +5 -3
  100. data/node_modules/govuk-frontend/govuk/core/_links.scss +13 -3
  101. data/node_modules/govuk-frontend/govuk/core/_lists.scss +17 -3
  102. data/node_modules/govuk-frontend/govuk/core/_section-break.scss +5 -3
  103. data/node_modules/govuk-frontend/govuk/core/_template.scss +5 -4
  104. data/node_modules/govuk-frontend/govuk/core/_typography.scss +5 -3
  105. data/node_modules/govuk-frontend/govuk/helpers/_clearfix.scss +1 -1
  106. data/node_modules/govuk-frontend/govuk/helpers/_colour.scss +1 -1
  107. data/node_modules/govuk-frontend/govuk/helpers/_device-pixels.scss +3 -3
  108. data/node_modules/govuk-frontend/govuk/helpers/_focused.scss +1 -1
  109. data/node_modules/govuk-frontend/govuk/helpers/_font-faces.scss +9 -11
  110. data/node_modules/govuk-frontend/govuk/helpers/_grid.scss +2 -1
  111. data/node_modules/govuk-frontend/govuk/helpers/_links.scss +246 -33
  112. data/node_modules/govuk-frontend/govuk/helpers/_media-queries.scss +2 -6
  113. data/node_modules/govuk-frontend/govuk/helpers/_shape-arrow.scss +1 -1
  114. data/node_modules/govuk-frontend/govuk/helpers/_spacing.scss +3 -2
  115. data/node_modules/govuk-frontend/govuk/helpers/_typography.scss +8 -7
  116. data/node_modules/govuk-frontend/govuk/helpers/_visually-hidden.scss +1 -1
  117. data/node_modules/govuk-frontend/govuk/objects/_all.scss +1 -0
  118. data/node_modules/govuk-frontend/govuk/objects/_button-group.scss +101 -0
  119. data/node_modules/govuk-frontend/govuk/objects/_form-group.scss +1 -4
  120. data/node_modules/govuk-frontend/govuk/objects/_grid.scss +3 -6
  121. data/node_modules/govuk-frontend/govuk/objects/_main-wrapper.scss +5 -4
  122. data/node_modules/govuk-frontend/govuk/objects/_width-container.scss +6 -4
  123. data/node_modules/govuk-frontend/govuk/overrides/_display.scss +6 -4
  124. data/node_modules/govuk-frontend/govuk/overrides/_spacing.scss +5 -3
  125. data/node_modules/govuk-frontend/govuk/overrides/_typography.scss +5 -3
  126. data/node_modules/govuk-frontend/govuk/overrides/_width.scss +6 -3
  127. data/node_modules/govuk-frontend/govuk/settings/_all.scss +2 -0
  128. data/node_modules/govuk-frontend/govuk/settings/_colours-applied.scss +11 -5
  129. data/node_modules/govuk-frontend/govuk/settings/_colours-organisations.scss +3 -0
  130. data/node_modules/govuk-frontend/govuk/settings/_colours-palette.scss +42 -35
  131. data/node_modules/govuk-frontend/govuk/settings/_compatibility.scss +0 -1
  132. data/node_modules/govuk-frontend/govuk/settings/_ie8.scss +1 -1
  133. data/node_modules/govuk-frontend/govuk/settings/_links.scss +62 -0
  134. data/node_modules/govuk-frontend/govuk/settings/_measurements.scss +4 -5
  135. data/node_modules/govuk-frontend/govuk/settings/_typography-font-families.scss +2 -2
  136. data/node_modules/govuk-frontend/govuk/settings/_typography-font.scss +14 -5
  137. data/node_modules/govuk-frontend/govuk/settings/_typography-responsive.scss +6 -2
  138. data/node_modules/govuk-frontend/govuk/tools/_compatibility.scss +1 -1
  139. data/node_modules/govuk-frontend/govuk/tools/_font-url.scss +1 -4
  140. data/node_modules/govuk-frontend/govuk/tools/_ie8.scss +1 -1
  141. data/node_modules/govuk-frontend/govuk/tools/_image-url.scss +1 -4
  142. data/node_modules/govuk-frontend/govuk/tools/_px-to-em.scss +1 -1
  143. data/node_modules/govuk-frontend/govuk/tools/_px-to-rem.scss +1 -1
  144. data/node_modules/govuk-frontend/govuk/utilities/_visually-hidden.scss +0 -1
  145. data/node_modules/govuk-frontend/govuk/vendor/_sass-mq.scss +0 -4
  146. data/package-lock.json +358 -288
  147. data/package.json +2 -2
  148. metadata +48 -67
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4adec245cbbc73fe2a14f73eb4a0eb2f9acf4d8d751f0786271c59f479c8b244
4
- data.tar.gz: 9017c133a8dace561bf56b4e2ec852b4dcdc15a341501b8784659f229f2f183a
3
+ metadata.gz: 67ad7c3f867522ea35890520f14663c8e12dfd48506cdc8d59cb1f74c7d263be
4
+ data.tar.gz: 10976db4f9c215001924964cde8aa82ed900eb205af720fc6ee1930ce3f34383
5
5
  SHA512:
6
- metadata.gz: 3da0c05902288480bf1953b7d5ad275742707cb8324cebe68a1f970cb9dda1b2c70a6538aa9af7a6272973e4b08b3a10108ad6591cbb78bae5aa4e46d436357d
7
- data.tar.gz: 1ca0540c1625e80f25d89426f893d15368da0c13b84e5824c4808abd62bfed7bf1e4b93738c2ecd76fe43d70fd23b5517494078ab94367f062f4a73f8c0cec8f
6
+ metadata.gz: ffd8c3389b4042b84f468823674df37c04eaae5a6c031b85d0200327a33ebd7a864e97e22a95d5c3ebb46ae4360b3ddc25cfefd940e2bb1e1f69ff1332fc744a
7
+ data.tar.gz: dc1402bf0283a38361f77691e45a09c861cca5430ba9cdc9a270e84718a027c57877a056c36a2a11902ee30c3d199805a6db466a31ea73ba8d953706cd1d29ca
data/.gitignore CHANGED
@@ -29,6 +29,7 @@
29
29
  .rvmrc
30
30
 
31
31
  /example/build
32
+ /example/.bundle
32
33
  /example/.sass-cache
33
34
 
34
35
  Gemfile.lock
data/.nvmrc CHANGED
@@ -1 +1 @@
1
- 10.16.0
1
+ 10
data/.travis.yml CHANGED
@@ -3,6 +3,8 @@ cache:
3
3
  bundler: true
4
4
  npm: true
5
5
  before_install:
6
+ - nvm install
7
+ - nvm use
6
8
  - gem update --system
7
9
  - gem install bundler
8
10
  before_script:
data/CHANGELOG.md CHANGED
@@ -1,5 +1,31 @@
1
1
  # Changelog
2
2
 
3
+ ## Unreleased
4
+
5
+ ## 2.4.0
6
+
7
+ - [Bump redcarpet to 3.5.1 to fix CVE-2020-26298](https://github.com/alphagov/tech-docs-gem/pull/226)
8
+ - [#238: Move the aria-expanded attribute to the correct element](https://github.com/alphagov/tech-docs-gem/pull/238)
9
+ - [#240: Update menu html structure so it's one single hierarchical list](https://github.com/alphagov/tech-docs-gem/pull/240)
10
+ - [#244: Don't change the focus of the page on initial load](https://github.com/alphagov/tech-docs-gem/pull/244)
11
+ - [#243: Fix focus state for links containing inline code](https://github.com/alphagov/tech-docs-gem/pull/243)
12
+ - [#245: Fix focus state for search results ‘Close’ button](https://github.com/alphagov/tech-docs-gem/pull/245)
13
+ - [#246: Update GOV.UK Frontend to v3.13.0](https://github.com/alphagov/tech-docs-gem/pull/246)
14
+
15
+ ## 2.3.0
16
+
17
+ - [#232: Update GOV.UK Frontend and use new link styles](https://github.com/alphagov/tech-docs-gem/pull/232)
18
+
19
+ ## 2.2.2
20
+
21
+ - [#223: Remove unnecessary CSS class on the search submit button](https://github.com/alphagov/tech-docs-gem/pull/223)
22
+ - [#224: Accessibility fix: Hide the 'table of contents close' button when search results are open](https://github.com/alphagov/tech-docs-gem/pull/224)
23
+
24
+ ## 2.2.1
25
+
26
+ - [#218: Remove unnecessary explicit dependencies: sprockets, activesupport, sass and pry](https://github.com/alphagov/tech-docs-gem/pull/218)
27
+ - [#125: Fix API docs showing required properties as optional](https://github.com/alphagov/tech-docs-gem/pull/125)
28
+
3
29
  ## 2.2.0
4
30
 
5
31
  ### Accessibility Fixes
@@ -100,7 +126,6 @@ You can look at the [2.0.6 milestone](https://github.com/alphagov/tech-docs-gem/
100
126
 
101
127
  ## 2.0.5
102
128
 
103
-
104
129
  Adds [new global configuration option](https://github.com/alphagov/tech-docs-gem/pull/122) that controls whether review banners appear or not at the bottom of pages when expiry dates are set in the frontmatter.
105
130
 
106
131
  [Fixes the hard-coded service link](https://github.com/alphagov/tech-docs-gem/pull/119) in the header.
@@ -32,7 +32,7 @@ Gem::Specification.new do |spec|
32
32
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
33
33
  spec.require_paths = ["lib"]
34
34
 
35
- spec.add_dependency "activesupport"
35
+ spec.add_dependency "autoprefixer-rails", "~> 10.2"
36
36
  spec.add_dependency "chronic", "~> 0.10.2"
37
37
  spec.add_dependency "middleman", "~> 4.0"
38
38
  spec.add_dependency "middleman-autoprefixer", "~> 2.10.0"
@@ -42,14 +42,9 @@ Gem::Specification.new do |spec|
42
42
  spec.add_dependency "middleman-sprockets", "~> 4.0.0"
43
43
  spec.add_dependency "middleman-syntax", "~> 3.2.0"
44
44
  spec.add_dependency "nokogiri"
45
- spec.add_dependency "openapi3_parser", "~> 0.5.0"
46
- spec.add_dependency "pry"
47
- spec.add_dependency "redcarpet", "~> 3.5.0"
48
- spec.add_dependency "sass"
49
- spec.add_dependency "sprockets", "~> 4.0.0"
45
+ spec.add_dependency "openapi3_parser", "~> 0.9.0"
46
+ spec.add_dependency "redcarpet", "~> 3.5.1"
50
47
 
51
-
52
- spec.add_development_dependency "bundler", "~> 2.2.0"
53
48
  spec.add_development_dependency "byebug"
54
49
  spec.add_development_dependency "capybara", "~> 3.32"
55
50
  spec.add_development_dependency "jasmine", "~> 3.5.0"
@@ -34,10 +34,9 @@
34
34
  arrayOfIds.push(uniqueId)
35
35
  $(this).addClass('collapsible__body')
36
36
  .attr('id', uniqueId)
37
- .attr('aria-expanded', 'false')
38
37
  })
39
38
  $heading.addClass('collapsible__heading')
40
- .after('<button class="collapsible__toggle" aria-controls="' + arrayOfIds.join(' ') + '"><span class="collapsible__toggle-label">Expand ' + $heading.text() + '</span><span class="collapsible__toggle-icon" aria-hidden="true"></button>')
39
+ .after('<button class="collapsible__toggle" aria-expanded="false" aria-controls="' + arrayOfIds.join(' ') + '"><span class="collapsible__toggle-label">Expand ' + $heading.text() + '</span><span class="collapsible__toggle-icon" aria-hidden="true"></button>')
41
40
  $topLevelItem.on('click', '.collapsible__toggle', function (e) {
42
41
  e.preventDefault()
43
42
  var $parent = $(this).parent()
@@ -47,14 +46,15 @@
47
46
  }
48
47
 
49
48
  function toggleHeading ($topLevelItem) {
50
- var isOpen = $topLevelItem.hasClass('is-open')
49
+ var setOpen = !$topLevelItem.hasClass('is-open')
50
+
51
51
  var $heading = $topLevelItem.find('> a')
52
- var $body = $topLevelItem.find('.collapsible__body')
52
+ var $button = $topLevelItem.find('.collapsible__toggle')
53
53
  var $toggleLabel = $topLevelItem.find('.collapsible__toggle-label')
54
54
 
55
- $topLevelItem.toggleClass('is-open', !isOpen)
56
- $body.attr('aria-expanded', isOpen ? 'false' : 'true')
57
- $toggleLabel.text(isOpen ? 'Expand ' + $heading.text() : 'Collapse ' + $heading.text())
55
+ $topLevelItem.toggleClass('is-open', setOpen)
56
+ $button.attr('aria-expanded', setOpen ? 'true' : 'false')
57
+ $toggleLabel.text(setOpen ? 'Collapse ' + $heading.text() : 'Expand ' + $heading.text())
58
58
  }
59
59
 
60
60
  function openActiveHeading () {
@@ -47,14 +47,12 @@
47
47
  fragment = fragmentForFirstElementInView()
48
48
  }
49
49
 
50
- handleChangeInActiveItem(fragment)
50
+ highlightActiveItemInToc(fragment)
51
51
  }
52
52
 
53
53
  function handleScrollEvent () {
54
- handleChangeInActiveItem(fragmentForFirstElementInView())
55
- }
54
+ var fragment = fragmentForFirstElementInView()
56
55
 
57
- function handleChangeInActiveItem (fragment) {
58
56
  storeCurrentPositionInHistoryApi(fragment)
59
57
  highlightActiveItemInToc(fragment)
60
58
  }
@@ -1,20 +1,19 @@
1
1
  $govuk-assets-path: "/assets/govuk/assets/";
2
2
 
3
3
  // Include only the bits of GOV.UK Frontend we need
4
- @import "govuk/settings/all";
5
- @import "govuk/tools/all";
6
- @import "govuk/helpers/all";
4
+ $govuk-new-link-styles: true;
5
+ @import "govuk/base";
7
6
 
8
7
  @import "govuk/core/all";
9
8
  @import "govuk/objects/all";
10
9
 
11
- @import "govuk/components/footer/footer";
12
- @import "govuk/components/header/header";
13
- @import "govuk/components/inset-text/inset-text";
14
- @import "govuk/components/input/input";
15
- @import "govuk/components/tag/tag";
16
- @import "govuk/components/skip-link/skip-link";
17
- @import "govuk/components/warning-text/warning-text";
10
+ @import "govuk/components/footer/index";
11
+ @import "govuk/components/header/index";
12
+ @import "govuk/components/inset-text/index";
13
+ @import "govuk/components/input/index";
14
+ @import "govuk/components/tag/index";
15
+ @import "govuk/components/skip-link/index";
16
+ @import "govuk/components/warning-text/index";
18
17
 
19
18
  @import "govuk/utilities/all";
20
19
  @import "govuk/overrides/all";
@@ -57,6 +57,10 @@ html.has-search-results-open {
57
57
  .app-pane__content {
58
58
  overflow: hidden;
59
59
  }
60
+
61
+ .toc__close{
62
+ display: none;
63
+ }
60
64
  }
61
65
  .search-results {
62
66
  display: none;
@@ -83,21 +87,9 @@ html.has-search-results-open {
83
87
  min-height: auto;
84
88
  }
85
89
 
86
- a:link, a:visited {
87
- text-decoration: none;
88
- color: $govuk-link-colour;
89
- }
90
-
91
- a:hover {
92
- text-decoration: underline;
93
-
94
- &:focus {
95
- text-decoration: none;
96
- }
97
- }
98
- a:focus {
99
- outline: none;
100
- @include govuk-focused-text;
90
+ a {
91
+ @include govuk-link-common;
92
+ @include govuk-link-style-no-visited-state;
101
93
  }
102
94
  }
103
95
  .search-results__inner {
@@ -138,16 +130,7 @@ html.has-search-results-open {
138
130
  cursor: pointer;
139
131
 
140
132
  &:focus {
141
- background-color: $govuk-focus-colour;
142
- outline: $govuk-focus-width solid transparent;
143
- box-shadow: inset 0 0 0 1px $govuk-focus-colour;
144
- }
145
-
146
- &:focus:not(:active):not(:hover) {
147
- border-color: $govuk-focus-colour;
148
- color: $govuk-focus-text-colour;
149
- background-color: $govuk-focus-colour;
150
- box-shadow: 0 2px 0 $govuk-focus-text-colour;
133
+ @include govuk-focused-text;
151
134
  }
152
135
 
153
136
  &::after {
@@ -185,7 +185,7 @@
185
185
  }
186
186
 
187
187
  a:focus code {
188
- background: inherit;
188
+ background: transparent;
189
189
  color: inherit;
190
190
  }
191
191
 
@@ -15,14 +15,18 @@
15
15
 
16
16
  &__list {
17
17
  li {
18
+ a {
19
+ @include govuk-link-decoration;
20
+ @include govuk-link-style-no-visited-state;
21
+ @include govuk-link-style-no-underline;
22
+ }
23
+
18
24
  a:link, a:visited {
19
25
  display: block;
20
26
  position: relative;
21
27
  padding: 8px govuk-spacing(6) 8px govuk-spacing(2);
22
28
  margin: 0 -1 * govuk-spacing(3);
23
29
  border-left: 5px solid transparent;
24
- text-decoration: none;
25
- color: $govuk-link-colour;
26
30
 
27
31
  @include govuk-media-query(tablet) {
28
32
  &.toc-link--in-view {
@@ -33,21 +37,17 @@
33
37
  }
34
38
  }
35
39
 
40
+ a:hover {
41
+ @include govuk-link-hover-decoration;
42
+ }
43
+
36
44
  a:focus {
37
- outline: none;
45
+ text-decoration: none;
38
46
 
39
47
  span {
40
48
  @include govuk-focused-text;
41
49
  }
42
50
  }
43
-
44
- a:hover {
45
- text-decoration: underline;
46
-
47
- &:focus {
48
- text-decoration: none;
49
- }
50
- }
51
51
  }
52
52
 
53
53
  // Top level
@@ -1,7 +1,6 @@
1
1
  require "erb"
2
2
  require "openapi3_parser"
3
3
  require "uri"
4
- require "pry"
5
4
  require "govuk_tech_docs/api_reference/api_reference_renderer"
6
5
 
7
6
  module GovukTechDocs
@@ -18,20 +18,15 @@ module GovukTechDocs
18
18
  end
19
19
 
20
20
  def api_full(info, servers)
21
- paths = ""
22
- paths_data = @document.paths
23
- paths_data.each do |path_data|
24
- # For some reason paths.each returns an array of arrays [title, object]
25
- # instead of an array of objects
26
- text = path_data[0]
27
- paths += path(text)
21
+ paths = @document.paths.keys.inject("") do |memo, text|
22
+ memo + path(text)
28
23
  end
29
- schemas = ""
30
- schemas_data = @document.components.schemas
31
- schemas_data.each do |schema_data|
32
- text = schema_data[0]
33
- schemas += schema(text)
24
+
25
+ schema_names = @document.components.schemas.keys
26
+ schemas = schema_names.inject("") do |memo, schema_name|
27
+ memo + schema(schema_name)
34
28
  end
29
+
35
30
  @template_api_full.result(binding)
36
31
  end
37
32
 
@@ -42,128 +37,78 @@ module GovukTechDocs
42
37
  @template_path.result(binding)
43
38
  end
44
39
 
45
- def schema(text)
46
- schemas = ""
47
- schemas_data = @document.components.schemas
48
- schemas_data.each do |schema_data|
49
- all_of = schema_data[1]["allOf"]
50
- properties = []
51
- if !all_of.blank?
52
- all_of.each do |schema_nested|
53
- schema_nested.properties.each do |property|
54
- properties.push property
55
- end
56
- end
57
- end
40
+ def schema(title)
41
+ schema = @document.components.schemas[title]
42
+ return unless schema
58
43
 
59
- schema_data[1].properties.each do |property|
60
- properties.push property
61
- end
44
+ properties = if schema.all_of
45
+ schema.all_of.each_with_object({}) do |nested, memo|
46
+ memo.merge!(nested.properties.to_h)
47
+ end
48
+ else
49
+ {}
50
+ end
62
51
 
63
- if schema_data[0] == text
64
- title = schema_data[0]
65
- schema = schema_data[1]
66
- return @template_schema.result(binding)
67
- end
68
- end
52
+ properties.merge!(schema.properties.to_h)
53
+ @template_schema.result(binding)
69
54
  end
70
55
 
71
56
  def schemas_from_path(text)
72
- path = @document.paths[text]
73
- operations = get_operations(path)
74
- # Get all referenced schemas
75
- schemas = []
76
- operations.compact.each_value do |operation|
77
- responses = operation.responses
78
- responses.each do |_rkey, response|
79
- if response.content["application/json"]
80
- schema = response.content["application/json"].schema
81
- schema_name = get_schema_name(schema.node_context.source_location.to_s)
82
- if !schema_name.nil?
83
- schemas.push schema_name
84
- end
85
- schemas.concat(schemas_from_schema(schema))
86
- end
57
+ operations = get_operations(@document.paths[text])
58
+ schemas = operations.flat_map do |_, operation|
59
+ operation.responses.inject([]) do |memo, (_, response)|
60
+ next memo unless response.content["application/json"]
61
+
62
+ schema = response.content["application/json"].schema
63
+
64
+ memo << schema.name if schema.name
65
+ memo + schemas_from_schema(schema)
87
66
  end
88
67
  end
68
+
89
69
  # Render all referenced schemas
90
- output = ""
91
- schemas.uniq.each do |schema_name|
92
- output += schema(schema_name)
93
- end
94
- if !output.empty?
95
- output.prepend('<h2 id="schemas">Schemas</h2>')
70
+ output = schemas.uniq.inject("") do |memo, schema_name|
71
+ memo + schema(schema_name)
96
72
  end
73
+
74
+ output.prepend('<h2 id="schemas">Schemas</h2>') unless output.empty?
97
75
  output
98
76
  end
99
77
 
100
78
  def schemas_from_schema(schema)
101
- schemas = []
102
- properties = []
103
- schema.properties.each do |property|
104
- properties.push property[1]
105
- end
106
- if schema.type == "array"
107
- properties.push schema.items
108
- end
109
- all_of = schema["allOf"]
110
- if !all_of.blank?
111
- all_of.each do |schema_nested|
112
- schema_nested.properties.each do |property|
113
- properties.push property[1]
114
- end
115
- end
116
- end
117
- properties.each do |property|
118
- # Must be a schema be referenced by another schema
119
- # And not a property of a schema
120
- if property.node_context.referenced_by.to_s.include?("#/components/schemas") &&
121
- !property.node_context.source_location.to_s.include?("/properties/")
122
- schema_name = get_schema_name(property.node_context.source_location.to_s)
123
- end
124
- if !schema_name.nil?
125
- schemas.push schema_name
126
- end
127
- # Check sub-properties for references
128
- schemas.concat(schemas_from_schema(property))
79
+ schemas = schema.properties.map(&:last)
80
+ schemas << schema.items if schema.items && schema.type == "array"
81
+ schemas += schema.all_of.to_a.flat_map { |s| s.properties.map(&:last) }
82
+
83
+ schemas.flat_map do |nested|
84
+ sub_schemas = schemas_from_schema(nested)
85
+ nested.name ? [nested.name] + sub_schemas : sub_schemas
129
86
  end
130
- schemas
131
87
  end
132
88
 
133
89
  def operations(path, path_id)
134
- output = ""
135
- operations = get_operations(path)
136
- operations.compact.each do |key, operation|
90
+ get_operations(path).inject("") do |memo, (key, operation)|
137
91
  id = "#{path_id}-#{key.parameterize}"
138
92
  parameters = parameters(operation, id)
139
93
  responses = responses(operation, id)
140
- output += @template_operation.result(binding)
94
+ memo + @template_operation.result(binding)
141
95
  end
142
- output
143
96
  end
144
97
 
145
98
  def parameters(operation, operation_id)
146
99
  parameters = operation.parameters
147
100
  id = "#{operation_id}-parameters"
148
- output = @template_parameters.result(binding)
149
- output
101
+ @template_parameters.result(binding)
150
102
  end
151
103
 
152
104
  def responses(operation, operation_id)
153
105
  responses = operation.responses
154
106
  id = "#{operation_id}-responses"
155
- output = @template_responses.result(binding)
156
- output
157
- end
158
-
159
- def markdown(text)
160
- if text
161
- Tilt["markdown"].new(context: @app) { text }.render
162
- end
107
+ @template_responses.result(binding)
163
108
  end
164
109
 
165
110
  def json_output(schema)
166
- properties = schema_properties(schema)
111
+ properties = schema_properties(schema)
167
112
  JSON.pretty_generate(properties)
168
113
  end
169
114
 
@@ -172,76 +117,26 @@ module GovukTechDocs
172
117
  end
173
118
 
174
119
  def schema_properties(schema_data)
175
- properties = Hash.new
176
- if defined? schema_data.properties
177
- schema_data.properties.each do |key, property|
178
- properties[key] = property
179
- end
180
- end
181
- properties.merge! get_all_of_hash(schema_data)
182
- properties_hash = Hash.new
183
- properties.each do |pkey, property|
184
- if property.type == "object"
185
- properties_hash[pkey] = Hash.new
186
- items = property.items
187
- if !items.blank?
188
- properties_hash[pkey] = schema_properties(items)
189
- end
190
- if !property.properties.blank?
191
- properties_hash[pkey] = schema_properties(property)
192
- end
193
- elsif property.type == "array"
194
- properties_hash[pkey] = Array.new
195
- items = property.items
196
- if !items.blank?
197
- properties_hash[pkey].push schema_properties(items)
198
- end
199
- else
200
- properties_hash[pkey] = !property.example.nil? ? property.example : property.type
201
- end
202
- end
203
-
204
- properties_hash
205
- end
206
-
207
- private
120
+ properties = schema_data.properties.to_h
208
121
 
209
- def get_all_of_array(schema)
210
- properties = Array.new
211
- if schema.is_a?(Array)
212
- schema = schema[1]
213
- end
214
- if schema["allOf"]
215
- all_of = schema["allOf"]
216
- end
217
- if !all_of.blank?
218
- all_of.each do |schema_nested|
219
- schema_nested.properties.each do |property|
220
- if property.is_a?(Array)
221
- property = property[1]
222
- end
223
- properties.push property
224
- end
225
- end
122
+ schema_data.all_of.to_a.each do |all_of_schema|
123
+ properties.merge!(all_of_schema.properties.to_h)
226
124
  end
227
- properties
228
- end
229
125
 
230
- def get_all_of_hash(schema)
231
- properties = Hash.new
232
- if schema["allOf"]
233
- all_of = schema["allOf"]
234
- end
235
- if !all_of.blank?
236
- all_of.each do |schema_nested|
237
- schema_nested.properties.each do |key, property|
238
- properties[key] = property
239
- end
240
- end
126
+ properties.each_with_object({}) do |(name, schema), memo|
127
+ memo[name] = case schema.type
128
+ when "object"
129
+ schema_properties(schema.items || schema)
130
+ when "array"
131
+ schema.items ? [schema_properties(schema.items)] : []
132
+ else
133
+ schema.example || schema.type
134
+ end
241
135
  end
242
- properties
243
136
  end
244
137
 
138
+ private
139
+
245
140
  def get_renderer(file)
246
141
  template_path = File.join(File.dirname(__FILE__), "templates/" + file)
247
142
  template = File.open(template_path, "r").read
@@ -249,31 +144,20 @@ module GovukTechDocs
249
144
  end
250
145
 
251
146
  def get_operations(path)
252
- operations = {}
253
- operations["get"] = path.get if defined? path.get
254
- operations["put"] = path.put if defined? path.put
255
- operations["post"] = path.post if defined? path.post
256
- operations["delete"] = path.delete if defined? path.delete
257
- operations["patch"] = path.patch if defined? path.patch
258
- operations
259
- end
260
-
261
- def get_schema_name(text)
262
- unless text.is_a?(String)
263
- return nil
264
- end
265
-
266
- # Schema dictates that it's always components['schemas']
267
- text.gsub(/#\/components\/schemas\//, "")
147
+ {
148
+ "get" => path.get,
149
+ "put" => path.put,
150
+ "post" => path.post,
151
+ "delete" => path.delete,
152
+ "patch" => path.patch,
153
+ }.compact
268
154
  end
269
155
 
270
156
  def get_schema_link(schema)
271
- schema_name = get_schema_name schema.node_context.source_location.to_s
272
- if !schema_name.nil?
273
- id = "schema-#{schema_name.parameterize}"
274
- output = "<a href='\##{id}'>#{schema_name}</a>"
275
- output
276
- end
157
+ return unless schema.name
158
+
159
+ id = "schema-#{schema.name.parameterize}"
160
+ "<a href='\##{id}'>#{schema.name}</a>"
277
161
  end
278
162
  end
279
163
  end