slimmer 9.6.0 → 10.0.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: d37cd678afb1296a6d4cbf84aee3bcd99a74df28
4
- data.tar.gz: d2708c4354d2dbf6c4521ee51826636c40a18b3e
3
+ metadata.gz: b7b991ffcdf6cdee0c893b13695537a444d9272a
4
+ data.tar.gz: 06bfc18db4b43fd71a9348ea4d2bf0b24113311a
5
5
  SHA512:
6
- metadata.gz: a3795f3e350eac43b774b3d08acc781b30017f8dd268ce937dc5bcb170023ee48ac1e4fee5081f43a5cc0310eef9f8d24584868e7e1458235d8e9a21ef9cc4ae
7
- data.tar.gz: a2b70d4c759b3f0993d3274b5aed1dbc9ff7abbed4ef61f86bbf9b02e260bdfb483f1c1b3c2823d096a91b6f810c40594c8feea7bec208f51954065cfac92ebc
6
+ metadata.gz: 9edba40f3ccaf964d893580121058a6b5aeba3d7d0112b068006c15251d941ac4960efeebeaec8347550b02364935daa82c602c1102951c47ac8e5cb7b5558dd
7
+ data.tar.gz: 46e4d0f6bab847439aca310d7e00d4b080e3b0ee2d6d44afc321b0d973550af13c7f4eedaaa3139b487810b3d10c50b812a4fee003868598d8185c7cadd68231
data/CHANGELOG.md CHANGED
@@ -1,3 +1,12 @@
1
+ # 10.0.0
2
+
3
+ * Removes the need_id meta tag, which is no longer used.
4
+ * Removes the functionality for breadcrumbs, related links and artefact-powered
5
+ metatags.
6
+ * Drop support for old Rails & Ruby versions. This gem now supports Rails 4.2 and 5.X
7
+ on Ruby 2.1 and 2.2.
8
+ * Renames `Slimmer::SharedTemplates` to `Slimmer::GovukComponents`
9
+
1
10
  # 9.6.0
2
11
 
3
12
  * Adds an 'inside header inserter' processor which allows an application to
@@ -19,7 +28,7 @@
19
28
 
20
29
  * Adds an RSpec helper that makes it easy for host applications to
21
30
  configure Slimmer correctly under test.
22
-
31
+
23
32
  Fixes `stub_shared_component_locales` helper to correctly stub HTTP
24
33
  requests to fetch locale information when rendering its templates.
25
34
 
data/README.md CHANGED
@@ -44,7 +44,7 @@ To get asset tag helpers to point to your external asset server, add
44
44
  ```rb
45
45
  config.action_controller.asset_host = "http://my.alternative.host"
46
46
  ```
47
-
47
+
48
48
  to `application.rb`.
49
49
 
50
50
  ## Specifying a template
@@ -101,25 +101,25 @@ YourApp::Application.configure do
101
101
  end
102
102
  ```
103
103
 
104
- ## Shared components
104
+ ## GOV.UK Components
105
105
 
106
- To use shared template components you need to include the shared template resolver
106
+ To use [shared template components](https://govuk-component-guide.herokuapp.com/) you need to include the GOV.UK component module:
107
107
 
108
108
  ```rb
109
109
  class ApplicationController < ActionController::Base
110
- include Slimmer::SharedTemplates
110
+ include Slimmer::GovukComponents
111
111
  end
112
112
  ```
113
113
 
114
- This will make calls out to static when you try and render a partial prefixed with `govuk-component`:
114
+ This will make calls out to static when you try and render a partial prefixed with `govuk_component`:
115
115
 
116
116
  ```erb
117
- <%= render partial: 'govuk-component/example_component' %>
117
+ <%= render partial: 'govuk_component/example_component' %>
118
118
  ```
119
119
 
120
120
  You will need a copy of static running for the templates to be loaded from.
121
121
 
122
- ### Testing shared components
122
+ ### Testing components
123
123
 
124
124
  In test mode (when `Rails.env.test?` returns `true`), shared components are not
125
125
  fetched from Static. Instead they are rendered as a dummy tag which contains a
@@ -130,8 +130,8 @@ component to assert that it was used. You can make it available in your tests
130
130
  with:
131
131
 
132
132
  ```rb
