slimmer 3.24.0 → 3.25.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.
data/CHANGELOG.md CHANGED
@@ -1,3 +1,13 @@
1
+ # 3.25.0
2
+
3
+ * Pass on GOVUK-Request-Id HTTP header when fetching templates
4
+ * Use correct asset host in test templates
5
+ * Remove a redundant ERB pass over fetched templates
6
+
7
+ # 3.24.0
8
+
9
+ * Removed CampaignNotificationInserter. The homepage no longer needs these inserted.
10
+
1
11
  # 3.1.0
2
12
 
3
13
  * 'Breadcrumb' trail is now populated from the artefact data. It adds the section and subsection.
data/README.md CHANGED
@@ -1,9 +1,9 @@
1
- Slimmer provides rack middleware for applying a standard header and footer around pages
2
- returned by a ruby (rack) application.
1
+ Slimmer provides Rack middleware for applying a standard header and footer around pages
2
+ returned by a Ruby (Rack) application.
3
3
 
4
4
  It does this by taking the page rendered by the application, extracting the contents of
5
- a div with id 'wrapper' and inserting that into a div with the same id in one of its templates.
6
- It also transfers various other details, such as meta, script, and style tags.
5
+ a `div` with id 'wrapper' and inserting that into a `div` with the same id in one of its
6
+ templates. It also transfers various other details, such as `meta`, `script`, and `style` tags.
7
7
 
8
8
  ## Use in a Rails app
9
9
 
@@ -35,11 +35,11 @@ To get asset tag helpers to point to your external asset server, add
35
35
 
36
36
  config.action_controller.asset_host = "http://my.alternative.host"
37
37
 
38
- to application.rb.
38
+ to `application.rb`.
39
39
 
40
40
  ## Specifying a template
41
41
 
42
- A specific template can be requested by giving its name in the X-Slimmer-Template HTTP header.
42
+ A specific template can be requested by giving its name in the `X-Slimmer-Template` HTTP header.
43
43
 
44
44
  In a controller action, you can do this by calling `slimmer_template`.
45
45
 
@@ -63,8 +63,9 @@ To get this, include Slimmer::Template in your ApplicationController:
63
63
 
64
64
  ## Logging
65
65
 
66
- Slimmer can be configured with a logger by passing in a logger instance (anything that quacks like an instance of Logger).
67
- For example to log to the Rails log, put the following in an initializer:
66
+ Slimmer can be configured with a logger by passing in a logger instance
67
+ (anything that quacks like an instance of `Logger`). For example, to log
68
+ to the Rails log, put the following in an initializer:
68
69
 
69
70
  YourApp::Application.configure do
70
71
  config.slimmer.logger = Rails.logger
@@ -74,7 +75,7 @@ For example to log to the Rails log, put the following in an initializer:
74
75
 
75
76
  **Debug logging**
76
77
 
