slimmer 15.3.0 → 15.4.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 +4 -0
- data/lib/slimmer.rb +0 -2
- data/lib/slimmer/processors/tag_mover.rb +16 -3
- data/lib/slimmer/version.rb +1 -1
- metadata +2 -3
- data/lib/slimmer/processors/footer_remover.rb +0 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 863bbe9dee726275663817de72e9565a12f648b792d49e736d87bba0d0de9367
|
4
|
+
data.tar.gz: 946b29270aa371b28a6b8c7e910e263bb0718f48bd337922de79a6bb1ce1475e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 823996625c9137fa1139ab7ea3d32f28f17c1d77edcbf2c4613c6038a6fa1c80263972c1d5cdeceb9dbabcd9c6985d6d183335034e97c43e32da3d290e8338c8
|
7
|
+
data.tar.gz: bdc96ffc6f0d51f93733158873fc12b0fb8a01de806cbfca43b3a40570787cb3564f25ad1f019bb763e38a276e14fa7134e7a030a344f12aca9386e937e19a0d
|
data/CHANGELOG.md
CHANGED
data/lib/slimmer.rb
CHANGED
@@ -32,12 +32,10 @@ module Slimmer
|
|
32
32
|
autoload :BodyClassCopier, "slimmer/processors/body_class_copier"
|
33
33
|
autoload :BodyInserter, "slimmer/processors/body_inserter"
|
34
34
|
autoload :ConditionalCommentMover, "slimmer/processors/conditional_comment_mover"
|
35
|
-
autoload :FooterRemover, "slimmer/processors/footer_remover"
|
36
35
|
autoload :MetadataInserter, "slimmer/processors/metadata_inserter"
|
37
36
|
autoload :HeaderContextInserter, "slimmer/processors/header_context_inserter"
|
38
37
|
autoload :InsideHeaderInserter, "slimmer/processors/inside_header_inserter"
|
39
38
|
autoload :NavigationMover, "slimmer/processors/navigation_mover"
|
40
|
-
autoload :SearchIndexSetter, "slimmer/processors/search_index_setter"
|
41
39
|
autoload :SearchPathSetter, "slimmer/processors/search_path_setter"
|
42
40
|
autoload :SearchParameterInserter, "slimmer/processors/search_parameter_inserter"
|
43
41
|
autoload :SearchRemover, "slimmer/processors/search_remover"
|
@@ -1,11 +1,11 @@
|
|
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])
|
5
4
|
move_tags(src, dest, "link", must_have: %w[href])
|
6
5
|
move_tags(src, dest, "meta", must_have: %w[name content], keys: %w[name content http-equiv], insertion_location: :top)
|
7
6
|
move_tags(src, dest, "meta", must_have: %w[property content], keys: %w[property content], insertion_location: :top)
|
8
7
|
move_tags(src, dest, "base", must_have: %w[href])
|
8
|
+
move_tags(src, dest, "script", keys: %w[src inner_html], head_if_attributes: %w[async defer])
|
9
9
|
end
|
10
10
|
|
11
11
|
def include_tag?(node, min_attrs)
|
@@ -31,21 +31,34 @@ module Slimmer::Processors
|
|
31
31
|
node
|
32
32
|
end
|
33
33
|
|
34
|
+
def head_or_body(node, head_if_attributes)
|
35
|
+
if head_if_attributes.any? { |attribute| node.has_attribute?(attribute) }
|
36
|
+
"head"
|
37
|
+
else
|
38
|
+
"body"
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
34
42
|
def move_tags(src, dest, type, opts)
|
35
43
|
comparison_attrs = opts[:keys] || opts[:must_have]
|
36
44
|
min_attrs = opts[:must_have] || []
|
45
|
+
head_if_attributes = opts[:head_if_attributes] || []
|
46
|
+
dest_node = "head"
|
37
47
|
already_there = dest.css(type).map { |node|
|
38
48
|
tag_fingerprint(node, comparison_attrs)
|
39
49
|
}.compact
|
40
|
-
dest_node = opts[:dest_node] || "head"
|
41
50
|
|
42
51
|
src.css(type).each do |node|
|
43
52
|
next unless include_tag?(node, min_attrs) && !already_there.include?(tag_fingerprint(node, comparison_attrs))
|
44
53
|
|
45
54
|
node = wrap_node(src, node)
|
55
|
+
if head_if_attributes.any?
|
56
|
+
dest_node = head_or_body(node, head_if_attributes)
|
57
|
+
insert_at_top = true if dest_node == "head"
|
58
|
+
end
|
46
59
|
node.remove
|
47
60
|
|
48
|
-
if opts[:insertion_location] == :top
|
61
|
+
if opts[:insertion_location] == :top || insert_at_top
|
49
62
|
dest.at_xpath("/html/#{dest_node}").prepend_child(node)
|
50
63
|
else
|
51
64
|
dest.at_xpath("/html/#{dest_node}") << node
|
data/lib/slimmer/version.rb
CHANGED
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: 15.
|
4
|
+
version: 15.4.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:
|
11
|
+
date: 2021-01-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -256,7 +256,6 @@ files:
|
|
256
256
|
- lib/slimmer/processors/body_class_copier.rb
|
257
257
|
- lib/slimmer/processors/body_inserter.rb
|
258
258
|
- lib/slimmer/processors/conditional_comment_mover.rb
|
259
|
-
- lib/slimmer/processors/footer_remover.rb
|
260
259
|
- lib/slimmer/processors/header_context_inserter.rb
|
261
260
|
- lib/slimmer/processors/inside_header_inserter.rb
|
262
261
|
- lib/slimmer/processors/metadata_inserter.rb
|