slimmer 14.0.0 → 15.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5e29edb1500e56cda58cd5b43463f19beb2b8e1e53a2a0c0c7bf4f88b1542c3d
4
- data.tar.gz: 90a425692e649c7f941f9f45a8966babff2f31dc888ada70d47ea86b7b365002
3
+ metadata.gz: 69efc7036b8f43e79f0a658b8cb7a4d1b8a3a6d6e7083adc4f0d7c5f94660de4
4
+ data.tar.gz: 1ea0fc004cc8eaf7b51db1071aa6d681bd178aa4f28e311a5c8c896330a2a0d0
5
5
  SHA512:
6
- metadata.gz: 2132180bb938d0db3a8dfe094a45b173254b52ec6847977480ae14a9ceec8a2c44da0dd54bfc7c4f062a2e050710ac5cdf3137b46a238993c40b148df631032f
7
- data.tar.gz: cb45e29c4f0d6d3874352a89f29146cc154279430a58535fe3e9ff6d46e53900171534a29209e5432f203073fe1708f578181d800f595d07844be52eda8d15f4
6
+ metadata.gz: 526e412c02dec4300125ef6047212538dea07fecf9842b0cfb2716e7f962c582b76ff921107ca3b039c053718a310adc29fe6d7035fb3544c5b0f66b73b83b4e
7
+ data.tar.gz: d414a38146b156fc6ba454798fe79741bff8b3f3015d42dad4b991e8f5f48e1bf9f0c46b2de7cb079c78b9beb62eeb9925c23ed5514c5a67d80b5e249b31fa83
@@ -1,3 +1,8 @@
1
+ # 15.0.0
2
+
3
+ * BREAKING: Test templates no longer embed links to production JavaScript files,
4
+ apps should provide their own dependencies.
5
+
1
6
  # 14.0.0
2
7
 
