web_optimizer 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
data/README.md
CHANGED
@@ -1,10 +1,12 @@
|
|
1
1
|
# AntigateApi
|
2
2
|
|
3
|
-
|
3
|
+
Some util script to optime your assets (images, js files, css files).
|
4
|
+
Contribute more are welcome, please drop me an email at
|
5
|
+
vo.mita.ov at gmail.com if you need help or want to contribute
|
4
6
|
|
5
7
|
## Installation
|
6
8
|
|
7
|
-
$ gem install
|
9
|
+
$ gem install web_optimizer
|
8
10
|
|
9
11
|
## Requirement
|
10
12
|
|
@@ -19,8 +21,9 @@ Antigate (Decode captcha service - antigate.com) wrapper
|
|
19
21
|
|
20
22
|
Compress CSS
|
21
23
|
```
|
22
|
-
WebOptimizer.compress_css(dir, ignore_paths)
|
23
|
-
WebOptimizer.compress_js(dir, ignore_paths)
|
24
|
+
WebOptimizer.compress_css(dir, ignore_paths=[])
|
25
|
+
WebOptimizer.compress_js(dir, ignore_paths=[])
|
26
|
+
WebOptimizer.compress_img(dir, ignore_paths=[])
|
24
27
|
```
|
25
28
|
|
26
29
|
## Contributing
|
@@ -30,3 +33,4 @@ WebOptimizer.compress_js(dir, ignore_paths)
|
|
30
33
|
3. Commit your changes (`git commit -am 'Add some feature'`)
|
31
34
|
4. Push to the branch (`git push origin my-new-feature`)
|
32
35
|
5. Create new Pull Request
|
36
|
+
|
@@ -9,7 +9,7 @@ module WebOptimizer
|
|
9
9
|
end
|
10
10
|
|
11
11
|
def self.compress_css_recursive(dir_path, ignore_paths, trict=false)
|
12
|
-
|
12
|
+
raise Exception.new("Invalid dir path") unless File.directory? dir
|
13
13
|
|
14
14
|
ignore_paths = ignore_paths.map do |path|
|
15
15
|
tmp_path = Pathname.new(path)
|
@@ -9,7 +9,7 @@ module WebOptimizer
|
|
9
9
|
end
|
10
10
|
|
11
11
|
def self.compress_js_recursive(dir, ignore_paths, trict=false)
|
12
|
-
|
12
|
+
raise Exception.new("Invalid dir path") unless File.directory? dir
|
13
13
|
|
14
14
|
ignore_paths = ignore_paths.map do |path|
|
15
15
|
tmp_path = Pathname.new(path)
|
@@ -4,21 +4,30 @@ require "active_support"
|
|
4
4
|
TMP_EXT_NAME = "-tmp.png"
|
5
5
|
|
6
6
|
module WebOptimizer
|
7
|
-
def self.compress_img(dir)
|
8
|
-
|
7
|
+
def self.compress_img(dir, ignore_paths=[])
|
8
|
+
raise Exception.new("Invalid dir path") unless File.directory? dir
|
9
9
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
10
|
+
ignore_paths = ignore_paths.map do |path|
|
11
|
+
tmp_path = Pathname.new(path)
|
12
|
+
tmp_path.absolute? ? path : File.join(dir, path)
|
13
|
+
end
|
14
|
+
|
15
|
+
unless check_include_dir(ignore_paths, dir)
|
16
|
+
Dir[File.join(dir, "**/*")].each do |image_path|
|
17
|
+
next if check_include_dir(ignore_paths, image_path)
|
18
|
+
|
19
|
+
if File.directory?(image_path)
|
20
|
+
compress_img(image_path)
|
21
|
+
elsif (file_ext = File.extname(image_path)) == ".png"
|
22
|
+
file_name = File.basename(image_path)
|
23
|
+
`/usr/local/bin/pngquant #{image_path} --ext #{TMP_EXT_NAME}`
|
24
|
+
new_file_path = image_path.gsub(file_ext, "-tmp.png")
|
25
|
+
`mv #{new_file_path} #{image_path}`
|
26
|
+
puts "[pngquant] #{image_path}"
|
27
|
+
elsif ['png'].any? { |ext| file_ext == ".#{ext}" }
|
28
|
+
puts "[image_optim] #{image_path}"
|
29
|
+
`/Users/tamvo/.rvm/gems/ruby-1.9.3-p194@general/bin/image_optim #{image_path}`
|
30
|
+
end
|
22
31
|
end
|
23
32
|
end
|
24
33
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: web_optimizer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,14 +9,14 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-01-
|
12
|
+
date: 2014-01-30 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: active_support
|
16
16
|
requirement: !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
|
-
- -
|
19
|
+
- - '>='
|
20
20
|
- !ruby/object:Gem::Version
|
21
21
|
version: '0'
|
22
22
|
type: :runtime
|
@@ -24,7 +24,7 @@ dependencies:
|
|
24
24
|
version_requirements: !ruby/object:Gem::Requirement
|
25
25
|
none: false
|
26
26
|
requirements:
|
27
|
-
- -
|
27
|
+
- - '>='
|
28
28
|
- !ruby/object:Gem::Version
|
29
29
|
version: '0'
|
30
30
|
- !ruby/object:Gem::Dependency
|
@@ -32,7 +32,7 @@ dependencies:
|
|
32
32
|
requirement: !ruby/object:Gem::Requirement
|
33
33
|
none: false
|
34
34
|
requirements:
|
35
|
-
- -
|
35
|
+
- - '>='
|
36
36
|
- !ruby/object:Gem::Version
|
37
37
|
version: '0'
|
38
38
|
type: :runtime
|
@@ -40,7 +40,7 @@ dependencies:
|
|
40
40
|
version_requirements: !ruby/object:Gem::Requirement
|
41
41
|
none: false
|
42
42
|
requirements:
|
43
|
-
- -
|
43
|
+
- - '>='
|
44
44
|
- !ruby/object:Gem::Version
|
45
45
|
version: '0'
|
46
46
|
description: Compress all css file in specified dir with yuicompressor
|
@@ -78,13 +78,13 @@ require_paths:
|
|
78
78
|
required_ruby_version: !ruby/object:Gem::Requirement
|
79
79
|
none: false
|
80
80
|
requirements:
|
81
|
-
- -
|
81
|
+
- - '>='
|
82
82
|
- !ruby/object:Gem::Version
|
83
83
|
version: '0'
|
84
84
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
85
85
|
none: false
|
86
86
|
requirements:
|
87
|
-
- -
|
87
|
+
- - '>='
|
88
88
|
- !ruby/object:Gem::Version
|
89
89
|
version: '0'
|
90
90
|
requirements: []
|