css_sprite 1.4.5 → 1.4.6

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/README.textile CHANGED
@@ -27,6 +27,10 @@ css sprite generates css_sprite image and css files automatically for you follow
27
27
  | twitter-icon-hover.png | .twitter-icon:hover |
28
28
  | logos_hover/gmail_logo.png | .logos:hover .gmail_logo |
29
29
  | logos-hover/gmail-logo.png | .logos:hover .gmail-logo |
30
+ | gmail_logo_active.png | .gmail_logo.active |
31
+ | gmail-logo-active.png | .gmail-logo.active |
32
+ | logos_active/gmail_logo.png | .logos.active .gmail_logo |
33
+ | logos-active/gmail-logo.png | .logos.active .gmail-logo |
30
34
 
31
35
  css_sprite directory is the directory whose name is "css_sprite" or "css_sprite" suffixed under public/images directory.
32
36
  css_sprite image is the image file automatically generated under public/images directory.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.4.5
1
+ 1.4.6
data/css_sprite.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{css_sprite}
8
- s.version = "1.4.5"
8
+ s.version = "1.4.6"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Richard Huang"]
12
- s.date = %q{2010-04-13}
12
+ s.date = %q{2010-04-19}
13
13
  s.description = %q{css_sprite is a rails plugin/gem to generate css sprite image automatically.}
14
14
  s.email = %q{flyerhzm@gmail.com}
