slimmer 3.5.0 → 3.6.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -17,6 +17,7 @@ module Slimmer
17
17
  TEMPLATE_HEADER = "#{HEADER_PREFIX}-Template"
18
18
  SKIP_HEADER = "#{HEADER_PREFIX}-Skip"
19
19
  SEARCH_PATH_HEADER = "#{HEADER_PREFIX}-Search-Path"
20
+ SEARCH_INDEX_HEADER = "#{HEADER_PREFIX}-Search-Index"
20
21
  ARTEFACT_HEADER = "#{HEADER_PREFIX}-Artefact"
21
22
  FORMAT_HEADER = "#{HEADER_PREFIX}-Format"
22
23
  RESULT_COUNT_HEADER = "#{HEADER_PREFIX}-Result-Count"
@@ -0,0 +1,26 @@
1
+ module Slimmer::Processors
2
+ include ERB::Util
3
+
4
+ class SearchIndexSetter
5
+ def initialize(response)
6
+ @response = response
7
+ end
8
+
9
+ def filter(content_document, page_template)
10
+ if search_index && page_template.at_css('form#search')
11
+ page_template.at_css('form#search') << hidden_input_element
12
+ end
13
+ end
14
+
15
+ private
16
+
17
+ def search_index
18
+ @response.headers[Slimmer::Headers::SEARCH_INDEX_HEADER]
19
+ end
20
+
21
+ def hidden_input_element
22
+ html = ERB.new('<input type="hidden" name="search-index" value="<%= search_index %>">').result(binding)
23
+ Nokogiri::HTML.fragment(html)
24
+ end
25
+ end
26
+ end
data/lib/slimmer/skin.rb CHANGED
@@ -139,6 +139,7 @@ module Slimmer
139
139
  Processors::RelatedItemsInserter.new(self, artefact),
140
140
  Processors::LogoClassInserter.new(artefact),
141
141
  Processors::ReportAProblemInserter.new(self, source_request.url),
142
+ Processors::SearchIndexSetter.new(response),
142
143
  ]
143
144
 
144
145
  template_name = response.headers[Headers::TEMPLATE_HEADER] || 'wrapper'
@@ -1,3 +1,3 @@
1
1
  module Slimmer
2
- VERSION = '3.5.0'
2
+ VERSION = '3.6.0'
3
3
  end
data/lib/slimmer.rb CHANGED
@@ -35,6 +35,7 @@ module Slimmer
35
35
  autoload :LogoClassInserter, 'slimmer/processors/logo_class_inserter'
36
36
  autoload :RelatedItemsInserter, 'slimmer/processors/related_items_inserter'
37
37
  autoload :ReportAProblemInserter, 'slimmer/processors/report_a_problem_inserter'
38
+ autoload :SearchIndexSetter, 'slimmer/processors/search_index_setter'
38
39
  autoload :SearchPathSetter, 'slimmer/processors/search_path_setter'
39
40
  autoload :SectionInserter, 'slimmer/processors/section_inserter'
40
41
  autoload :TagMover, 'slimmer/processors/tag_mover'
@@ -0,0 +1,39 @@
1
+ require "test_helper"
2
+
3
+ module SearchIndexSetterTest
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-Index" => "government",
21
+ }
22
+
23
+ given_response 200, DOCUMENT_WITH_SEARCH, headers
24
+
25
+ def test_should_insert_index_field
26
+ search_index = Nokogiri::HTML.parse(last_response.body).at_css('#search input[name=search-index]')['value']
27
+ assert_equal "government", search_index
28
+ end
29
+ end
30
+
31
+ class WithoutHeaderTest < SlimmerIntegrationTest
32
+ given_response 200, DOCUMENT_WITH_SEARCH, {}
33
+
34
+ def test_should_not_insert_index_field
35
+ search_index = Nokogiri::HTML.parse(last_response.body).at_css('#search input[name=search-index]')
36
+ assert_equal nil, search_index
37
+ end
38
+ end
39
+ end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: slimmer
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 3.5.0
5
+ version: 3.6.0
6
6
  platform: ruby
7
7
  authors:
8
8
  - Ben Griffiths
@@ -180,51 +180,53 @@ extra_rdoc_files: []
180
180
  files:
181
181
  - README.md
182
182
  - CHANGELOG.md
183
- - lib/tasks/slimmer.rake
184
183
  - lib/slimmer.rb
185
- - lib/slimmer/skin.rb
186
- - lib/slimmer/railtie.rb
187
- - lib/slimmer/template.rb
188
- - lib/slimmer/test_template.rb
189
- - lib/slimmer/test.rb
190
184
  - lib/slimmer/app.rb
191
- - lib/slimmer/processors/logo_class_inserter.rb
192
- - lib/slimmer/processors/body_class_copier.rb
185
+ - lib/slimmer/test_template.rb
186
+ - lib/slimmer/version.rb
187
+ - lib/slimmer/railtie.rb
193
188
  - lib/slimmer/processors/tag_mover.rb
189
+ - lib/slimmer/processors/body_class_copier.rb
190
+ - lib/slimmer/processors/logo_class_inserter.rb
191
+ - lib/slimmer/processors/header_context_inserter.rb
192
+ - lib/slimmer/processors/search_index_setter.rb
193
+ - lib/slimmer/processors/report_a_problem_inserter.rb
194
+ - lib/slimmer/processors/footer_remover.rb
195
+ - lib/slimmer/processors/google_analytics_configurator.rb
196
+ - lib/slimmer/processors/admin_title_inserter.rb
194
197
  - lib/slimmer/processors/search_path_setter.rb
