slimmer 1.1.16 → 1.1.17

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.
@@ -5,7 +5,7 @@ module Slimmer
5
5
  end
6
6
 
7
7
  def filter(src,dest)
8
- body = src.fragment(src.at_css(@path))
8
+ body = Nokogiri::HTML.fragment(src.at_css(@path).to_html)
9
9
  dest.at_css(@path).replace(body)
10
10
  end
11
11
  end
@@ -19,7 +19,9 @@ module Slimmer
19
19
  set_custom_var(slot, name, @headers[key])
20
20
  }.compact.join("\n");
21
21
 
22
- dest.at_css("#ga-params").content += custom_vars
22
+ if dest.at_css("#ga-params")
23
+ dest.at_css("#ga-params").content += custom_vars
24
+ end
23
25
  end
24
26
 
25
27
  private
@@ -26,35 +26,35 @@ module Slimmer
26
26
  end
27
27
 
28
28
  def template(template_name)
29
- logger.debug "Slimmer: Looking for template #{template_name}"
29
+ logger.debug "Slimmer: Looking for template '#{template_name}'"
30
30
  return cached_template(template_name) if template_cached? template_name
31
31
  logger.debug "Slimmer: Asking for the template to be loaded"
32
32
  load_template template_name
33
33
  end
34
34
 
35
35
  def template_cached? name
36
- logger.debug "Slimmer: Checking cache for template #{name}"
36
+ logger.debug "Slimmer: Checking cache for template '#{name}'"
37
37
  cached = !cached_template(name).nil?
38
38
  logger.debug "Slimmer: Cache hit = #{cached}"
39
39
  cached
40
40
  end
41
41
 
42
42
  def cached_template name
43
- logger.debug "Slimmer: Trying to load cached template #{name}"
43
+ logger.debug "Slimmer: Trying to load cached template '#{name}'"
44
44
  templated_cache[name]
45
45
  end
46
46
 
47
47
  def cache name, template
48
- logger.debug "Slimmer: Asked to cache #{name}. use_cache = #{use_cache}"
48
+ logger.debug "Slimmer: Asked to cache '#{name}'. use_cache = #{use_cache}"
49
49
  return unless use_cache
50
50
  logger.debug "Slimmer: performing caching"
51
51
  templated_cache[name] = template
52
52
  end
53
53
 
54
54
  def load_template template_name
55
- logger.debug "Slimmer: Loading template #{template_name}"
55
+ logger.debug "Slimmer: Loading template '#{template_name}'"
56
56
  url = template_url template_name
57
- logger.debug "Slimmer: template lives at #{url}"
57
+ logger.debug "Slimmer: template lives at '#{url}'"
58
58
  source = open(url, "r:UTF-8", :ssl_verify_mode => OpenSSL::SSL::VERIFY_NONE).read
59
59
  logger.debug "Slimmer: Evaluating the template as ERB"
60
60
  template = ERB.new(source).result binding
@@ -3,6 +3,7 @@ require 'slimmer/skin'
3
3
  module Slimmer
4
4
  class Skin
5
5
  def load_template name
6
+ logger.debug "Slimmer: TEST MODE - Loading fixture template from #{__FILE__}"
6
7
  %q{
7
8
  <html>
8
9
  <head>
@@ -12,11 +13,11 @@ module Slimmer
12
13
  <script src="http://static.preview.alphagov.co.uk/javascripts/libs/jquery/plugins/jquery.base64.js" defer></script>
13
14
  <script src="http://static.preview.alphagov.co.uk/javascripts/libs/jquery/plugins/jquery.mustache.js" defer></script>
14
15
  <script src="http://static.preview.alphagov.co.uk/javascripts/search.js" defer></script>
16
+ <script src="http://static.preview.alphagov.co.uk/javascripts/core.js" defer></script>
15
17
  <script src="http://static.preview.alphagov.co.uk/javascripts/devolution.js" defer></script>
16
18
  <script src="http://static.preview.alphagov.co.uk/javascripts/popup.js" defer></script>
17
- <script src="http://static.preview.alphagov.co.uk/javascripts/feedback.js" defer></script>
18
- <script src="http://static.preview.alphagov.co.uk/javascripts/customisation-settings.js" defer></script>
19
19
  <script src="http://static.preview.alphagov.co.uk/javascripts/geo-locator.js" defer></script>
20
+ <script src="http://static.preview.alphagov.co.uk/javascripts/customisation-settings.js" defer></script>
20
21
  </head>
21
22
  <body>
22
23
  <div class="header-context">Header</div>
@@ -1,3 +1,3 @@
1
1
  module Slimmer
2
- VERSION = '1.1.16'
2
+ VERSION = '1.1.17'
3
3
  end
@@ -13,6 +13,19 @@ class BodyInserterTest < MiniTest::Unit::TestCase
13
13
  assert_in template, "#wrapper", %{<p>this should be moved</p>}
14
14
  end
15
15
 
16
+ def test_should_copy_across_unicode_characters_without_messing_with_their_encoding
17
+ unicode_endash = [0x2013].pack('U*')
18
+ template = as_nokogiri %{
19
+ <html><body><div><div id="wrapper"></div></div></body></html>
20
+ }
21
+ source = as_nokogiri %{
22
+ <html><body><nav></nav><div id="wrapper"><p>#{unicode_endash}</p></div></body></html>
23
+ }
24
+
25
+ Slimmer::BodyInserter.new.filter(source, template)
26
+ assert_equal unicode_endash, template.at_css("#wrapper p").inner_text
27
+ end
28
+
16
29
  def test_should_allow_replacement_of_arbitrary_wrappers
17
30
  template = as_nokogiri %{
18
31
  <html><body><div>
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: slimmer
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 1.1.16
5
+ version: 1.1.17
6
6
  platform: ruby
7
7
  authors:
8
8
  - Ben Griffiths
@@ -180,7 +180,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
180
180
  requirements:
181
181
  - - ">="
182
182
  - !ruby/object:Gem::Version
183
- hash: -4073073452221252431
183
+ hash: -4136330702604149835
184
184
  segments:
185
185
  - 0
186
186
  version: "0"
@@ -189,7 +189,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
189
189
  requirements:
190
190
  - - ">="
191
191
  - !ruby/object:Gem::Version
192
- hash: -4073073452221252431
192
+ hash: -4136330702604149835
193
193
  segments:
194
194
  - 0
195
195
  version: "0"