optipng 0.1.0 → 0.2.0
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.
- data/Gemfile +1 -1
- data/Gemfile.lock +2 -2
- data/README.md +4 -0
- data/VERSION +1 -1
- data/lib/optipng.rb +23 -7
- data/optipng.gemspec +60 -0
- data/test +9 -2
- metadata +5 -4
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -9,7 +9,7 @@ GEM
|
|
9
9
|
bundler (~> 1.0.0)
|
10
10
|
git (>= 1.2.5)
|
11
11
|
rake
|
12
|
-
pipe-run (0.
|
12
|
+
pipe-run (0.2.0)
|
13
13
|
rake (0.8.7)
|
14
14
|
unix-whereis (0.1.0)
|
15
15
|
command-builder (>= 0.1.0)
|
@@ -23,5 +23,5 @@ DEPENDENCIES
|
|
23
23
|
bundler (~> 1.0.0)
|
24
24
|
command-builder (>= 0.1.0)
|
25
25
|
jeweler (~> 1.5.2)
|
26
|
-
pipe-run (>= 0.
|
26
|
+
pipe-run (>= 0.2.0)
|
27
27
|
unix-whereis (>= 0.1.0)
|
data/README.md
CHANGED
@@ -14,6 +14,9 @@ Some examples follow: (for details, see module documentation)
|
|
14
14
|
# and then will return for example:
|
15
15
|
# '#<struct Optipng::Result succeed={"foo.png => -22.1}}, errors=[["empty.png", "Unrecognized image file format"], ["nonexist.png", "Can't open the input file"]]>
|
16
16
|
|
17
|
+
It can be also run asynchronously by non-blocking way (with [`eventmachine`][4])
|
18
|
+
simply by giving block with one argument to `#optimize`. See documentation.
|
19
|
+
|
17
20
|
### Call Result
|
18
21
|
|
19
22
|
Result contains members `:success` and `:errors`. Sucess member contains
|
@@ -45,3 +48,4 @@ further details.
|
|
45
48
|
[1]: http://optipng.sourceforge.net/
|
46
49
|
[2]: http://github.com/martinkozak/qrpc/issues
|
47
50
|
[3]: http://www.martinkozak.net/
|
51
|
+
[4]: http://rubyeventmachine.com/
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.2.0
|
data/lib/optipng.rb
CHANGED
@@ -47,14 +47,18 @@ module Optipng
|
|
47
47
|
##
|
48
48
|
# Performs optimizations above file or set of files.
|
49
49
|
#
|
50
|
+
# If block is given, runs +optipng+ asynchronously. In that case,
|
51
|
+
# +em-pipe-run+ file must be already required.
|
52
|
+
#
|
50
53
|
# @param [String, Array] paths file path or array of paths for optimizing
|
51
54
|
# @param [Hash] options options
|
55
|
+
# @param [Proc] block block for giving back the results
|
52
56
|
# @option options [Integer] :level optimization level (0-7)
|
53
57
|
# @option options [Boolean] :debug turn on debugging mode, so command will be put out to the +STDERR+
|
54
58
|
# @return [Struct] see {Result}
|
55
59
|
#
|
56
60
|
|
57
|
-
def self.optimize(paths, options = { })
|
61
|
+
def self.optimize(paths, options = { }, &block)
|
58
62
|
|
59
63
|
# Command
|
60
64
|
cmd = CommandBuilder::new(self::COMMAND)
|
@@ -75,12 +79,24 @@ module Optipng
|
|
75
79
|
if options[:debug] == true
|
76
80
|
STDERR.write cmd.to_s + "\n"
|
77
81
|
end
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
82
|
+
|
83
|
+
cmd = cmd.to_s
|
84
|
+
|
85
|
+
# Blocking
|
86
|
+
if block.nil?
|
87
|
+
output = Pipe.run(cmd)
|
88
|
+
|
89
|
+
# Parses output
|
90
|
+
succeed, errors = __parse_output(output)
|
91
|
+
return self::Result::new(succeed, errors)
|
92
|
+
|
93
|
+
# Non-blocking
|
94
|
+
else
|
95
|
+
Pipe.run(cmd) do |output|
|
96
|
+
succeed, errors = __parse_output(output)
|
97
|
+
block.call(self::Result::new(succeed, errors))
|
98
|
+
end
|
99
|
+
end
|
84
100
|
|
85
101
|
end
|
86
102
|
|
data/optipng.gemspec
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{optipng}
|
8
|
+
s.version = "0.2.0"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Martin Kozák"]
|
12
|
+
s.date = %q{2011-02-22}
|
13
|
+
s.email = %q{martinkozak@martinkozak.net}
|
14
|
+
s.extra_rdoc_files = [
|
15
|
+
"LICENSE.txt",
|
16
|
+
"README.md"
|
17
|
+
]
|
18
|
+
s.files = [
|
19
|
+
".document",
|
20
|
+
"Gemfile",
|
21
|
+
"Gemfile.lock",
|
22
|
+
"LICENSE.txt",
|
23
|
+
"README.md",
|
24
|
+
"Rakefile",
|
25
|
+
"VERSION",
|
26
|
+
"lib/optipng.rb",
|
27
|
+
"optipng.gemspec",
|
28
|
+
"test"
|
29
|
+
]
|
30
|
+
s.homepage = %q{https://github.com/martinkozak/optipng}
|
31
|
+
s.licenses = ["MIT"]
|
32
|
+
s.require_paths = ["lib"]
|
33
|
+
s.rubygems_version = %q{1.5.2}
|
34
|
+
s.summary = %q{Ruby interface to 'optipng' tool.}
|
35
|
+
|
36
|
+
if s.respond_to? :specification_version then
|
37
|
+
s.specification_version = 3
|
38
|
+
|
39
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
40
|
+
s.add_runtime_dependency(%q<pipe-run>, [">= 0.2.0"])
|
41
|
+
s.add_runtime_dependency(%q<command-builder>, [">= 0.1.0"])
|
42
|
+
s.add_runtime_dependency(%q<unix-whereis>, [">= 0.1.0"])
|
43
|
+
s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
|
44
|
+
s.add_development_dependency(%q<jeweler>, ["~> 1.5.2"])
|
45
|
+
else
|
46
|
+
s.add_dependency(%q<pipe-run>, [">= 0.2.0"])
|
47
|
+
s.add_dependency(%q<command-builder>, [">= 0.1.0"])
|
48
|
+
s.add_dependency(%q<unix-whereis>, [">= 0.1.0"])
|
49
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
50
|
+
s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
|
51
|
+
end
|
52
|
+
else
|
53
|
+
s.add_dependency(%q<pipe-run>, [">= 0.2.0"])
|
54
|
+
s.add_dependency(%q<command-builder>, [">= 0.1.0"])
|
55
|
+
s.add_dependency(%q<unix-whereis>, [">= 0.1.0"])
|
56
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
57
|
+
s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
data/test
CHANGED
@@ -3,6 +3,13 @@
|
|
3
3
|
|
4
4
|
$:.push("./lib")
|
5
5
|
require "optipng"
|
6
|
+
require "em-pipe-run"
|
6
7
|
|
7
|
-
|
8
|
-
puts Optipng.
|
8
|
+
EM::run do
|
9
|
+
puts Optipng.available?.inspect
|
10
|
+
Optipng.optimize(["1.png", "4.png", "mp.png"], :level => 7, :debug => true) do |result|
|
11
|
+
puts result.inspect
|
12
|
+
end
|
13
|
+
|
14
|
+
puts "xxx"
|
15
|
+
end
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: optipng
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.
|
5
|
+
version: 0.2.0
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- "Martin Koz\xC3\xA1k"
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-02-
|
13
|
+
date: 2011-02-22 00:00:00 +01:00
|
14
14
|
default_executable:
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
@@ -20,7 +20,7 @@ dependencies:
|
|
20
20
|
requirements:
|
21
21
|
- - ">="
|
22
22
|
- !ruby/object:Gem::Version
|
23
|
-
version: 0.
|
23
|
+
version: 0.2.0
|
24
24
|
type: :runtime
|
25
25
|
prerelease: false
|
26
26
|
version_requirements: *id001
|
@@ -86,6 +86,7 @@ files:
|
|
86
86
|
- Rakefile
|
87
87
|
- VERSION
|
88
88
|
- lib/optipng.rb
|
89
|
+
- optipng.gemspec
|
89
90
|
- test
|
90
91
|
has_rdoc: true
|
91
92
|
homepage: https://github.com/martinkozak/optipng
|
@@ -101,7 +102,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
101
102
|
requirements:
|
102
103
|
- - ">="
|
103
104
|
- !ruby/object:Gem::Version
|
104
|
-
hash: -
|
105
|
+
hash: -1525761151381107860
|
105
106
|
segments:
|
106
107
|
- 0
|
107
108
|
version: "0"
|