grosser-smusher 0.3 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -9,7 +9,7 @@ end
9
9
  #Gemspec
10
10
  require 'echoe'
11
11
  porject_name = 'smusher'
12
- Echoe.new(porject_name , '0.3') do |p|
12
+ Echoe.new(porject_name , '0.3.1') do |p|
13
13
  p.description = "Automatic Lossless Reduction Of All Your Images"
14
14
  p.url = "http://github.com/grosser/#{porject_name}"
15
15
  p.author = "Michael Grosser"
data/lib/smusher.rb CHANGED
@@ -4,7 +4,6 @@ require 'json'
4
4
 
5
5
  module Smusher
6
6
  extend self
7
- EMPTY_FILE_SIZE = 4
8
7
 
9
8
  # optimize the given image !!coverts gif to png!!
10
9
  def optimize_image(file)
@@ -31,7 +30,7 @@ private
31
30
 
32
31
  def write_optimized_data(file)
33
32
  data = optimized_image_data_for(file)
34
- File.open(file,'w') {|f| f.puts data}
33
+ File.open(file,'w') {|f| f.puts data} unless data.nil?
35
34
  end
36
35
 
37
36
  def sanitize_folder(folder)
@@ -64,14 +63,14 @@ private
64
63
  end
65
64
 
66
65
  def empty?(file)
67
- size(file) <= EMPTY_FILE_SIZE
66
+ size(file) <= 4 #empty file = 4kb
68
67
  end
69
68
 
70
69
  def with_logging(file)
71
70
  puts "sushing #{file}"
72
71
 
73
72
  before = size(file)
74
- yield
73
+ begin; yield; rescue; puts $!; end
75
74
  after = size(file)
76
75
 
77
76
  result = "#{(100*after)/before}%"
@@ -80,9 +79,10 @@ private
80
79
 
81
80
  def optimized_image_data_for(file)
82
81
  #TODO use rest-client --> independent of curl
83
- response = `curl -F files[]=@#{file} http://smush.it/ws.php -s`
84
- return nil if response['error']
85
- path = JSON.parse(response)['dest']
82
+ response = JSON.parse(`curl -F files[]=@#{file} http://smush.it/ws.php -s`)
83
+ raise "smush.it: #{response['error']}" if response['error']
84
+ path = response['dest']
85
+ raise "no dest path found" unless path
86
86
  `curl http://smush.it/#{path} -s`
87
87
  end
88
88
  end
data/smusher.gemspec CHANGED
@@ -2,17 +2,17 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{smusher}
5
- s.version = "0.3"
5
+ s.version = "0.3.1"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Michael Grosser"]
9
- s.date = %q{2009-01-25}
9
+ s.date = %q{2009-01-26}
10
10
  s.default_executable = %q{smusher}
11
11
  s.description = %q{Automatic Lossless Reduction Of All Your Images}
12
12
  s.email = %q{grosser.michael@gmail.com}
13
13
  s.executables = ["smusher"]
14
14
  s.extra_rdoc_files = ["lib/smusher.rb", "bin/smusher", "README.markdown"]
15
- s.files = ["Manifest", "nbproject/private/private.xml", "nbproject/private/rake-d.txt", "nbproject/project.xml", "nbproject/project.properties", "lib/smusher.rb", "spec/out/people.jpg", "spec/spec_helper.rb", "spec/smusher_spec.rb", "spec/images/logo.gif", "spec/images/woman.jpeg", "spec/images/add.png", "spec/images/drink_empty.png", "spec/images/people.jpg", "spec/images/water.JPG", "spec/reduced/fam.png", "spec/reduced/add.png", "bin/smusher", "Rakefile", "README.markdown", "smusher.gemspec"]
15
+ s.files = ["Manifest", "nbproject/private/private.xml", "nbproject/private/rake-d.txt", "nbproject/project.xml", "nbproject/project.properties", "lib/smusher.rb", "spec/out/people.jpg", "spec/spec_helper.rb", "spec/smusher_spec.rb", "spec/images/logo.gif", "spec/images/woman.jpeg", "spec/images/add.png", "spec/images/drink_empty.png", "spec/images/people.jpg", "spec/images/water.JPG", "spec/reduced/fam.png", "spec/reduced/add.png", "ar.gif", "bin/smusher", "Rakefile", "README.markdown", "smusher.gemspec"]
16
16
  s.has_rdoc = true
17
17
  s.homepage = %q{http://github.com/grosser/smusher}
18
18
  s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Smusher", "--main", "README.markdown"]
data/spec/smusher_spec.rb CHANGED
@@ -88,32 +88,12 @@ describe :smusher do
88
88
  it "reverts a file that got larger" do
89
89
  Smusher.send(:with_protection,@file) do
90
90
  write(File.open(@file).read + 'x')
91
- @before.should_not == size
92
91
  end
93
92
  @before.should == size
94
93
  end
95
94
 
96
95
  it "reverts a file that got empty" do
97
- Smusher.send(:with_protection,@file) do
98
- write nil
99
- size.should == Smusher::EMPTY_FILE_SIZE
100
- end
101
- size.should == @before
102
- end
103
-
104
- it "reverts a file that has error-suggesting size" do
105
- write("valid-file-contents")
106
- @before = size
107
- @before.should > Smusher::EMPTY_FILE_SIZE
108
-
109
- #gets overwritten by failure data size
110
- Smusher.send(:with_protection,@file) do
111
- write nil
112
- size.should == Smusher::EMPTY_FILE_SIZE
113
- end
114
-
115
- #and should be reverted
116
- size.should_not == Smusher::EMPTY_FILE_SIZE
96
+ Smusher.send(:with_protection,@file){write nil}
117
97
  size.should == @before
118
98
  end
119
99
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: grosser-smusher
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
  - Michael Grosser
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-01-25 00:00:00 -08:00
12
+ date: 2009-01-26 00:00:00 -08:00
13
13
  default_executable: smusher
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -67,6 +67,7 @@ files:
67
67
  - spec/images/water.JPG
68
68
  - spec/reduced/fam.png
69
69
  - spec/reduced/add.png
70
+ - ar.gif
70
71
  - bin/smusher
71
72
  - Rakefile
72
73
  - README.markdown