govuk_navigation_helpers 2.3.1 → 2.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 783242d5e27cba520c2b62463bc8b98f3db7caa3
4
- data.tar.gz: c9600fd1a77522e033c6f42c8e84e0c82909e782
3
+ metadata.gz: 925f41952a73c6f57ba09696d8b3eb9f3cd4f460
4
+ data.tar.gz: c60be579e0918ac56ab9720e07fc7d9957113d0a
5
5
  SHA512:
6
- metadata.gz: 8322866da307b50a8621068bee8e5571db753405bcdb7087bb95e23975d67f4dc33a4fe3816c3b1bf83de7b8e9d21e943ba6ebbfe973ff341ebb62983c825f9b
7
- data.tar.gz: f6db60711406ccd72a5c2fd7046a4bbdc40adf5709f0a1c62f83ad733c5c6bf1a4a4fa628abc4440182c8507c6885212bb086e5c906f9647406041825b6db3e3
6
+ metadata.gz: 793282df094eb26e965a5ae97215a2279b7f72bf6afec86cbca844c4fc216231ce7c082800ee3526cbeacd9dd12191697f55ff9aa7b04e1e3d0d699bfc5a97fe
7
+ data.tar.gz: ba673437955eea0d5ceda36cfe1b53522e278adfa14ca79b9a4228c4d1a89c15d06477befa4ac1f56f6527344edd6081e7ced480d51397a88b249dabf22095de
@@ -1,3 +1,7 @@
1
+ ## 2.4.0
2
+
3
+ * Add helper for rendering sidebar on taxonomy content pages.
4
+
1
5
  ## 2.3.1
2
6
 
3
7
  * Convert all ContentItem initialization objects to a hash
@@ -1,5 +1,7 @@
1
1
  #!/usr/bin/env groovy
2
2
 