133
- require 'slimmer/test_helpers/shared_templates'
134
- include Slimmer::TestHelpers::SharedTemplates
133
+ require 'slimmer/test_helpers/govuk_components'
134
+ include Slimmer::TestHelpers::GovukComponents
135
135
  ```
136
136
 
137
137
  And then assert that the component has been used:
data/lib/slimmer.rb CHANGED
@@ -16,9 +16,8 @@ module Slimmer
16
16
  autoload :Template, 'slimmer/template'
17
17
  autoload :App, 'slimmer/app'
18
18
  autoload :Headers, 'slimmer/headers'
19
- autoload :Artefact, 'slimmer/artefact'
20
19
 
21
- autoload :SharedTemplates, 'slimmer/shared_templates'
20
+ autoload :GovukComponents, 'slimmer/govuk_components'
22
21
  autoload :ComponentResolver, 'slimmer/component_resolver'
23
22
  autoload :I18nBackend, 'slimmer/i18n_backend'
24
23
 
@@ -31,13 +30,11 @@ module Slimmer
31
30
  autoload :HeaderContextInserter, 'slimmer/processors/header_context_inserter'
32
31
  autoload :InsideHeaderInserter, 'slimmer/processors/inside_header_inserter'
33
32
  autoload :NavigationMover, 'slimmer/processors/navigation_mover'
34
- autoload :RelatedItemsInserter, 'slimmer/processors/related_items_inserter'
35
33
  autoload :ReportAProblemInserter, 'slimmer/processors/report_a_problem_inserter'
36
34
  autoload :SearchIndexSetter, 'slimmer/processors/search_index_setter'
37
35
  autoload :SearchPathSetter, 'slimmer/processors/search_path_setter'
38
36
  autoload :SearchParameterInserter, 'slimmer/processors/search_parameter_inserter'
39
37
  autoload :SearchRemover, 'slimmer/processors/search_remover'
40
- autoload :SectionInserter, 'slimmer/processors/section_inserter'
41
38
  autoload :TagMover, 'slimmer/processors/tag_mover'
42
39
  autoload :TitleInserter, 'slimmer/processors/title_inserter'
43
40
  end
@@ -1,9 +1,9 @@
1
1
  require 'cucumber'
2
2
 
3
3
  require 'slimmer/test'
4
- require 'slimmer/test_helpers/shared_templates'
4
+ require 'slimmer/test_helpers/govuk_components'
5
5
 
6
- World(Slimmer::TestHelpers::SharedTemplates)
6
+ World(Slimmer::TestHelpers::GovukComponents)
7
7
 
8
8
  Before do
9
9
  stub_shared_component_locales
@@ -1,10 +1,10 @@
1
1
  module Slimmer
2
- module SharedTemplates
2
+ module GovukComponents
3
3
  def self.included into
4
- into.before_action :add_shared_templates
4
+ into.before_action :add_govuk_components
5
5
  end
6
6
 
7
- def add_shared_templates
7
+ def add_govuk_components
8
8
  append_view_path Slimmer::ComponentResolver.new
9
9
 
10
10
  return if slimmer_backend_included?
@@ -20,7 +20,6 @@ module Slimmer
20
20
  }
21
21
 
22
22
  APPLICATION_NAME_HEADER = "#{HEADER_PREFIX}-#{SLIMMER_HEADER_MAPPING[:application_name]}"
23
- ARTEFACT_HEADER = "#{HEADER_PREFIX}-Artefact"
24
23
  FORMAT_HEADER = "#{HEADER_PREFIX}-#{SLIMMER_HEADER_MAPPING[:format]}"
25
24
  ORGANISATIONS_HEADER = "#{HEADER_PREFIX}-#{SLIMMER_HEADER_MAPPING[:organisations]}"
26
25
  REPORT_A_PROBLEM_FORM = "#{HEADER_PREFIX}-#{SLIMMER_HEADER_MAPPING[:report_a_problem]}"
@@ -40,46 +39,5 @@ module Slimmer
40
39
  headers["#{HEADER_PREFIX}-#{header_suffix}"] = value.to_s if value
41
40
  end
42
41
  end
43
-
44
- def set_slimmer_artefact(artefact_input)
45
- if artefact_input.is_a?(Hash) or artefact_input.is_a?(OpenStruct)
46
- artefact = artefact_input.dup
47
- elsif artefact_input.respond_to?(:to_hash)
48
- artefact = artefact_input.to_hash
49
- end
50
- yield artefact if block_given?
51
- headers[ARTEFACT_HEADER] = artefact.to_json
52
- end
53
-
54
- def set_slimmer_artefact_overriding_section(artefact_input, details = {})
55
- set_slimmer_artefact(artefact_input) do |artefact|
56
- if tag = slimmer_section_tag_for_details(details)
57
- artefact["tags"] = [tag] + (artefact["tags"] || [])
58
- end
59
- end
60
- end
61
-
62
- def set_slimmer_dummy_artefact(details = {})
63
- set_slimmer_artefact({}) do |artefact|
64
- artefact["title"] = details[:title] if details[:title]
65
- if tag = slimmer_section_tag_for_details(details)
66
- artefact["tags"] = [tag]
67
- end
68
- end
69
- end
70
-
71
- def slimmer_section_tag_for_details(details)
72
- if details[:section_name] and details[:section_link]
73
- tag = {
74
- "title" => details[:section_name],
75
- "details" => {"type" => "section"},
76
- "content_with_tag" => {"web_url" => details[:section_link]},
77
- }
78
- if details[:parent]
79
- tag["parent"] = slimmer_section_tag_for_details(details[:parent])
80
- end
81
- tag
82
- end
83
- end
84
42
  end
85
43
  end
@@ -1,19 +1,13 @@
1
1
  module Slimmer::Processors
2
2
  class MetadataInserter
3
- def initialize(response, artefact, app_name)
3
+ def initialize(response, app_name)
4
4
  @headers = response.headers
5
- @artefact = artefact
6
5
  @app_name = app_name
7
6
  end
8
7
 
9
8
  def filter(src, dest)
10
9
  head = dest.at_css('head')
11
10
 
12
- if @artefact
13
- add_meta_tag('section', @artefact.primary_root_section["title"].downcase, head) if @artefact.primary_root_section
14
- add_meta_tag('need-ids', @artefact.need_ids.join(',').downcase, head) if @artefact.need_ids
15
- end
16
-
17
11
  add_meta_tag('analytics:organisations', @headers[Slimmer::Headers::ORGANISATIONS_HEADER], head)
18
12
  add_meta_tag('analytics:world-locations', @headers[Slimmer::Headers::WORLD_LOCATIONS_HEADER], head)
19
13
  add_meta_tag('format', @headers[Slimmer::Headers::FORMAT_HEADER], head)
data/lib/slimmer/rspec.rb CHANGED
@@ -2,10 +2,10 @@ require 'rspec/core'
2
2
 
3
3
  require 'slimmer'
4
4
  require 'slimmer/test'
5
- require 'slimmer/test_helpers/shared_templates'
5
+ require 'slimmer/test_helpers/govuk_components'
6
6
 
7
7
  RSpec.configure do |config|
8
- config.include Slimmer::TestHelpers::SharedTemplates
8
+ config.include Slimmer::TestHelpers::GovukComponents
9
9
 
10
10
  config.before { stub_shared_component_locales }
11
11
  end
data/lib/slimmer/skin.rb CHANGED
@@ -104,7 +104,6 @@ module Slimmer
104
104
  end
105
105
 
106
106
  def success(source_request, response, body)
107
- artefact = artefact_from_header(response)
108
107
  wrapper_id = options[:wrapper_id] || 'wrapper'
109
108
  processors = [
110
109
  Processors::TitleInserter.new(),
@@ -115,11 +114,9 @@ module Slimmer
115
114
  Processors::BodyClassCopier.new,
116
115
  Processors::InsideHeaderInserter.new,
117
116
  Processors::HeaderContextInserter.new(),
118
- Processors::SectionInserter.new(artefact),
119
- Processors::MetadataInserter.new(response, artefact, options[:app_name]),
117
+ Processors::MetadataInserter.new(response, options[:app_name]),
120
118
  Processors::SearchParameterInserter.new(response),
121
119
  Processors::SearchPathSetter.new(response),
122
- Processors::RelatedItemsInserter.new(self, artefact),
123
120
  Processors::ReportAProblemInserter.new(self,
124
121
  source_request.url,
125
122
  response.headers,
@@ -137,16 +134,5 @@ module Slimmer
137
134
  ]
138
135
  process(processors, body, template(template_name), rack_env)
139
136
  end
140
-
141
- def artefact_from_header(response)
142
- if response.headers.include?(Headers::ARTEFACT_HEADER)
143
- Artefact.new JSON.parse(response.headers[Headers::ARTEFACT_HEADER])
144
- else
145
- nil
146
- end
147
- rescue JSON::ParserError => e
148
- logger.error "Slimmer: Failed while parsing artefact header: #{[ e.message, e.backtrace ].flatten.join("\n")}"
149
- nil
150
- end
151
137
  end
152
138
  end
@@ -2,7 +2,7 @@ require 'webmock'
2
2
 
3
3
  module Slimmer
4
4
  module TestHelpers
5
- module SharedTemplates
5
+ module GovukComponents
6
6
  def stub_shared_component_locales
7
7
  stub_request(:get, /https?:\/\/\S+.gov.uk\/templates\/locales\/.+/).
8
8
  to_return(status: 400, headers: {})
@@ -1,3 +1,3 @@
1
1
  module Slimmer
2
- VERSION = '9.6.0'
2
+ VERSION = '10.0.0'
3
3
  end
data/test/headers_test.rb CHANGED
@@ -49,142 +49,9 @@ class HeadersTest < MiniTest::Test
49
49
  assert_equal "rhubarb", headers["X-Slimmer-Skip"]
50
50
  end
51
51
 
52
- def test_should_skip_missing_headers
53
- set_slimmer_headers section: "rhubarb"
54
- refute_includes headers.keys, "X-Slimmer-Need-ID"
55
- end
56
-
57
52
  def test_should_raise_an_exception_if_a_header_has_a_typo
58
53
  assert_raises Slimmer::Headers::InvalidHeader do
59
54
  set_slimmer_headers seccion: "wrong"
60
55
  end
61
56
  end
62
57
  end
63
-
64
- describe Slimmer::Headers do
65
- include Slimmer::Headers
66
- attr_accessor :headers
67
-
68
- before do
69
- self.headers = {}
70
- end
71
-
72
- describe "setting the artefact header" do
73
- it "should convert a hash to JSON and insert into the header" do
74
- artefact = {"foo" => "bar"}
75
- self.set_slimmer_artefact(artefact)
76
- assert_equal artefact.to_json, headers[Slimmer::Headers::ARTEFACT_HEADER]
77
- end
78
-
79
- it "should convert an OpenStruct to JSON" do
80
- artefact = OpenStruct.new("foo" => "bar")
81
- self.set_slimmer_artefact(artefact)
82
- assert_equal({"foo" => "bar"}.to_json, headers[Slimmer::Headers::ARTEFACT_HEADER])
83
- end
84
-
85
- it "should handle an object that responds to :to_hash" do
86
- hash = {"foo" => "bar", "slug" => "vat-rates"}
87
- artefact = stub("Response", :to_hash => hash)
88
- self.set_slimmer_artefact(artefact)
89
- assert_equal hash.to_json, headers[Slimmer::Headers::ARTEFACT_HEADER]
90
- end
91
-
92
- it "should not have side-effects on the passed in hash" do
93
- artefact = {"foo" => "bar", "slug" => "vat-rates", "actions" => "some_actions"}
94
- artefact_copy = artefact.dup
95
- self.set_slimmer_artefact(artefact)
96
- assert_equal artefact_copy, artefact
97
- end
98
- end
99
-
100
- describe "setting the artefact and adding a dummy section" do
101
- it "should setup a section tag for the given name and link" do
102
- artefact_input = {"foo" => "bar", "slug" => "vat-rates", "actions" => "some_actions"}
103
- self.set_slimmer_artefact_overriding_section(artefact_input, :section_name => "Foo", :section_link => "/something/foo")
104
-
105
- artefact = JSON.parse(headers[Slimmer::Headers::ARTEFACT_HEADER])
106
-
107
- assert_equal "Foo", artefact["tags"][0]["title"]
108
- assert_equal "section", artefact["tags"][0]["details"]["type"]
109
- assert_equal "/something/foo", artefact["tags"][0]["content_with_tag"]["web_url"]
110
- end
111
-
112
- it "should not overwrite existing tags" do
113
- artefact_input = {"foo" => "bar", "slug" => "vat-rates", "actions" => "some_actions", "tags" => ["foo", "bar"]}
114
- self.set_slimmer_artefact_overriding_section(artefact_input, :section_name => "Foo", :section_link => "/something/foo")
115
-
116
- artefact = JSON.parse(headers[Slimmer::Headers::ARTEFACT_HEADER])
117
-
118
- assert_equal ["foo", "bar"], artefact["tags"][1..-1]
119
- end
120
-
121
- it "should not have side-effects on the passed in hash" do
122
- artefact_input = {"foo" => "bar", "slug" => "vat-rates", "actions" => "some_actions"}
123
- artefact_copy = artefact_input.dup
124
- self.set_slimmer_artefact_overriding_section(artefact_input, :section_name => "Foo", :section_link => "/foo")
125
- assert_equal artefact_copy, artefact_input
126
- end
127
-
128
- it "should work correctly with a gds_api response object" do
129
- input_artefact = {"foo" => "bar", "slug" => "vat-rates", "actions" => "some_actions"}
130
- api_response = GdsApi::Response.new(stub("HTTP Response", :code => 200, :body => input_artefact.to_json))
131
- self.set_slimmer_artefact_overriding_section(api_response, :section_name => "Foo", :section_link => "/something/foo")
132
-
133
- artefact = JSON.parse(headers[Slimmer::Headers::ARTEFACT_HEADER])
134
-
135
- assert_equal "Foo", artefact["tags"][0]["title"]
136
- assert_equal "section", artefact["tags"][0]["details"]["type"]
137
- assert_equal "/something/foo", artefact["tags"][0]["content_with_tag"]["web_url"]
138
- end
139
- end
140
-
141
- describe "setting a dummy artefact in the artefact header" do
142
- it "should setup an artefact title" do
143
- self.set_slimmer_dummy_artefact(:title => "Foo")
144
-
145
- artefact = JSON.parse(headers[Slimmer::Headers::ARTEFACT_HEADER])
146
-
147
- assert_equal "Foo", artefact["title"]
148
- end
149
-
150
- it "should setup a section tag for the given name and link" do
151
- self.set_slimmer_dummy_artefact(:section_name => "Foo", :section_link => "/something/foo")
152
-
153
- artefact = JSON.parse(headers[Slimmer::Headers::ARTEFACT_HEADER])
154
-
155
- assert_equal "Foo", artefact["tags"][0]["title"]
156
- assert_equal "section", artefact["tags"][0]["details"]["type"]
157
- assert_equal "/something/foo", artefact["tags"][0]["content_with_tag"]["web_url"]
158
- end
159
-
160
- it "can set up a section tag with multiple levels of parents" do
161
- self.set_slimmer_dummy_artefact(
162
- :section_name => "Foo",
163
- :section_link => "/something/baz/bar/foo",
164
- :parent => {
165
- :section_name => "Bar",
166
- :section_link => "/something/baz/bar",
167
- :parent => {
168
- :section_name => "Baz",
169
- :section_link => "/something/baz"
170
- }
171
- }
172
- )
173
-
174
- artefact = JSON.parse(headers[Slimmer::Headers::ARTEFACT_HEADER])
175
-
176
- assert_equal "Foo", artefact["tags"][0]["title"]
177
- assert_equal "section", artefact["tags"][0]["details"]["type"]
178
- assert_equal "/something/baz/bar/foo", artefact["tags"][0]["content_with_tag"]["web_url"]
179
-
180
- assert_equal "Bar", artefact["tags"][0]["parent"]["title"]
181
- assert_equal "section", artefact["tags"][0]["parent"]["details"]["type"]
182
- assert_equal "/something/baz/bar", artefact["tags"][0]["parent"]["content_with_tag"]["web_url"]
183
-
184
- assert_equal "Baz", artefact["tags"][0]["parent"]["parent"]["title"]
185
- assert_equal "section", artefact["tags"][0]["parent"]["parent"]["details"]["type"]
186
- assert_equal "/something/baz", artefact["tags"][0]["parent"]["parent"]["content_with_tag"]["web_url"]
187
-
188
- end
189
- end
190
- end
@@ -31,14 +31,9 @@ module MetadataInserterTest
31
31
  def setup
32
32
  super
33
33
 
34
- artefact = artefact_for_slug_in_a_subsection("something", "rhubarb/in-puddings")
35
- artefact["details"].merge!(
36
- "need_ids" => [100001,100002],
37
- )
38
34
  headers = {
39
35
  Slimmer::Headers::FORMAT_HEADER => "custard",
40
36
  Slimmer::Headers::RESULT_COUNT_HEADER => "3",
41
- Slimmer::Headers::ARTEFACT_HEADER => artefact.to_json,
42
37
  Slimmer::Headers::ORGANISATIONS_HEADER => "<P1><D422>",
43
38
  Slimmer::Headers::WORLD_LOCATIONS_HEADER => "<WL3>"
44
39
  }
@@ -46,18 +41,10 @@ module MetadataInserterTest
46
41
  given_response 200, GENERIC_DOCUMENT, headers
47
42
  end
48
43
 
49
- def test_should_include_section_meta_tag
50
- assert_meta_tag "section", "rhubarb"
51
- end
52
-
53
44
  def test_should_include_format_meta_tag
54
45
  assert_meta_tag "format", "custard"
55
46
  end
56
47
 
57
- def test_should_include_need_ids_meta_tag
58
- assert_meta_tag "need-ids", "100001,100002"
59
- end
60
-
61
48
  def test_should_include_organisations_meta_tag
62
49
  assert_meta_tag "analytics:organisations", "<P1><D422>"
63
50
  end
@@ -71,28 +58,6 @@ module MetadataInserterTest
71
58
  end
72
59
  end
73
60
 
74
- class WithInvalidAttributes < SlimmerIntegrationTest
75
- include MetaTagAssertions
76
-
77
- def setup
78
- super
79
- end
80
-
81
- def test_should_skip_passing_need_ids_if_they_are_nil
82
- artefact = artefact_for_slug_in_a_subsection("something", "rhubarb/in-puddings")
83
- headers = {
84
- Slimmer::Headers::ARTEFACT_HEADER => artefact.to_json,
85
- Slimmer::Headers::FORMAT_HEADER => "custard"
86
- }
87
- given_response 200, GENERIC_DOCUMENT, headers
88
-
89
- refute_meta_tag "need-ids"
90
- # the presence of these attributes tests that the nil check worked
91
- assert_meta_tag "section", "rhubarb"
92
- assert_meta_tag "format", "custard"
93
- end
94
- end
95
-
96
61
  class WithoutHeadersTest < SlimmerIntegrationTest
97
62
  include MetaTagAssertions
98
63
 
@@ -106,10 +71,6 @@ module MetadataInserterTest
106
71
  refute_meta_tag "format"
107
72
  end
108
73
 
109
- def test_should_omit_need_ID
110
- refute_meta_tag "need-ids"
111
- end
112
-
113
74
  def test_should_omit_organisations
114
75
  refute_meta_tag "analytics:organisations"
115
76
  end
@@ -122,28 +83,4 @@ module MetadataInserterTest
122
83
  refute_meta_tag "search-result-count"
123
84
  end
124
85
  end
125
-
126
- class WithNilHeaderTest < SlimmerIntegrationTest
127
- include MetaTagAssertions
128
-
129
- def setup
130
- super
131
-
132
- artefact = artefact_for_slug_in_a_subsection("something", "rhubarb/in-puddings")
133
- artefact["details"].merge!(
134
- "need_ids" => [100001, 100002],
135
- )
136
- headers = {
137
- Slimmer::Headers::RESULT_COUNT_HEADER => "3",
138
- Slimmer::Headers::ARTEFACT_HEADER => artefact.to_json,
139
- Slimmer::Headers::ORGANISATIONS_HEADER => "<P1><D422>"
140
- }
141
-
142
- given_response 200, GENERIC_DOCUMENT, headers
143
- end
144
-
145
- def test_should_include_organisation_meta_tag_without_crashing
146
- assert_meta_tag "analytics:organisations", "<P1><D422>"
147
- end
148
- end
149
86
  end