slimmer 3.10.1 → 3.11.0

Sign up to get free protection for your applications and to get access to all the features.
data/lib/slimmer.rb CHANGED
@@ -25,6 +25,7 @@ module Slimmer
25
25
  autoload :Artefact, 'slimmer/artefact'
26
26
 
27
27
  module Processors
28
+ autoload :BetaNoticeInserter, 'slimmer/processors/beta_notice_inserter'
28
29
  autoload :BodyClassCopier, 'slimmer/processors/body_class_copier'
29
30
  autoload :BodyInserter, 'slimmer/processors/body_inserter'
30
31
  autoload :ConditionalCommentMover, 'slimmer/processors/conditional_comment_mover'
@@ -5,6 +5,7 @@ module Slimmer
5
5
  HEADER_PREFIX = "X-Slimmer"
6
6
 
7
7
  SLIMMER_HEADER_MAPPING = {
8
+ beta: "Beta",
8
9
  campaign_notification:"Campaign-Notification",
9
10
  format: "Format",
10
11
  need_id: "Need-ID",
@@ -18,6 +19,7 @@ module Slimmer
18
19
  }
19
20
 
20
21
  ARTEFACT_HEADER = "#{HEADER_PREFIX}-Artefact"
22
+ BETA_HEADER = "#{HEADER_PREFIX}-#{SLIMMER_HEADER_MAPPING[:beta]}"
21
23
  CAMPAIGN_NOTIFICATION = "#{HEADER_PREFIX}-#{SLIMMER_HEADER_MAPPING[:campaign_notification]}"
22
24
  FORMAT_HEADER = "#{HEADER_PREFIX}-#{SLIMMER_HEADER_MAPPING[:format]}"
23
25
  ORGANISATIONS_HEADER = "#{HEADER_PREFIX}-#{SLIMMER_HEADER_MAPPING[:organisations]}"
@@ -0,0 +1,29 @@
1
+ module Slimmer::Processors
2
+ class BetaNoticeInserter
3
+ def initialize(skin, headers)
4
+ @skin = skin
5
+ @headers = headers
6
+ end
7
+
8
+ def filter(content_document, page_template)
9
+ if should_add_beta_notice?
10
+ page_template.css('body').add_class('beta')
11
+ if header = page_template.at_css('#global-header')
12
+ header.add_next_sibling(beta_notice_block)
13
+ end
14
+ if footer = page_template.at_css('footer#footer')
15
+ footer.add_previous_sibling(beta_notice_block)
16
+ end
17
+ end
18
+ end
19
+
20
+ def should_add_beta_notice?
21
+ !! @headers[Slimmer::Headers::BETA_HEADER]
22
+ end
23
+
24
+ def beta_notice_block
25
+ @beta_notice_block ||= @skin.template('beta_notice')
26
+ end
27
+ end
28
+ end
29
+
data/lib/slimmer/skin.rb CHANGED
@@ -129,6 +129,7 @@ module Slimmer
129
129
  Processors::SearchIndexSetter.new(response),
130
130
  Processors::MetaViewportRemover.new(response),
131
131
  Processors::CampaignNotificationInserter.new(self, response.headers),
132
+ Processors::BetaNoticeInserter.new(self, response.headers),
132
133
  ]
133
134
 
134
135
  template_name = response.headers[Headers::TEMPLATE_HEADER] || 'wrapper'
data/lib/slimmer/test.rb CHANGED
@@ -7,6 +7,8 @@ module Slimmer
7
7
  logger.debug "Slimmer: TEST MODE - Loading fixture template from #{__FILE__}"
8
8
  if name =~ /\A(.*)\.raw\z/
9
9
  %{<div id="test-#{$1}"></div>}
10
+ elsif name == "beta_notice"
11
+ %{<div class="beta-notice"><p>This page is BETA.</p></div>}
10
12
  elsif name == "campaign"
11
13
  '<section class="black" id="campaign-notification"><div><p>Notifications!</p></div></section>'
12
14
  else
@@ -3,24 +3,12 @@ module Slimmer::TestTemplate
3
3
  <html>
4
4
  <head>
5
5
  <title>Test Template</title>
