Skip to content

Commit a5df4d9

Browse files
authored
Merge pull request #460 from alphagov/release/v6-1-0-beta
Release/v6 1 0 beta
2 parents 4017be2 + 6644a97 commit a5df4d9

19 files changed

Lines changed: 516 additions & 17 deletions

CHANGELOG.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
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
27

38
- Update version of `openapi3_parser` allowing support for Ruby 4.0.
49

@@ -7,7 +12,7 @@
712
> commonmarker >= 1.0 declares required_ruby_version >= 3.3.22
813
> If you are using an older ruby verion this may cause issues in your environment. We recommend upgrading to a version >= 3.
914
10-
## 6.0.0
15+
## 6.0.0.beta
1116

1217
- [Bump Design System to V6](https://github.com/alphagov/tech-docs-gem/pull/442), which brings in:
1318
- changes to the colour palette
@@ -25,7 +30,6 @@ ability, we're marking it as a major bump.
2530
- [Bump jasmine-core from 5.5.0 to 5.13.0 #448](https://github.com/alphagov/tech-docs-gem/pull/448)
2631
- [Ban pre|post-install NPM scripts #453](https://github.com/alphagov/tech-docs-gem/pull/453)
2732

28-
2933
## 5.2.1
3034

3135
- [Add option to not render child resources when creating a table of contents](https://github.com/alphagov/tech-docs-gem/pull/439/changes)

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ Find out how to [contribute](https://tdt-documentation.london.cloudapps.digital/
1515

1616
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/).
1717

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+
1820
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`.
1921

2022
## Table of contents helper functions
@@ -158,9 +160,8 @@ The documentation is [© Crown copyright][copyright] and available under the ter
158160
[mit]: LICENCE
159161
[copyright]: http://www.nationalarchives.gov.uk/information-management/re-using-public-sector-information/uk-government-licensing-framework/crown-copyright/
160162
[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/
162164
[tdt-template]: https://github.com/alphagov/tech-docs-template
163-
[tdt-readme]: https://github.com/alphagov/tech-docs-template/blob/main/README.md
164165
[mmt]: https://middlemanapp.com/advanced/project_templates/
165166

166167
[jas]: https://jasmine.github.io/

example/config.rb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,18 @@
77
proxy "/a-proxied-page.html", "templates/proxy_template.html", locals: {
88
title: "I am a title",
99
}
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

example/config/tech-docs.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
# Host to use for canonical URL generation (without trailing slash)
22
host: https://docs.example.com
33

4+
# Enable GOV.UK Design System nunjucks components (https://design-system.service.gov.uk/components)
5+
enable_govuk_components: true
6+
47
# Header-related options
58
show_govuk_logo: true
69
service_name: My First Service
@@ -14,6 +17,7 @@ header_links:
1417
Expired with owner: /expired-page-with-owner.html
1518
Not expired page: /not-expired-page.html
1619
Single page nav: /single-page-nav.html
20+
Active pages: /active-pages/
1721

1822
footer_links:
1923
Accessibility: /hidden-page.html
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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.

example/source/index.html.md.erb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,10 @@ To change the title of the page or include additional files you'll need to edit
1818
If you want slightly more control, you can always use <strong>HTML</strong>.
1919

2020
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] %>
2122

22-
<%= warning_text "Look out! A warning!" %>
23+
<%= govukButton({
24+
text: "Click me!"
25+
}) %>
26+
27+
<% end %>

govuk_tech_docs.gemspec

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,10 @@ Gem::Specification.new do |spec|
5454
spec.add_dependency "openapi3_parser", "~> 0.10.1"
5555
spec.add_dependency "redcarpet", "~> 3.6"
5656
spec.add_dependency "sassc-embedded", "~> 1.78.0"
57-
spec.add_dependency "terser", "~> 1.2.3"
5857

5958
spec.add_development_dependency "benchmark"
59+
spec.add_dependency "schmooze", "~> 0.2.0"
60+
spec.add_dependency "terser", "~> 1.2.3"
6061
spec.add_development_dependency "byebug"
6162
spec.add_development_dependency "capybara", "~> 3.32"
6263
spec.add_development_dependency "ostruct"

lib/govuk_tech_docs.rb

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
require "govuk_tech_docs/unique_identifier_generator"
2525
require "govuk_tech_docs/warning_text_extension"
2626
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"
2729

2830
module SassWarningSupressor
2931
def warn(message)
@@ -101,11 +103,35 @@ def format_date(date)
101103
end
102104

103105
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
109135
end
110136
end
111137

@@ -138,5 +164,9 @@ def active_page(page_path)
138164
else
139165
context.ignore "search/*"
140166
end
167+
168+
if context.config[:tech_docs][:enable_govuk_components]
169+
context.activate :custom_method_missing_handler
170+
end
141171
end
142172
end
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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 commit comments

Comments
 (0)