3
8
  * Remove handling of non-200 responses (#245)
data/README.md CHANGED
@@ -96,3 +96,7 @@ Add the following code to spec/spec_helper:
96
96
  ```rb
97
97
  require 'slimmer/rspec'
98
98
  ```
99
+
100
+ ## Licence
101
+
102
+ [MIT License](LICENCE)
data/Rakefile CHANGED
@@ -1,8 +1,9 @@
1
- # -*- encoding: utf-8 -*-
2
-
3
1
  require "bundler/gem_tasks"
4
2
  require "rdoc/task"
5
3
  require "rake/testtask"
4
+ require "rubocop/rake_task"
5
+
6
+ RuboCop::RakeTask.new
6
7
 
7
8
  Dir.glob("lib/tasks/*.rake").each { |r| import r }
8
9
 
@@ -18,4 +19,4 @@ Rake::TestTask.new("test") do |t|
18
19
  t.verbose = true
19
20
  end
20
21
 
21
- task default: %i[test]
22
+ task default: %i[test rubocop]
@@ -35,7 +35,7 @@ module Slimmer
35
35
  if response_can_be_rewritten?(status, headers)
36
36
  response = Rack::Response.new(body, status, headers)
37
37
 
38
- if !skip_slimmer?(env, response)
38
+ unless skip_slimmer?(env, response)
39
39
  status, headers, body = rewrite_response(env, response)
40
40
  end
41
41
  end
@@ -61,7 +61,7 @@ module Slimmer
61
61
  end
62
62
 
63
63
  def skip_slimmer_header?(response)
64
- !!response.headers[Headers::SKIP_HEADER]
64
+ response.headers.key?(Headers::SKIP_HEADER)
65
65
  end
66
66
 
67
67
  def s(body)
@@ -9,17 +9,17 @@ module Slimmer
9
9
 
10
10
  # @private
11
11
  SLIMMER_HEADER_MAPPING = {
12
- application_name: "Application-Name",
13
- format: "Format",
14
- page_owner: "Page-Owner",
15
- organisations: "Organisations",
16
- world_locations: "World-Locations",
17
- result_count: "Result-Count",
18
- search_parameters: "Search-Parameters",
19
- section: "Section",
20
- skip: "Skip",
21
- template: "Template",
22
- remove_search: "Remove-Search",
12
+ application_name: "Application-Name",
13
+ format: "Format",
14
+ page_owner: "Page-Owner",
15
+ organisations: "Organisations",
16
+ world_locations: "World-Locations",
17
+ result_count: "Result-Count",
18
+ search_parameters: "Search-Parameters",
19
+ section: "Section",
20
+ skip: "Skip",
21
+ template: "Template",
22
+ remove_search: "Remove-Search",
23
23
  }.freeze
24
24
 
25
25
  # @private
@@ -1,10 +1,10 @@
1
1
  module Slimmer::Processors
2
2
  class TagMover
3
3
  def filter(src, dest)
4
- move_tags(src, dest, "script", dest_node: "body", keys: %w(src inner_html))
4
+ move_tags(src, dest, "script", dest_node: "body", keys: %w[src inner_html])
5
5
  move_tags(src, dest, "link", must_have: %w[href])
6
- move_tags(src, dest, "meta", must_have: %w(name content), keys: %w[name content http-equiv], insertion_location: :top)
7
- move_tags(src, dest, "meta", must_have: %w(property content), keys: %w(property content), insertion_location: :top)
6
+ move_tags(src, dest, "meta", must_have: %w[name content], keys: %w[name content http-equiv], insertion_location: :top)
7
+ move_tags(src, dest, "meta", must_have: %w[property content], keys: %w[property content], insertion_location: :top)
8
8
  end
9
9
 
10
10
  def include_tag?(node, min_attrs)
@@ -39,15 +39,15 @@ module Slimmer::Processors
39
39
  dest_node = opts[:dest_node] || "head"
40
40
 
41
41
  src.css(type).each do |node|
42
- if include_tag?(node, min_attrs) && !already_there.include?(tag_fingerprint(node, comparison_attrs))
43
- node = wrap_node(src, node)
44
- node.remove
45
-
46
- if opts[:insertion_location] == :top
47
- dest.at_xpath("/html/#{dest_node}").prepend_child(node)
48
- else
49
- dest.at_xpath("/html/#{dest_node}") << node
50
- end
42
+ next unless include_tag?(node, min_attrs) && !already_there.include?(tag_fingerprint(node, comparison_attrs))
43
+
44
+ node = wrap_node(src, node)
45
+ node.remove
46
+
47
+ if opts[:insertion_location] == :top
48
+ dest.at_xpath("/html/#{dest_node}").prepend_child(node)
49
+ else
50
+ dest.at_xpath("/html/#{dest_node}") << node
51
51
  end
52
52
  end
53
53
  end
@@ -5,12 +5,12 @@ module Slimmer
5
5
  class Skin
6
6
  attr_accessor :asset_host, :logger, :strict, :options
7
7
 
8
- def initialize options = {}
8
+ def initialize(options = {})
9
9
  @options = options
10
10
  @asset_host = options[:asset_host]
11
11
 
12
12
  @logger = options[:logger] || NullLogger.instance
13
- @strict = options[:strict] || %w{development test}.include?(ENV["RACK_ENV"])
13
+ @strict = options[:strict] || %w[development test].include?(ENV["RACK_ENV"])
14
14
  end
15
15
 
16
16
  def template(template_name)
@@ -42,7 +42,7 @@ module Slimmer
42
42
  doc = Nokogiri::HTML.parse(html)
43
43
  if strict
44
44
  errors = doc.errors.select(&:error?).reject { |e| ignorable?(e) }
45
- if !errors.empty?
45
+ unless errors.empty?
46
46
  error = errors.first
47
47
  message = "In #{description_for_error_message}: '#{error.message}' at line #{error.line} col #{error.column} (code #{error.code}).\n"
48
48
  message << "Add ?skip_slimmer=1 to the url to show the raw backend request.\n\n"
@@ -59,7 +59,7 @@ module Slimmer
59
59
  lines = [""] + html.split("\n")
60
60
  from = [1, error.line - context_size].max
61
61
  to = [lines.size - 1, error.line + context_size].min
62
- context = (from..to).zip(lines[from..to]).map { |lineno, line| "%4d: %s" % [lineno, line] }
62
+ context = (from..to).zip(lines[from..to]).map { |lineno, line| sprintf("%4d: %s", lineno, line) }
63
63
  marker = " " * (error.column - 1) + "-----v"
64
64
  context.insert(context_size, marker)
65
65
  context.join("\n")
@@ -1,16 +1,15 @@
1
1
  module Slimmer
2
2
  module Template
3
- def self.included into
3
+ def self.included(into)
4
4
  into.extend ClassMethods
5
5
  end
6
6
 
7
- def slimmer_template template_name
7
+ def slimmer_template(template_name)
8
8
  response.headers[Slimmer::Headers::TEMPLATE_HEADER] = template_name.to_s
9
9
  end
10
10
 
11
-
12
11
  module ClassMethods
13
- def slimmer_template template_name
12
+ def slimmer_template(template_name)
14
13
  after_action do
15
14
  response.headers[Slimmer::Headers::TEMPLATE_HEADER] ||= template_name.to_s
16
15
  end
@@ -2,10 +2,10 @@ require "slimmer/skin"
2
2
 
3
3
  module Slimmer
4
4
  class Skin
5
- def load_template name
5
+ def load_template(name)
6
6
  logger.debug "Slimmer: TEST MODE - Loading fixture template from #{__FILE__}"
7
7
  if name =~ /\A(.*)\.raw\z/
8
- %{<div id="test-#{$1}"></div>}
8
+ %(<div id="test-#{Regexp.last_match(1)}"></div>)
9
9
  elsif File.exist?(template_path = File.join(File.dirname(__FILE__), "test_templates", "#{name}.html"))
10
10
  File.read(template_path)
11
11
  else
@@ -19,9 +19,5 @@
19
19
  <div id="wrapper"></div>
20
20
 
21
21
  <footer id="footer"></footer>
22
-
23
- <script src="https://assets.publishing.service.gov.uk/static/govuk-template.js" type="text/javascript"></script>
24
- <script src="https://assets.publishing.service.gov.uk/static/libs/jquery/jquery-1.7.2.js" type="text/javascript"></script>
25
- <script src="https://assets.publishing.service.gov.uk/static/header-footer-only.js" type="text/javascript"></script>
26
22
  </body>
27
23
  </html>
@@ -19,9 +19,5 @@
19
19
  <div id="wrapper"></div>
20
20
 
21
21
  <footer id="footer"></footer>
22
-
23
- <script src="https://assets.publishing.service.gov.uk/static/govuk-template.js" type="text/javascript"></script>
24
- <script src="https://assets.publishing.service.gov.uk/static/libs/jquery/jquery-1.7.2.js" type="text/javascript"></script>
25
- <script src="https://assets.publishing.service.gov.uk/static/application.js" type="text/javascript"></script>
26
22
  </body>
27
23
  </html>
@@ -1,3 +1,3 @@
1
1
  module Slimmer
2
- VERSION = "14.0.0".freeze
2
+ VERSION = "15.0.0".freeze
3
3
  end
@@ -6,9 +6,9 @@ namespace :slimmer do
6
6
  path_to_static = "../static/public"
7
7
  path_to_public = "public"
8
8
  commands = ["cd #{path_to_public}"]
9
- Dir.glob("../static/public/*") { |f|
9
+ Dir.glob("../static/public/*") do |f|
10
10
  commands << "ln -s #{path_to_static}/#{f}"
11
- }
11
+ end
12
12
  commands << ["cd .."]
13
13
  run commands.join(" && ")
14
14
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: slimmer
3
3
  version: !ruby/object:Gem::Version
4
- version: 14.0.0
4
+ version: 15.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - GOV.UK Dev
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-05-14 00:00:00.000000000 Z
11
+ date: 2020-05-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -184,14 +184,14 @@ dependencies:
184
184
  requirements:
185
185
  - - "~>"
186
186
  - !ruby/object:Gem::Version
187
- version: 2.0.0
187
+ version: '3'
188
188
  type: :development
189
189
  prerelease: false
190
190
  version_requirements: !ruby/object:Gem::Requirement
191
191
  requirements:
192
192
  - - "~>"
193
193
  - !ruby/object:Gem::Version
194
- version: 2.0.0
194
+ version: '3'
195
195
  - !ruby/object:Gem::Dependency
196
196
  name: timecop
197
197
  requirement: !ruby/object:Gem::Requirement