grosser-smusher 0.3.4 → 0.3.5

Sign up to get free protection for your applications and to get access to all the features.
data/README.markdown CHANGED
@@ -22,11 +22,12 @@ Optimize a single image or a whole folder in the cloud.
22
22
  converting gif-s to png-s:
23
23
 
24
24
  - called with a folder gif-s will not be converted
25
- - called on a singe .gif, it will be converted if it is optimizeable
25
+ - called on a single .gif or wildcard, image(s) will be converted if optimizeable
26
26
 
27
27
  Usage:
28
28
  smusher /apps/x/public/images [options]
29
29
  smusher /apps/x/public/images/x.png [options]
30
+ smusher /apps/x/public/images/*.png [options]
30
31
 
31
32
  Options are:
32
33
  -q, --quiet no output
@@ -35,7 +36,7 @@ Options are:
35
36
 
36
37
  Protection
37
38
  ==========
38
- Any image that returns a failure code, is larger than before,
39
+ Any image that returns a failure code, is larger than before,
39
40
  or is empty will not be saved.
40
41
 
41
42
  Example
@@ -55,15 +56,17 @@ Example
55
56
  TODO
56
57
  ====
57
58
  - only optimize 'new' images -> save time when doing on each deploy
58
- - support wildcars like `smusher images/*.png` ?
59
59
  - convert gifs to png, even if the new size is the same, for consistency (atm only those which get smaller are converted)
60
60
 
61
61
  ALTERNATIVES
62
62
  ============
63
63
  If you want to lossless reduce images and minify css + js, try [reduce](http://github.com/grosser/reduce).
64
64
 
65
- Author
65
+ Authors
66
66
  ======
67
- Michael Grosser
67
+ ###Contributors
68
+ - [retr0h](http://geminstallthat.wordpress.com/)
69
+
70
+ [Michael Grosser](http://pragmatig.wordpress.com)
68
71
  grosser.michael@gmail.com
69
72
  Hereby placed under public domain, do what you want, just do not hold me accountable...
data/VERSION.yml CHANGED
@@ -1,4 +1,4 @@
1
- ---
2
- :major: 0
1
+ ---
3
2
  :minor: 3
4
- :patch: 4
3
+ :patch: 5
4
+ :major: 0
data/bin/smusher CHANGED
@@ -4,7 +4,7 @@ require 'optparse'
4
4
  require 'smusher'
5
5
 
6
6
  options = {}
7
- path = ARGV.shift
7
+ path = ARGV.first
8
8
  OptionParser.new do |opts|
9
9
  opts.banner = <<BANNER
10
10
  Optimize a single image or a whole folder in the cloud.
@@ -16,17 +16,21 @@ gif`s:
16
16
  Usage:
17
17
  smusher /apps/x/public/images [options]
18
18
  smusher /apps/x/public/images/x.png [options]
19
+ smusher /apps/x/public/images/*.png [options]
19
20
 
20
21
  Options are:
21
22
  BANNER
22
23
  opts.on("-q", "--quiet","no output") { options[:quiet]=true }
23
24
  opts.on("-c", "--convert-gifs","convert all .gif`s in the given folder") { options[:convert_gifs]=true }
24
25
  opts.parse!(ARGV)
25
- puts opts if path.to_s.empty? or not File.exist?(path)
26
+ if path.to_s.empty? or not File.exist?(path)
27
+ puts opts
28
+ exit
29
+ end
26
30
  end
27
31
 
28
32
  if File.directory?(path)
29
33
  Smusher.optimize_images_in_folder(path,options)
30
34
  else
31
- Smusher.optimize_image(path,options)
35
+ Smusher.optimize_image(ARGV,options)
32
36
  end
data/lib/smusher.rb CHANGED
@@ -11,19 +11,22 @@ module Smusher
11
11
 
12
12
  # optimize the given image
13
13
  # converts gif to png, if size is lower
14
- def optimize_image(file,options={})
15
- check_options(options)
16
- puts "THIS FILE IS EMPTY!!! #{file}" and return if size(file).zero?
17
- success = false
18
-
19
- with_logging(file,options[:quiet]) do
20
- write_optimized_data(file)
21
- success = true
22
- end
23
-
24
- if success
25
- gif = /\.gif$/
26
- `mv #{file} #{file.sub(gif,'.png')}` if file =~ gif
14
+ # can be called with a file-path or an array of files-paths
15
+ def optimize_image(files,options={})
16
+ files.each do |file|
17
+ check_options(options)
18
+ puts "THIS FILE IS EMPTY!!! #{file}" and return if size(file).zero?
19
+ success = false
20
+
21
+ with_logging(file,options[:quiet]) do
22
+ write_optimized_data(file)
23
+ success = true
24
+ end
25
+
26
+ if success
27
+ gif = /\.gif$/
28
+ `mv #{file} #{file.sub(gif,'.png')}` if file =~ gif
29
+ end
27
30
  end
28
31
  end
29
32
 
data/spec/smusher_spec.rb CHANGED
@@ -28,6 +28,12 @@ describe :smusher do
28
28
  size.should < original_size
29
29
  end
30
30
 
31
+ it "can be called with an array of files" do
32
+ original_size = size
33
+ Smusher.optimize_image([@file])
34
+ size.should < original_size
35
+ end
36
+
31
37
  it "it does nothing if size stayed the same" do
32
38
  original_size = size
33
39
  Smusher.expects(:optimized_image_data_for).returns File.read(@file)
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
4
+ version: 0.3.5
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-03-13 00:00:00 -07:00
12
+ date: 2009-03-25 00:00:00 -07:00
13
13
  default_executable: smusher
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency