slimmer 3.1.1 → 3.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/slimmer/headers.rb +7 -1
- data/lib/slimmer/processors/google_analytics_configurator.rb +11 -12
- data/lib/slimmer/processors/section_inserter.rb +9 -3
- data/lib/slimmer/skin.rb +1 -1
- data/lib/slimmer/version.rb +1 -1
- data/test/headers_test.rb +7 -0
- data/test/processors/google_analytics_test.rb +17 -10
- data/test/processors/section_inserter_test.rb +3 -3
- metadata +49 -49
data/lib/slimmer/headers.rb
CHANGED
@@ -18,6 +18,8 @@ module Slimmer
|
|
18
18
|
SKIP_HEADER = "#{HEADER_PREFIX}-Skip"
|
19
19
|
SEARCH_PATH_HEADER = "#{HEADER_PREFIX}-Search-Path"
|
20
20
|
ARTEFACT_HEADER = "#{HEADER_PREFIX}-Artefact"
|
21
|
+
FORMAT_HEADER = "#{HEADER_PREFIX}-Format"
|
22
|
+
RESULT_COUNT_HEADER = "#{HEADER_PREFIX}-Result-Count"
|
21
23
|
|
22
24
|
def set_slimmer_headers(hash)
|
23
25
|
raise InvalidHeader if (hash.keys - SLIMMER_HEADER_MAPPING.keys).any?
|
@@ -28,7 +30,11 @@ module Slimmer
|
|
28
30
|
end
|
29
31
|
|
30
32
|
def set_slimmer_artefact(artefact_input)
|
31
|
-
|
33
|
+
if artefact_input.is_a?(Hash) or artefact_input.is_a?(OpenStruct)
|
34
|
+
artefact = artefact_input.dup
|
35
|
+
elsif artefact_input.respond_to?(:to_hash)
|
36
|
+
artefact = artefact_input.to_hash
|
37
|
+
end
|
32
38
|
headers[ARTEFACT_HEADER] = artefact.to_json
|
33
39
|
end
|
34
40
|
|
@@ -3,25 +3,24 @@ require "json"
|
|
3
3
|
module Slimmer::Processors
|
4
4
|
class GoogleAnalyticsConfigurator
|
5
5
|
PAGE_LEVEL_EVENT = 3
|
6
|
-
HEADER_MAPPING = {
|
7
|
-
"Section" => "X-SLIMMER-SECTION",
|
8
|
-
"Format" => "X-SLIMMER-FORMAT",
|
9
|
-
"NeedID" => "X-SLIMMER-NEED-ID",
|
10
|
-
"Proposition" => "X-SLIMMER-PROPOSITION",
|
11
|
-
"ResultCount" => "X-SLIMMER-RESULT-COUNT"
|
12
|
-
}
|
13
6
|
|
14
|
-
def initialize(response)
|
7
|
+
def initialize(response, artefact)
|
15
8
|
@headers = response.headers
|
9
|
+
@artefact = artefact
|
16
10
|
end
|
17
11
|
|
18
12
|
def filter(src, dest)
|
19
|
-
custom_vars =
|
20
|
-
|
21
|
-
|
13
|
+
custom_vars = []
|
14
|
+
if @artefact
|
15
|
+
custom_vars << set_custom_var(1, "Section", @artefact.primary_section["title"]) if @artefact.primary_section
|
16
|
+
custom_vars << set_custom_var(3, "NeedID", @artefact.need_id)
|
17
|
+
custom_vars << set_custom_var(4, "Proposition", (@artefact.business_proposition ? 'business' : 'citizen')) unless @artefact.business_proposition.nil?
|
18
|
+
end
|
19
|
+
custom_vars << set_custom_var(2, "Format", @headers[Slimmer::Headers::FORMAT_HEADER])
|
20
|
+
custom_vars << set_custom_var(5, "ResultCount", @headers[Slimmer::Headers::RESULT_COUNT_HEADER])
|
22
21
|
|
23
22
|
if dest.at_css("#ga-params")
|
24
|
-
dest.at_css("#ga-params").content += custom_vars
|
23
|
+
dest.at_css("#ga-params").content += custom_vars.compact.join("\n")
|
25
24
|
end
|
26
25
|
end
|
27
26
|
|
@@ -8,20 +8,26 @@ module Slimmer::Processors
|
|
8
8
|
if @artefact and (list = dest.at_css('.header-context nav[role=navigation] ol'))
|
9
9
|
if (section = @artefact.primary_section)
|
10
10
|
append_tag(list, section["parent"]) if section["parent"]
|
11
|
-
append_tag(list, section)
|
11
|
+
append_tag(list, section, :strong => true)
|
12
12
|
end
|
13
13
|
end
|
14
14
|
end
|
15
15
|
|
16
16
|
private
|
17
17
|
|
18
|
-
def append_tag(list, tag)
|
18
|
+
def append_tag(list, tag, opts = {})
|
19
19
|
link_node = Nokogiri::XML::Node.new('a', list)
|
20
20
|
link_node['href'] = tag["content_with_tag"]["web_url"]
|
21
21
|
link_node.content = tag["title"]
|
22
22
|
|
23
23
|
list_item = Nokogiri::XML::Node.new('li', list)
|
24
|
-
|
24
|
+
if opts[:strong]
|
25
|
+
strong = Nokogiri::XML::Node.new('strong', list)
|
26
|
+
strong.add_child(link_node)
|
27
|
+
list_item.add_child(strong)
|
28
|
+
else
|
29
|
+
list_item.add_child(link_node)
|
30
|
+
end
|
25
31
|
|
26
32
|
list.add_child(list_item)
|
27
33
|
end
|
data/lib/slimmer/skin.rb
CHANGED
@@ -129,7 +129,7 @@ module Slimmer
|
|
129
129
|
Processors::BodyClassCopier.new,
|
130
130
|
Processors::HeaderContextInserter.new(),
|
131
131
|
Processors::SectionInserter.new(artefact),
|
132
|
-
Processors::GoogleAnalyticsConfigurator.new(response),
|
132
|
+
Processors::GoogleAnalyticsConfigurator.new(response, artefact),
|
133
133
|
Processors::SearchPathSetter.new(response),
|
134
134
|
Processors::RelatedItemsInserter.new(self, artefact),
|
135
135
|
Processors::LogoClassInserter.new(artefact),
|
data/lib/slimmer/version.rb
CHANGED
data/test/headers_test.rb
CHANGED
@@ -77,6 +77,13 @@ describe Slimmer::Headers do
|
|
77
77
|
assert_equal({"foo" => "bar"}.to_json, headers[Slimmer::Headers::ARTEFACT_HEADER])
|
78
78
|
end
|
79
79
|
|
80
|
+
it "should handle an object that responds to :to_hash" do
|
81
|
+
hash = {"foo" => "bar", "slug" => "vat-rates"}
|
82
|
+
artefact = stub("Response", :to_hash => hash)
|
83
|
+
self.set_slimmer_artefact(artefact)
|
84
|
+
assert_equal hash.to_json, headers[Slimmer::Headers::ARTEFACT_HEADER]
|
85
|
+
end
|
86
|
+
|
80
87
|
it "should not have side-effects on the passed in hash" do
|
81
88
|
artefact = {"foo" => "bar", "slug" => "vat-rates", "actions" => "some_actions"}
|
82
89
|
artefact_copy = artefact.dup
|
@@ -1,4 +1,4 @@
|
|
1
|
-
|
1
|
+
require_relative "../test_helper"
|
2
2
|
require "v8"
|
3
3
|
|
4
4
|
module GoogleAnalyticsTest
|
@@ -51,15 +51,22 @@ module GoogleAnalyticsTest
|
|
51
51
|
include JavaScriptAssertions
|
52
52
|
PAGE_LEVEL_EVENT = 3
|
53
53
|
|
54
|
-
|
55
|
-
|
56
|
-
"X-Slimmer-Format" => "custard",
|
57
|
-
"X-Slimmer-Need-ID" => "42",
|
58
|
-
"X-Slimmer-Proposition" => "trifle",
|
59
|
-
"X-Slimmer-Result-Count" => "3"
|
60
|
-
}
|
54
|
+
def setup
|
55
|
+
super
|
61
56
|
|
62
|
-
|
57
|
+
artefact = artefact_for_slug_in_a_section("something", "rhubarb")
|
58
|
+
artefact["details"].merge!(
|
59
|
+
"need_id" => "42",
|
60
|
+
"business_proposition" => true
|
61
|
+
)
|
62
|
+
headers = {
|
63
|
+
Slimmer::Headers::FORMAT_HEADER => "custard",
|
64
|
+
Slimmer::Headers::RESULT_COUNT_HEADER => "3",
|
65
|
+
Slimmer::Headers::ARTEFACT_HEADER => artefact.to_json
|
66
|
+
}
|
67
|
+
|
68
|
+
given_response 200, GENERIC_DOCUMENT, headers
|
69
|
+
end
|
63
70
|
|
64
71
|
def test_should_pass_section_to_GA
|
65
72
|
assert_custom_var 1, "Section", "rhubarb", PAGE_LEVEL_EVENT
|
@@ -86,7 +93,7 @@ module GoogleAnalyticsTest
|
|
86
93
|
end
|
87
94
|
|
88
95
|
def test_should_pass_proposition_to_GA
|
89
|
-
assert_custom_var 4, "Proposition", "
|
96
|
+
assert_custom_var 4, "Proposition", "business", PAGE_LEVEL_EVENT
|
90
97
|
end
|
91
98
|
|
92
99
|
def test_should_set_section_in_GOVUK_object
|
@@ -38,7 +38,7 @@ class SectionInserterTest < MiniTest::Unit::TestCase
|
|
38
38
|
Slimmer::Processors::SectionInserter.new(artefact).filter(:any_source, template)
|
39
39
|
list = template.at_css(".header-context nav[role=navigation] ol")
|
40
40
|
assert_in list, "li:nth-child(1)", %{<a href="/">Home</a>}
|
41
|
-
assert_in list, "li:nth-child(2)", %{<a href="https://www.test.gov.uk/browse/business">Business</a>}
|
41
|
+
assert_in list, "li:nth-child(2)", %{<strong><a href="https://www.test.gov.uk/browse/business">Business</a></strong>}
|
42
42
|
end
|
43
43
|
|
44
44
|
def test_should_add_section_link_subsection_link_and_title_to_breadcrumb
|
@@ -62,7 +62,7 @@ class SectionInserterTest < MiniTest::Unit::TestCase
|
|
62
62
|
list = template.at_css(".header-context nav[role=navigation] ol")
|
63
63
|
assert_in list, "li:nth-child(1)", %{<a href="/">Home</a>}
|
64
64
|
assert_in list, "li:nth-child(2)", %{<a href="https://www.test.gov.uk/browse/business">Business</a>}
|
65
|
-
assert_in list, "li:nth-child(3)", %{<a href="https://www.test.gov.uk/browse/business/employing-people">Employing people</a>}
|
65
|
+
assert_in list, "li:nth-child(3)", %{<strong><a href="https://www.test.gov.uk/browse/business/employing-people">Employing people</a></strong>}
|
66
66
|
end
|
67
67
|
|
68
68
|
def test_should_add_links_after_last_item_in_breadcrumb
|
@@ -90,7 +90,7 @@ class SectionInserterTest < MiniTest::Unit::TestCase
|
|
90
90
|
assert_in list, "li:nth-child(1)", %{<a href="/">Home</a>}
|
91
91
|
assert_in list, "li:nth-child(2)", %{<a href="/browse">All Sections</a>}
|
92
92
|
assert_in list, "li:nth-child(3)", %{<a href="https://www.test.gov.uk/browse/business">Business</a>}
|
93
|
-
assert_in list, "li:nth-child(4)", %{<a href="https://www.test.gov.uk/browse/business/employing-people">Employing people</a>}
|
93
|
+
assert_in list, "li:nth-child(4)", %{<strong><a href="https://www.test.gov.uk/browse/business/employing-people">Employing people</a></strong>}
|
94
94
|
end
|
95
95
|
|
96
96
|
def test_should_do_nothing_if_navigation_not_in_template
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: slimmer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 3.
|
5
|
+
version: 3.2.0
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Ben Griffiths
|
@@ -11,7 +11,7 @@ autorequire:
|
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
13
|
|
14
|
-
date: 2012-09-
|
14
|
+
date: 2012-09-17 00:00:00 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: nokogiri
|
@@ -159,49 +159,49 @@ files:
|
|
159
159
|
- README.md
|
160
160
|
- CHANGELOG.md
|
161
161
|
- lib/tasks/slimmer.rake
|
162
|
-
- lib/slimmer.rb
|
163
|
-
- lib/slimmer/skin.rb
|
164
|
-
- lib/slimmer/railtie.rb
|
165
|
-
- lib/slimmer/template.rb
|
166
|
-
- lib/slimmer/test_template.rb
|
167
|
-
- lib/slimmer/test.rb
|
168
|
-
- lib/slimmer/app.rb
|
169
|
-
- lib/slimmer/processors/logo_class_inserter.rb
|
162
|
+
- lib/slimmer/version.rb
|
170
163
|
- lib/slimmer/processors/body_class_copier.rb
|
171
|
-
- lib/slimmer/processors/tag_mover.rb
|
172
|
-
- lib/slimmer/processors/search_path_setter.rb
|
173
|
-
- lib/slimmer/processors/title_inserter.rb
|
174
164
|
- lib/slimmer/processors/google_analytics_configurator.rb
|
175
|
-
- lib/slimmer/processors/conditional_comment_mover.rb
|
176
165
|
- lib/slimmer/processors/related_items_inserter.rb
|
177
|
-
- lib/slimmer/processors/header_context_inserter.rb
|
178
166
|
- lib/slimmer/processors/body_inserter.rb
|
179
|
-
- lib/slimmer/processors/
|
167
|
+
- lib/slimmer/processors/logo_class_inserter.rb
|
180
168
|
- lib/slimmer/processors/report_a_problem_inserter.rb
|
181
|
-
- lib/slimmer/processors/section_inserter.rb
|
182
169
|
- lib/slimmer/processors/footer_remover.rb
|
183
|
-
- lib/slimmer/
|
184
|
-
- lib/slimmer/
|
170
|
+
- lib/slimmer/processors/conditional_comment_mover.rb
|
171
|
+
- lib/slimmer/processors/admin_title_inserter.rb
|
172
|
+
- lib/slimmer/processors/section_inserter.rb
|
173
|
+
- lib/slimmer/processors/search_path_setter.rb
|
174
|
+
- lib/slimmer/processors/tag_mover.rb
|
175
|
+
- lib/slimmer/processors/title_inserter.rb
|
176
|
+
- lib/slimmer/processors/header_context_inserter.rb
|
177
|
+
- lib/slimmer/template.rb
|
178
|
+
- lib/slimmer/railtie.rb
|
179
|
+
- lib/slimmer/test.rb
|
185
180
|
- lib/slimmer/artefact.rb
|
181
|
+
- lib/slimmer/skin.rb
|
182
|
+
- lib/slimmer/app.rb
|
183
|
+
- lib/slimmer/headers.rb
|
184
|
+
- lib/slimmer/test_template.rb
|
185
|
+
- lib/slimmer.rb
|
186
186
|
- Rakefile
|
187
|
-
- test/
|
188
|
-
- test/artefact_test.rb
|
189
|
-
- test/fixtures/related.raw.html.erb
|
190
|
-
- test/fixtures/500.html.erb
|
191
|
-
- test/fixtures/404.html.erb
|
192
|
-
- test/fixtures/wrapper.html.erb
|
193
|
-
- test/fixtures/report_a_problem.raw.html.erb
|
194
|
-
- test/skin_test.rb
|
195
|
-
- test/processors/logo_class_inserter_test.rb
|
196
|
-
- test/processors/google_analytics_test.rb
|
187
|
+
- test/processors/related_items_inserter_test.rb
|
197
188
|
- test/processors/report_a_problem_inserter_test.rb
|
198
|
-
- test/processors/body_inserter_test.rb
|
199
|
-
- test/processors/search_path_setter_test.rb
|
200
189
|
- test/processors/section_inserter_test.rb
|
201
|
-
- test/processors/
|
190
|
+
- test/processors/google_analytics_test.rb
|
202
191
|
- test/processors/header_context_inserter_test.rb
|
203
|
-
- test/
|
192
|
+
- test/processors/body_inserter_test.rb
|
193
|
+
- test/processors/logo_class_inserter_test.rb
|
194
|
+
- test/processors/search_path_setter_test.rb
|
195
|
+
- test/artefact_test.rb
|
196
|
+
- test/skin_test.rb
|
197
|
+
- test/headers_test.rb
|
204
198
|
- test/test_template_dependency_on_static_test.rb
|
199
|
+
- test/typical_usage_test.rb
|
200
|
+
- test/fixtures/500.html.erb
|
201
|
+
- test/fixtures/404.html.erb
|
202
|
+
- test/fixtures/report_a_problem.raw.html.erb
|
203
|
+
- test/fixtures/related.raw.html.erb
|
204
|
+
- test/fixtures/wrapper.html.erb
|
205
205
|
- test/test_helper.rb
|
206
206
|
- bin/render_slimmer_error
|
207
207
|
homepage: http://github.com/alphagov/slimmer
|
@@ -217,7 +217,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
217
217
|
requirements:
|
218
218
|
- - ">="
|
219
219
|
- !ruby/object:Gem::Version
|
220
|
-
hash:
|
220
|
+
hash: 3747362976319846846
|
221
221
|
segments:
|
222
222
|
- 0
|
223
223
|
version: "0"
|
@@ -226,7 +226,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
226
226
|
requirements:
|
227
227
|
- - ">="
|
228
228
|
- !ruby/object:Gem::Version
|
229
|
-
hash:
|
229
|
+
hash: 3747362976319846846
|
230
230
|
segments:
|
231
231
|
- 0
|
232
232
|
version: "0"
|
@@ -238,22 +238,22 @@ signing_key:
|
|
238
238
|
specification_version: 3
|
239
239
|
summary: Thinner than the skinner
|
240
240
|
test_files:
|
241
|
-
- test/
|
242
|
-
- test/artefact_test.rb
|
243
|
-
- test/fixtures/related.raw.html.erb
|
244
|
-
- test/fixtures/500.html.erb
|
245
|
-
- test/fixtures/404.html.erb
|
246
|
-
- test/fixtures/wrapper.html.erb
|
247
|
-
- test/fixtures/report_a_problem.raw.html.erb
|
248
|
-
- test/skin_test.rb
|
249
|
-
- test/processors/logo_class_inserter_test.rb
|
250
|
-
- test/processors/google_analytics_test.rb
|
241
|
+
- test/processors/related_items_inserter_test.rb
|
251
242
|
- test/processors/report_a_problem_inserter_test.rb
|
252
|
-
- test/processors/body_inserter_test.rb
|
253
|
-
- test/processors/search_path_setter_test.rb
|
254
243
|
- test/processors/section_inserter_test.rb
|
255
|
-
- test/processors/
|
244
|
+
- test/processors/google_analytics_test.rb
|
256
245
|
- test/processors/header_context_inserter_test.rb
|
257
|
-
- test/
|
246
|
+
- test/processors/body_inserter_test.rb
|
247
|
+
- test/processors/logo_class_inserter_test.rb
|
248
|
+
- test/processors/search_path_setter_test.rb
|
249
|
+
- test/artefact_test.rb
|
250
|
+
- test/skin_test.rb
|
251
|
+
- test/headers_test.rb
|
258
252
|
- test/test_template_dependency_on_static_test.rb
|
253
|
+
- test/typical_usage_test.rb
|
254
|
+
- test/fixtures/500.html.erb
|
255
|
+
- test/fixtures/404.html.erb
|
256
|
+
- test/fixtures/report_a_problem.raw.html.erb
|
257
|
+
- test/fixtures/related.raw.html.erb
|
258
|
+
- test/fixtures/wrapper.html.erb
|
259
259
|
- test/test_helper.rb
|