6
- <script src="https://static.preview.alphagov.co.uk/static/libs/jquery/jquery-1.7.2.min.js"></script><!-- no defer on jquery -->
7
- <script src="https://static.preview.alphagov.co.uk/static/libs/jquery/jquery-ui-1.8.16.custom.min.js" defer></script>
8
- <script src="https://static.preview.alphagov.co.uk/static/libs/jquery/plugins/jquery.base64.js" defer></script>
9
- <script src="https://static.preview.alphagov.co.uk/static/libs/jquery/plugins/jquery.mustache.js" defer></script>
10
- <script src="https://static.preview.alphagov.co.uk/static/search.js" defer></script>
11
- <script src="https://static.preview.alphagov.co.uk/static/core.js" defer></script>
12
- <script src="https://static.preview.alphagov.co.uk/static/devolution.js" defer></script>
13
- <script src="https://static.preview.alphagov.co.uk/static/popup.js" defer></script>
14
- <script src="https://static.preview.alphagov.co.uk/static/geo-locator.js" defer></script>
15
- <script src="https://static.preview.alphagov.co.uk/static/customisation-settings.js" defer></script>
16
- <script src="https://static.preview.alphagov.co.uk/static/welcome.js" defer></script>
17
- <script src="https://static.preview.alphagov.co.uk/static/browse.js" defer></script>
18
- <script src="https://static.preview.alphagov.co.uk/static/jquery.history.js" defer></script>
19
- <script src="https://static.preview.alphagov.co.uk/static/jquery.tabs.js" defer></script>
20
- <script src="https://static.preview.alphagov.co.uk/static/libs/jquery/plugins/jquery.player.min.js" defer></script>
6
+ <script src="https://static.preview.alphagov.co.uk/static/libs/jquery/jquery-1.7.2.min.js" type="text/javascript"></script><!-- no defer on jquery -->
7
+ <script src="https://static.preview.alphagov.co.uk/static/application.js" type="text/javascript" defer="defer"></script>
21
8
  </head>
22
9
  <body>
23
- <div class="header-context">
10
+ <header id="global-header"></header>
11
+ <div id="global-navigation" class="header-context">
24
12
  <nav role="navigation">
25
13
  <ol class="group">
26
14
  <li><a href="/">Home</a></li>
@@ -29,6 +17,8 @@ module Slimmer::TestTemplate
29
17
  </div>
30
18
 
31
19
  <div id="wrapper"></div>
20
+
21
+ <footer id="footer"></footer>
32
22
  </body>
33
23
  </html>
34
24
  }
@@ -1,3 +1,3 @@
1
1
  module Slimmer
2
- VERSION = '3.10.1'
2
+ VERSION = '3.11.0'
3
3
  end
@@ -0,0 +1,3 @@
1
+ <div class="beta-notice">
2
+ <p>This page is in beta</p>
3
+ </div>
@@ -2,21 +2,23 @@
2
2
  <html>
3
3
  <head>
4
4
  <title>Slimmer, yay!</title>
5
- </head>
6
- <body>
7
- <div class="content">
8
- <header><h1>I AM A TITLE</h1></header>
9
- <div class="header-context">
10
- <nav role="navigation"><ol><li>MySite</li></ol></nav>
11
- </div>
12
- <div id="wrapper" class="group">
13
- </div>
14
- </div>
15
-
16
5
  <script id="ga-params" type="text/javascript">
17
6
  var GOVUK = GOVUK || {};
18
7
  GOVUK.Analytics = GOVUK.Analytics || {};
19
8
  var _gaq = _gaq || [];
20
9
  </script>
10
+ </head>
11
+ <body>
12
+ <header id="global-header"><h1>I AM A TITLE</h1></header>
13
+
14
+ <div id="global-navigation" class="header-context">
15
+ <nav role="navigation"><ol><li>MySite</li></ol></nav>
16
+ </div>
17
+
18
+ <div id="wrapper" class="group">
19
+ </div>
20
+
21
+ <footer id="footer">
22
+ </footer>
21
23
  </body>
22
24
  </html>
data/test/test_helper.rb CHANGED
@@ -77,6 +77,7 @@ class SlimmerIntegrationTest < MiniTest::Unit::TestCase
77
77
  use_template(template_name)
78
78
  use_template('related.raw')
79
79
  use_template('report_a_problem.raw')
80
+ use_template('beta_notice')
80
81
  use_template('campaign')
81
82
 
82
83
  fetch_page
@@ -136,6 +136,11 @@ module TypicalUsage
136
136
  def test_should_add_logo_classes_to_wrapper
137
137
  assert_rendered_in_template "#wrapper.directgov"
138
138
  end
139
+
140
+ def test_should_not_add_beta_notice_to_non_beta_pages
141
+ assert_no_selector "body.beta"
142
+ assert_no_selector ".beta-notice"
143
+ end
139
144
  end
140
145
 
141
146
  class ConditionalCommentTest < SlimmerIntegrationTest
@@ -248,6 +253,24 @@ module TypicalUsage
248
253
  end
249
254
  end
250
255
 
256
+ class BetaNoticeInserterTest < SlimmerIntegrationTest
257
+ def test_should_add_beta_warnings
258
+ given_response 200, %{
259
+ <html>
260
+ <body class="wibble">
261
+ <div id="wrapper">The body of the page</div>
262
+ </body>
263
+ </html>
264
+ }, {Slimmer::Headers::BETA_HEADER => '1'}
265
+
266
+ # beta notice after cookie bar
267
+ assert_rendered_in_template "body.beta.wibble #global-header + div.beta-notice"
268
+
269
+ # beta notice before footer
270
+ assert_rendered_in_template "body.beta.wibble div.beta-notice + #footer"
271
+ end
272
+ end
273
+
251
274
  class Error500ResponseTest < SlimmerIntegrationTest
252
275
  include Rack::Test::Methods
253
276
 
@@ -346,7 +369,7 @@ module TypicalUsage
346
369
  }, {}, {wrapper_id: "custom_wrapper"}
347
370
 
348
371
  def test_should_replace_wrapper_with_custom_wrapper
349
- assert_rendered_in_template "body .content #custom_wrapper", "The body of the page"
372
+ assert_rendered_in_template "body #custom_wrapper", "The body of the page"
350
373
  assert_no_selector "#wrapper"
351
374
  end
352
375
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: slimmer
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 3.10.1
5
+ version: 3.11.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-01-29 00:00:00 Z
14
+ date: 2013-02-20 00:00:00 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: nokogiri
@@ -180,55 +180,57 @@ 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/search_index_setter.rb
193
- - lib/slimmer/processors/body_class_copier.rb
185
+ - lib/slimmer/test_template.rb
186
+ - lib/slimmer/version.rb
187
+ - lib/slimmer/railtie.rb
194
188
  - lib/slimmer/processors/tag_mover.rb
195
- - lib/slimmer/processors/title_inserter.rb
196
- - lib/slimmer/processors/google_analytics_configurator.rb
197
- - lib/slimmer/processors/conditional_comment_mover.rb
198
- - lib/slimmer/processors/related_items_inserter.rb
189
+ - lib/slimmer/processors/body_class_copier.rb
190
+ - lib/slimmer/processors/logo_class_inserter.rb
191
+ - lib/slimmer/processors/beta_notice_inserter.rb
199
192
  - lib/slimmer/processors/header_context_inserter.rb
200
- - lib/slimmer/processors/body_inserter.rb
201
- - lib/slimmer/processors/report_a_problem_inserter.rb
202
193
  - lib/slimmer/processors/meta_viewport_remover.rb
194
+ - lib/slimmer/processors/search_index_setter.rb
195
+ - lib/slimmer/processors/report_a_problem_inserter.rb
203
196
  - lib/slimmer/processors/campaign_notification_inserter.rb
204
- - lib/slimmer/processors/section_inserter.rb
205
197
  - lib/slimmer/processors/footer_remover.rb
206
- - lib/slimmer/headers.rb
207
- - lib/slimmer/version.rb
198
+ - lib/slimmer/processors/google_analytics_configurator.rb
199
+ - lib/slimmer/processors/title_inserter.rb
200
+ - lib/slimmer/processors/related_items_inserter.rb
201
+ - lib/slimmer/processors/section_inserter.rb
202
+ - lib/slimmer/processors/conditional_comment_mover.rb
203
+ - lib/slimmer/processors/body_inserter.rb
208
204
  - lib/slimmer/artefact.rb
205
+ - lib/slimmer/skin.rb
206
+ - lib/slimmer/headers.rb
207
+ - lib/slimmer/template.rb
208
+ - lib/slimmer/test.rb
209
+ - lib/tasks/slimmer.rake
209
210
  - Rakefile
210
- - test/headers_test.rb
211
- - test/artefact_test.rb
212
- - test/fixtures/related.raw.html.erb
213
- - test/fixtures/campaign.html.erb
214
- - test/fixtures/500.html.erb
215
- - test/fixtures/404.html.erb
216
- - test/fixtures/wrapper.html.erb
217
- - test/fixtures/report_a_problem.raw.html.erb
218
- - test/skin_test.rb
219
- - test/processors/campaign_notification_inserter_test.rb
220
- - test/processors/meta_viewport_remover_test.rb
221
- - test/processors/logo_class_inserter_test.rb
222
- - test/processors/search_index_setter_test.rb
211
+ - test/processors/header_context_inserter_test.rb
223
212
  - test/processors/google_analytics_test.rb
