slimmer 1.1.47 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/slimmer/tag_mover.rb +8 -0
- data/lib/slimmer/version.rb +1 -1
- data/test/typical_usage_test.rb +29 -6
- metadata +28 -28
data/lib/slimmer/tag_mover.rb
CHANGED
@@ -16,6 +16,13 @@ module Slimmer
|
|
16
16
|
end.compact.sort
|
17
17
|
end
|
18
18
|
|
19
|
+
def wrap_node(src, node)
|
20
|
+
if node.previous_sibling.to_s =~ /<!--\[if[^\]]+\]>-->/ and node.next_sibling.to_s == '<!--<![endif]-->'
|
21
|
+
node = Nokogiri::XML::NodeSet.new(src, [node.previous_sibling, node, node.next_sibling])
|
22
|
+
end
|
23
|
+
node
|
24
|
+
end
|
25
|
+
|
19
26
|
def move_tags(src, dest, type, opts)
|
20
27
|
comparison_attrs = opts[:keys] || opts[:must_have]
|
21
28
|
min_attrs = opts[:must_have]
|
@@ -25,6 +32,7 @@ module Slimmer
|
|
25
32
|
|
26
33
|
src.css(type).each do |node|
|
27
34
|
if include_tag?(node, min_attrs) && !already_there.include?(tag_fingerprint(node, comparison_attrs))
|
35
|
+
node = wrap_node(src, node)
|
28
36
|
node.remove
|
29
37
|
dest.at_xpath('/html/head') << node
|
30
38
|
end
|
data/lib/slimmer/version.rb
CHANGED
data/test/typical_usage_test.rb
CHANGED
@@ -78,7 +78,6 @@ module TypicalUsage
|
|
78
78
|
<meta name="x-section-name" content="This section">
|
79
79
|
<meta name="x-section-link" content="/this_section">
|
80
80
|
<script src="blah.js"></script>
|
81
|
-
<!--[if lt IE 9]><link href="app-ie.css" rel="stylesheet" type="text/css"><![endif]-->
|
82
81
|
<link href="app.css" rel="stylesheet" type="text/css">
|
83
82
|
</head>
|
84
83
|
<body class="body_class">
|
@@ -107,11 +106,6 @@ module TypicalUsage
|
|
107
106
|
assert_rendered_in_template "head link[href='app.css']"
|
108
107
|
end
|
109
108
|
|
110
|
-
def test_should_move_conditional_comments_into_the_head
|
111
|
-
element = Nokogiri::HTML.parse(last_response.body).at_xpath('//comment()')
|
112
|
-
assert_match /app-ie\.css/, element.to_s, 'Not found conditional comment in output'
|
113
|
-
end
|
114
|
-
|
115
109
|
def test_should_copy_the_class_of_the_body_element
|
116
110
|
assert_rendered_in_template "body.body_class"
|
117
111
|
end
|
@@ -122,6 +116,35 @@ module TypicalUsage
|
|
122
116
|
|
123
117
|
end
|
124
118
|
|
119
|
+
class ConditionalCommentTest < SlimmerIntegrationTest
|
120
|
+
given_response 200, %{
|
121
|
+
<html>
|
122
|
+
<head><title>The title of the page</title>
|
123
|
+
<!--[if lt IE 9]><link href="app-ie.css" rel="stylesheet" type="text/css"><![endif]-->
|
124
|
+
</head>
|
125
|
+
</html>
|
126
|
+
}
|
127
|
+
def test_should_find_conditional_comments_copied_into_the_head
|
128
|
+
element = Nokogiri::HTML.parse(last_response.body).at_xpath('//comment()')
|
129
|
+
assert_match element.to_s, /app-ie\.css/, 'Not found conditional comment in output'
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
class WrapTagTest < SlimmerIntegrationTest
|
134
|
+
given_response 200, %{
|
135
|
+
<html>
|
136
|
+
<head>
|
137
|
+
<!--[if gt IE 8]>--><link href="app.css" rel="stylesheet" type="text/css"><!--<![endif]-->
|
138
|
+
</head>
|
139
|
+
</html>
|
140
|
+
}
|
141
|
+
def test_should_find_stylesheet_wrapped_with_conditional_comments
|
142
|
+
assert_rendered_in_template "head link[href='app.css']"
|
143
|
+
element = Nokogiri::HTML.parse(last_response.body).at_xpath('/html/head')
|
144
|
+
assert_match element.to_s, /<!--\[if gt IE 8\]>-->.*app\.css.*<!--<!\[endif\]-->/m, 'Not found conditional comment in output'
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
125
148
|
class ResponseWithRelatedItemsTest < SlimmerIntegrationTest
|
126
149
|
include GdsApi::TestHelpers::Panopticon
|
127
150
|
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: slimmer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 1.
|
5
|
+
version: 1.2.0
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Ben Griffiths
|
@@ -11,7 +11,7 @@ autorequire:
|
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
13
|
|
14
|
-
date: 2012-
|
14
|
+
date: 2012-08-02 00:00:00 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: nokogiri
|
@@ -161,41 +161,41 @@ extra_rdoc_files: []
|
|
161
161
|
files:
|
162
162
|
- README.md
|
163
163
|
- CHANGELOG.md
|
164
|
-
- lib/slimmer
|
164
|
+
- lib/tasks/slimmer.rake
|
165
|
+
- lib/slimmer/body_class_copier.rb
|
166
|
+
- lib/slimmer/version.rb
|
167
|
+
- lib/slimmer/google_analytics_configurator.rb
|
165
168
|
- lib/slimmer/related_items_inserter.rb
|
166
|
-
- lib/slimmer/
|
169
|
+
- lib/slimmer/body_inserter.rb
|
170
|
+
- lib/slimmer/template.rb
|
171
|
+
- lib/slimmer/footer_remover.rb
|
167
172
|
- lib/slimmer/railtie.rb
|
168
173
|
- lib/slimmer/test.rb
|
169
|
-
- lib/slimmer/footer_remover.rb
|
170
174
|
- lib/slimmer/skin.rb
|
171
175
|
- lib/slimmer/conditional_comment_mover.rb
|
176
|
+
- lib/slimmer/url_rewriter.rb
|
177
|
+
- lib/slimmer/app.rb
|
178
|
+
- lib/slimmer/admin_title_inserter.rb
|
172
179
|
- lib/slimmer/section_inserter.rb
|
173
|
-
- lib/slimmer/title_inserter.rb
|
174
180
|
- lib/slimmer/search_path_setter.rb
|
175
|
-
- lib/slimmer/url_rewriter.rb
|
176
|
-
- lib/slimmer/body_class_copier.rb
|
177
181
|
- lib/slimmer/headers.rb
|
178
|
-
- lib/slimmer/version.rb
|
179
|
-
- lib/slimmer/google_analytics_configurator.rb
|
180
|
-
- lib/slimmer/admin_title_inserter.rb
|
181
182
|
- lib/slimmer/tag_mover.rb
|
182
|
-
- lib/slimmer/
|
183
|
-
- lib/slimmer/
|
183
|
+
- lib/slimmer/title_inserter.rb
|
184
|
+
- lib/slimmer/header_context_inserter.rb
|
184
185
|
- lib/slimmer.rb
|
185
|
-
- lib/tasks/slimmer.rake
|
186
186
|
- Rakefile
|
187
|
-
- test/typical_usage_test.rb
|
188
|
-
- test/test_helper.rb
|
189
|
-
- test/headers_test.rb
|
190
187
|
- test/processors/header_context_inserter_test.rb
|
191
188
|
- test/processors/body_inserter_test.rb
|
189
|
+
- test/skin_test.rb
|
190
|
+
- test/headers_test.rb
|
191
|
+
- test/google_analytics_test.rb
|
192
|
+
- test/typical_usage_test.rb
|
192
193
|
- test/fixtures/500.html.erb
|
193
|
-
- test/fixtures/related.raw.html.erb
|
194
194
|
- test/fixtures/404.html.erb
|
195
|
+
- test/fixtures/related.raw.html.erb
|
195
196
|
- test/fixtures/wrapper.html.erb
|
197
|
+
- test/test_helper.rb
|
196
198
|
- test/search_path_setter_test.rb
|
197
|
-
- test/skin_test.rb
|
198
|
-
- test/google_analytics_test.rb
|
199
199
|
- bin/render_slimmer_error
|
200
200
|
homepage: http://github.com/alphagov/slimmer
|
201
201
|
licenses: []
|
@@ -210,7 +210,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
210
210
|
requirements:
|
211
211
|
- - ">="
|
212
212
|
- !ruby/object:Gem::Version
|
213
|
-
hash:
|
213
|
+
hash: -1131306322543169285
|
214
214
|
segments:
|
215
215
|
- 0
|
216
216
|
version: "0"
|
@@ -219,7 +219,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
219
219
|
requirements:
|
220
220
|
- - ">="
|
221
221
|
- !ruby/object:Gem::Version
|
222
|
-
hash:
|
222
|
+
hash: -1131306322543169285
|
223
223
|
segments:
|
224
224
|
- 0
|
225
225
|
version: "0"
|
@@ -231,15 +231,15 @@ signing_key:
|
|
231
231
|
specification_version: 3
|
232
232
|
summary: Thinner than the skinner
|
233
233
|
test_files:
|
234
|
-
- test/typical_usage_test.rb
|
235
|
-
- test/test_helper.rb
|
236
|
-
- test/headers_test.rb
|
237
234
|
- test/processors/header_context_inserter_test.rb
|
238
235
|
- test/processors/body_inserter_test.rb
|
236
|
+
- test/skin_test.rb
|
237
|
+
- test/headers_test.rb
|
238
|
+
- test/google_analytics_test.rb
|
239
|
+
- test/typical_usage_test.rb
|
239
240
|
- test/fixtures/500.html.erb
|
240
|
-
- test/fixtures/related.raw.html.erb
|
241
241
|
- test/fixtures/404.html.erb
|
242
|
+
- test/fixtures/related.raw.html.erb
|
242
243
|
- test/fixtures/wrapper.html.erb
|
244
|
+
- test/test_helper.rb
|
243
245
|
- test/search_path_setter_test.rb
|
244
|
-
- test/skin_test.rb
|
245
|
-
- test/google_analytics_test.rb
|