slimmer 4.2.2 → 4.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +5 -0
- data/lib/slimmer/headers.rb +2 -0
- data/lib/slimmer/processors/search_parameter_inserter.rb +50 -0
- data/lib/slimmer/skin.rb +1 -0
- data/lib/slimmer/version.rb +1 -1
- data/lib/slimmer.rb +1 -0
- data/test/processors/search_parameter_inserter_test.rb +52 -0
- metadata +39 -36
data/CHANGELOG.md
CHANGED
data/lib/slimmer/headers.rb
CHANGED
@@ -16,6 +16,7 @@ module Slimmer
|
|
16
16
|
world_locations: "World-Locations",
|
17
17
|
remove_meta_viewport: "Remove-Meta-Viewport",
|
18
18
|
result_count: "Result-Count",
|
19
|
+
search_parameters: "Search-Parameters",
|
19
20
|
section: "Section",
|
20
21
|
skip: "Skip",
|
21
22
|
template: "Template",
|
@@ -33,6 +34,7 @@ module Slimmer
|
|
33
34
|
REMOVE_META_VIEWPORT = "#{HEADER_PREFIX}-#{SLIMMER_HEADER_MAPPING[:remove_meta_viewport]}"
|
34
35
|
RESULT_COUNT_HEADER = "#{HEADER_PREFIX}-#{SLIMMER_HEADER_MAPPING[:result_count]}"
|
35
36
|
SEARCH_PATH_HEADER = "#{HEADER_PREFIX}-Search-Path"
|
37
|
+
SEARCH_PARAMETERS_HEADER = "#{HEADER_PREFIX}-#{SLIMMER_HEADER_MAPPING[:search_parameters]}"
|
36
38
|
SKIP_HEADER = "#{HEADER_PREFIX}-#{SLIMMER_HEADER_MAPPING[:skip]}"
|
37
39
|
TEMPLATE_HEADER = "#{HEADER_PREFIX}-#{SLIMMER_HEADER_MAPPING[:template]}"
|
38
40
|
|
@@ -0,0 +1,50 @@
|
|
1
|
+
require 'json'
|
2
|
+
|
3
|
+
module Slimmer::Processors
|
4
|
+
class SearchParameterInserter
|
5
|
+
def initialize(response)
|
6
|
+
@response = response
|
7
|
+
end
|
8
|
+
|
9
|
+
def filter(content_document, page_template)
|
10
|
+
search_form = page_template.at_css('form#search')
|
11
|
+
if search_parameters && search_form
|
12
|
+
search_parameters.each_pair do |name, value|
|
13
|
+
# Value can either be a string or an array of values
|
14
|
+
if value.is_a? Array
|
15
|
+
array_name = "#{name}[]"
|
16
|
+
value.each do |array_value|
|
17
|
+
add_hidden_input(search_form, array_name, array_value)
|
18
|
+
end
|
19
|
+
else
|
20
|
+
add_hidden_input(search_form, name, value)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def add_hidden_input(search_form, name, value)
|
27
|
+
element = Nokogiri::XML::Node.new('input', search_form)
|
28
|
+
element['type'] = 'hidden'
|
29
|
+
element['name'] = name
|
30
|
+
element['value'] = value.to_s
|
31
|
+
search_form.add_child(element)
|
32
|
+
end
|
33
|
+
|
34
|
+
def search_parameters
|
35
|
+
@search_parameters ||= parse_search_parameters
|
36
|
+
end
|
37
|
+
|
38
|
+
def parse_search_parameters
|
39
|
+
header_value = @response.headers.fetch(Slimmer::Headers::SEARCH_PARAMETERS_HEADER)
|
40
|
+
if header_value.nil?
|
41
|
+
[]
|
42
|
+
else
|
43
|
+
JSON.parse(header_value)
|
44
|
+
end
|
45
|
+
rescue JSON::ParserError => e
|
46
|
+
logger.error "Slimmer: Failed while parsing search parameters header: #{[ e.message, e.backtrace ].flatten.join("\n")}"
|
47
|
+
[]
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
data/lib/slimmer/skin.rb
CHANGED
@@ -116,6 +116,7 @@ module Slimmer
|
|
116
116
|
Processors::HeaderContextInserter.new(),
|
117
117
|
Processors::SectionInserter.new(artefact),
|
118
118
|
Processors::GoogleAnalyticsConfigurator.new(response, artefact),
|
119
|
+
Processors::SearchParameterInserter.new(response),
|
119
120
|
Processors::SearchPathSetter.new(response),
|
120
121
|
Processors::RelatedItemsInserter.new(self, artefact),
|
121
122
|
Processors::LogoClassInserter.new(artefact),
|
data/lib/slimmer/version.rb
CHANGED
data/lib/slimmer.rb
CHANGED
@@ -43,6 +43,7 @@ module Slimmer
|
|
43
43
|
autoload :ReportAProblemInserter, 'slimmer/processors/report_a_problem_inserter'
|
44
44
|
autoload :SearchIndexSetter, 'slimmer/processors/search_index_setter'
|
45
45
|
autoload :SearchPathSetter, 'slimmer/processors/search_path_setter'
|
46
|
+
autoload :SearchParameterInserter, 'slimmer/processors/search_parameter_inserter'
|
46
47
|
autoload :SectionInserter, 'slimmer/processors/section_inserter'
|
47
48
|
autoload :TagMover, 'slimmer/processors/tag_mover'
|
48
49
|
autoload :TitleInserter, 'slimmer/processors/title_inserter'
|
@@ -0,0 +1,52 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
module SearchParameterInserterTest
|
4
|
+
|
5
|
+
DOCUMENT_WITH_SEARCH = <<-END
|
6
|
+
<html>
|
7
|
+
<head>
|
8
|
+
</head>
|
9
|
+
<body class="body_class">
|
10
|
+
<div id="wrapper">
|
11
|
+
<form id="search" action="/path/to/search">
|
12
|
+
</form>
|
13
|
+
</div>
|
14
|
+
</body>
|
15
|
+
</html>
|
16
|
+
END
|
17
|
+
|
18
|
+
class WithHeaderTest < SlimmerIntegrationTest
|
19
|
+
headers = {
|
20
|
+
"X-Slimmer-Search-Parameters" => '{"filter_organisations": ["land-registry"], "count": 20}',
|
21
|
+
}
|
22
|
+
|
23
|
+
given_response 200, DOCUMENT_WITH_SEARCH, headers
|
24
|
+
|
25
|
+
def test_should_add_hidden_input
|
26
|
+
hidden_inputs = Nokogiri::HTML.parse(last_response.body).css('#search input[type=hidden]')
|
27
|
+
assert_equal %{<input type="hidden" name="filter_organisations[]" value="land-registry"><input type="hidden" name="count" value="20">}, hidden_inputs.to_s
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
class WithInvalidHeaderTest < SlimmerIntegrationTest
|
32
|
+
headers = {
|
33
|
+
"X-Slimmer-Search-Parameters" => '[not-valid-json',
|
34
|
+
}
|
35
|
+
|
36
|
+
given_response 200, DOCUMENT_WITH_SEARCH, headers
|
37
|
+
|
38
|
+
def test_should_not_add_hidden_input
|
39
|
+
hidden_inputs = Nokogiri::HTML.parse(last_response.body).at_css('#search input[type=hidden]')
|
40
|
+
assert_equal nil, hidden_inputs
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
class WithoutHeaderTest < SlimmerIntegrationTest
|
45
|
+
given_response 200, DOCUMENT_WITH_SEARCH, {}
|
46
|
+
|
47
|
+
def test_should_leave_original_search_action
|
48
|
+
hidden_inputs = Nokogiri::HTML.parse(last_response.body).at_css('#search input[type=hidden]')
|
49
|
+
assert_equal nil, hidden_inputs
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: slimmer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.
|
4
|
+
version: 4.3.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,11 +10,11 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2014-08-
|
13
|
+
date: 2014-08-28 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: nokogiri
|
17
|
-
requirement: &
|
17
|
+
requirement: &12654680 !ruby/object:Gem::Requirement
|
18
18
|
none: false
|
19
19
|
requirements:
|
20
20
|
- - ~>
|
@@ -22,10 +22,10 @@ dependencies:
|
|
22
22
|
version: 1.5.0
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
|
-
version_requirements: *
|
25
|
+
version_requirements: *12654680
|
26
26
|
- !ruby/object:Gem::Dependency
|
27
27
|
name: rack
|
28
|
-
requirement: &
|
28
|
+
requirement: &12651000 !ruby/object:Gem::Requirement
|
29
29
|
none: false
|
30
30
|
requirements:
|
31
31
|
- - ! '>='
|
@@ -33,10 +33,10 @@ dependencies:
|
|
33
33
|
version: 1.3.5
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
|
-
version_requirements: *
|
36
|
+
version_requirements: *12651000
|
37
37
|
- !ruby/object:Gem::Dependency
|
38
38
|
name: plek
|
39
|
-
requirement: &
|
39
|
+
requirement: &12611740 !ruby/object:Gem::Requirement
|
40
40
|
none: false
|
41
41
|
requirements:
|
42
42
|
- - ! '>='
|
@@ -44,10 +44,10 @@ dependencies:
|
|
44
44
|
version: 0.1.8
|
45
45
|
type: :runtime
|
46
46
|
prerelease: false
|
47
|
-
version_requirements: *
|
47
|
+
version_requirements: *12611740
|
48
48
|
- !ruby/object:Gem::Dependency
|
49
49
|
name: json
|
50
|
-
requirement: &
|
50
|
+
requirement: &12610620 !ruby/object:Gem::Requirement
|
51
51
|
none: false
|
52
52
|
requirements:
|
53
53
|
- - ! '>='
|
@@ -55,10 +55,10 @@ dependencies:
|
|
55
55
|
version: '0'
|
56
56
|
type: :runtime
|
57
57
|
prerelease: false
|
58
|
-
version_requirements: *
|
58
|
+
version_requirements: *12610620
|
59
59
|
- !ruby/object:Gem::Dependency
|
60
60
|
name: null_logger
|
61
|
-
requirement: &
|
61
|
+
requirement: &12994680 !ruby/object:Gem::Requirement
|
62
62
|
none: false
|
63
63
|
requirements:
|
64
64
|
- - ! '>='
|
@@ -66,10 +66,10 @@ dependencies:
|
|
66
66
|
version: '0'
|
67
67
|
type: :runtime
|
68
68
|
prerelease: false
|
69
|
-
version_requirements: *
|
69
|
+
version_requirements: *12994680
|
70
70
|
- !ruby/object:Gem::Dependency
|
71
71
|
name: rest-client
|
72
|
-
requirement: &
|
72
|
+
requirement: &12992200 !ruby/object:Gem::Requirement
|
73
73
|
none: false
|
74
74
|
requirements:
|
75
75
|
- - ! '>='
|
@@ -77,10 +77,10 @@ dependencies:
|
|
77
77
|
version: '0'
|
78
78
|
type: :runtime
|
79
79
|
prerelease: false
|
80
|
-
version_requirements: *
|
80
|
+
version_requirements: *12992200
|
81
81
|
- !ruby/object:Gem::Dependency
|
82
82
|
name: activesupport
|
83
|
-
requirement: &
|
83
|
+
requirement: &13077780 !ruby/object:Gem::Requirement
|
84
84
|
none: false
|
85
85
|
requirements:
|
86
86
|
- - ! '>='
|
@@ -88,10 +88,10 @@ dependencies:
|
|
88
88
|
version: '0'
|
89
89
|
type: :runtime
|
90
90
|
prerelease: false
|
91
|
-
version_requirements: *
|
91
|
+
version_requirements: *13077780
|
92
92
|
- !ruby/object:Gem::Dependency
|
93
93
|
name: minitest
|
94
|
-
requirement: &
|
94
|
+
requirement: &13162460 !ruby/object:Gem::Requirement
|
95
95
|
none: false
|
96
96
|
requirements:
|
97
97
|
- - ~>
|
@@ -99,10 +99,10 @@ dependencies:
|
|
99
99
|
version: '5.4'
|
100
100
|
type: :development
|
101
101
|
prerelease: false
|
102
|
-
version_requirements: *
|
102
|
+
version_requirements: *13162460
|
103
103
|
- !ruby/object:Gem::Dependency
|
104
104
|
name: rake
|
105
|
-
requirement: &
|
105
|
+
requirement: &13161720 !ruby/object:Gem::Requirement
|
106
106
|
none: false
|
107
107
|
requirements:
|
108
108
|
- - ~>
|
@@ -110,10 +110,10 @@ dependencies:
|
|
110
110
|
version: 0.9.2.2
|
111
111
|
type: :development
|
112
112
|
prerelease: false
|
113
|
-
version_requirements: *
|
113
|
+
version_requirements: *13161720
|
114
114
|
- !ruby/object:Gem::Dependency
|
115
115
|
name: rack-test
|
116
|
-
requirement: &
|
116
|
+
requirement: &13161220 !ruby/object:Gem::Requirement
|
117
117
|
none: false
|
118
118
|
requirements:
|
119
119
|
- - ~>
|
@@ -121,10 +121,10 @@ dependencies:
|
|
121
121
|
version: 0.6.1
|
122
122
|
type: :development
|
123
123
|
prerelease: false
|
124
|
-
version_requirements: *
|
124
|
+
version_requirements: *13161220
|
125
125
|
- !ruby/object:Gem::Dependency
|
126
126
|
name: mocha
|
127
|
-
requirement: &
|
127
|
+
requirement: &13157920 !ruby/object:Gem::Requirement
|
128
128
|
none: false
|
129
129
|
requirements:
|
130
130
|
- - ~>
|
@@ -132,10 +132,10 @@ dependencies:
|
|
132
132
|
version: '1.1'
|
133
133
|
type: :development
|
134
134
|
prerelease: false
|
135
|
-
version_requirements: *
|
135
|
+
version_requirements: *13157920
|
136
136
|
- !ruby/object:Gem::Dependency
|
137
137
|
name: webmock
|
138
|
-
requirement: &
|
138
|
+
requirement: &13228420 !ruby/object:Gem::Requirement
|
139
139
|
none: false
|
140
140
|
requirements:
|
141
141
|
- - =
|
@@ -143,10 +143,10 @@ dependencies:
|
|
143
143
|
version: 1.18.0
|
144
144
|
type: :development
|
145
145
|
prerelease: false
|
146
|
-
version_requirements: *
|
146
|
+
version_requirements: *13228420
|
147
147
|
- !ruby/object:Gem::Dependency
|
148
148
|
name: therubyracer
|
149
|
-
requirement: &
|
149
|
+
requirement: &13278420 !ruby/object:Gem::Requirement
|
150
150
|
none: false
|
151
151
|
requirements:
|
152
152
|
- - ~>
|
@@ -154,10 +154,10 @@ dependencies:
|
|
154
154
|
version: 0.10.2
|
155
155
|
type: :development
|
156
156
|
prerelease: false
|
157
|
-
version_requirements: *
|
157
|
+
version_requirements: *13278420
|
158
158
|
- !ruby/object:Gem::Dependency
|
159
159
|
name: gem_publisher
|
160
|
-
requirement: &
|
160
|
+
requirement: &13276620 !ruby/object:Gem::Requirement
|
161
161
|
none: false
|
162
162
|
requirements:
|
163
163
|
- - ~>
|
@@ -165,10 +165,10 @@ dependencies:
|
|
165
165
|
version: 1.1.1
|
166
166
|
type: :development
|
167
167
|
prerelease: false
|
168
|
-
version_requirements: *
|
168
|
+
version_requirements: *13276620
|
169
169
|
- !ruby/object:Gem::Dependency
|
170
170
|
name: gds-api-adapters
|
171
|
-
requirement: &
|
171
|
+
requirement: &13275620 !ruby/object:Gem::Requirement
|
172
172
|
none: false
|
173
173
|
requirements:
|
174
174
|
- - =
|
@@ -176,10 +176,10 @@ dependencies:
|
|
176
176
|
version: 2.7.1
|
177
177
|
type: :development
|
178
178
|
prerelease: false
|
179
|
-
version_requirements: *
|
179
|
+
version_requirements: *13275620
|
180
180
|
- !ruby/object:Gem::Dependency
|
181
181
|
name: timecop
|
182
|
-
requirement: &
|
182
|
+
requirement: &13275100 !ruby/object:Gem::Requirement
|
183
183
|
none: false
|
184
184
|
requirements:
|
185
185
|
- - ~>
|
@@ -187,7 +187,7 @@ dependencies:
|
|
187
187
|
version: 0.5.1
|
188
188
|
type: :development
|
189
189
|
prerelease: false
|
190
|
-
version_requirements: *
|
190
|
+
version_requirements: *13275100
|
191
191
|
description: Rack middleware for skinning pages using a specific template
|
192
192
|
email:
|
193
193
|
- bengriffiths@gmail.com
|
@@ -228,6 +228,7 @@ files:
|
|
228
228
|
- lib/slimmer/processors/beta_label_inserter.rb
|
229
229
|
- lib/slimmer/processors/report_a_problem_inserter.rb
|
230
230
|
- lib/slimmer/processors/title_inserter.rb
|
231
|
+
- lib/slimmer/processors/search_parameter_inserter.rb
|
231
232
|
- lib/slimmer/processors/body_inserter.rb
|
232
233
|
- lib/slimmer/processors/alpha_label_inserter.rb
|
233
234
|
- lib/slimmer/processors/footer_remover.rb
|
@@ -265,6 +266,7 @@ files:
|
|
265
266
|
- test/processors/google_analytics_test.rb
|
266
267
|
- test/processors/meta_viewport_remover_test.rb
|
267
268
|
- test/processors/alpha_label_inserter_test.rb
|
269
|
+
- test/processors/search_parameter_inserter_test.rb
|
268
270
|
- test/processors/section_inserter_test.rb
|
269
271
|
- test/processors/report_a_problem_inserter_test.rb
|
270
272
|
- test/processors/tag_mover_test.rb
|
@@ -285,7 +287,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
285
287
|
version: '0'
|
286
288
|
segments:
|
287
289
|
- 0
|
288
|
-
hash:
|
290
|
+
hash: 992587451464763226
|
289
291
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
290
292
|
none: false
|
291
293
|
requirements:
|
@@ -294,7 +296,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
294
296
|
version: '0'
|
295
297
|
segments:
|
296
298
|
- 0
|
297
|
-
hash:
|
299
|
+
hash: 992587451464763226
|
298
300
|
requirements: []
|
299
301
|
rubyforge_project: slimmer
|
300
302
|
rubygems_version: 1.8.11
|
@@ -329,6 +331,7 @@ test_files:
|
|
329
331
|
- test/processors/google_analytics_test.rb
|
330
332
|
- test/processors/meta_viewport_remover_test.rb
|
331
333
|
- test/processors/alpha_label_inserter_test.rb
|
334
|
+
- test/processors/search_parameter_inserter_test.rb
|
332
335
|
- test/processors/section_inserter_test.rb
|
333
336
|
- test/processors/report_a_problem_inserter_test.rb
|
334
337
|
- test/processors/tag_mover_test.rb
|