govuk_tech_docs 6.0.1 → 6.1.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e490b72c74aec01a8e39fa25446e74c7b85cdb81b8e95902d823fc6619ffeabe
4
- data.tar.gz: a0a7fee77936966f916c0c6351a5614bdf33e6086ee1a0eeab19dca60deb518b
3
+ metadata.gz: 9db5229bb2ed62d045e446c4e58b00b534358309485c0bf431a79b290618a69e
4
+ data.tar.gz: 12fef07d23a5ead0eb3befdb8f32dba7ee9fc2a3176796b6d0db9c9c11367715
5
5
  SHA512:
6
- metadata.gz: 5df8899a2930b154ed270903e47523eb1c4246c074bab40681872d89ecbff9e0ce6510817547d4a3b1120a68510fe29ae9d6a399835706fd6ab3420c3a20c326
7
- data.tar.gz: e7bb22be432a4f76a8fa265d09a62747d5ad4be4fae6d85638f2085e96e10665aa311b708a644e2923eda2afdcc1f31f852d538372083d574a2477d88c2b87dc
6
+ metadata.gz: 55fbf011e6d71d37e2847e19ead1177b6ab35a01dc7383c53e14e6e0bc1c7506766949dc99f2eb48906008b3b7d48dd545b4019a4ac9dd2b7250769d1bab820e
7
+ data.tar.gz: 5d263eda7c095456b07eb593d7292efb3a1ec951e6e6b74c19f31f2eb94c3f9d4f79a363b7f5072ac4d1a12741f3f1424f5b441506bfbc8ac769cc8098261e0b
data/CHANGELOG.md CHANGED
@@ -1,8 +1,18 @@
1
- ## 6.0.1
1
+ # 6.1.0
2
+
3
+ - [Add custom extensions to render GOV.UK Design System nunjucks components](https://github.com/alphagov/tech-docs-gem/pull/443/changes)
4
+ - [Fix inconsistent active tab behaviour](https://github.com/alphagov/tech-docs-gem/pull/452)
5
+
6
+ # 6.0.1
2
7
 
3
8
  - Update version of `openapi3_parser` allowing support for Ruby 4.0.
4
9
 
5
- ## 6.0.0
10
+ > Note:
11
+ > openapi3_parser ~> 0.10.1 has a delcares a depndancy on commonmarker >= 1.0
12
+ > commonmarker >= 1.0 declares required_ruby_version >= 3.3.22
13
+ > If you are using an older ruby verion this may cause issues in your environment. We recommend upgrading to a version >= 3.
14
+
15
+ ## 6.0.0.beta
6
16
 
7
17
  - [Bump Design System to V6](https://github.com/alphagov/tech-docs-gem/pull/442), which brings in:
8
18
  - changes to the colour palette
@@ -20,7 +30,6 @@ ability, we're marking it as a major bump.
20
30
  - [Bump jasmine-core from 5.5.0 to 5.13.0 #448](https://github.com/alphagov/tech-docs-gem/pull/448)
21
31
  - [Ban pre|post-install NPM scripts #453](https://github.com/alphagov/tech-docs-gem/pull/453)
22
32
 
23
-
24
33
  ## 5.2.1
25
34
 
26
35
  - [Add option to not render child resources when creating a table of contents](https://github.com/alphagov/tech-docs-gem/pull/439/changes)
data/README.md CHANGED
@@ -15,6 +15,8 @@ Find out how to [contribute](https://tdt-documentation.london.cloudapps.digital/
15
15
 
16
16
  This gem uses [GOV.UK Frontend](https://github.com/alphagov/govuk-frontend), part of the [GOV.UK Design System](https://design-system.service.gov.uk/).
17
17
 
18
+ This gem can also use [GOV.UK Design System nunjucks components](https://design-system.service.gov.uk/components/). It is recommended that you use these as they are user researched and accessibility tested. An example using the `govukButton` component is available in the [example site in this gem](./example/source/index.html.md.erb).
19
+
18
20
  We use `npm` to download the govuk-frontend package. To update to a new version, change the version in the [package.json file](package.json) and run `npm update`.
19
21
 
20
22
  ## Table of contents helper functions
@@ -158,9 +160,8 @@ The documentation is [© Crown copyright][copyright] and available under the ter
158
160
  [mit]: LICENCE
159
161
  [copyright]: http://www.nationalarchives.gov.uk/information-management/re-using-public-sector-information/uk-government-licensing-framework/crown-copyright/
160
162
  [ogl]: http://www.nationalarchives.gov.uk/doc/open-government-licence/version/3/
161
- [tdt-docs]: https://tdt-documentation.london.cloudapps.digital
163
+ [tdt-docs]: https://github.com/alphagov/tdt-documentation/
162
164
  [tdt-template]: https://github.com/alphagov/tech-docs-template
163
- [tdt-readme]: https://github.com/alphagov/tech-docs-template/blob/main/README.md
164
165
  [mmt]: https://middlemanapp.com/advanced/project_templates/
165
166
 
166
167
  [jas]: https://jasmine.github.io/
@@ -1,6 +1,9 @@
1
1
  # Host to use for canonical URL generation (without trailing slash)
2
2
  host: https://docs.example.com
3
3
 
4
+ # Enable GOV.UK Design System nunjucks components (https://design-system.service.gov.uk/components)
5
+ enable_govuk_components: true
6
+
4
7
  # Header-related options
5
8
  show_govuk_logo: true
6
9
  service_name: My First Service
@@ -14,6 +17,7 @@ header_links:
14
17
  Expired with owner: /expired-page-with-owner.html
15
18
  Not expired page: /not-expired-page.html
16
19
  Single page nav: /single-page-nav.html
20
+ Active pages: /active-pages/
17
21
 
18
22
  footer_links:
19
23
  Accessibility: /hidden-page.html
data/example/config.rb CHANGED
@@ -7,3 +7,18 @@ ignore "templates/*"
7
7
  proxy "/a-proxied-page.html", "templates/proxy_template.html", locals: {
8
8
  title: "I am a title",
9
9
  }
10
+
11
+ gem_root = File.expand_path("..", __dir__)
12
+ files.watch :reload, path: File.join(gem_root, "lib")
13
+
14
+ configure :development do
15
+ ready do
16
+ files.on_change :reload do |changed|
17
+ changed.each do |file|
18
+ next unless file.full_path.extname == ".rb"
19
+
20
+ load file.full_path.to_s
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,7 @@
1
+ ---
2
+ title: Active page section root
3
+ ---
4
+
5
+ # This is a section landing page, under the "Active pages" navigation link.
6
+
7
+ The "Active pages" navigation link should be active.
@@ -0,0 +1,7 @@
1
+ ---
2
+ title: Active page sub section root
3
+ ---
4
+
5
+ # This is a section sub section, under the "Active pages" navigation link.
6
+
7
+ The "Active pages" navigation link should STILL BE active.
@@ -18,5 +18,10 @@ To change the title of the page or include additional files you'll need to edit
18
18
  If you want slightly more control, you can always use <strong>HTML</strong>.
19
19
 
20
20
  For more detail and troubleshooting, take a look at the `README.md` file in the root of this project.
21
+ <% if config[:tech_docs][:enable_govuk_components] %>
21
22
 
22
- <%= warning_text "Look out! A warning!" %>
23
+ <%= govukButton({
24
+ text: "Click me!"
25
+ }) %>
26
+
27
+ <% end %>
@@ -54,9 +54,10 @@ Gem::Specification.new do |spec|
54
54
  spec.add_dependency "openapi3_parser", "~> 0.10.1"
55
55
  spec.add_dependency "redcarpet", "~> 3.6"
56
56
  spec.add_dependency "sassc-embedded", "~> 1.78.0"
57
- spec.add_dependency "terser", "~> 1.2.3"
58
57
 
59
58
  spec.add_development_dependency "benchmark"
59
+ spec.add_dependency "schmooze", "~> 0.2.0"
60
+ spec.add_dependency "terser", "~> 1.2.3"
60
61
  spec.add_development_dependency "byebug"
61
62
  spec.add_development_dependency "capybara", "~> 3.32"
62
63
  spec.add_development_dependency "ostruct"
@@ -0,0 +1,30 @@
1
+ require "middleman-core"
2
+
3
+ module GovukTechDocs
4
+ class CustomMethodMissingHandler < Middleman::Extension
5
+ def initialize(app, options_hash = {}, &block)
6
+ super
7
+ end
8
+
9
+ helpers do
10
+ def method_missing(method_name, *args, &block)
11
+ if method_name.to_s.start_with?("govuk")
12
+ begin
13
+ data = args.first || {}
14
+ @renderer ||= GovukTechDocs::GovukNunjuckComponenetRenderer.new(File.expand_path("../../", __dir__))
15
+ @renderer.render_govuk_component(method_name, data).html_safe
16
+ rescue StandardError => e
17
+ raise e
18
+ end
19
+ else
20
+ super
21
+ end
22
+ end
23
+
24
+ def respond_to_missing?(method_name, include_private = false)
25
+ method_name.to_s.start_with?("govuk") || super
26
+ end
27
+ end
28
+ end
29
+ end
30
+ ::Middleman::Extensions.register(:custom_method_missing_handler, GovukTechDocs::CustomMethodMissingHandler)
@@ -0,0 +1,43 @@
1
+ require "schmooze"
2
+
3
+ module GovukTechDocs
4
+ class GovukNunjuckComponenetRenderer < Schmooze::Base
5
+ dependencies nunjucks: "nunjucks"
6
+
7
+ def initialize(gem_root)
8
+ super(gem_root) # Pass it up to Schmooze so it finds node_modules
9
+ @gem_root = gem_root
10
+ end
11
+
12
+ method :render_nunjucks_template, <<~JS
13
+ (templateString, templateData, searchPaths) => {
14
+ const env = nunjucks.configure(searchPaths, { autoescape: true });
15
+ return env.renderString(templateString, templateData);
16
+ }
17
+ JS
18
+
19
+ def get_component_template_name(component_name)
20
+ component_name.to_s.delete_prefix("govuk")
21
+ .gsub(/([A-Z]+)([A-Z][a-z])/, '\1-\2') # Handle acronyms like "JSONData"
22
+ .gsub(/([a-z\d])([A-Z])/, '\1-\2') # Handle standard "CamelCase"
23
+ .downcase
24
+ end
25
+
26
+ def render_govuk_component(component_name, template_data)
27
+ # 1. Logic for search paths belongs here now
28
+
29
+ search_paths = [File.join(@gem_root, "node_modules/govuk-frontend/dist")]
30
+ component_template_name = get_component_template_name(component_name)
31
+ # 2. Call the JS method defined above
32
+ nunjucks_template_string = <<~NJK
33
+ {% from "govuk/components/#{component_template_name}/macro.njk" import #{component_name} %}
34
+ {{ #{component_name}(template_data) }}
35
+ NJK
36
+ render_nunjucks_template(nunjucks_template_string, { "template_data" => template_data }, search_paths)
37
+ # rubocop:disable Lint/UselessAssignment
38
+ rescue StandardError => e
39
+ raise "Could not load GOV.UK component #{component_name} with data #{template_data}."
40
+ end
41
+ # rubocop:enable Lint/UselessAssignment
42
+ end
43
+ end
@@ -1,3 +1,3 @@
1
1
  module GovukTechDocs
2
- VERSION = "6.0.1".freeze
2
+ VERSION = "6.1.0".freeze
3
3
  end
@@ -24,6 +24,8 @@ require "govuk_tech_docs/unique_identifier_extension"
24
24
  require "govuk_tech_docs/unique_identifier_generator"
25
25
  require "govuk_tech_docs/warning_text_extension"
26
26
  require "govuk_tech_docs/api_reference/api_reference_extension"
27
+ require "govuk_tech_docs/custom_method_missing_handler"
28
+ require "govuk_tech_docs/govuk_nunjuck_componenet_renderer"
27
29
 
28
30
  module SassWarningSupressor
29
31
  def warn(message)
@@ -101,11 +103,35 @@ module GovukTechDocs
101
103
  end
102
104
 
103
105
  def active_page(page_path)
104
- [
105
- page_path == "/" && current_page.path == "index.html",
106
- "/#{current_page.path}" == page_path,
107
- !current_page.data.parent.nil? && current_page.data.parent.to_s == page_path,
108
- ].any?
106
+ # if we are on the homepage e.g Documentation: /
107
+ if page_path == "/" && current_page.url == "/"
108
+ return true
109
+ end
110
+
111
+ # if we are on a single page the header links point to e.g Expired page: /expired-page.html
112
+ if "/#{current_page.path}" == page_path
113
+ return true
114
+ end
115
+
116
+ # If the doc maintainer has set the parent data in the frontmatter for the current page,
117
+ # and it matches the value in the config e.g
118
+ # Expired page: /expired-page.html (config) and parent: /expired-page.html (child-of-expired-page.html)
119
+ if !current_page.data.parent.nil? && current_page.data.parent.to_s == page_path
120
+ return true
121
+ end
122
+
123
+ # If we have a nested directory structure that matches a navigation link e.g Active pages: /active-pages/
124
+ if current_page.url.start_with?(page_path)
125
+ # feels like a weird check, but stops false positive where "/" for root is also the start of "/active-pages"
126
+ if page_path == "/"
127
+ return current_page.url == "/"
128
+ end
129
+
130
+ # safe to return true, since we aren't in the situation above
131
+ return true
132
+ end
133
+ # no other reason to believe we're active
134
+ false
109
135
  end
110
136
  end
111
137
 
@@ -138,5 +164,9 @@ module GovukTechDocs
138
164
  else
139
165
  context.ignore "search/*"
140
166
  end
167
+
168
+ if context.config[:tech_docs][:enable_govuk_components]
169
+ context.activate :custom_method_missing_handler
170
+ end
141
171
  end
142
172
  end
data/package-lock.json CHANGED
@@ -7,7 +7,8 @@
7
7
  "name": "tech-docs-gem",
8
8
  "license": "MIT",
9
9
  "dependencies": {
10
- "govuk-frontend": "^6.0.0"
10
+ "govuk-frontend": "^6.0.0",
11
+ "nunjucks": "~3.2.4"
11
12
  },
12
13
  "devDependencies": {
13
14
  "jasmine-browser-runner": "^3.0.0",
@@ -76,6 +77,12 @@
76
77
  "node": ">=14"
77
78
  }
78
79
  },
80
+ "node_modules/a-sync-waterfall": {
81
+ "version": "1.0.1",
82
+ "resolved": "https://registry.npmjs.org/a-sync-waterfall/-/a-sync-waterfall-1.0.1.tgz",
83
+ "integrity": "sha512-RYTOHHdWipFUliRFMCS4X2Yn2X8M87V/OpSqWzKKOGhzqyUxzyVmhHDH9sAvG+ZuQf/TAOFsLCpMw09I1ufUnA==",
84
+ "license": "MIT"
85
+ },
79
86
  "node_modules/accepts": {
80
87
  "version": "2.0.0",
81
88
  "resolved": "https://registry.npmjs.org/accepts/-/accepts-2.0.0.tgz",
@@ -257,6 +264,12 @@
257
264
  "url": "https://github.com/sponsors/ljharb"
258
265
  }
259
266
  },
267
+ "node_modules/asap": {
268
+ "version": "2.0.6",
269
+ "resolved": "https://registry.npmjs.org/asap/-/asap-2.0.6.tgz",
270
+ "integrity": "sha512-BSHWgDSAiKs50o2Re8ppvp3seVHXSRM44cdSsT9FfNEUUZLOGWVCsiWaRPWM1Znn+mqZ1OfVZ3z3DWEzSp7hRA==",
271
+ "license": "MIT"
272
+ },
260
273
  "node_modules/astral-regex": {
261
274
  "version": "1.0.0",
262
275
  "resolved": "https://registry.npmjs.org/astral-regex/-/astral-regex-1.0.0.tgz",
@@ -474,6 +487,15 @@
474
487
  "dev": true,
475
488
  "license": "MIT"
476
489
  },
490
+ "node_modules/commander": {
491
+ "version": "5.1.0",
492
+ "resolved": "https://registry.npmjs.org/commander/-/commander-5.1.0.tgz",
493
+ "integrity": "sha512-P0CysNDQ7rtVw4QIQtm+MRxV66vKFSvlsQvGYXZWR3qFU0jlMKHZZZgw8e+8DSah4UDKMqnknRDQz+xuQXQ/Zg==",
494
+ "license": "MIT",
495
+ "engines": {
496
+ "node": ">= 6"
497
+ }
498
+ },
477
499
  "node_modules/concat-map": {
478
500
  "version": "0.0.1",
479
501
  "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz",
@@ -3327,6 +3349,31 @@
3327
3349
  "semver": "bin/semver"
3328
3350
  }
3329
3351
  },
3352
+ "node_modules/nunjucks": {
3353
+ "version": "3.2.4",
3354
+ "resolved": "https://registry.npmjs.org/nunjucks/-/nunjucks-3.2.4.tgz",
3355
+ "integrity": "sha512-26XRV6BhkgK0VOxfbU5cQI+ICFUtMLixv1noZn1tGU38kQH5A5nmmbk/O45xdyBhD1esk47nKrY0mvQpZIhRjQ==",
3356
+ "license": "BSD-2-Clause",
3357
+ "dependencies": {
3358
+ "a-sync-waterfall": "^1.0.0",
3359
+ "asap": "^2.0.3",
3360
+ "commander": "^5.1.0"
3361
+ },
3362
+ "bin": {
3363
+ "nunjucks-precompile": "bin/precompile"
3364
+ },
3365
+ "engines": {
3366
+ "node": ">= 6.9.0"
3367
+ },
3368
+ "peerDependencies": {
3369
+ "chokidar": "^3.3.0"
3370
+ },
3371
+ "peerDependenciesMeta": {
3372
+ "chokidar": {
3373
+ "optional": true
3374
+ }
3375
+ }
3376
+ },
3330
3377
  "node_modules/object-assign": {
3331
3378
  "version": "4.1.1",
3332
3379
  "resolved": "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz",
data/package.json CHANGED
@@ -8,7 +8,8 @@
8
8
  "test-server": "jasmine-browser-runner serve --config=spec/javascripts/support/jasmine-browser.mjs"
9
9
  },
10
10
  "dependencies": {
11
- "govuk-frontend": "^6.0.0"
11
+ "govuk-frontend": "^6.0.0",
12
+ "nunjucks": "~3.2.4"
12
13
  },
13
14
  "devDependencies": {
14
15
  "jasmine-browser-runner": "^3.0.0",
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: govuk_tech_docs
3
3
  version: !ruby/object:Gem::Version
4
- version: 6.0.1
4
+ version: 6.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Government Digital Service
@@ -276,33 +276,47 @@ dependencies:
276
276
  - !ruby/object:Gem::Version
277
277
  version: 1.78.0
278
278
  - !ruby/object:Gem::Dependency
279
- name: terser
279
+ name: benchmark
280
+ requirement: !ruby/object:Gem::Requirement
281
+ requirements:
282
+ - - ">="
283
+ - !ruby/object:Gem::Version
284
+ version: '0'
285
+ type: :development
286
+ prerelease: false
287
+ version_requirements: !ruby/object:Gem::Requirement
288
+ requirements:
289
+ - - ">="
290
+ - !ruby/object:Gem::Version
291
+ version: '0'
292
+ - !ruby/object:Gem::Dependency
293
+ name: schmooze
280
294
  requirement: !ruby/object:Gem::Requirement
281
295
  requirements:
282
296
  - - "~>"
283
297
  - !ruby/object:Gem::Version
284
- version: 1.2.3
298
+ version: 0.2.0
285
299
  type: :runtime
286
300
  prerelease: false
287
301
  version_requirements: !ruby/object:Gem::Requirement
288
302
  requirements:
289
303
  - - "~>"
290
304
  - !ruby/object:Gem::Version
291
- version: 1.2.3
305
+ version: 0.2.0
292
306
  - !ruby/object:Gem::Dependency
293
- name: benchmark
307
+ name: terser
294
308
  requirement: !ruby/object:Gem::Requirement
295
309
  requirements:
296
- - - ">="
310
+ - - "~>"
297
311
  - !ruby/object:Gem::Version
298
- version: '0'
299
- type: :development
312
+ version: 1.2.3
313
+ type: :runtime
300
314
  prerelease: false
301
315
  version_requirements: !ruby/object:Gem::Requirement
302
316
  requirements:
303
- - - ">="
317
+ - - "~>"
304
318
  - !ruby/object:Gem::Version
305
- version: '0'
319
+ version: 1.2.3
306
320
  - !ruby/object:Gem::Dependency
307
321
  name: byebug
308
322
  requirement: !ruby/object:Gem::Requirement
@@ -419,6 +433,8 @@ files:
419
433
  - example/Gemfile
420
434
  - example/config.rb
421
435
  - example/config/tech-docs.yml
436
+ - example/source/active-pages/index.html.md.erb
437
+ - example/source/active-pages/sub-section/index.html.md.erb
422
438
  - example/source/api-path.html.md
423
439
  - example/source/api-reference.html.md
424
440
  - example/source/child-of-expired-page.html.md
@@ -488,6 +504,8 @@ files:
488
504
  - lib/govuk_tech_docs/api_reference/templates/responses.html.erb
489
505
  - lib/govuk_tech_docs/api_reference/templates/schema.html.erb
490
506
  - lib/govuk_tech_docs/contribution_banner.rb
507
+ - lib/govuk_tech_docs/custom_method_missing_handler.rb
508
+ - lib/govuk_tech_docs/govuk_nunjuck_componenet_renderer.rb
491
509
  - lib/govuk_tech_docs/meta_tags.rb
492
510
  - lib/govuk_tech_docs/page_review.rb
493
511
  - lib/govuk_tech_docs/pages.rb