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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: cbc26072f28ee34bd76e290982940cdddc081c07
4
- data.tar.gz: 1e4ef5b70c7eae75e67e652b83af1dda4c83c542
3
+ metadata.gz: 4054e9ae1eb0fbce4c30c4152d58ec6674b90b9a
4
+ data.tar.gz: ebd3e0082f208d1d00a68d398057f7effbfced44
5
5
  SHA512:
6
- metadata.gz: 0ae38c29532314a023ecbf47b68548ff3f617ee5da1b7cf0b72a70bbe924044114c615496d66e6c964a1a466d1a3cfe282efe65d9ca77f8178c59fce40b99fa1
7
- data.tar.gz: 6b0ee8a3d25ce67ff3de7cfd2a2eba591b7f00f788d6e16372770ec221da08f6e8519cafe0da1f67ff25d09a900adfb6b1c2f37999ea7ad7e322458bd2f7d87e
6
+ metadata.gz: f1a43d6dc862b49ad5c797b3bf504a3f635a9e1adba8cacb9164e04add9f15f65a3ef98357c45c16a80ea87527fab7883f8fcfdda25ba9ae95dde32fb0f683bf
7
+ data.tar.gz: 81604765e64c4fce8f5da1001214a88320ac8f487324088e2ff77105a547ee62340644b07bf26d5a4dd2fa6636d43c42763576725e06ab791eb7783a91043820
@@ -1,8 +1,11 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 2.2.1
4
- - 2.1.1
5
- - 2.0.0
3
+ - 2.5
4
+ - 2.4
5
+ - 2.3
6
+ - 2.2
7
+ - 2.1
8
+ - 2.0
6
9
  - 1.9.3
7
10
  - jruby-18mode # JRuby in 1.8 mode
8
11
  - jruby-19mode # JRuby in 1.9 mode
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
- raise MissingCompressorError, "No JavaScript Compressor. Please set the :javascript_compressor option"
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
- raise MissingCompressorError, "No CSS Compressor. Please set the :css_compressor option"
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
@@ -1,3 +1,4 @@
1
1
  module HtmlCompressor
2
2
  class MissingCompressorError < StandardError; end
3
+ class NotFoundCompressorError < StandardError; end
3
4
  end
@@ -1,3 +1,3 @@
1
1
  module HtmlCompressor
2
- VERSION = "0.3.1"
2
+ VERSION = "0.4.0"
3
3
  end
@@ -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.3.1
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: 2016-09-23 00:00:00.000000000 Z
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
- - ".gitignore"
77
- - ".travis.yml"
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.4.5
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