Skip to content

Commit

Permalink
Merge pull request #300 from alphagov/iterate-branding
Browse files Browse the repository at this point in the history
Iterate branding model
  • Loading branch information
andysellick authored May 10, 2018
2 parents b53fa52 + ccbf81d commit 5dc0bb1
Show file tree
Hide file tree
Showing 8 changed files with 76 additions and 25 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Unreleased

* Add an optional `canonical` meta tag.
* Add an optional `canonical` meta tag (PR #302)
* Iterate branding model (PR #300)

# 7.2.0

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
margin_bottom_class = " gem-c-document-list--bottom-margin" if local_assigns[:margin_bottom]

brand ||= false
brand_helper = GovukPublishingComponents::Presenters::BrandHelper.new(brand)
brand_helper = GovukPublishingComponents::AppHelpers::BrandHelper.new(brand)
%>
<% if items.any? %>
<ol class="gem-c-document-list<%= margin_bottom_class %><%= margin_top_class %> <%= brand_helper.get_brand %>">
<ol class="gem-c-document-list<%= margin_bottom_class %><%= margin_top_class %> <%= brand_helper.brand_class %>">
<% items.each do |item| %>
<li class="gem-c-document-list__item">
<h3 class="gem-c-document-list__item-title">
Expand All @@ -16,7 +16,7 @@
item[:link][:text],
item[:link][:path],
data: item[:link][:data_attributes],
class: brand_helper.get_brand_element("color")
class: brand_helper.color_class
)
%>
</h3>
Expand Down
6 changes: 3 additions & 3 deletions docs/component_branding.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ To add colours to a component, modify the component to follow the example below.
brand_helper = GovukPublishingComponents::Presenters::BrandHelper.new(brand)
%>
<div class="gem-c-component <%= brand_helper.get_brand %>">
<div class="gem-c-component__title <%= brand_helper.get_brand_element("border-color") %>">
<div class="gem-c-component <%= brand_helper.brand_class %>">
<div class="gem-c-component__title <%= brand_helper.brand_border_color %>">
Example element that requires a coloured border
</div>
<a href="#" class="<%= brand_helper.get_brand_element("color") %>">
<a href="#" class="<%= brand_helper.brand_color %>">
Example element that requires coloured text
</a>
</div>
Expand Down
2 changes: 1 addition & 1 deletion lib/govuk_publishing_components.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
require "govuk_publishing_components/config"
require "govuk_publishing_components/engine"
require "govuk_publishing_components/presenters/brand_helper"
require "govuk_publishing_components/presenters/contextual_navigation"
require "govuk_publishing_components/presenters/related_navigation_helper"
require "govuk_publishing_components/presenters/step_by_step_nav_helper"
Expand All @@ -15,6 +14,7 @@
require "govuk_publishing_components/presenters/content_item"

require "govuk_publishing_components/app_helpers/taxon_breadcrumbs"
require "govuk_publishing_components/app_helpers/brand_helper"

module GovukPublishingComponents
end
25 changes: 25 additions & 0 deletions lib/govuk_publishing_components/app_helpers/brand_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
module GovukPublishingComponents
module AppHelpers
class BrandHelper
def initialize(brand)
@brand = brand if brand
end

# Apply government organisation branding to individual components, specifically
# link colour and border colour
# see https://github.com/alphagov/govuk_publishing_components/blob/master/docs/component_branding.md

def brand_class
"brand--#{@brand}" if @brand
end

def border_color_class
"brand__border-color" if @brand
end

def color_class
"brand__color" if @brand
end
end
end
end
17 changes: 0 additions & 17 deletions lib/govuk_publishing_components/presenters/brand_helper.rb

This file was deleted.

21 changes: 21 additions & 0 deletions spec/components/document_list_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -131,4 +131,25 @@ def component_name
assert_select "#{li} a[data-track-label='/link2']", text: "Link 2"
assert_select "#{li} a[data-track-options='{\"dimension28\":\"2\",\"dimension29\":\"Link 2\"}']", text: "Link 2"
end

it "adds branding correctly" do
render_component(
brand: 'attorney-generals-office',
items: [
{
link: {
text: "School behaviour and attendance: parental responsibility measures",
path: "/government/publications/parental-responsibility-measures-for-behaviour-and-attendance",
},
metadata: {
public_updated_at: Time.zone.parse("2017-01-05 14:50:33 +0000"),
document_type: "Statutory guidance"
}
}
]
)

assert_select '.gem-c-document-list.brand--attorney-generals-office'
assert_select '.gem-c-document-list .gem-c-document-list__item-title .brand__color'
end
end
21 changes: 21 additions & 0 deletions spec/lib/app_helpers/brand_helper_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
require 'spec_helper'

RSpec.describe GovukPublishingComponents::AppHelpers::BrandHelper do
describe "Brand helper" do
it "returns nothing if no brand is specified" do
brand = GovukPublishingComponents::AppHelpers::BrandHelper.new(nil)

expect(brand.brand_class).to eql(nil)
expect(brand.border_color_class).to eql(nil)
expect(brand.color_class).to eql(nil)
end

it "returns the expected brand" do
brand = GovukPublishingComponents::AppHelpers::BrandHelper.new('attorney-generals-office')

expect(brand.brand_class).to eql('brand--attorney-generals-office')
expect(brand.border_color_class).to eql('brand__border-color')
expect(brand.color_class).to eql('brand__color')
end
end
end

0 comments on commit 5dc0bb1

Please sign in to comment.