3
+ REPOSITORY = 'govuk_navigation_helpers'
4
+
3
5
  node {
4
6
  def govuk = load '/var/lib/jenkins/groovy_scripts/govuk_jenkinslib.groovy'
5
7
 
@@ -33,8 +35,35 @@ node {
33
35
 
34
36
  if(env.BRANCH_NAME == "master") {
35
37
  stage('Publish Gem') {
36
- sshagent(['govuk-ci-ssh-key']) {
37
- govuk.runRakeTask("publish_gem --trace")
38
+ def version = sh(
39
+ script: /ruby -e "puts eval(File.read('${REPOSITORY}.gemspec'), TOPLEVEL_BINDING).version.to_s"/,
40
+ returnStdout: true
41
+ ).trim()
42
+
43
+ def taggedReleaseExists = sh(
44
+ script: "git tag | grep v${version}",
45
+ returnStatus: true
46
+ ) == 0
47
+
48
+ if (taggedReleaseExists) {
49
+ echo "Version ${version} has already been tagged on Github"
50
+ } else {
51
+ echo('Pushing tag')
52
+ govuk.pushTag(REPOSITORY, env.BRANCH_NAME, 'v' + version)
53
+ }
54
+
55
+ def escapedVersion = version.replaceAll(/\./, /\\\\./)
56
+ def versionAlreadyPublished = sh(
57
+ script: /gem list ^${REPOSITORY}\$ --remote --all --quiet | grep [^0-9\\.]${escapedVersion}[^0-9\\.]/,
58
+ returnStatus: true
59
+ ) == 0
60
+
61
+ if (versionAlreadyPublished) {
62
+ echo "Version ${version} has already been published to rubygems.org"
63
+ } else {
64
+ echo('Publishing gem')
65
+ sh("gem build ${REPOSITORY}.gemspec")
66
+ sh("gem push '${REPOSITORY}-${version}.gem'")
38
67
  }
39
68
  }
40
69
  }
@@ -2,6 +2,7 @@ require "govuk_navigation_helpers/version"
2
2
  require "govuk_navigation_helpers/breadcrumbs"
3
3
  require "govuk_navigation_helpers/related_items"
4
4
  require "govuk_navigation_helpers/taxon_breadcrumbs"
5
+ require "govuk_navigation_helpers/taxonomy_sidebar"
5
6
 
6
7
  module GovukNavigationHelpers
7
8
  class NavigationHelper
@@ -25,6 +26,15 @@ module GovukNavigationHelpers
25
26
  TaxonBreadcrumbs.new(content_item).breadcrumbs
26
27
  end
27
28
 
29
+ # Generate a payload containing taxon sidebar data. Intended for use with
30
+ # the related items component.
31
+ #
32
+ # @return [Hash] Payload for the GOV.UK related items component
33
+ # @see http://govuk-component-guide.herokuapp.com/components/related_items
34
+ def taxonomy_sidebar
35
+ TaxonomySidebar.new(content_item).sidebar
36
+ end
37
+
28
38
  # Generate a related items payload
29
39
  #
30
40
  # @return [Hash] Payload for the GOV.UK Component
@@ -1,6 +1,7 @@
1
1
  module GovukNavigationHelpers
2
- # Simple wrapper around a content store representation of a content item. Works
3
- # for both the main content item and the expanded links in the links hash.
2
+ # Simple wrapper around a content store representation of a content item.
3
+ # Works for both the main content item and the expanded links in the links
4
+ # hash.
4
5
  #
5
6
  # @private
6
7
  class ContentItem
@@ -17,12 +18,20 @@ module GovukNavigationHelpers
17
18
  end
18
19
 
19
20
  def parent_taxon
20
- # TODO: Determine what to do when there are multiple taxons/parents. For now just display the first of each.
21
- taxon = content_store_response.dig("links", "taxons", 0)
22
- return ContentItem.new(taxon) if taxon
21
+ # TODO: Determine what to do when there are multiple taxons/parents. For
22
+ # now just display the first of each.
23
+ parent_taxons.first
24
+ end
25
+
26
+ def parent_taxons
27
+ # First handle the case for content items tagged to the taxonomy.
28
+ taxons = Array(content_store_response.dig("links", "taxons"))
29
+ return taxons.map { |taxon| ContentItem.new(taxon) } if taxons.any?
23
30
 
24
- parent_taxon = content_store_response.dig("links", "parent_taxons", 0)
25
- return ContentItem.new(parent_taxon) if parent_taxon
31
+ # If that link isn't present, assume we're dealing with a taxon and check
32
+ # for its parents in the taxonomy.
33
+ parent_taxons = Array(content_store_response.dig("links", "parent_taxons"))
34
+ parent_taxons.map { |taxon| ContentItem.new(taxon) }
26
35
  end
27
36
 
28
37
  def mainstream_browse_pages
@@ -39,6 +48,10 @@ module GovukNavigationHelpers
39
48
  content_store_response.fetch("base_path")
40
49
  end
41
50
 
51
+ def description
52
+ content_store_response.fetch("description", "")
53
+ end
54
+
42
55
  def content_id
43
56
  content_store_response.fetch("content_id")
44
57
  end
@@ -0,0 +1,26 @@
1
+ module GovukNavigationHelpers
2
+ class TaxonomySidebar
3
+ def initialize(content_item)
4
+ @content_item = ContentItem.new content_item
5
+ end
6
+
7
+ def sidebar
8
+ {
9
+ sections: taxons.any? ? [{ title: "More about", items: taxons }] : []
10
+ }
11
+ end
12
+
13
+ private
14
+
15
+ def taxons
16
+ parent_taxons = @content_item.parent_taxons
17
+ parent_taxons.map do |parent_taxon|
18
+ {
19
+ title: parent_taxon.title,
20
+ url: parent_taxon.base_path,
21
+ description: parent_taxon.description,
22
+ }
23
+ end
24
+ end
25
+ end
26
+ end
@@ -1,3 +1,3 @@
1
1
  module GovukNavigationHelpers
2
- VERSION = "2.3.1".freeze
2
+ VERSION = "2.4.0".freeze
3
3
  end
@@ -0,0 +1,66 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe GovukNavigationHelpers::TaxonomySidebar do
4
+ describe '#sidebar' do
5
+ it 'can handle any valid content item' do
6
+ generator = GovukSchemas::RandomExample.for_schema(
7
+ 'placeholder',
8
+ schema_type: 'frontend'
9
+ )
10
+
11
+ expect { sidebar_for(generator.payload) }.to_not raise_error
12
+ end
13
+
14
+ context 'given a content item not tagged to any taxon' do
15
+ it 'returns an empty sidebar hash' do
16
+ content_item = { "links" => {} }
17
+
18
+ expect(sidebar_for(content_item)).to eq(
19
+ sections: []
20
+ )
21
+ end
22
+ end
23
+
24
+ context 'given a content item tagged to taxons' do
25
+ it 'returns a sidebar hash containing a list of parent taxons' do
26
+ content_item = content_item_tagged_to_taxon
27
+
28
+ expect(sidebar_for(content_item)).to eq(
29
+ sections: [
30
+ {
31
+ title: "More about",
32
+ items: [
33
+ { title: "Taxon 1", url: "/taxon-1", description: "The 1st taxon." },
34
+ { title: "Taxon 2", url: "/taxon-2", description: "The 2nd taxon." },
35
+ ],
36
+ }
37
+ ]
38
+ )
39
+ end
40
+ end
41
+ end
42
+
43
+ def sidebar_for(content_item)
44
+ GovukNavigationHelpers::NavigationHelper.new(content_item).taxonomy_sidebar
45
+ end
46
+
47
+ def content_item_tagged_to_taxon
48
+ {
49
+ "title" => "A piece of content",
50
+ "links" => {
51
+ "taxons" => [
52
+ {
53
+ "title" => "Taxon 1",
54
+ "base_path" => "/taxon-1",
55
+ "description" => "The 1st taxon.",
56
+ },
57
+ {
58
+ "title" => "Taxon 2",
59
+ "base_path" => "/taxon-2",
60
+ "description" => "The 2nd taxon.",
61
+ },
62
+ ],
63
+ },
64
+ }
65
+ end
66
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: govuk_navigation_helpers
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.3.1
4
+ version: 2.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - GOV.UK Dev
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-02-16 00:00:00.000000000 Z
11
+ date: 2017-02-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -147,11 +147,13 @@ files:
147
147
  - lib/govuk_navigation_helpers/grouped_related_links.rb
148
148
  - lib/govuk_navigation_helpers/related_items.rb
149
149
  - lib/govuk_navigation_helpers/taxon_breadcrumbs.rb
150
+ - lib/govuk_navigation_helpers/taxonomy_sidebar.rb
150
151
  - lib/govuk_navigation_helpers/version.rb
151
152
  - spec/breadcrumbs_spec.rb
152
153
  - spec/related_items_spec.rb
153
154
  - spec/spec_helper.rb
154
155
  - spec/taxon_breadcrumbs_spec.rb
156
+ - spec/taxonomy_sidebar_spec.rb
155
157
  homepage: https://github.com/alphagov/govuk_navigation_helpers
156
158
  licenses:
157
159
  - MIT
@@ -181,3 +183,4 @@ test_files:
181
183
  - spec/related_items_spec.rb
182
184
  - spec/spec_helper.rb
183
185
  - spec/taxon_breadcrumbs_spec.rb
186
+ - spec/taxonomy_sidebar_spec.rb