jpegoptim 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 +7 -2
- data/VERSION +1 -1
- data/lib/jpegoptim.rb +24 -9
- data/test +9 -2
- metadata +4 -5
- data/jpegoptim.gemspec +0 -60
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
@@ -1,7 +1,7 @@
|
|
1
1
|
Jpegoptim
|
2
2
|
=========
|
3
3
|
|
4
|
-
**Jpegoptim** provides Ruby interface to the `jpegoptim` tool.
|
4
|
+
**Jpegoptim** provides Ruby interface to the [`jpegoptim`][1] tool.
|
5
5
|
Some examples follow: (for details, see module documentation)
|
6
6
|
|
7
7
|
require "jpegoptim"
|
@@ -10,10 +10,13 @@ Some examples follow: (for details, see module documentation)
|
|
10
10
|
|
11
11
|
Jpegoptim.optimize(["foo.jpg", "empty.jpg", "nonexist.jpg"], { :preserve => true, :strip => :all })
|
12
12
|
|
13
|
-
# will run 'jpegoptim --strip-all --preserve foo.jpg bar.
|
13
|
+
# will run 'jpegoptim --strip-all --preserve foo.jpg bar.jpg empty.jpg'
|
14
14
|
# and then will return for example:
|
15
15
|
# '#<struct Jpegoptim::Result succeed={"foo.jpg => -22.1}}, errors=[["empty.jpg", "ERROR"]]>
|
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
|
@@ -57,5 +60,7 @@ Copyright
|
|
57
60
|
Copyright © 2011 [Martin Kozák][3]. See `LICENSE.txt` for
|
58
61
|
further details.
|
59
62
|
|
63
|
+
[1]: http://www.kokkonen.net/tjko/projects.html
|
60
64
|
[2]: http://github.com/martinkozak/qrpc/issues
|
61
65
|
[3]: http://www.martinkozak.net/
|
66
|
+
[4]: http://rubyeventmachine.com/
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.2.0
|
data/lib/jpegoptim.rb
CHANGED
@@ -7,7 +7,7 @@ require "unix/whereis"
|
|
7
7
|
|
8
8
|
##
|
9
9
|
# The +jpegoptim+ tool command frontend.
|
10
|
-
# @see
|
10
|
+
# @see http://www.kokkonen.net/tjko/projects.html
|
11
11
|
#
|
12
12
|
|
13
13
|
module Jpegoptim
|
@@ -67,8 +67,12 @@ module Jpegoptim
|
|
67
67
|
# responsible for optimizing files on the right place. Use Ruby
|
68
68
|
# methods for it.
|
69
69
|
#
|
70
|
+
# If block is given, runs +jpegoptim+ asynchronously. In that case,
|
71
|
+
# +em-pipe-run+ file must be already required.
|
72
|
+
#
|
70
73
|
# @param [String, Array] paths file path or array of paths for optimizing
|
71
74
|
# @param [Hash] options options
|
75
|
+
# @param [Proc] block block for giving back the results
|
72
76
|
# @option options [Boolean, Symbol] :strip says what informations strip, see +jpegoptim+ documentation, default is +:all+
|
73
77
|
# @option options [Boolean] :preserve turns on preserving the timestamps
|
74
78
|
# @option options [Integer] :max set maximum image quality factor
|
@@ -76,7 +80,7 @@ module Jpegoptim
|
|
76
80
|
# @return [Struct] see {Result}
|
77
81
|
#
|
78
82
|
|
79
|
-
def self.optimize(paths, options = { })
|
83
|
+
def self.optimize(paths, options = { }, &block)
|
80
84
|
|
81
85
|
# Command
|
82
86
|
cmd = CommandBuilder::new(self::COMMAND)
|
@@ -111,13 +115,24 @@ module Jpegoptim
|
|
111
115
|
if options[:debug] == true
|
112
116
|
STDERR.write cmd.to_s + "\n"
|
113
117
|
end
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
118
|
+
|
119
|
+
cmd = cmd.to_s
|
120
|
+
|
121
|
+
# Blocking
|
122
|
+
if block.nil?
|
123
|
+
output = Pipe.run(cmd)
|
124
|
+
|
125
|
+
# Parses output
|
126
|
+
succeed, errors = __parse_output(output)
|
127
|
+
return self::Result::new(succeed, errors)
|
128
|
+
|
129
|
+
# Non-blocking
|
130
|
+
else
|
131
|
+
Pipe.run(cmd) do |output|
|
132
|
+
succeed, errors = __parse_output(output)
|
133
|
+
block.call(self::Result::new(succeed, errors))
|
134
|
+
end
|
135
|
+
end
|
121
136
|
end
|
122
137
|
|
123
138
|
|
data/test
CHANGED
@@ -3,6 +3,13 @@
|
|
3
3
|
|
4
4
|
$:.push("./lib")
|
5
5
|
require "jpegoptim"
|
6
|
+
require "em-pipe-run"
|
6
7
|
|
7
|
-
|
8
|
-
puts Jpegoptim.
|
8
|
+
EM::run do
|
9
|
+
puts Jpegoptim.available?.inspect
|
10
|
+
Jpegoptim.optimize(["x.jpg"], { :preserve => true, :strip => :all, :debug => true }) do |results|
|
11
|
+
puts results.inspect
|
12
|
+
end
|
13
|
+
|
14
|
+
puts "something"
|
15
|
+
end
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: jpegoptim
|
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
|
@@ -85,7 +85,6 @@ files:
|
|
85
85
|
- README.md
|
86
86
|
- Rakefile
|
87
87
|
- VERSION
|
88
|
-
- jpegoptim.gemspec
|
89
88
|
- lib/jpegoptim.rb
|
90
89
|
- test
|
91
90
|
has_rdoc: true
|
@@ -102,7 +101,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
102
101
|
requirements:
|
103
102
|
- - ">="
|
104
103
|
- !ruby/object:Gem::Version
|
105
|
-
hash: -
|
104
|
+
hash: -56402776733951615
|
106
105
|
segments:
|
107
106
|
- 0
|
108
107
|
version: "0"
|
data/jpegoptim.gemspec
DELETED
@@ -1,60 +0,0 @@
|
|
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{jpegoptim}
|
8
|
-
s.version = "0.1.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-21}
|
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
|
-
"jpegoptim.gemspec",
|
27
|
-
"lib/jpegoptim.rb",
|
28
|
-
"test"
|
29
|
-
]
|
30
|
-
s.homepage = %q{https://github.com/martinkozak/jpegoptim}
|
31
|
-
s.licenses = ["MIT"]
|
32
|
-
s.require_paths = ["lib"]
|
33
|
-
s.rubygems_version = %q{1.5.2}
|
34
|
-
s.summary = %q{Ruby interface to 'jpegoptim' 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.1.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.1.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.1.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
|
-
|