html_press 0.8.0 → 0.8.1

Sign up to get free protection for your applications and to get access to all the features.
data/Readme.md CHANGED
@@ -1,8 +1,6 @@
1
- #html_press
1
+ # HtmlPress [![Build Status](https://secure.travis-ci.org/stereobooster/html_press.png?branch=master)](https://secure.travis-ci.org/#!/stereobooster/html_press) [![Dependency Status](https://gemnasium.com/stereobooster/html_press.png?travis)](https://gemnasium.com/stereobooster/html_press) [![Code Climate](https://codeclimate.com/badge.png)](https://codeclimate.com/github/stereobooster/html_press)
2
2
 
3
- [![Build Status](https://secure.travis-ci.org/stereobooster/html_press.png?branch=master)](http://travis-ci.org/stereobooster/html_press)
4
-
5
- ## how it works
3
+ ## How it works
6
4
 
7
5
  Remove all whitespace junk. Leave only HTML
8
6
 
@@ -1,26 +1,26 @@
1
- # -*- encoding: utf-8 -*-
2
- $:.push File.expand_path("../lib", __FILE__)
3
- require "html_press/version"
4
-
5
- Gem::Specification.new do |s|
6
- s.name = "html_press"
7
- s.version = HtmlPress::VERSION
8
- s.authors = ["stereobooster"]
9
- s.email = ["stereobooster@gmail.com"]
10
- s.homepage = "https://github.com/stereobooster/html_press"
11
- s.summary = %q{Compress html}
12
- s.description = %q{Ruby gem for compressing html}
13
- s.license = "MIT"
14
-
15
- s.files = `git ls-files`.split("\n")
16
- s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
17
- s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
18
- s.require_paths = ["lib"]
19
-
20
- s.add_development_dependency "rspec"
21
- s.add_development_dependency "rake"
22
-
23
- s.add_dependency "multi_css", ">= 0.1.0"
24
- s.add_dependency "uglifier"
25
- s.add_dependency "htmlentities"
26
- end
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "html_press/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "html_press"
7
+ s.version = HtmlPress::VERSION
8
+ s.authors = ["stereobooster"]
9
+ s.email = ["stereobooster@gmail.com"]
10
+ s.homepage = "https://github.com/stereobooster/html_press"
11
+ s.summary = %q{Compress html}
12
+ s.description = %q{Ruby gem for compressing html}
13
+ s.license = "MIT"
14
+
15
+ s.files = `git ls-files`.split("\n")
16
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
17
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
18
+ s.require_paths = ["lib"]
19
+
20
+ s.add_development_dependency "rspec"
21
+ s.add_development_dependency "rake"
22
+
23
+ s.add_dependency "multi_css", ">= 0.1.0"
24
+ s.add_dependency "multi_js"
25
+ s.add_dependency "htmlentities"
26
+ end
@@ -1,18 +1,23 @@
1
- require "html_press/version"
2
- require "html_press/uglifier"
3
- require "html_press/html_entities"
4
- require "html_press/html"
5
-
6
- require 'multi_css'
7
-
8
- module HtmlPress
9
- def self.press(text, options = {})
10
- HtmlPress::Html.new(options).press text
11
- end
12
-
13
- # for backward compatibility
14
- def self.compress(text, options = {})
15
- HtmlPress::Html.new(options).press text
16
- end
17
-
18
- end
1
+ require "html_press/version"
2
+ require "html_press/html_entities"
3
+ require "html_press/html"
4
+
5
+ require 'multi_css'
6
+ require 'multi_js'
7
+
8
+ module HtmlPress
9
+ def self.press(text, options = {})
10
+ HtmlPress::Html.new(options).press text
11
+ end
12
+
13
+ # for backward compatibility
14
+ def self.compress(text, options = {})
15
+ HtmlPress::Html.new(options).press text
16
+ end
17
+
18
+ def self.js_compressor (text, options = nil)
19
+ options ||= {}
20
+ options[:inline_script] = true
21
+ MultiJs.compile(text, options).gsub(/;$/,'')
22
+ end
23
+ end
@@ -74,7 +74,7 @@ module HtmlPress
74
74
  begin
75
75
  js_compressed = HtmlPress.js_compressor js, @options[:js_minifier_options]
76
76
  m.gsub!(js, js_compressed)
77
- rescue Exception => e
77
+ rescue MultiJs::ParseError => e
78
78
  log e.message
79
79
  end
80
80
  reserve m
@@ -214,7 +214,7 @@ module HtmlPress
214
214
 
215
215
  def attr(attribute, delimiter, tag)
216
216
  re = "([a-z\\-_:]+)(=" + delimiter + "[^" + delimiter + "]*" + delimiter + ")?"
217
- re = Regexp.new re
217
+ re = Regexp.new re, true
218
218
  value_original = attribute.gsub(re, "\\2")
219
219
  value = value_original.downcase
220
220
  name_original = attribute.gsub(re, "\\1")
@@ -298,7 +298,7 @@ module HtmlPress
298
298
  if delimiter == "\""
299
299
  value_original.gsub! "\"", "'"
300
300
  end
301
- rescue Exception => e
301
+ rescue MultiJs::ParseError => e
302
302
  log e.message
303
303
  end
304
304
  end
@@ -1,3 +1,3 @@
1
1
  module HtmlPress
2
- VERSION = "0.8.0"
2
+ VERSION = "0.8.1"
3
3
  end
@@ -81,13 +81,20 @@ describe HtmlPress do
81
81
  HtmlPress.press(text).should eql text2
82
82
  end
83
83
 
84
- # TODO concatenate adjacent script tags
85
84
  it "should remove whitespaces between script tags" do
86
85
  text = "<p></p> <script>var a</script> \t <script>var b</script>"
87
86
  text2 = "<p></p> <script>var a</script><script>var b</script>"
88
87
  HtmlPress.press(text).should eql text2
89
88
  end
90
89
 
90
+ it "should concatenate adjacent script tags" do
91
+ pending "Not implemented yet" do
92
+ text = "<p></p> <script>var a</script> \t <script>function b(){}</script>"
93
+ text2 = "<p></p> <script>var a;function b(){}</script>"
94
+ HtmlPress.press(text).should eql text2
95
+ end
96
+ end
97
+
91
98
  it "should treat text inside IE conditional comments as it was without comments" do
92
99
  text = "<div class=\"a\" id=\"b\"> </div> <p></p>"
93
100
  text2 = HtmlPress.press(text)
@@ -114,6 +121,11 @@ describe HtmlPress do
114
121
  # HtmlPress.press("<p class = a></p>").should eql "<p class=a></p>"
115
122
  end
116
123
 
124
+ it "should work with different case attributes" do
125
+ text = '<embed allowFullScreen="true" allowScriptAccess="always"/>'
126
+ HtmlPress.press(text).should eql text
127
+ end
128
+
117
129
  it "should optimize attributes" do
118
130
  HtmlPress.press("<p class=\"a b\"></p>").should eql "<p class=\"a b\"></p>"
119
131
  # TODO http(s):// to //
@@ -132,12 +144,13 @@ describe HtmlPress do
132
144
  HtmlPress.press(text).should eql text
133
145
  end
134
146
 
135
- # TODO
136
- # it "should compress namespaces" do
137
- # text = "<html xmlns:og=\"http://ogp.me/ns#\" class=\"a b\"><og:like>like</og:like></html>"
138
- # text1 = "<html xmlns:a=\"http://ogp.me/ns#\" class=\"a b\"><a:like>like</a:like></html>"
139
- # HtmlPress.press(text).should eql text1
140
- # end
147
+ it "should compress namespaces" do
148
+ pending "Not implemented yet" do
149
+ text = "<html xmlns:og=\"http://ogp.me/ns#\" class=\"a b\"><og:like>like</og:like></html>"
150
+ text1 = "<html xmlns:a=\"http://ogp.me/ns#\" class=\"a b\"><a:like>like</a:like></html>"
151
+ HtmlPress.press(text).should eql text1
152
+ end
153
+ end
141
154
 
142
155
  it "should not modify input value" do
143
156
  text = "<div> </div>"
@@ -175,15 +188,17 @@ describe HtmlPress do
175
188
  HtmlPress.press("<input disabled=\"disabled\"/>").should eql "<input disabled/>"
176
189
  # readonly (input type=text/password, textarea)
177
190
  HtmlPress.press("<input readonly=\"readonly\"/>").should eql "<input readonly/>"
178
- # HtmlPress.press("<script src=\"example.com\" async=\"async\"></script>").should eql "<script src=\"example.com\" async></script>"
179
- # HtmlPress.press("<script src=\"example.com\" defer=\"defer\"></script>").should eql "<script src=\"example.com\" async></script>"
180
- # HtmlPress.press("<select multiple=\"multiple\"/>").should eql "<select multiple/>"
181
- # ismap isMap (img, input type=image)
182
- # declare (object; never used)
183
- # noresize noResize (frame)
184
- # nowrap noWrap (td, th; deprecated)
185
- # noshade noShade (hr; deprecated)
186
- # compact (ul, ol, dl, menu, dir; deprecated)
191
+ pending "Not implemented yet" do
192
+ HtmlPress.press("<script src=\"example.com\" async=\"async\"></script>").should eql "<script src=\"example.com\" async></script>"
193
+ HtmlPress.press("<script src=\"example.com\" defer=\"defer\"></script>").should eql "<script src=\"example.com\" defer></script>"
194
+ HtmlPress.press("<select multiple=\"multiple\"/>").should eql "<select multiple/>"
195
+ # ismap isMap (img, input type=image)
196
+ # declare (object; never used)
197
+ # noresize noResize (frame)
198
+ # nowrap noWrap (td, th; deprecated)
199
+ # noshade noShade (hr; deprecated)
200
+ # compact (ul, ol, dl, menu, dir; deprecated)
201
+ end
187
202
  end
188
203
 
189
204
  it "should remove attributes with default values" do
@@ -235,9 +250,8 @@ describe HtmlPress do
235
250
  end
236
251
  end
237
252
 
238
- # TODO
239
- # it "should concatenate adjecent style tags" do
240
- # all stylle tags can be collected, concatneated and placed in header
241
- # end
242
-
253
+ it "should concatenate adjecent style tags" do
254
+ pending "Not implemented yet"
255
+ # all stylle tags can be collected, concatneated and placed in header
256
+ end
243
257
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: html_press
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.0
4
+ version: 0.8.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-11-28 00:00:00.000000000 Z
12
+ date: 2013-01-05 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
@@ -60,7 +60,7 @@ dependencies:
60
60
  - !ruby/object:Gem::Version
61
61
  version: 0.1.0
62
62
  - !ruby/object:Gem::Dependency
63
- name: uglifier
63
+ name: multi_js
64
64
  requirement: !ruby/object:Gem::Requirement
65
65
  none: false
66
66
  requirements:
@@ -108,7 +108,6 @@ files:
108
108
  - lib/html_press.rb
109
109
  - lib/html_press/html.rb
110
110
  - lib/html_press/html_entities.rb
111
- - lib/html_press/uglifier.rb
112
111
  - lib/html_press/version.rb
113
112
  - profile/index.html
114
113
  - profile/profile.rb
@@ -126,15 +125,21 @@ required_ruby_version: !ruby/object:Gem::Requirement
126
125
  - - ! '>='
127
126
  - !ruby/object:Gem::Version
128
127
  version: '0'
128
+ segments:
129
+ - 0
130
+ hash: 868935485
129
131
  required_rubygems_version: !ruby/object:Gem::Requirement
130
132
  none: false
131
133
  requirements:
132
134
  - - ! '>='
133
135
  - !ruby/object:Gem::Version
134
136
  version: '0'
137
+ segments:
138
+ - 0
139
+ hash: 868935485
135
140
  requirements: []
136
141
  rubyforge_project:
137
- rubygems_version: 1.8.23
142
+ rubygems_version: 1.8.24
138
143
  signing_key:
139
144
  specification_version: 3
140
145
  summary: Compress html
@@ -1,15 +0,0 @@
1
- module HtmlPress
2
- begin
3
- require 'uglifier'
4
- # Available options https://github.com/lautis/uglifier#options
5
- def self.js_compressor (text, options = nil)
6
- options ||= {}
7
- options[:inline_script] = true
8
- Uglifier.new(options).compile(text).gsub(/;$/,'')
9
- end
10
- rescue LoadError => e
11
- def self.js_compressor (text, options = nil)
12
- text
13
- end
14
- end
15
- end