15
15
  s.extra_rdoc_files = [
@@ -27,12 +27,14 @@ Gem::Specification.new do |s|
27
27
  "spec/css_sprite/sprite_spec.rb",
28
28
  "spec/public/images/another_css_sprite/no_image",
29
29
  "spec/public/images/css_sprite/gmail_logo.png",
30
+ "spec/public/images/css_sprite/gmail_logo_active.png",
30
31
  "spec/public/images/css_sprite/hotmail_logo.png",
31
32
  "spec/public/images/css_sprite/icons/facebook_icon.png",
32
33
  "spec/public/images/css_sprite/icons/facebook_icon_hover.png",
33
34
  "spec/public/images/css_sprite/icons/twitter_icon.png",
34
35
  "spec/public/images/css_sprite/icons/twitter_icon_hover.png",
35
36
  "spec/public/images/css_sprite/logos/gmail_logo.png",
37
+ "spec/public/images/css_sprite/logos/gmail_logo_active.png",
36
38
  "spec/public/images/css_sprite/logos_hover/gmail_logo.png",
37
39
  "spec/public/images/css_sprite/not_image.txt",
38
40
  "spec/spec.opts",
@@ -42,7 +44,7 @@ Gem::Specification.new do |s|
42
44
  s.homepage = %q{http://github.com/flyerhzm/css_sprite}
43
45
  s.rdoc_options = ["--charset=UTF-8"]
44
46
  s.require_paths = ["lib"]
45
- s.rubygems_version = %q{1.3.5}
47
+ s.rubygems_version = %q{1.3.6}
46
48
  s.summary = %q{css_sprite is a rails plugin/gem to generate css sprite image automatically.}
47
49
  s.test_files = [
48
50
  "spec/css_sprite/sprite_spec.rb",
@@ -16,16 +16,19 @@ class Sprite
16
16
  end
17
17
  end
18
18
 
19
+ # execute the css sprite operation
19
20
  def build
20
21
  directories = css_sprite_directories
21
22
  directories.each { |directory| execute(directory) }
22
23
  end
23
24
 
25
+ # execute the css sprite operation if stylesheet is expired
24
26
  def check
25
27
  directories = css_sprite_directories
26
28
  directories.each { |directory| execute(directory) if expire?(directory) }
27
29
  end
28
30
 
31
+ # output the css sprite image and stylesheet
29
32
  def execute(directory)
30
33
  results = output_image(directory)
31
34
  unless results.empty?
@@ -34,6 +37,7 @@ class Sprite
34
37
  end
35
38
  end
36
39
 
40
+ # detect if the stylesheet is expired or not?
37
41
  def expire?(directory)
38
42
  if sass?
39
43
  stylesheet_path = dest_sass_path(directory)
@@ -43,12 +47,12 @@ class Sprite
43
47
  return true unless File.exist?(stylesheet_path)
44
48
  stylesheet_mtime = File.new(stylesheet_path).mtime
45
49
  Dir["**/*"].each do |path|
46
- # it is a directory
47
50
  return true if path !~ /.*\..*/ and File.new(path).mtime > stylesheet_mtime
48
51
  end
49
52
  return false
50
53
  end
51
54
 
55
+ # output stylesheet, sass or css
52
56
  def output_stylesheet(directory, results)
53
57
  if sass?
54
58
  output_sass(directory, results)
@@ -57,16 +61,19 @@ class Sprite
57
61
  end
58
62
  end
59
63
 
64
+ # use sass or css?
60
65
  def sass?
61
66
  @config['engine'] == 'sass'
62
67
  end
63
68
 
69
+ # detect all the css sprite directories. e.g. public/images/css_sprite, public/images/widget_css_sprite
64
70
  def css_sprite_directories
65
71
  Dir.entries(@image_path).collect do |d|
66
72
  File.join(@image_path, d) if File.directory?(File.join(@image_path, d)) and d =~ /css_sprite$/
67
73
  end.compact
68
74
  end
69
75
 
76
+ # output the css sprite image and return all the images properies.
70
77
  def output_image(directory)
71
78
  results = []
72
79
  sources = all_images(directory)
@@ -89,6 +96,7 @@ class Sprite
89
96
  results
90
97
  end
91
98
 
99
+ # opitmize the css sprite image
92
100
  def optimize_image(directory)
93
101
  unless @config['disable_optimization']
94
102
  dest_image_path = dest_image_path(directory)
@@ -98,6 +106,7 @@ class Sprite
98
106
  end
99
107
  end
100
108
 
109
+ # output the css sprite css
101
110
  def output_css(directory, results)
102
111
  unless results.empty?
103
112
  dest_image_name = dest_image_name(directory)
@@ -130,6 +139,7 @@ class Sprite
130
139
  end
131
140
  end
132
141
 
142
+ # output the css sprite sass file
133
143
  def output_sass(directory, results)
134
144
  unless results.empty?
135
145
  dest_image_name = dest_image_name(directory)
@@ -161,6 +171,7 @@ class Sprite
161
171
  end
162
172
  end
163
173
 
174
+ # get all the class names within the same css sprite image
164
175
  def class_names(results, options={})
165
176
  options = {:count_per_line => 5}.merge(options)
166
177
  class_names = []
@@ -171,10 +182,12 @@ class Sprite
171
182
  class_names
172
183
  end
173
184
 
185
+ # get the css class name from image name
174
186
  def class_name(name)
175
- ".#{name.gsub('/', ' .').sub(/[_-]hover\b/, ':hover')}"
187
+ ".#{name.gsub('/', ' .').gsub(/[_-]hover\b/, ':hover').gsub(/[_-]active\b/, '.active')}"
176
188
  end
177
189
 
190
+ # read all images under the css sprite directory
178
191
  def all_images(directory)
179
192
  images = []
180
193
  Find.find(directory) do |path|
@@ -185,22 +198,27 @@ class Sprite
185
198
  images
186
199
  end
187
200
 
201
+ # destination css sprite image path
188
202
  def dest_image_path(directory)
189
203
  directory + ".png"
190
204
  end
191
205
 
206
+ # destination css sprite image name
192
207
  def dest_image_name(directory)
193
208
  File.basename(directory) + ".png"
194
209
  end
195
210
 
211
+ # destination css file path
196
212
  def dest_css_path(directory)
197
213
  File.join(@stylesheet_path, File.basename(directory) + '.css')
198
214
  end
199
215
 
216
+ # destination sass file path
200
217
  def dest_sass_path(directory)
201
218
  File.join(@stylesheet_path, 'sass', File.basename(directory) + '.sass')
202
219
  end
203
220
 
221
+ # append src_image to the dest_image with position (x, y)
204
222
  def composite_images(dest_image, src_image, x, y)
205
223
  width = [src_image.columns + x, dest_image.columns].max
206
224
  height = [src_image.rows + y, dest_image.rows].max
@@ -210,27 +228,48 @@ class Sprite
210
228
  image
211
229
  end
212
230
 
231
+ # get the Magick::Image
213
232
  def get_image(image_filename)
214
233
  Magick::Image::read(image_filename).first
215
234
  end
216
235
 
236
+ # get image properties, including name, width and height
217
237
  def image_properties(image, directory)
218
- directory_length = directory.length + 1
219
- extname_length = File.extname(image.filename).length
220
- name = image.filename.slice(directory_length...-extname_length)
221
- without = false
222
- if hover?(name)
223
- not_hover_file = image.filename.sub(/[_-]hover\./, '.').sub(/[_-]hover\//, '/')
224
- if File.exist?(not_hover_file)
225
- not_hover_image = get_image(not_hover_file)
226
- without = true if image.columns == not_hover_image.columns and image.rows == not_hover_image.rows
238
+ name = get_image_name(image, directory)
239
+ need_wh?(image, directory) ? {:name => name, :width => image.columns, :height => image.rows} : {:name => name}
240
+ end
241
+
242
+ # check if the hover class needs width and height
243
+ # if the hover class has the same width and height property with not hover class,
244
+ # then the hover class does not need width and height
245
+ def need_wh?(image, directory)
246
+ name = get_image_name(image, directory)
247
+ if hover?(name) or active?(name)
248
+ not_file = image.filename.sub(/[_-](hover|active)\./, '.').sub(/[_-](hover|active)\//, '/')
249
+ if File.exist?(not_file)
250
+ not_image = get_image(not_file)
251
+ return false if image.columns == not_image.columns and image.rows == not_image.rows
227
252
  end
228
253
  end
229
- without ? {:name => name} : {:name => name, :width => image.columns, :height => image.rows}
254
+ return true
230
255
  end
231
-
232
- def hover?(name)
233
- name =~ /[_-]hover$|[_-]hover\//
256
+
257
+ # get the image name substracting base directory and extname
258
+ def get_image_name(image, directory)
259
+ directory_length = directory.length + 1
260
+ extname_length = File.extname(image.filename).length
261
+ image.filename.slice(directory_length...-extname_length)
262
+ end
263
+
264
+ # test if the filename contains a hover or active.
265
+ # e.g. icons/twitter_hover, icons_hover/twitter
266
+ # e.g. icons/twitter_active, icons_active/twitter
267
+ [:active, :hover].each do |method|
268
+ class_eval <<-EOF
269
+ def #{method}?(name)
270
+ name =~ /[_-]#{method}$|[_-]#{method}\\//
271
+ end
272
+ EOF
234
273
  end
235
274
 
236
275
  end
@@ -54,8 +54,10 @@ describe Sprite do
54
54
  File.join(IMAGE_PATH, 'css_sprite/icons/facebook_icon_hover.png'),
55
55
  File.join(IMAGE_PATH, 'css_sprite/hotmail_logo.png'),
56
56
  File.join(IMAGE_PATH, 'css_sprite/gmail_logo.png'),
57
+ File.join(IMAGE_PATH, 'css_sprite/gmail_logo_active.png'),
57
58
  File.join(IMAGE_PATH, 'css_sprite/logos_hover/gmail_logo.png'),
58
- File.join(IMAGE_PATH, 'css_sprite/logos/gmail_logo.png')]
59
+ File.join(IMAGE_PATH, 'css_sprite/logos/gmail_logo.png'),
60
+ File.join(IMAGE_PATH, 'css_sprite/logos/gmail_logo_active.png')]
59
61
  actual_images = @sprite.all_images(File.join(IMAGE_PATH, 'css_sprite'))
60
62
  actual_images.size.should == expected_images.size
61
63
  expected_images.each do |expected_image|
@@ -99,6 +101,12 @@ describe Sprite do
99
101
  @sprite.class_name("twitter_hover_icon_hover").should == ".twitter_hover_icon:hover"
100
102
  @sprite.class_name("logos_hover/gmail_logo").should == ".logos:hover .gmail_logo"
101
103
  end
104
+
105
+ it "should get class_name with active class" do
106
+ @sprite.class_name("gmail_logo_active").should == ".gmail_logo.active"
107
+ @sprite.class_name("logos_active/gmail_logo").should == ".logos.active .gmail_logo"
108
+ @sprite.class_name("logos/gmail_logo_active").should == ".logos .gmail_logo.active"
109
+ end
102
110
  end
103
111
 
104
112
  describe "dest_image_path" do
metadata CHANGED
@@ -1,7 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: css_sprite
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.5
4
+ prerelease: false
5
+ segments:
6
+ - 1
7
+ - 4
8
+ - 6
9
+ version: 1.4.6
5
10
  platform: ruby
6
11
  authors:
7
12
  - Richard Huang
@@ -9,19 +14,21 @@ autorequire:
9
14
  bindir: bin
10
15
  cert_chain: []
11
16
 
12
- date: 2010-04-13 00:00:00 -06:00
17
+ date: 2010-04-19 00:00:00 +08:00
13
18
  default_executable:
14
19
  dependencies:
15
20
  - !ruby/object:Gem::Dependency
16
21
  name: rmagick
17
- type: :runtime
18
- version_requirement:
19
- version_requirements: !ruby/object:Gem::Requirement
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
20
24
  requirements:
21
25
  - - ">="
22
26
  - !ruby/object:Gem::Version
27
+ segments:
28
+ - 0
23
29
  version: "0"
24
- version:
30
+ type: :runtime
31
+ version_requirements: *id001
25
32
  description: css_sprite is a rails plugin/gem to generate css sprite image automatically.
26
33
  email: flyerhzm@gmail.com
27
34
  executables: []
@@ -42,12 +49,14 @@ files:
42
49
  - spec/css_sprite/sprite_spec.rb
43
50
  - spec/public/images/another_css_sprite/no_image
44
51
  - spec/public/images/css_sprite/gmail_logo.png
52
+ - spec/public/images/css_sprite/gmail_logo_active.png
45
53
  - spec/public/images/css_sprite/hotmail_logo.png
46
54
  - spec/public/images/css_sprite/icons/facebook_icon.png
47
55
  - spec/public/images/css_sprite/icons/facebook_icon_hover.png
48
56
  - spec/public/images/css_sprite/icons/twitter_icon.png
49
57
  - spec/public/images/css_sprite/icons/twitter_icon_hover.png
50
58
  - spec/public/images/css_sprite/logos/gmail_logo.png
59
+ - spec/public/images/css_sprite/logos/gmail_logo_active.png
51
60
  - spec/public/images/css_sprite/logos_hover/gmail_logo.png
52
61
  - spec/public/images/css_sprite/not_image.txt
53
62
  - spec/spec.opts
@@ -66,18 +75,20 @@ required_ruby_version: !ruby/object:Gem::Requirement
66
75
  requirements:
67
76
  - - ">="
68
77
  - !ruby/object:Gem::Version
78
+ segments:
79
+ - 0
69
80
  version: "0"
70
- version:
71
81
  required_rubygems_version: !ruby/object:Gem::Requirement
72
82
  requirements:
73
83
  - - ">="
74
84
  - !ruby/object:Gem::Version
85
+ segments:
86
+ - 0
75
87
  version: "0"
76
- version:
77
88
  requirements: []
78
89
 
79
90
  rubyforge_project:
80
- rubygems_version: 1.3.5
91
+ rubygems_version: 1.3.6
81
92
  signing_key:
82
93
  specification_version: 3
83
94
  summary: css_sprite is a rails plugin/gem to generate css sprite image automatically.