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 +4 -4
- data/CHANGELOG.md +5 -0
- data/README.md +4 -0
- data/Rakefile +4 -3
- data/lib/slimmer/app.rb +2 -2
- data/lib/slimmer/headers.rb +11 -11
- data/lib/slimmer/processors/tag_mover.rb +12 -12
- data/lib/slimmer/skin.rb +4 -4
- data/lib/slimmer/template.rb +3 -4
- data/lib/slimmer/test.rb +2 -2
- data/lib/slimmer/test_templates/header_footer_only.html +0 -4
- data/lib/slimmer/test_templates/wrapper.html +0 -4
- data/lib/slimmer/version.rb +1 -1
- data/lib/tasks/slimmer.rake +2 -2
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 69efc7036b8f43e79f0a658b8cb7a4d1b8a3a6d6e7083adc4f0d7c5f94660de4
|
4
|
+
data.tar.gz: 1ea0fc004cc8eaf7b51db1071aa6d681bd178aa4f28e311a5c8c896330a2a0d0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 526e412c02dec4300125ef6047212538dea07fecf9842b0cfb2716e7f962c582b76ff921107ca3b039c053718a310adc29fe6d7035fb3544c5b0f66b73b83b4e
|
7
|
+
data.tar.gz: d414a38146b156fc6ba454798fe79741bff8b3f3015d42dad4b991e8f5f48e1bf9f0c46b2de7cb079c78b9beb62eeb9925c23ed5514c5a67d80b5e249b31fa83
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
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]
|
data/lib/slimmer/app.rb
CHANGED
@@ -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
|
-
|
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
|
-
|
64
|
+
response.headers.key?(Headers::SKIP_HEADER)
|
65
65
|
end
|
66
66
|
|
67
67
|
def s(body)
|
data/lib/slimmer/headers.rb
CHANGED
@@ -9,17 +9,17 @@ module Slimmer
|
|
9
9
|
|
10
10
|
# @private
|
11
11
|
SLIMMER_HEADER_MAPPING = {
|
12
|
-
application_name:
|
13
|
-
format:
|
14
|
-
page_owner:
|
15
|
-
organisations:
|
16
|
-
world_locations:
|
17
|
-
result_count:
|
18
|
-
search_parameters:
|
19
|
-
section:
|
20
|
-
skip:
|
21
|
-
template:
|
22
|
-
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
|
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
|
7
|
-
move_tags(src, dest, "meta", must_have: %w
|
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
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
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
|
data/lib/slimmer/skin.rb
CHANGED
@@ -5,12 +5,12 @@ module Slimmer
|
|
5
5
|
class Skin
|
6
6
|
attr_accessor :asset_host, :logger, :strict, :options
|
7
7
|
|
8
|
-
def initialize
|
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
|
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
|
-
|
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"
|
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")
|
data/lib/slimmer/template.rb
CHANGED
@@ -1,16 +1,15 @@
|
|
1
1
|
module Slimmer
|
2
2
|
module Template
|
3
|
-
def self.included
|
3
|
+
def self.included(into)
|
4
4
|
into.extend ClassMethods
|
5
5
|
end
|
6
6
|
|
7
|
-
def slimmer_template
|
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
|
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
|
data/lib/slimmer/test.rb
CHANGED
@@ -2,10 +2,10 @@ require "slimmer/skin"
|
|
2
2
|
|
3
3
|
module Slimmer
|
4
4
|
class Skin
|
5
|
-
def load_template
|
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
|
-
%
|
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>
|
data/lib/slimmer/version.rb
CHANGED
data/lib/tasks/slimmer.rake
CHANGED
@@ -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/*")
|
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:
|
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-
|
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:
|
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:
|
194
|
+
version: '3'
|
195
195
|
- !ruby/object:Gem::Dependency
|
196
196
|
name: timecop
|
197
197
|
requirement: !ruby/object:Gem::Requirement
|