htmlcompressor 0.3.1 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +6 -3
- data/README.md +4 -0
- data/lib/htmlcompressor/compressor.rb +20 -11
- data/lib/htmlcompressor/exceptions.rb +1 -0
- data/lib/htmlcompressor/version.rb +1 -1
- data/test/compressor_test.rb +42 -0
- data/test/resources/html/testCompressCustomHtmlTemplates.html +1 -1
- data/test/resources/html/testCompressCustomHtmlTemplatesResult.html +1 -1
- metadata +15 -15
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4054e9ae1eb0fbce4c30c4152d58ec6674b90b9a
|
4
|
+
data.tar.gz: ebd3e0082f208d1d00a68d398057f7effbfced44
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f1a43d6dc862b49ad5c797b3bf504a3f635a9e1adba8cacb9164e04add9f15f65a3ef98357c45c16a80ea87527fab7883f8fcfdda25ba9ae95dde32fb0f683bf
|
7
|
+
data.tar.gz: 81604765e64c4fce8f5da1001214a88320ac8f487324088e2ff77105a547ee62340644b07bf26d5a4dd2fa6636d43c42763576725e06ab791eb7783a91043820
|
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -47,6 +47,10 @@ options = {
|
|
47
47
|
}
|
48
48
|
```
|
49
49
|
|
50
|
+
Htmlcompressor also ships a rack middleware that can be used with rails, sinatra or rack.
|
51
|
+
|
52
|
+
**However keep in mind that compression is slow (especially when also compressing javascript or css) and can negatively impact the performance of your website. Take your measurements and adopt a different strategy if necessary**
|
53
|
+
|
50
54
|
Using rack middleware (in rails) is as easy as:
|
51
55
|
|
52
56
|
```ruby
|
@@ -385,6 +385,16 @@ module HtmlCompressor
|
|
385
385
|
|
386
386
|
def return_blocks(html, preBlocks, taBlocks, scriptBlocks, styleBlocks, eventBlocks, condCommentBlocks, skipBlocks, lineBreakBlocks, userBlocks)
|
387
387
|
|
388
|
+
# put skip blocks back
|
389
|
+
html = html.gsub(TEMP_SKIP_PATTERN) do |match|
|
390
|
+
i = $1.to_i
|
391
|
+
if skipBlocks.size > i
|
392
|
+
skipBlocks[i]
|
393
|
+
else
|
394
|
+
''
|
395
|
+
end
|
396
|
+
end
|
397
|
+
|
388
398
|
# put line breaks back
|
389
399
|
if @options[:preserve_line_breaks]
|
390
400
|
html = html.gsub(TEMP_LINE_BREAK_PATTERN) do |match|
|
@@ -455,15 +465,6 @@ module HtmlCompressor
|
|
455
465
|
end
|
456
466
|
end
|
457
467
|
|
458
|
-
# put skip blocks back
|
459
|
-
html = html.gsub(TEMP_SKIP_PATTERN) do |match|
|
460
|
-
i = $1.to_i
|
461
|
-
if skipBlocks.size > i
|
462
|
-
skipBlocks[i]
|
463
|
-
else
|
464
|
-
''
|
465
|
-
end
|
466
|
-
end
|
467
468
|
|
468
469
|
# put user blocks back
|
469
470
|
unless @options[:preserve_patterns].nil?
|
@@ -528,7 +529,11 @@ module HtmlCompressor
|
|
528
529
|
end
|
529
530
|
|
530
531
|
if javascript_compressor.nil?
|
531
|
-
|
532
|
+
if @options[:javascript_compressor].is_a?(Symbol)
|
533
|
+
raise NotFoundCompressorError, "JavaScript Compressor \"#{@options[:javascript_compressor]}\" not found, please check :javascript_compressor option"
|
534
|
+
else
|
535
|
+
raise MissingCompressorError, "No JavaScript Compressor. Please set the :javascript_compressor option"
|
536
|
+
end
|
532
537
|
end
|
533
538
|
|
534
539
|
# detect CDATA wrapper
|
@@ -556,7 +561,11 @@ module HtmlCompressor
|
|
556
561
|
end
|
557
562
|
|
558
563
|
if css_compressor.nil?
|
559
|
-
|
564
|
+
if @options[:css_compressor].is_a?(Symbol)
|
565
|
+
raise NotFoundCompressorError, "CSS Compressor \"#{@options[:css_compressor]}\" not found, please check :css_compressor option"
|
566
|
+
else
|
567
|
+
raise MissingCompressorError, "No CSS Compressor. Please set the :css_compressor option"
|
568
|
+
end
|
560
569
|
end
|
561
570
|
|
562
571
|
# detect CDATA wrapper
|
data/test/compressor_test.rb
CHANGED
@@ -224,6 +224,48 @@ module HtmlCompressor
|
|
224
224
|
assert_equal result, compressor.compress(source)
|
225
225
|
end
|
226
226
|
|
227
|
+
def test_dont_replace_javascript_inside_js_templates
|
228
|
+
source = read_resource("testCompressCustomHtmlTemplates.html")
|
229
|
+
result = read_resource("testCompressCustomHtmlTemplates.html")
|
230
|
+
compressor = Compressor.new(:compress_js_templates => false, :remove_quotes => true)
|
231
|
+
assert_equal result, compressor.compress(source)
|
232
|
+
end
|
233
|
+
|
234
|
+
def test_javascript_compressor_not_found
|
235
|
+
source = read_resource("testCompressJavaScript.html");
|
236
|
+
|
237
|
+
compressor = Compressor.new(
|
238
|
+
:compress_javascript => true,
|
239
|
+
:javascript_compressor => :not_existing_compressor,
|
240
|
+
:remove_intertag_spaces => true,
|
241
|
+
:compress_js_templates => true
|
242
|
+
)
|
243
|
+
|
244
|
+
exception = assert_raises(NotFoundCompressorError) do
|
245
|
+
compressor.compress(source)
|
246
|
+
end
|
247
|
+
|
248
|
+
expect_message = 'JavaScript Compressor "not_existing_compressor" not found, please check :javascript_compressor option'
|
249
|
+
assert_equal(expect_message, exception.message)
|
250
|
+
end
|
251
|
+
|
252
|
+
def test_css_compressor_not_found
|
253
|
+
source = read_resource("testCompressCss.html");
|
254
|
+
|
255
|
+
compressor = Compressor.new(
|
256
|
+
:enabled => true,
|
257
|
+
:compress_css => true,
|
258
|
+
:css_compressor => :not_existing_compressor,
|
259
|
+
:compress_javascript => false
|
260
|
+
)
|
261
|
+
|
262
|
+
exception = assert_raises(NotFoundCompressorError) do
|
263
|
+
compressor.compress(source)
|
264
|
+
end
|
265
|
+
|
266
|
+
expect_message = 'CSS Compressor "not_existing_compressor" not found, please check :css_compressor option'
|
267
|
+
assert_equal(expect_message, exception.message)
|
268
|
+
end
|
227
269
|
end
|
228
270
|
|
229
271
|
end
|
@@ -1 +1 @@
|
|
1
|
-
<script type="text/html"> <a attribute="value"> <!-- comment --> <b> </script>
|
1
|
+
<script type="text/html"> <a attribute="value" onclick="alert('hello world')"> <!-- comment --> <b> </script>
|
@@ -1 +1 @@
|
|
1
|
-
<script type="text/html"> <a attribute="value"> <b> </script>
|
1
|
+
<script type="text/html"> <a attribute="value" onclick="alert('hello world')"> <b> </script>
|
metadata
CHANGED
@@ -1,69 +1,69 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: htmlcompressor
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Paolo Chiodi
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-12-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: yui-compressor
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - ~>
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '0.9'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- -
|
24
|
+
- - ~>
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0.9'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: closure-compiler
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- -
|
31
|
+
- - ~>
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '1.1'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- -
|
38
|
+
- - ~>
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '1.1'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rake
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- -
|
45
|
+
- - ~>
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: 10.3.2
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- -
|
52
|
+
- - ~>
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: 10.3.2
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: minitest
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- -
|
59
|
+
- - ~>
|
60
60
|
- !ruby/object:Gem::Version
|
61
61
|
version: '5.0'
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- -
|
66
|
+
- - ~>
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '5.0'
|
69
69
|
description: Put your html on a diet
|
@@ -73,8 +73,8 @@ executables: []
|
|
73
73
|
extensions: []
|
74
74
|
extra_rdoc_files: []
|
75
75
|
files:
|
76
|
-
-
|
77
|
-
-
|
76
|
+
- .gitignore
|
77
|
+
- .travis.yml
|
78
78
|
- CHANGELOG
|
79
79
|
- Gemfile
|
80
80
|
- LICENSE
|
@@ -222,17 +222,17 @@ require_paths:
|
|
222
222
|
- lib
|
223
223
|
required_ruby_version: !ruby/object:Gem::Requirement
|
224
224
|
requirements:
|
225
|
-
- -
|
225
|
+
- - '>='
|
226
226
|
- !ruby/object:Gem::Version
|
227
227
|
version: '0'
|
228
228
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
229
229
|
requirements:
|
230
|
-
- -
|
230
|
+
- - '>='
|
231
231
|
- !ruby/object:Gem::Version
|
232
232
|
version: '0'
|
233
233
|
requirements: []
|
234
234
|
rubyforge_project:
|
235
|
-
rubygems_version: 2.
|
235
|
+
rubygems_version: 2.0.14.1
|
236
236
|
signing_key:
|
237
237
|
specification_version: 4
|
238
238
|
summary: htmlcompressor provides a class and a rack middleware to minify html pages
|