Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add show_review_banner configuration option #122

Merged
merged 2 commits into from
Oct 11, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ Selectively include only the CSS for the GOV.UK Frontend components that we are

Fix service name to link to the configured `service_link`, rather than being hardcoded to `/` ([#119](https://github.com/alphagov/tech-docs-gem/issues/119))

Add the `show_review_banner` global configuration option allowing users to hide the page review banner.

## 2.0.4

Adds `footer_links` option for displaying links in the footer and ability to hide pages from left hand navigation.
Expand Down
12 changes: 12 additions & 0 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -214,3 +214,15 @@ If set to `false`, the red banner will not appear when the page needs to be revi
See the separate [documentation for page expiry][expiry] for more details.

[expiry]: https://tdt-documentation.london.cloudapps.digital/page-expiry.html#page-expiry-and-review

## `show_review_banner`

Decides whether or not to display the page review banner, regardless of whether the page needs to be reviewed or not.

If not present or set to `true`, the banner will be displayed on the page. This is the default behaviour.

If set to `false`, the banner will not be displayed.

See the separate [documentation for page expiry][expiry] for more details.

[expiry]: https://tdt-documentation.london.cloudapps.digital/page-expiry.html#page-expiry-and-review
9 changes: 4 additions & 5 deletions docs/page-expiry.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,13 @@ Setting `show_expiry: false` generates a blue banner with the last reviewed date
This feature relies on JavaScript being enabled on the user's browser to
display the relevant notices.

If you want to disable the banners, but keep the review dates in the frontmatter, add the following to `source/javascripts/application.js`
If you want to disable the banners, but keep the review dates in the frontmatter, add the following to your global configuration file:

```js
// Disable page expiry banner
window.GOVUK.Modules.PageExpiry = null;
```yaml
show_review_banner: false
```

For example if you do not want any page expiry banner at the bottom of the page, but want to have the review dates in the frontmatter for Daniel the Manual Spaniel to pick up.
The page review banner will no longer appear at the bottom of the page, but Daniel the Manual Spaniel will still notify you about expired pages.

## Frontmatter configuration

Expand Down
51 changes: 0 additions & 51 deletions example/config/hide-expiry.yml

This file was deleted.

4 changes: 4 additions & 0 deletions lib/govuk_tech_docs/page_review.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ def show_expiry?
@config[:tech_docs].fetch(:show_expiry, true)
end

def show_review_banner?
@config[:tech_docs].fetch(:show_review_banner, true)
end

private

def default_owner_slack
Expand Down
2 changes: 1 addition & 1 deletion lib/source/layouts/_page_review.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<% if current_page_review.under_review? %>
<% if current_page_review.under_review? && current_page_review.show_review_banner? %>
<div data-module='page-expiry' data-last-reviewed-on="<%= current_page_review.review_by %>">
<div class='page-expiry--<%= current_page_review.show_expiry? ? "not-expired" : "default" %>'>
This page was last reviewed on <%= format_date current_page_review.last_reviewed_on %>.
Expand Down
18 changes: 17 additions & 1 deletion spec/features/page_expiration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,24 @@
then_i_dont_see_review_date
end

it "hides the review banner when show_review_banner is false" do
when_the_site_is_created_hiding_review_banner
and_i_visit_an_expired_page
then_i_dont_see_the_review_banner
and_i_visit_a_not_expired_page
then_i_dont_see_the_review_banner
end

def when_the_site_is_created
rebuild_site!
end

def when_the_site_is_created_hiding_expiry
rebuild_site!(config: "config/hide-expiry.yml")
rebuild_site!(overrides: { 'show_expiry' => false })
end

def when_the_site_is_created_hiding_review_banner
rebuild_site!(overrides: { 'show_review_banner' => false })
end

def and_i_visit_an_expired_page
Expand All @@ -47,4 +59,8 @@ def then_i_dont_see_the_page_has_expired
def then_i_dont_see_review_date
expect(page).to have_no_content "It needs to be reviewed again on"
end

def then_i_dont_see_the_review_banner
expect(page).to have_no_content "This page was last reviewed"
end
end
29 changes: 20 additions & 9 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
$LOAD_PATH.unshift(File.expand_path('../lib', __dir__))

require 'govuk_tech_docs'
require 'tempfile'
require 'yaml'

# This file was generated by the `rspec --init` command. Conventionally, all
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
Expand All @@ -21,16 +23,25 @@
#
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
RSpec.configure do |config|
def rebuild_site!(config: "config/tech-docs.yml")
command = [
"cd example",
"rm -rf build",
"bundle install --quiet",
"CONFIG_FILE=#{config} NO_CONTRACTS=true middleman build --bail --show-exceptions"
].join(" && ")
def rebuild_site!(config: "config/tech-docs.yml", overrides: {})
config_file = Tempfile.new('tech_docs_config')

unless system(command)
raise "`middleman build` failed, see the log for more info"
begin
Dir.chdir('example') do
new_config = YAML.load_file(config).merge(overrides)
config_file.write(YAML.dump(new_config))
config_file.close
command = [
"rm -rf build",
"bundle install --quiet",
"CONFIG_FILE=#{config_file.path} NO_CONTRACTS=true middleman build --bail --show-exceptions"
].join(" && ")
unless system(command)
raise "`middleman build` failed, see the log for more info"
end
end
ensure
config_file.unlink
end
end

Expand Down