htmlcompressor 0.3.0 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG +2 -0
- data/README.md +3 -1
- data/htmlcompressor.gemspec +1 -1
- data/lib/htmlcompressor/compressor.rb +13 -11
- data/lib/htmlcompressor/version.rb +1 -1
- data/test/compressor_test.rb +10 -0
- data/test/resources/html/testRemoveSpacesInsideTagsDisabledResult.html +1 -0
- metadata +8 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cbc26072f28ee34bd76e290982940cdddc081c07
|
4
|
+
data.tar.gz: 1e4ef5b70c7eae75e67e652b83af1dda4c83c542
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0ae38c29532314a023ecbf47b68548ff3f617ee5da1b7cf0b72a70bbe924044114c615496d66e6c964a1a466d1a3cfe282efe65d9ca77f8178c59fce40b99fa1
|
7
|
+
data.tar.gz: 6b0ee8a3d25ce67ff3de7cfd2a2eba591b7f00f788d6e16372770ec221da08f6e8519cafe0da1f67ff25d09a900adfb6b1c2f37999ea7ad7e322458bd2f7d87e
|
data/CHANGELOG
CHANGED
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,
|
data/htmlcompressor.gemspec
CHANGED
@@ -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
|
-
|
761
|
+
if @options[:remove_spaces_inside_tags]
|
762
|
+
html = html.gsub(TAG_PROPERTY_PATTERN, '\1=')
|
761
763
|
|
762
|
-
|
764
|
+
#remove ending spaces inside tags
|
763
765
|
|
764
|
-
|
766
|
+
html.gsub!(TAG_END_SPACE_PATTERN) do |match|
|
765
767
|
|
766
|
-
|
767
|
-
|
768
|
+
group_1 = $1
|
769
|
+
group_2 = $2
|
768
770
|
|
769
|
-
|
770
|
-
|
771
|
-
|
772
|
-
|
773
|
-
|
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
|
|
data/test/compressor_test.rb
CHANGED
@@ -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.
|
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:
|
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:
|
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:
|
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
|