195
198
  - lib/slimmer/processors/title_inserter.rb
196
- - lib/slimmer/processors/google_analytics_configurator.rb
197
- - lib/slimmer/processors/conditional_comment_mover.rb
198
199
  - lib/slimmer/processors/related_items_inserter.rb
199
- - lib/slimmer/processors/header_context_inserter.rb
200
- - lib/slimmer/processors/body_inserter.rb
201
- - lib/slimmer/processors/admin_title_inserter.rb
202
- - lib/slimmer/processors/report_a_problem_inserter.rb
203
200
  - lib/slimmer/processors/section_inserter.rb
204
- - lib/slimmer/processors/footer_remover.rb
205
- - lib/slimmer/headers.rb
206
- - lib/slimmer/version.rb
201
+ - lib/slimmer/processors/conditional_comment_mover.rb
202
+ - lib/slimmer/processors/body_inserter.rb
207
203
  - lib/slimmer/artefact.rb
204
+ - lib/slimmer/skin.rb
205
+ - lib/slimmer/headers.rb
206
+ - lib/slimmer/template.rb
207
+ - lib/slimmer/test.rb
208
+ - lib/tasks/slimmer.rake
208
209
  - Rakefile
209
- - test/headers_test.rb
210
- - test/artefact_test.rb
211
- - test/fixtures/related.raw.html.erb
212
- - test/fixtures/500.html.erb
213
- - test/fixtures/404.html.erb
214
- - test/fixtures/wrapper.html.erb
215
- - test/fixtures/report_a_problem.raw.html.erb
216
- - test/skin_test.rb
217
- - test/processors/logo_class_inserter_test.rb
210
+ - test/processors/header_context_inserter_test.rb
218
211
  - test/processors/google_analytics_test.rb
219
- - test/processors/report_a_problem_inserter_test.rb
220
212
  - test/processors/body_inserter_test.rb
221
- - test/processors/search_path_setter_test.rb
213
+ - test/processors/search_index_setter_test.rb
214
+ - test/processors/report_a_problem_inserter_test.rb
222
215
  - test/processors/section_inserter_test.rb
216
+ - test/processors/search_path_setter_test.rb
223
217
  - test/processors/related_items_inserter_test.rb
224
- - test/processors/header_context_inserter_test.rb
225
- - test/typical_usage_test.rb
218
+ - test/processors/logo_class_inserter_test.rb
226
219
  - test/test_template_dependency_on_static_test.rb
220
+ - test/headers_test.rb
227
221
  - test/test_helper.rb
222
+ - test/typical_usage_test.rb
223
+ - test/artefact_test.rb
224
+ - test/skin_test.rb
225
+ - test/fixtures/404.html.erb
226
+ - test/fixtures/500.html.erb
227
+ - test/fixtures/wrapper.html.erb
228
+ - test/fixtures/related.raw.html.erb
229
+ - test/fixtures/report_a_problem.raw.html.erb
228
230
  - bin/render_slimmer_error
229
231
  homepage: http://github.com/alphagov/slimmer
230
232
  licenses: []
@@ -239,7 +241,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
239
241
  requirements:
240
242
  - - ">="
241
243
  - !ruby/object:Gem::Version
242
- hash: 3294139728486751681
244
+ hash: 2398001210038307961
243
245
  segments:
244
246
  - 0
245
247
  version: "0"
@@ -248,7 +250,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
248
250
  requirements:
249
251
  - - ">="
250
252
  - !ruby/object:Gem::Version
251
- hash: 3294139728486751681
253
+ hash: 2398001210038307961
252
254
  segments:
253
255
  - 0
254
256
  version: "0"
@@ -260,22 +262,23 @@ signing_key:
260
262
  specification_version: 3
261
263
  summary: Thinner than the skinner
262
264
  test_files:
263
- - test/headers_test.rb
264
- - test/artefact_test.rb
265
- - test/fixtures/related.raw.html.erb
266
- - test/fixtures/500.html.erb
267
- - test/fixtures/404.html.erb
268
- - test/fixtures/wrapper.html.erb
269
- - test/fixtures/report_a_problem.raw.html.erb
270
- - test/skin_test.rb
271
- - test/processors/logo_class_inserter_test.rb
265
+ - test/processors/header_context_inserter_test.rb
272
266
  - test/processors/google_analytics_test.rb
273
- - test/processors/report_a_problem_inserter_test.rb
274
267
  - test/processors/body_inserter_test.rb
275
- - test/processors/search_path_setter_test.rb
268
+ - test/processors/search_index_setter_test.rb
269
+ - test/processors/report_a_problem_inserter_test.rb
276
270
  - test/processors/section_inserter_test.rb
271
+ - test/processors/search_path_setter_test.rb
277
272
  - test/processors/related_items_inserter_test.rb
278
- - test/processors/header_context_inserter_test.rb
279
- - test/typical_usage_test.rb
273
+ - test/processors/logo_class_inserter_test.rb
280
274
  - test/test_template_dependency_on_static_test.rb
275
+ - test/headers_test.rb
281
276
  - test/test_helper.rb
277
+ - test/typical_usage_test.rb
278
+ - test/artefact_test.rb
279
+ - test/skin_test.rb
280
+ - test/fixtures/404.html.erb
281
+ - test/fixtures/500.html.erb
282
+ - test/fixtures/wrapper.html.erb
283
+ - test/fixtures/related.raw.html.erb
284
+ - test/fixtures/report_a_problem.raw.html.erb