htmlcompressor 0.3.0 → 0.3.1

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: 6a42bf9b016097f11b30a077ea1a4dcd1aa27910
4
- data.tar.gz: d3a5fa18ac4b6f14b8404affdb9c4ffce4ab7fde
3
+ metadata.gz: cbc26072f28ee34bd76e290982940cdddc081c07
4
+ data.tar.gz: 1e4ef5b70c7eae75e67e652b83af1dda4c83c542
5
5
  SHA512:
6
- metadata.gz: 273c064fef6bff5af96aedc4d25697d3780973c4bf2b198f0584a8e3755614b07e68e05c6895265447c6f41bc6da6be2b24dfeeb71cba9115f7e373e8210e856
7
- data.tar.gz: a5f2dad4e8bdb618f18eac053c68ad1d395f6db10d77807a0c81401e31ea9eabf11608888d8d6d4f11990c8efb68d850a8b402961185fa69389fe7b35a089106
6
+ metadata.gz: 0ae38c29532314a023ecbf47b68548ff3f617ee5da1b7cf0b72a70bbe924044114c615496d66e6c964a1a466d1a3cfe282efe65d9ca77f8178c59fce40b99fa1
7
+ data.tar.gz: 6b0ee8a3d25ce67ff3de7cfd2a2eba591b7f00f788d6e16372770ec221da08f6e8519cafe0da1f67ff25d09a900adfb6b1c2f37999ea7ad7e322458bd2f7d87e
data/CHANGELOG CHANGED
@@ -1,3 +1,5 @@
1
+ 0.3.1 - 23/09/2016
2
+ Add option flag to disable "remove spaces inside tags"
1
3
  0.3.0 - 09/09/2015
2
4
  Fix CDATA errors
3
5
  0.2.0 - 32/03/2015
data/README.md CHANGED
@@ -6,7 +6,8 @@
6
6
  Htmlcompressor provides tools to minify html code.
7
7
  It includes
8
8
  - HtmlCompressor::Compressor class which is a raw port of [google's htmlcompressor](http://code.google.com/p/htmlcompressor/)
9
- - HtmlCompressor::Rack a rack middleware to compress html pages on the fly
9
+ - HtmlCompressor::Rack a rack middleware to compress html pages on the fly.
10
+ Beware that the compressor has proved to be too slow in many circunstances to be used for on the fly or real time execution. I encourage you to use it only for build-time optimisations or decrease the number of optimisations that are run at execution time.
10
11
 
11
12
  Please note that Htmlcompressor is still in alpha version and need some additional love.
12
13
 
@@ -24,6 +25,7 @@ The compressor ships with basic and safe default options that may be overwritten
24
25
  ```ruby
25
26
  options = {
26
27
  :enabled => true,
28
+ :remove_spaces_inside_tags => true,
27
29
  :remove_multi_spaces => true,
28
30
  :remove_comments => true,
29
31
  :remove_intertag_spaces => false,
@@ -10,7 +10,7 @@ Gem::Specification.new do |gem|
10
10
 
11
11
  gem.add_development_dependency 'yui-compressor', '~> 0.9'
12
12
  gem.add_development_dependency 'closure-compiler', '~> 1.1'
13
- gem.add_development_dependency 'rake'
13
+ gem.add_development_dependency 'rake', '~> 10.3.2'
14
14
  gem.add_development_dependency 'minitest', '~> 5.0'
15
15
 
16
16
  gem.files = `git ls-files`.split($\)
@@ -107,6 +107,7 @@ module HtmlCompressor
107
107
  # default settings
108
108
  :remove_comments => true,
109
109
  :remove_multi_spaces => true,
110
+ :remove_spaces_inside_tags => true,
110
111
 
111
112
  # optional settings
112
113
  :javascript_compressor => :yui,
@@ -757,24 +758,25 @@ module HtmlCompressor
757
758
  def remove_spaces_inside_tags(html)
758
759
  #remove spaces around equals sign inside tags
759
760
 
760
- html = html.gsub(TAG_PROPERTY_PATTERN, '\1=')
761
+ if @options[:remove_spaces_inside_tags]
762
+ html = html.gsub(TAG_PROPERTY_PATTERN, '\1=')
761
763
 
762
- #remove ending spaces inside tags
764
+ #remove ending spaces inside tags
763
765
 
764
- html.gsub!(TAG_END_SPACE_PATTERN) do |match|
766
+ html.gsub!(TAG_END_SPACE_PATTERN) do |match|
765
767
 
766
- group_1 = $1
767
- group_2 = $2
768
+ group_1 = $1
769
+ group_2 = $2
768
770
 
769
- # keep space if attribute value is unquoted before trailing slash
770
- if group_2.start_with?("/") and (TAG_LAST_UNQUOTED_VALUE_PATTERN =~ group_1)
771
- "#{group_1} #{group_2}"
772
- else
773
- "#{group_1}#{group_2}"
771
+ # keep space if attribute value is unquoted before trailing slash
772
+ if group_2.start_with?("/") and (TAG_LAST_UNQUOTED_VALUE_PATTERN =~ group_1)
773
+ "#{group_1} #{group_2}"
774
+ else
775
+ "#{group_1}#{group_2}"
776
+ end
774
777
  end
775
778
  end
776
779
 
777
-
778
780
  html
779
781
  end
780
782
 
@@ -1,3 +1,3 @@
1
1
  module HtmlCompressor
2
- VERSION = "0.3.0"
2
+ VERSION = "0.3.1"
3
3
  end
@@ -22,6 +22,16 @@ module HtmlCompressor
22
22
  assert_equal result, compressor.compress(source)
23
23
  end
24
24
 
25
+ def test_remove_spaces_inside_tags_disabled
26
+ source = read_resource("testRemoveSpacesInsideTags.html")
27
+ result = read_resource("testRemoveSpacesInsideTagsDisabledResult.html")
28
+
29
+ compressor = Compressor.new(:remove_multi_spaces => false, :remove_spaces_inside_tags => false)
30
+
31
+ assert_equal result, compressor.compress(source)
32
+ end
33
+
34
+
25
35
  def test_remove_comments
26
36
  source = read_resource("testRemoveComments.html")
27
37
  result = read_resource("testRemoveCommentsResult.html")
@@ -0,0 +1 @@
1
+ <a href="a"/> qwe = eee <a href ="x" /> <a href= "x"/> <a href = "x" > <input value="test" /> <input value=test /> <input value=test > <br />
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: htmlcompressor
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Paolo Chiodi
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-09-09 00:00:00.000000000 Z
11
+ date: 2016-09-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: yui-compressor
@@ -42,16 +42,16 @@ dependencies:
42
42
  name: rake
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ">="
45
+ - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '0'
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
- version: '0'
54
+ version: 10.3.2
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: minitest
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -184,6 +184,7 @@ files:
184
184
  - test/resources/html/testRemoveScriptAttributes.html
185
185
  - test/resources/html/testRemoveScriptAttributesResult.html
186
186
  - test/resources/html/testRemoveSpacesInsideTags.html
187
+ - test/resources/html/testRemoveSpacesInsideTagsDisabledResult.html
187
188
  - test/resources/html/testRemoveSpacesInsideTagsResult.html
188
189
  - test/resources/html/testRemoveStyleAttributes.html
189
190
  - test/resources/html/testRemoveStyleAttributesResult.html
@@ -334,6 +335,7 @@ test_files:
334
335
  - test/resources/html/testRemoveScriptAttributes.html
335
336
  - test/resources/html/testRemoveScriptAttributesResult.html
336
337
  - test/resources/html/testRemoveSpacesInsideTags.html
338
+ - test/resources/html/testRemoveSpacesInsideTagsDisabledResult.html
337
339
  - test/resources/html/testRemoveSpacesInsideTagsResult.html
338
340
  - test/resources/html/testRemoveStyleAttributes.html
339
341
  - test/resources/html/testRemoveStyleAttributesResult.html