spittle 0.9.0 → 0.9.1

Sign up to get free protection for your applications and to get access to all the features.
data/README CHANGED
@@ -12,8 +12,42 @@ It takes your PNG's, chews them up and spits out sprites!
12
12
 
13
13
  point bin/spittle at a directory, and watch it sprite away!
14
14
 
15
+ INSTALLATION
15
16
 
17
+ We're hosted at gemcutter. I believe 'sudo gem install gemcutter' then 'gem tumble'.
18
+ Then you can run:
16
19
 
17
- currently only supports images of the same height - this will change soon.
20
+ > sudo gem install spittle
18
21
 
19
- thx to tjennings for the initial spike and help
22
+ USAGE
23
+
24
+ > spittle <directory>
25
+
26
+ For a full list of options:
27
+
28
+ > spittle -h
29
+
30
+ LIMITATIONS
31
+
32
+ - only supports images of the same height and color type.
33
+ - only supports RGB and RGBA color types
34
+ - does not support color profiles (can cause a slight change in color from the source image)
35
+
36
+ FEATURES
37
+
38
+ - automatically generates PNG sprites from a set of PNG images
39
+ - automatically generates css classes to access images within the sprite
40
+ - customize the css template for each sprite
41
+
42
+ ROADMAP - by priority
43
+
44
+ - Rails plugin & rake tasks
45
+ - Support varying height in source images
46
+ - Use mtime tracking to prevent regeneration of sprites that have not changed
47
+ - Support color profiles
48
+ - Support global css template override
49
+
50
+ AUTHORS
51
+
52
+ aberant - Colin Harris
53
+ tjennings - Tyler Jennings
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.9.0
1
+ 0.9.1
data/bin/spittle CHANGED
@@ -1,15 +1,36 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
+ require 'optparse'
3
4
  require File.dirname(__FILE__) + "/../lib/spittle.rb"
4
5
 
6
+
7
+ options = {}
8
+ opts = OptionParser.new do |opts|
9
+ opts.banner = "Usage: spittle [options] directory"
10
+
11
+ opts.on("-o", "--out FILE", "Write css output to an alternate location") do |file|
12
+ options[:css_file] = file
13
+ end
14
+
15
+ opts.on("-p", "--path-prefix PREFIX", "prepend sprite paths with the given string") do |prefix|
16
+ options[:path_prefix] = prefix
17
+ end
18
+
19
+ opts.on_tail("-h", "--help", "Prints this message") do
20
+ puts opts
21
+ exit
22
+ end
23
+
24
+ opts.parse!(ARGV)
25
+ end
26
+
5
27
  dir = ARGV[0]
6
28
 
7
- if dir
8
- Spittle::Processor.new(:source => dir).write
9
- else
10
- puts
11
- puts "spittle! it chews up your PNG's and spits out sprites!"
12
- puts "useage: spittle DIRECTORY"
13
- puts "eg. spittle my_images"
14
- puts
15
- end
29
+ unless dir
30
+ puts opts.help
31
+ exit
32
+ end
33
+
34
+ options[:source] = dir
35
+ Spittle::Processor.new(options).write
36
+
@@ -1,61 +1,61 @@
1
+ .apple_iphone {
2
+ background: transparent url(/tacos/apple/sprite.png) -234px 0px no-repeat;
3
+ width:116;
4
+ height:38;
5
+ text-indent:-5000px;
6
+ }
7
+
1
8
  .apple_itunes {
2
- background: transparent url(/apple/sprite.png) -350px 0px no-repeat;
9
+ background: transparent url(/tacos/apple/sprite.png) -350px 0px no-repeat;
3
10
  width:116;
4
11
  height:38;
5
12
  text-indent:-5000px;
6
13
  }
7
14
 
8
15
  .apple_mac {
9
- background: transparent url(/apple/sprite.png) -466px 0px no-repeat;
16
+ background: transparent url(/tacos/apple/sprite.png) -466px 0px no-repeat;
10
17
  width:116;
11
18
  height:38;
12
19
  text-indent:-5000px;
13
20
  }
14
21
 
15
22
  .apple_apple {
16
- background: transparent url(/apple/sprite.png) 0px 0px no-repeat;
23
+ background: transparent url(/tacos/apple/sprite.png) 0px 0px no-repeat;
17
24
  width:117;
18
25
  height:38;
19
26
  text-indent:-5000px;
20
27
  }
21
28
 