224
- - test/processors/report_a_problem_inserter_test.rb
225
213
  - test/processors/body_inserter_test.rb
214
+ - test/processors/search_index_setter_test.rb
215
+ - test/processors/meta_viewport_remover_test.rb
216
+ - test/processors/report_a_problem_inserter_test.rb
226
217
  - test/processors/section_inserter_test.rb
218
+ - test/processors/campaign_notification_inserter_test.rb
227
219
  - test/processors/related_items_inserter_test.rb
228
- - test/processors/header_context_inserter_test.rb
229
- - test/typical_usage_test.rb
220
+ - test/processors/logo_class_inserter_test.rb
230
221
  - test/test_template_dependency_on_static_test.rb
222
+ - test/headers_test.rb
231
223
  - test/test_helper.rb
224
+ - test/typical_usage_test.rb
225
+ - test/artefact_test.rb
226
+ - test/skin_test.rb
227
+ - test/fixtures/campaign.html.erb
228
+ - test/fixtures/404.html.erb
229
+ - test/fixtures/beta_notice.html.erb
230
+ - test/fixtures/500.html.erb
231
+ - test/fixtures/wrapper.html.erb
232
+ - test/fixtures/related.raw.html.erb
233
+ - test/fixtures/report_a_problem.raw.html.erb
232
234
  - bin/render_slimmer_error
233
235
  homepage: http://github.com/alphagov/slimmer
234
236
  licenses: []
@@ -243,7 +245,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
243
245
  requirements:
244
246
  - - ">="
245
247
  - !ruby/object:Gem::Version
246
- hash: -4345242334148281785
248
+ hash: 3638550350140807883
247
249
  segments:
248
250
  - 0
249
251
  version: "0"
@@ -252,7 +254,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
252
254
  requirements:
253
255
  - - ">="
254
256
  - !ruby/object:Gem::Version
255
- hash: -4345242334148281785
257
+ hash: 3638550350140807883
256
258
  segments:
257
259
  - 0
258
260
  version: "0"
@@ -264,25 +266,26 @@ signing_key:
264
266
  specification_version: 3
265
267
  summary: Thinner than the skinner
266
268
  test_files:
267
- - test/headers_test.rb
268
- - test/artefact_test.rb
269
- - test/fixtures/related.raw.html.erb
270
- - test/fixtures/campaign.html.erb
271
- - test/fixtures/500.html.erb
272
- - test/fixtures/404.html.erb
273
- - test/fixtures/wrapper.html.erb
274
- - test/fixtures/report_a_problem.raw.html.erb
275
- - test/skin_test.rb
276
- - test/processors/campaign_notification_inserter_test.rb
277
- - test/processors/meta_viewport_remover_test.rb
278
- - test/processors/logo_class_inserter_test.rb
279
- - test/processors/search_index_setter_test.rb
269
+ - test/processors/header_context_inserter_test.rb
280
270
  - test/processors/google_analytics_test.rb
281
- - test/processors/report_a_problem_inserter_test.rb
282
271
  - test/processors/body_inserter_test.rb
272
+ - test/processors/search_index_setter_test.rb
273
+ - test/processors/meta_viewport_remover_test.rb
274
+ - test/processors/report_a_problem_inserter_test.rb
283
275
  - test/processors/section_inserter_test.rb
276
+ - test/processors/campaign_notification_inserter_test.rb
284
277
  - test/processors/related_items_inserter_test.rb
285
- - test/processors/header_context_inserter_test.rb
286
- - test/typical_usage_test.rb
278
+ - test/processors/logo_class_inserter_test.rb
287
279
  - test/test_template_dependency_on_static_test.rb
280
+ - test/headers_test.rb
288
281
  - test/test_helper.rb
282
+ - test/typical_usage_test.rb
283
+ - test/artefact_test.rb
284
+ - test/skin_test.rb
285
+ - test/fixtures/campaign.html.erb
286
+ - test/fixtures/404.html.erb
287
+ - test/fixtures/beta_notice.html.erb
288
+ - test/fixtures/500.html.erb
289
+ - test/fixtures/wrapper.html.erb
290
+ - test/fixtures/related.raw.html.erb
291
+ - test/fixtures/report_a_problem.raw.html.erb