Browse Source

Merge pull request #390 from communitiesuk/content-helper

Add helper to render Markdown content pages
routes-to-csv
Paul Robert Lloyd 3 years ago committed by GitHub
parent
commit
afc60d627b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      Gemfile
  2. 5
      Gemfile.lock
  3. 24
      app/controllers/content_controller.rb
  4. 0
      app/views/content/accessibility_statement.md
  5. 9
      app/views/content/page.html.erb
  6. 0
      app/views/content/privacy_notice.md
  7. 4
      config/routes.rb
  8. 34
      spec/requests/content_controller_spec.rb

2
Gemfile

@ -19,6 +19,8 @@ gem "bootsnap", ">= 1.4.4", require: false
gem "govuk-components" gem "govuk-components"
# GOV UK component form builder DSL # GOV UK component form builder DSL
gem "govuk_design_system_formbuilder" gem "govuk_design_system_formbuilder"
# Convert Markdown into GOV.UK frontend-styled HTML
gem "govuk_markdown"
# GOV UK Notify # GOV UK Notify
gem "notifications-ruby-client" gem "notifications-ruby-client"
# Turbo and Stimulus # Turbo and Stimulus

5
Gemfile.lock

@ -181,6 +181,9 @@ GEM
activemodel (>= 6.1) activemodel (>= 6.1)
activesupport (>= 6.1) activesupport (>= 6.1)
deep_merge (~> 1.2.1) deep_merge (~> 1.2.1)
govuk_markdown (1.0.0)
activesupport
redcarpet
has_scope (0.8.0) has_scope (0.8.0)
actionpack (>= 5.2) actionpack (>= 5.2)
activesupport (>= 5.2) activesupport (>= 5.2)
@ -328,6 +331,7 @@ GEM
rb-fsevent (0.11.1) rb-fsevent (0.11.1)
rb-inotify (0.10.1) rb-inotify (0.10.1)
ffi (~> 1.0) ffi (~> 1.0)
redcarpet (3.5.1)
redis (4.6.0) redis (4.6.0)
regexp_parser (2.2.1) regexp_parser (2.2.1)
request_store (1.5.1) request_store (1.5.1)
@ -476,6 +480,7 @@ DEPENDENCIES
factory_bot_rails factory_bot_rails
govuk-components govuk-components
govuk_design_system_formbuilder govuk_design_system_formbuilder
govuk_markdown
hotwire-rails hotwire-rails
json-schema json-schema
listen (~> 3.3) listen (~> 3.3)

24
app/controllers/content_controller.rb

@ -0,0 +1,24 @@
class ContentController < ApplicationController
def accessibility_statement
render_content_page :accessibility_statement
end
def privacy_notice
render_content_page :privacy_notice, page_title: "Privacy notice for tenants and buyers of new social housing"
end
private
def render_content_page(page_name, page_title: nil, locals: {})
raw_content = File.read("app/views/content/#{page_name}.md")
content_with_erb_tags_replaced = ApplicationController.renderer.render(
inline: raw_content,
locals:,
)
@page_title = page_title || page_name.to_s.humanize
@page_content = GovukMarkdown.render(content_with_erb_tags_replaced).html_safe
render "content/page"
end
end

0
app/views/content/accessibility_statement.md

9
app/views/content/page.html.erb

@ -0,0 +1,9 @@
<%= content_for :title, @page_title %>
<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds-from-desktop">
<h1 class="govuk-heading-xl"><%= @page_title %></h1>
<%= @page_content %>
</div>
</div>

0
app/views/content/privacy_notice.md

4
config/routes.rb

@ -33,6 +33,10 @@ Rails.application.routes.draw do
root to: "start#index" root to: "start#index"
# Content pages
get "/accessibility-statement", to: "content#accessibility_statement"
get "/privacy-notice", to: "content#privacy_notice"
resources :users do resources :users do
member do member do
get "password/edit", to: "users#edit_password" get "password/edit", to: "users#edit_password"

34
spec/requests/content_controller_spec.rb

@ -0,0 +1,34 @@
require "rails_helper"
RSpec.describe ContentController, type: :request do
let(:headers) { { "Accept" => "text/html" } }
let(:page) { Capybara::Node::Simple.new(response.body) }
describe "render privacy notice content page" do
before do
get "/privacy-notice", headers: headers, params: {}
end
it "returns a 200" do
expect(response).to have_http_status(:success)
end
it "returns the page" do
expect(page).to have_title("Privacy notice")
end
end
describe "render accessibility statement content page" do
before do
get "/accessibility-statement", headers: headers, params: {}
end
it "returns a 200" do
expect(response).to have_http_status(:success)
end
it "returns the page" do
expect(page).to have_title("Accessibility statement")
end
end
end
Loading…
Cancel
Save