22
- .apple_store {
23
- background: transparent url(/apple/sprite.png) -744px 0px no-repeat;
29
+ .apple_support {
30
+ background: transparent url(/tacos/apple/sprite.png) -860px 0px no-repeat;
24
31
  width:116;
25
32
  height:38;
26
33
  text-indent:-5000px;
27
34
  }
28
35
 
29
36
  .apple_search {
30
- background: transparent url(/apple/sprite.png) -582px 0px no-repeat;
37
+ background: transparent url(/tacos/apple/sprite.png) -582px 0px no-repeat;
31
38
  width:162;
32
39
  height:38;
33
40
  text-indent:-5000px;
34
41
  }
35
42
 
36
43
  .apple_divider {
37
- background: transparent url(/apple/sprite.png) -117px 0px no-repeat;
44
+ background: transparent url(/tacos/apple/sprite.png) -117px 0px no-repeat;
38
45
  width:1;
39
46
  height:38;
40
47
  text-indent:-5000px;
41
48
  }
42
49
 
43
- .apple_support {
44
- background: transparent url(/apple/sprite.png) -860px 0px no-repeat;
50
+ .apple_store {
51
+ background: transparent url(/tacos/apple/sprite.png) -744px 0px no-repeat;
45
52
  width:116;
46
53
  height:38;
47
54
  text-indent:-5000px;
48
55
  }
49
56
 
50
57
  .apple_downloads {
51
- background: transparent url(/apple/sprite.png) -118px 0px no-repeat;
52
- width:116;
53
- height:38;
54
- text-indent:-5000px;
55
- }
56
-
57
- .apple_iphone {
58
- background: transparent url(/apple/sprite.png) -234px 0px no-repeat;
58
+ background: transparent url(/tacos/apple/sprite.png) -118px 0px no-repeat;
59
59
  width:116;
60
60
  height:38;
61
61
  text-indent:-5000px;
data/init.rb ADDED
@@ -0,0 +1 @@
1
+ # Include hook code here
@@ -1,9 +1,22 @@
1
1
  class DirectoryProcessor
2
- def initialize(dir)
2
+
3
+ DEFAULT_TEMPLATE = <<-EOF
4
+ .<name>_<image_name> {
5
+ background: transparent url(<image_loc>) <offset>px 0px no-repeat;
6
+ width:<width>;
7
+ height:<height>;
8
+ text-indent:-5000px;
9
+ }
10
+
11
+ EOF
12
+
13
+ def initialize(dir, options = {})
14
+ @options = options
3
15
  @dir = dir
4
16
  files = images
5
17
  @sprite = PNG::Sprite.new
6
18
  files.each {|f| @sprite.append(PNG::Image.open(f))}
19
+ #puts "#{@dir} #{files.size} files"
7
20
  end
8
21
 
9
22
  def images
@@ -36,23 +49,26 @@ class DirectoryProcessor
36
49
 
37
50
  def image_loc
38
51
  #TODO: Lame!
39
- ("/" + @dir + "/sprite.png").gsub("/./", "/")
52
+ base = ("/" + @dir + "/sprite.png").gsub("/./", "/").gsub("//", "/")
53
+ base = @options[:path_prefix] + base if @options[:path_prefix]
54
+ base
40
55
  end
41
56
 
42
- FRAG = <<-EOF
43
- .<name>_<image_name> {
44
- background: transparent url(<image_loc>) <offset>px 0px no-repeat;
45
- width:<width>;
46
- height:<height>;
47
- text-indent:-5000px;
48
- }
57
+ def template_file
58
+ @dir + "/template.css"
59
+ end
49
60
 
50
- EOF
61
+ def template
62
+ if File.exists?(template_file)
63
+ return File.read(template_file)
64
+ end
65
+ return DEFAULT_TEMPLATE
66
+ end
51
67
 
52
68
  def css
53
69
  @sprite.locations.inject("") do |out, image|
54
70
  image_name, properties = image
55
- out << FRAG.gsub("<name>", dir_name).
71
+ out << template.gsub("<name>", dir_name).
56
72
  gsub("<image_name>", image_name.to_s).
57
73
  gsub("<width>", properties[:width].to_s).
58
74
  gsub("<height>", properties[:height].to_s).
data/lib/spittle/image.rb CHANGED
@@ -32,6 +32,10 @@ module PNG
32
32
  f.write(generate_png)
33
33
  end
34
34
  end
35
+
36
+ def to_s
37
+ "#{@name} (#{height} x #{width})"
38
+ end
35
39
 
36
40
  def merge_left( other )
37
41
  l = other.rows
@@ -1,6 +1,7 @@
1
1
  module Spittle
2
2
  class Processor
3
3
  def initialize(opts)
4
+ #puts "Processing Directory #{opts[:source]}"
4
5
  @options = opts
5
6
  @processors = dir_processors
6
7
  @css_builder = StylesheetBuilder.new(@options[:source])
@@ -17,7 +18,7 @@ module Spittle
17
18
  end
18
19
 
19
20
  def dir_processors
20
- directories.map{|d| DirectoryProcessor.new(d)}
21
+ directories.map{|d| DirectoryProcessor.new(d, @options)}
21
22
  end
22
23
 
23
24
  def cleanup
@@ -22,9 +22,6 @@ describe 'PNG' do
22
22
  read("#{@expected_dir}/merge_right_test.png").should == read("#{@tmp_dir}/merge_right_test.png")
23
23
  end
24
24
 
25
- def read(file_name)
26
- File.read(file_name)
27
- end
28
25
  end
29
26
 
30
27
  describe "Dir sprite" do
@@ -58,9 +55,14 @@ describe "Dir sprite" do
58
55
 
59
56
  describe "CSS fragments" do
60
57
  before :all do
58
+ @template = @dir + "/template.css"
61
59
  @css = @spriter.css
62
60
  end
63
61
 
62
+ after do
63
+ File.delete(@template) rescue {}
64
+ end
65
+
64
66
  it "should compose class names" do
65
67
  @css.should include( ".words_latitude")
66
68
  @css.should include( ".words_of" )
@@ -73,6 +75,12 @@ describe "Dir sprite" do
73
75
  it "should write css fragments for a sprite" do
74
76
  File.exists?(@css_file).should be_true
75
77
  end
78
+
79
+ it "can be overidden by including a template.css in the sprite directory" do
80
+ File.open(@template, 'w'){|f| f.write("override")}
81
+ @spriter.write
82
+ @spriter.css.should include("override")
83
+ end
76
84
  end
77
85
  end
78
86
 
@@ -107,7 +115,7 @@ describe "Complete spriting process" do
107
115
  before :all do
108
116
  @dir = File.dirname(__FILE__) + "/sprite_dirs"
109
117
  @css_file = @dir + "/sprite.css"
110
- @spittle = Spittle::Processor.new(:source => @dir, :css_file => @css_file)
118
+ @spittle = Spittle::Processor.new(:path_prefix => "/images", :source => @dir, :css_file => @css_file)
111
119
  @spittle.write
112
120
  end
113
121
 
@@ -118,6 +126,11 @@ describe "Complete spriting process" do
118
126
  File.exists?(@dir + "/words/sprite.png").should be_false
119
127
  end
120
128
 
129
+ it "prepends a path prefix to all sprites in the css file" do
130
+ file = read(@css_file)
131
+ file.should include("/images/spec/sprite_dirs/words")
132
+ end
133
+
121
134
  it "can find all the sprite directories" do
122
135
  dirs = @spittle.directories.map{|d| d.split('/').last}
123
136
  dirs.should include( "words" )
@@ -132,3 +145,8 @@ describe "Complete spriting process" do
132
145
  File.exists?(@dir + "/words/fragment.css").should be_true
133
146
  end
134
147
  end
148
+
149
+ def read(file_name)
150
+ File.read(file_name)
151
+ end
152
+
data/spittle.gemspec ADDED
@@ -0,0 +1,118 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{spittle}
8
+ s.version = "0.9.1"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["aberant", "tjennings"]
12
+ s.date = %q{2009-11-16}
13
+ s.default_executable = %q{spittle}
14
+ s.description = %q{pure ruby PNG}
15
+ s.email = ["qzzzq1@gmail.com", "tyler.jennings@gmail.com"]
16
+ s.executables = ["spittle"]
17
+ s.extra_rdoc_files = [
18
+ "README"
19
+ ]
20
+ s.files = [
21
+ ".gitignore",
22
+ "README",
23
+ "Rakefile",
24
+ "VERSION",
25
+ "bin/spittle",
26
+ "examples/sprites/README",
27
+ "examples/sprites/apple/apple.png",
28
+ "examples/sprites/apple/divider.png",
29
+ "examples/sprites/apple/downloads.png",
30
+ "examples/sprites/apple/fragment.css",
31
+ "examples/sprites/apple/iphone.png",
32
+ "examples/sprites/apple/itunes.png",
33
+ "examples/sprites/apple/mac.png",
34
+ "examples/sprites/apple/search.png",
35
+ "examples/sprites/apple/sprite.png",
36
+ "examples/sprites/apple/store.png",
37
+ "examples/sprites/apple/support.png",
38
+ "examples/sprites/fragment.css",
39
+ "examples/sprites/index.html",
40
+ "examples/sprites/server.rb",
41
+ "examples/sprites/sprite.css",
42
+ "examples/sprites/words/fragment.css",
43
+ "examples/sprites/words/latitude.png",
44
+ "examples/sprites/words/of.png",
45
+ "examples/sprites/words/set.png",
46
+ "examples/sprites/words/specified.png",
47
+ "examples/sprites/words/sprite.css",
48
+ "examples/sprites/words/sprite.png",
49
+ "init.rb",
50
+ "lib/spittle.rb",
51
+ "lib/spittle/chunk.rb",
52
+ "lib/spittle/directory_spriter.rb",
53
+ "lib/spittle/file_header.rb",
54
+ "lib/spittle/filters.rb",
55
+ "lib/spittle/idat.rb",
56
+ "lib/spittle/iend.rb",
57
+ "lib/spittle/ihdr.rb",
58
+ "lib/spittle/image.rb",
59
+ "lib/spittle/parser.rb",
60
+ "lib/spittle/processor.rb",
61
+ "lib/spittle/sprite.rb",
62
+ "lib/spittle/stylesheet_builder.rb",
63
+ "spec/builders/image_builder.rb",
64
+ "spec/css_fragments/deep/style/fragment.css",
65
+ "spec/css_fragments/some/fragment.css",
66
+ "spec/expected_output/merge_right_test.png",
67
+ "spec/expected_output/write_test.png",
68
+ "spec/images/lightening.png",
69
+ "spec/integration_spec.rb",
70
+ "spec/lib/file_header_spec.rb",
71
+ "spec/lib/idat_spec.rb",
72
+ "spec/lib/ihdr_spec.rb",
73
+ "spec/lib/image_spec.rb",
74
+ "spec/lib/parser_spec.rb",
75
+ "spec/lib/sprite_spec.rb",
76
+ "spec/spec.opts",
77
+ "spec/spec_helper.rb",
78
+ "spec/sprite_dirs/words/latitude.png",
79
+ "spec/sprite_dirs/words/of.png",
80
+ "spec/sprite_dirs/words/set.png",
81
+ "spec/sprite_dirs/words/specified.png",
82
+ "spec/tmp/merge_right_test.png",
83
+ "spec/tmp/write_test.png",
84
+ "spittle.gemspec",
85
+ "tasks/spittle_tasks.rake"
86
+ ]
87
+ s.homepage = %q{http://github.com/aberant/spittle}
88
+ s.rdoc_options = ["--charset=UTF-8"]
89
+ s.require_paths = ["lib"]
90
+ s.rubygems_version = %q{1.3.5}
91
+ s.summary = %q{pure ruby PNG}
92
+ s.test_files = [
93
+ "spec/builders/image_builder.rb",
94
+ "spec/integration_spec.rb",
95
+ "spec/lib/file_header_spec.rb",
96
+ "spec/lib/idat_spec.rb",
97
+ "spec/lib/ihdr_spec.rb",
98
+ "spec/lib/image_spec.rb",
99
+ "spec/lib/parser_spec.rb",
100
+ "spec/lib/sprite_spec.rb",
101
+ "spec/spec_helper.rb",
102
+ "examples/sprites/server.rb"
103
+ ]
104
+
105
+ if s.respond_to? :specification_version then
106
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
107
+ s.specification_version = 3
108
+
109
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
110
+ s.add_development_dependency(%q<rspec>, [">= 0"])
111
+ else
112
+ s.add_dependency(%q<rspec>, [">= 0"])
113
+ end
114
+ else
115
+ s.add_dependency(%q<rspec>, [">= 0"])
116
+ end
117
+ end
118
+
@@ -0,0 +1,9 @@
1
+ desc "Generates sprites"
2
+ task :sprite do
3
+ require File.dirname(__FILE__) + "/../lib/spittle.rb"
4
+
5
+ opts = {:source => RAILS_ROOT + "/public/images/sprites",
6
+ :path_prefix => "/images"}
7
+
8
+ Spittle::Processor.new(opts).write
9
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spittle
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.0
4
+ version: 0.9.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - aberant
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2009-11-14 00:00:00 -06:00
13
+ date: 2009-11-16 00:00:00 -06:00
14
14
  default_executable: spittle
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
@@ -62,6 +62,7 @@ files:
62
62
  - examples/sprites/words/specified.png
63
63
  - examples/sprites/words/sprite.css
64
64
  - examples/sprites/words/sprite.png
65
+ - init.rb
65
66
  - lib/spittle.rb
66
67
  - lib/spittle/chunk.rb
67
68
  - lib/spittle/directory_spriter.rb
@@ -96,6 +97,8 @@ files:
96
97
  - spec/sprite_dirs/words/specified.png
97
98
  - spec/tmp/merge_right_test.png
98
99
  - spec/tmp/write_test.png
100
+ - spittle.gemspec
101
+ - tasks/spittle_tasks.rake
99
102
  has_rdoc: true
100
103
  homepage: http://github.com/aberant/spittle
101
104
  licenses: []