-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #384 from alphagov/v4-v5-co-hosting
Host v4 in its own folder
- Loading branch information
Showing
35 changed files
with
2,008 additions
and
93 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,3 +25,4 @@ Staticfile.auth | |
|
||
# Sassdocs generated files | ||
data/sassdoc.json | ||
data/sassdoc-v4.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
## | ||
# Middleman extension fixing the menu button in the header | ||
# | ||
# The element is missing a `hidden` attribute, which the extension | ||
# adds using Nokogiri when rendering the `layouts/_header.erb` partial | ||
# | ||
# @see https://middlemanapp.com/advanced/custom-extensions/ | ||
class HeaderMenuFixExtension < Middleman::Extension | ||
def initialize(app, options_hash = {}, &block) | ||
super | ||
|
||
# @see https://github.com/middleman/middleman/blob/ad0e0ee9ba5e017e4f3f1cc861f4fa2a4c04f198/middleman-core/lib/middleman-core/extension.rb#L63 | ||
app.after_render do |content, path| | ||
# The `after_render` hook will trigger for each renderer (eg. md, erb) | ||
# and each partial/layout being rendered. We only care about the one | ||
# containing the menu button, which is `layouts/_header.erb` | ||
next unless path == "layouts/_header.erb" | ||
|
||
html = Nokogiri::HTML5.fragment(content) | ||
|
||
menu_button = html.search(".govuk-header__menu-button").first | ||
next unless menu_button | ||
|
||
menu_button["hidden"] = "" | ||
|
||
html.serialize | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
## | ||
# Extra helpers for customising the rendering of the table of contents in the sidebar | ||
# so it accomodates a separate table of contents for the `v4` section of the site | ||
module TableOfContentsHelpers | ||
## | ||
# Override `render_page_tree` so it can be bypassed when rendering the children | ||
# of a specific given page (stored in `@parent_page`) (see `without_child_pages_for` bellow). | ||
# This enables not rendering the child pages of the `index`, as they'll be rendered | ||
# individually as well. | ||
# This is due to the lack of abstraction for the test checking whether to render a resource | ||
# as a single item or an item the tree of its children | ||
# See: https://github.com/alphagov/tech-docs-gem/blob/207bcb8593197f3aad8983018ca0a91db7783410/lib/govuk_tech_docs/table_of_contents/helpers.rb#L74 | ||
def render_page_tree(resources, *args) | ||
return "" if resources == @parent_page&.children | ||
|
||
super(resources, *args) | ||
end | ||
|
||
## | ||
# Temporarily excludes the children of the given page | ||
# from being rendered by `render_page_tree` while it runs | ||
# in the block passed to this method | ||
# | ||
# @example | ||
# | ||
# without_child_pages_for(a_page) do | ||
# render_page_tree(some_pages_including_a_page,...) | ||
# end | ||
def without_child_pages_for(parent_page) | ||
@parent_page = parent_page | ||
|
||
yield | ||
ensure | ||
@parent_page = nil | ||
end | ||
|
||
## | ||
# Forces a page configured hidden from the navigation with | ||
# `hide_in_navigation: true` to be rendered in the navigation when | ||
# `render_page_tree` runs in the block this method receives | ||
# | ||
# @example | ||
# | ||
# with_page_in_navigation(a_page) do | ||
# render_page_tree(some_pages_including_a_page,...) | ||
# end | ||
def with_page_in_navigation(page) | ||
original = page.data.hide_in_navigation | ||
page.data.hide_in_navigation = false | ||
|
||
yield | ||
ensure | ||
page.data.hide_in_navigation = original | ||
end | ||
end |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<% | ||
wrap_layout :core do | ||
html = yield | ||
|
||
content_for(:toc_module, "in-page-navigation") | ||
|
||
# For v4 pages, we only want the pages under the `v4` folder | ||
resources = sitemap.resources.select do |r| | ||
r.path.start_with?('v4/') | ||
end | ||
|
||
content_for :sidebar do | ||
# Because all the pages for `v4` are children of `v4/index.html`, | ||
# they'd appear as items under the v4 index in the sidebar, which we don't want | ||
# so we exclude the rendering of child pages for the v4 index page | ||
v4_index = resources.find{ |r| r.path == 'v4/index.html' } | ||
|
||
with_page_in_navigation(v4_index) do | ||
without_child_pages_for(v4_index) do | ||
render_page_tree(resources, current_page, config, html) | ||
end | ||
end | ||
end | ||
|
||
html | ||
end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.