diff --git a/CHANGELOG.md b/CHANGELOG.md index a58b0db50b..b188b2caa7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/app/views/govuk_publishing_components/components/_document_list.html.erb b/app/views/govuk_publishing_components/components/_document_list.html.erb index 5cf3d79017..b446f92208 100644 --- a/app/views/govuk_publishing_components/components/_document_list.html.erb +++ b/app/views/govuk_publishing_components/components/_document_list.html.erb @@ -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? %> -
    +
      <% items.each do |item| %>
    1. @@ -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 ) %>

      diff --git a/docs/component_branding.md b/docs/component_branding.md index 94ba7bc6c1..a6cf7f7b9e 100644 --- a/docs/component_branding.md +++ b/docs/component_branding.md @@ -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) %> -
      -
      "> +
      +
      Example element that requires a coloured border
      - "> + Example element that requires coloured text
      diff --git a/lib/govuk_publishing_components.rb b/lib/govuk_publishing_components.rb index ac0185bc1b..0282d537cb 100644 --- a/lib/govuk_publishing_components.rb +++ b/lib/govuk_publishing_components.rb @@ -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" @@ -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 diff --git a/lib/govuk_publishing_components/app_helpers/brand_helper.rb b/lib/govuk_publishing_components/app_helpers/brand_helper.rb new file mode 100644 index 0000000000..30132234df --- /dev/null +++ b/lib/govuk_publishing_components/app_helpers/brand_helper.rb @@ -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 diff --git a/lib/govuk_publishing_components/presenters/brand_helper.rb b/lib/govuk_publishing_components/presenters/brand_helper.rb deleted file mode 100644 index 479e335883..0000000000 --- a/lib/govuk_publishing_components/presenters/brand_helper.rb +++ /dev/null @@ -1,17 +0,0 @@ -module GovukPublishingComponents - module Presenters - class BrandHelper - def initialize(brand) - @brand = brand if brand - end - - def get_brand - "brand--#{@brand}" if @brand - end - - def get_brand_element(attribute) - "brand__#{attribute}" if @brand - end - end - end -end diff --git a/spec/components/document_list_spec.rb b/spec/components/document_list_spec.rb index e4b85e96c9..86b9b8fe8a 100644 --- a/spec/components/document_list_spec.rb +++ b/spec/components/document_list_spec.rb @@ -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 diff --git a/spec/lib/app_helpers/brand_helper_spec.rb b/spec/lib/app_helpers/brand_helper_spec.rb new file mode 100644 index 0000000000..c64636c9d9 --- /dev/null +++ b/spec/lib/app_helpers/brand_helper_spec.rb @@ -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