77
- By default if you pass in a logger with its log level set to debug, slimmer will dup this logger and reduce the level to info. (Slimmer's debug logging is very noisy). To prevent this, set the `enable_debugging` option to true. e.g. for Rails:
78
+ By default if you pass in a logger with its log level set to `debug`, slimmer will dup this logger and reduce the level to `info`. (Slimmer's debug logging is very noisy). To prevent this, set the `enable_debugging` option to true. e.g. for Rails:
78
79
 
79
80
  YourApp::Application.configure do
80
81
  config.slimmer.enable_debugging = true
data/lib/slimmer.rb CHANGED
@@ -5,10 +5,8 @@
5
5
 
6
6
  require 'nokogiri'
7
7
  require 'erb'
8
- require 'open-uri'
9
8
  require 'plek'
10
9
  require 'null_logger'
11
- require 'openssl'
12
10
  require 'lrucache'
13
11
 
14
12
  require 'slimmer/version'
data/lib/slimmer/app.rb CHANGED
@@ -1,3 +1,5 @@
1
+ require 'slimmer/govuk_request_id'
2
+
1
3
  module Slimmer
2
4
  class App
3
5
  attr_accessor :logger
@@ -81,6 +83,9 @@ module Slimmer
81
83
  def rewrite_response(env, response)
82
84
  request = Rack::Request.new(env)
83
85
 
86
+ # Store the request id so it can be passed on with any template requests
87
+ GovukRequestId.value = env['HTTP_GOVUK_REQUEST_ID']
88
+
84
89
  rewritten_body = case response.status
85
90
  when 200
86
91
  @skin.success request, response, s(response.body)
@@ -0,0 +1,18 @@
1
+ module Slimmer
2
+ class GovukRequestId
3
+ class << self
4
+ def set?
5
+ !(value.nil? || value.empty?)
6
+ end
7
+
8
+ def value
9
+ Thread.current[:slimmer_govuk_request_id]
10
+ end
11
+
12
+ def value=(new_id)
13
+ Thread.current[:slimmer_govuk_request_id] = new_id
14
+ end
15
+ end
16
+ end
17
+ end
18
+
data/lib/slimmer/skin.rb CHANGED
@@ -1,3 +1,6 @@
1
+ require 'rest_client'
2
+ require 'slimmer/govuk_request_id'
3
+
1
4
  module Slimmer
2
5
  class Skin
3
6
  attr_accessor :use_cache, :template_cache, :asset_host, :logger, :strict, :options
@@ -28,14 +31,11 @@ module Slimmer
28
31
 
29
32
  def load_template(template_name)
30
33
  url = template_url(template_name)
31
- source = open(url, "r:UTF-8", :ssl_verify_mode => OpenSSL::SSL::VERIFY_NONE).read
32
- if template_name =~ /\.raw/
33
- template = source
34
- else
35
- template = ERB.new(source).result binding
36
- end
37
- template
38
- rescue OpenURI::HTTPError => e
34
+ headers = {}
35
+ headers[:govuk_request_id] = GovukRequestId.value if GovukRequestId.set?
36
+ response = RestClient.get(url, headers)
37
+ response.body
38
+ rescue RestClient::Exception => e
39
39
  raise TemplateNotFoundException, "Unable to fetch: '#{template_name}' from '#{url}' because #{e}", caller
40
40
  rescue Errno::ECONNREFUSED => e
41
41
  raise CouldNotRetrieveTemplate, "Unable to fetch: '#{template_name}' from '#{url}' because #{e}", caller
@@ -107,9 +107,7 @@ module Slimmer
107
107
  end_time = Time.now
108
108
  logger.debug "Slimmer: Skinning process completed at #{end_time} (#{end_time - start_time}s)"
109
109
 
110
- # this is a horrible fix to Nokogiri removing the closing </noscript> tag required by Google Website Optimizer.
111
- # http://www.google.com/support/websiteoptimizer/bin/answer.py?hl=en_us&answer=64418
112
- dest.to_html.sub(/<noscript rel=("|')placeholder("|')>/, "")
110
+ dest.to_html
113
111
  end
114
112
 
115
113
  def success(source_request, response, body)
@@ -16,12 +16,8 @@
16
16
 
17
17
  <footer id="footer"></footer>
18
18
 
19
- <script src="https://static.preview.alphagov.co.uk/static/govuk-template.js" type="text/javascript"></script>
20
- <script src="https://static.preview.alphagov.co.uk/static/libs/jquery/jquery-1.7.2.js" type="text/javascript"></script>
21
- <script defer src="https://static.preview.alphagov.co.uk/static/libs/jquery/plugins/jquery.base64.js?body=1" type="text/javascript"></script>
22
- <script defer src="https://static.preview.alphagov.co.uk/static/user-satisfaction-survey.js?body=1" type="text/javascript"></script>
23
- <script defer src="https://static.preview.alphagov.co.uk/static/core.js?body=1" type="text/javascript"></script>
24
- <script defer src="https://static.preview.alphagov.co.uk/static/report-a-problem.js?body=1" type="text/javascript"></script>
25
- <script src="https://static.preview.alphagov.co.uk/static/header-footer-only.js" type="text/javascript"></script>
19
+ <script src="https://assets-origin.preview.alphagov.co.uk/static/govuk-template.js" type="text/javascript"></script>
20
+ <script src="https://assets-origin.preview.alphagov.co.uk/static/libs/jquery/jquery-1.7.2.js" type="text/javascript"></script>
21
+ <script src="https://assets-origin.preview.alphagov.co.uk/static/header-footer-only.js" type="text/javascript"></script>
26
22
  </body>
27
23
  </html>
@@ -16,8 +16,8 @@
16
16
 
17
17
  <footer id="footer"></footer>
18
18
 
19
- <script src="https://static.preview.alphagov.co.uk/static/govuk-template.js" type="text/javascript"></script>
20
- <script src="https://static.preview.alphagov.co.uk/static/libs/jquery/jquery-1.7.2.js" type="text/javascript"></script>
21
- <script src="https://static.preview.alphagov.co.uk/static/application.js" type="text/javascript"></script>
19
+ <script src="https://assets-origin.preview.alphagov.co.uk/static/govuk-template.js" type="text/javascript"></script>
20
+ <script src="https://assets-origin.preview.alphagov.co.uk/static/libs/jquery/jquery-1.7.2.js" type="text/javascript"></script>
21
+ <script src="https://assets-origin.preview.alphagov.co.uk/static/application.js" type="text/javascript"></script>
22
22
  </body>
23
23
  </html>
@@ -1,3 +1,3 @@
1
1
  module Slimmer
2
- VERSION = '3.24.0'
2
+ VERSION = '3.25.0'
3
3
  end
@@ -0,0 +1,10 @@
1
+ require_relative 'test_helper'
2
+
3
+ describe 'CHANGELOG' do
4
+
5
+ it "should have an entry for the current version" do
6
+ changelog_contents = File.read(File.expand_path("../../CHANGELOG.md", __FILE__))
7
+
8
+ assert_match /^#+\s*#{Regexp.escape(Slimmer::VERSION)}/, changelog_contents, "No entry for #{Slimmer::VERSION} found in CHANGELOG.md"
9
+ end
10
+ end
data/test/skin_test.rb CHANGED
@@ -10,10 +10,38 @@ describe Slimmer::Skin do
10
10
 
11
11
  template = skin.template 'example'
12
12
 
13
- assert_requested :get, "http://example.local/templates/example.html.erb"
13
+ assert_requested :get, expected_url
14
14
  assert_equal "<foo />", template
15
15
  end
16
16
 
17
+ describe "should pass the GOVUK-Request-Id header when requesting the template" do
18
+ before do
19
+ @skin = Slimmer::Skin.new asset_host: "http://example.local/"
20
+ @expected_url = "http://example.local/templates/example.html.erb"
21
+ stub_request(:get, @expected_url).to_return :body => "<foo />"
22
+ end
23
+
24
+ it "should pass the value from the original request if set" do
25
+ Slimmer::GovukRequestId.value = '12345'
26
+ template = @skin.template('example')
27
+
28
+ assert_requested :get, @expected_url do |request|
29
+ request.headers['Govuk-Request-Id'] == '12345'
30
+ end
31
+ assert_equal "<foo />", template
32
+ end
33
+
34
+ it "shouldnot set the header if the value is not set" do
35
+ Slimmer::GovukRequestId.value = ''
36
+ template = @skin.template('example')
37
+
38
+ assert_requested :get, @expected_url do |request|
39
+ ! request.headers.has_key?('Govuk-Request-Id')
40
+ end
41
+ assert_equal "<foo />", template
42
+ end
43
+ end
44
+
17
45
  describe "template caching" do
18
46
  it "should not cache the template by default" do
19
47
  skin = Slimmer::Skin.new asset_host: "http://example.local/"
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: 3.24.0
4
+ version: 3.25.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2013-12-10 00:00:00.000000000 Z
13
+ date: 2014-01-09 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: nokogiri
@@ -108,6 +108,22 @@ dependencies:
108
108
  - - ~>
109
109
  - !ruby/object:Gem::Version
110
110
  version: 0.1.3
111
+ - !ruby/object:Gem::Dependency
112
+ name: rest-client
113
+ requirement: !ruby/object:Gem::Requirement
114
+ none: false
115
+ requirements:
116
+ - - ! '>='
117
+ - !ruby/object:Gem::Version
118
+ version: '0'
119
+ type: :runtime
120
+ prerelease: false
121
+ version_requirements: !ruby/object:Gem::Requirement
122
+ none: false
123
+ requirements:
124
+ - - ! '>='
125
+ - !ruby/object:Gem::Version
126
+ version: '0'
111
127
  - !ruby/object:Gem::Dependency
112
128
  name: rake
113
129
  requirement: !ruby/object:Gem::Requirement
@@ -257,6 +273,7 @@ files:
257
273
  - lib/slimmer/test.rb
258
274
  - lib/slimmer/version.rb
259
275
  - lib/slimmer/artefact.rb
276
+ - lib/slimmer/govuk_request_id.rb
260
277
  - lib/slimmer/template.rb
261
278
  - lib/slimmer/processors/header_context_inserter.rb
262
279
  - lib/slimmer/processors/navigation_mover.rb
@@ -278,6 +295,7 @@ files:
278
295
  - lib/tasks/slimmer.rake
279
296
  - lib/slimmer.rb
280
297
  - Rakefile
298
+ - test/changelog_test.rb
281
299
  - test/typical_usage_test.rb
282
300
  - test/skin_test.rb
283
301
  - test/artefact_test.rb
@@ -318,7 +336,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
318
336
  version: '0'
319
337
  segments:
320
338
  - 0
321
- hash: -3770913411525795405
339
+ hash: 3065065351120828273
322
340
  required_rubygems_version: !ruby/object:Gem::Requirement
323
341
  none: false
324
342
  requirements:
@@ -327,7 +345,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
327
345
  version: '0'
328
346
  segments:
329
347
  - 0
330
- hash: -3770913411525795405
348
+ hash: 3065065351120828273
331
349
  requirements: []
332
350
  rubyforge_project: slimmer
333
351
  rubygems_version: 1.8.23
@@ -335,6 +353,7 @@ signing_key:
335
353
  specification_version: 3
336
354
  summary: Thinner than the skinner
337
355
  test_files:
356
+ - test/changelog_test.rb
338
357
  - test/typical_usage_test.rb
339
358
  - test/skin_test.rb
340
359
  - test/artefact_test.rb