slimmer 3.15.0 → 3.16.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -26,6 +26,7 @@ module Slimmer
26
26
  REMOVE_META_VIEWPORT = "#{HEADER_PREFIX}-#{SLIMMER_HEADER_MAPPING[:remove_meta_viewport]}"
27
27
  RESULT_COUNT_HEADER = "#{HEADER_PREFIX}-#{SLIMMER_HEADER_MAPPING[:result_count]}"
28
28
  SEARCH_INDEX_HEADER = "#{HEADER_PREFIX}-Search-Index"
29
+ SEARCH_PATH_HEADER = "#{HEADER_PREFIX}-Search-Path"
29
30
  SKIP_HEADER = "#{HEADER_PREFIX}-#{SLIMMER_HEADER_MAPPING[:skip]}"
30
31
  TEMPLATE_HEADER = "#{HEADER_PREFIX}-#{SLIMMER_HEADER_MAPPING[:template]}"
31
32
 
@@ -0,0 +1,17 @@
1
+ module Slimmer::Processors
2
+ class SearchPathSetter
3
+ def initialize(response)
4
+ @response = response
5
+ end
6
+
7
+ def filter(content_document, page_template)
8
+ if search_scope && page_template.at_css('form#search')
9
+ page_template.at_css('form#search').attributes["action"].value = search_scope
10
+ end
11
+ end
12
+
13
+ def search_scope
14
+ @response.headers[Slimmer::Headers::SEARCH_PATH_HEADER]
15
+ end
16
+ end
17
+ end
data/lib/slimmer/skin.rb CHANGED
@@ -124,6 +124,7 @@ module Slimmer
124
124
  Processors::HeaderContextInserter.new(),
125
125
  Processors::SectionInserter.new(artefact),
126
126
  Processors::GoogleAnalyticsConfigurator.new(response, artefact),
127
+ Processors::SearchPathSetter.new(response),
127
128
  Processors::RelatedItemsInserter.new(self, artefact),
128
129
  Processors::LogoClassInserter.new(artefact),
129
130
  Processors::ReportAProblemInserter.new(self, source_request.url),
@@ -1,3 +1,3 @@
1
1
  module Slimmer
2
- VERSION = '3.15.0'
2
+ VERSION = '3.16.0'
3
3
  end
data/lib/slimmer.rb CHANGED
@@ -39,6 +39,7 @@ module Slimmer
39
39
  autoload :RelatedItemsInserter, 'slimmer/processors/related_items_inserter'
40
40
  autoload :ReportAProblemInserter, 'slimmer/processors/report_a_problem_inserter'
41
41
  autoload :SearchIndexSetter, 'slimmer/processors/search_index_setter'
42
+ autoload :SearchPathSetter, 'slimmer/processors/search_path_setter'
42
43
  autoload :SectionInserter, 'slimmer/processors/section_inserter'
43
44
  autoload :TagMover, 'slimmer/processors/tag_mover'
44
45
  autoload :TitleInserter, 'slimmer/processors/title_inserter'
@@ -0,0 +1,39 @@
1
+ require "test_helper"
2
+
3
+ module SearchPathSetterTest
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-Path" => "/specialist/search",
21
+ }
22
+
23
+ given_response 200, DOCUMENT_WITH_SEARCH, headers
24
+
25
+ def test_should_rewrite_search_action
26
+ search_action = Nokogiri::HTML.parse(last_response.body).at_css('#search')["action"]
27
+ assert_equal "/specialist/search", search_action
28
+ end
29
+ end
30
+
31
+ class WithoutHeaderTest < SlimmerIntegrationTest
32
+ given_response 200, DOCUMENT_WITH_SEARCH, {}
33
+
34
+ def test_should_leave_original_search_action
35
+ search_action = Nokogiri::HTML.parse(last_response.body).at_css('#search')["action"]
36
+ assert_equal "/path/to/search", search_action
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.15.0
5
+ version: 3.16.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: 2013-04-09 00:00:00 Z
14
+ date: 2013-04-23 00:00:00 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: nokogiri
@@ -192,6 +192,7 @@ files:
192
192
  - lib/slimmer/processors/search_index_setter.rb
193
193
  - lib/slimmer/processors/body_class_copier.rb
194
194
  - lib/slimmer/processors/tag_mover.rb
195
+ - lib/slimmer/processors/search_path_setter.rb
195
196
  - lib/slimmer/processors/title_inserter.rb
196
197
  - lib/slimmer/processors/google_analytics_configurator.rb
197
198
  - lib/slimmer/processors/navigation_mover.rb
@@ -228,6 +229,7 @@ files:
228
229
  - test/processors/google_analytics_test.rb
229
230
  - test/processors/report_a_problem_inserter_test.rb
230
231
  - test/processors/body_inserter_test.rb
232
+ - test/processors/search_path_setter_test.rb
231
233
  - test/processors/section_inserter_test.rb
232
234
  - test/processors/related_items_inserter_test.rb
233
235
  - test/processors/header_context_inserter_test.rb
@@ -248,7 +250,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
248
250
  requirements:
249
251
  - - ">="
250
252
  - !ruby/object:Gem::Version
251
- hash: -467376133944042160
253
+ hash: -2273354827305852219
252
254
  segments:
253
255
  - 0
254
256
  version: "0"
@@ -257,7 +259,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
257
259
  requirements:
258
260
  - - ">="
259
261
  - !ruby/object:Gem::Version
260
- hash: -467376133944042160
262
+ hash: -2273354827305852219
261
263
  segments:
262
264
  - 0
263
265
  version: "0"
@@ -288,6 +290,7 @@ test_files:
288
290
  - test/processors/google_analytics_test.rb
289
291
  - test/processors/report_a_problem_inserter_test.rb
290
292
  - test/processors/body_inserter_test.rb
293
+ - test/processors/search_path_setter_test.rb
291
294
  - test/processors/section_inserter_test.rb
292
295
  - test/processors/related_items_inserter_test.rb
293
296
  - test/processors/header_context_inserter_test.rb