sprites 0.0.1.pre3 → 0.0.1.rc1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +18 -0
- data/features/step_definitions/common_steps.rb +1 -1
- data/lib/sprites/application.rb +21 -5
- data/lib/sprites/autoload.rb +1 -0
- data/lib/sprites/autoloader.rb +16 -0
- data/lib/sprites/configuration.rb +8 -17
- data/lib/sprites/rails/autoload.rb +13 -0
- data/lib/sprites/rails/sprites.rake +0 -8
- data/lib/sprites/rails.rb +18 -2
- data/lib/sprites/sprite.rb +44 -72
- data/lib/sprites/sprite_generators/chunky_png_generator.rb +6 -3
- data/lib/sprites/sprite_piece.rb +2 -2
- data/lib/sprites/sprite_pieces.rb +11 -13
- data/lib/sprites/sprites.rb +12 -26
- data/lib/sprites/stylesheet.rb +6 -2
- data/lib/sprites/test/sprite_generator_tester.rb +4 -3
- data/lib/sprites/version.rb +1 -1
- data/lib/sprites.rb +15 -6
- data/spec/fixtures/project1/config/sprites.rb +142 -142
- data/spec/fixtures/project1/public/images/sprite_images/foo/bar.png +0 -0
- data/spec/fixtures/project2/public/images/sprite_images/bas/bar.png +0 -0
- data/spec/fixtures/project2/public/images/sprite_images/bas/bas.png +0 -0
- data/spec/fixtures/project2/public/images/sprite_images/bas/bkgd_main_copy.png +0 -0
- data/spec/fixtures/project2/public/images/sprite_images/bas/foo.png +0 -0
- data/spec/fixtures/project2/public/images/sprite_images/bas/fubar.png +0 -0
- data/spec/fixtures/rails_project1/app/assets/images/sprite_images/bas/bar.png +0 -0
- data/spec/fixtures/rails_project1/app/assets/images/sprite_images/bas/bas.png +0 -0
- data/spec/fixtures/rails_project1/app/assets/images/sprite_images/bas/bkgd_main_copy.png +0 -0
- data/spec/fixtures/rails_project1/app/assets/images/sprite_images/bas/foo.png +0 -0
- data/spec/fixtures/rails_project1/app/assets/images/sprite_images/bas/fubar.png +0 -0
- data/spec/fixtures/rails_project1/config/application.rb +3 -0
- data/spec/fixtures/rails_project1/config/environment.rb +2 -1
- data/spec/fixtures/rails_project1/config/sprites.rb +90 -142
- data/spec/fixtures/rails_project2/Rakefile +5 -0
- data/spec/fixtures/rails_project2/app/assets/images/sprite_images/bas/bar.png +0 -0
- data/spec/fixtures/rails_project2/app/assets/images/sprite_images/bas/bas.png +0 -0
- data/spec/fixtures/rails_project2/app/assets/images/sprite_images/bas/bkgd_main_copy.png +0 -0
- data/spec/fixtures/rails_project2/app/assets/images/sprite_images/bas/foo.png +0 -0
- data/spec/fixtures/rails_project2/app/assets/images/sprite_images/bas/fubar.png +0 -0
- data/spec/fixtures/rails_project2/app/assets/images/sprite_images/buttons/btn-black-default-28.png +0 -0
- data/spec/fixtures/rails_project2/app/assets/images/sprite_images/buttons/btn-black-default-cap-28.png +0 -0
- data/spec/fixtures/rails_project2/app/assets/images/sprite_images/buttons/btn-black-default-cap-long.png +0 -0
- data/spec/fixtures/rails_project2/app/assets/images/sprite_images/buttons/btn-black-default.png +0 -0
- data/spec/fixtures/rails_project2/app/assets/images/sprite_images/buttons/btn-black-onclick-28.png +0 -0
- data/spec/fixtures/{rails_project1/app/assets/images/sprite_images/buttons/dark_background/btn-red-default-cap.png → rails_project2/app/assets/images/sprite_images/buttons/btn-black-onclick-cap-28.png} +0 -0
- data/spec/fixtures/rails_project2/app/assets/images/sprite_images/buttons/btn-black-onclick-cap-long.png +0 -0
- data/spec/fixtures/rails_project2/app/assets/images/sprite_images/buttons/btn-black-onclick.png +0 -0
- data/spec/fixtures/rails_project2/app/assets/images/sprite_images/buttons/btn-black-rollover-28.png +0 -0
- data/spec/fixtures/rails_project2/app/assets/images/sprite_images/buttons/btn-black-rollover-cap-28.png +0 -0
- data/spec/fixtures/rails_project2/app/assets/images/sprite_images/buttons/btn-black-rollover-cap-long.png +0 -0
- data/spec/fixtures/rails_project2/app/assets/images/sprite_images/buttons/btn-black-rollover.png +0 -0
- data/spec/fixtures/rails_project2/app/assets/images/sprite_images/buttons/btn-blackarrow-default.png +0 -0
- data/spec/fixtures/rails_project2/app/assets/images/sprite_images/buttons/btn-blackarrow-onclick.png +0 -0
- data/spec/fixtures/rails_project2/app/assets/images/sprite_images/buttons/btn-blackarrow-rollover.png +0 -0
- data/spec/fixtures/rails_project2/app/assets/images/sprite_images/buttons/btn-blue-default-cap.png +0 -0
- data/spec/fixtures/rails_project2/app/assets/images/sprite_images/buttons/btn-blue-default-drop.png +0 -0
- data/spec/fixtures/{rails_project1/app/assets/images/sprite_images/buttons/dark_background/btn-white-rollover-cap.png → rails_project2/app/assets/images/sprite_images/buttons/btn-blue-default-edge.png} +0 -0
- data/spec/fixtures/rails_project2/app/assets/images/sprite_images/buttons/btn-blue-default.png +0 -0
- data/spec/fixtures/rails_project2/app/assets/images/sprite_images/buttons/btn-blue-onclick-cap.png +0 -0
- data/spec/fixtures/rails_project2/app/assets/images/sprite_images/buttons/btn-blue-onclick-drop.png +0 -0
- data/spec/fixtures/{rails_project1/app/assets/images/sprite_images/buttons/dark_background/btn-white-onclick-cap.png → rails_project2/app/assets/images/sprite_images/buttons/btn-blue-onclick-edge.png} +0 -0
- data/spec/fixtures/rails_project2/app/assets/images/sprite_images/buttons/btn-blue-onclick.png +0 -0
- data/spec/fixtures/rails_project2/app/assets/images/sprite_images/buttons/btn-blue-rollover-cap.png +0 -0
- data/spec/fixtures/rails_project2/app/assets/images/sprite_images/buttons/btn-blue-rollover-drop.png +0 -0
- data/spec/fixtures/{rails_project1/app/assets/images/sprite_images/buttons/dark_background/btn-white-default-cap.png → rails_project2/app/assets/images/sprite_images/buttons/btn-blue-rollover-edge.png} +0 -0
- data/spec/fixtures/rails_project2/app/assets/images/sprite_images/buttons/btn-blue-rollover.png +0 -0
- data/spec/fixtures/rails_project2/app/assets/images/sprite_images/buttons/btn-green-default-cap.png +0 -0
- data/spec/fixtures/rails_project2/app/assets/images/sprite_images/buttons/btn-green-default-drop.png +0 -0
- data/spec/fixtures/rails_project2/app/assets/images/sprite_images/buttons/btn-green-default-edge.png +0 -0
- data/spec/fixtures/rails_project2/app/assets/images/sprite_images/buttons/btn-green-default.png +0 -0
- data/spec/fixtures/rails_project2/app/assets/images/sprite_images/buttons/btn-green-onclick-cap.png +0 -0
- data/spec/fixtures/rails_project2/app/assets/images/sprite_images/buttons/btn-green-onclick-drop.png +0 -0
- data/spec/fixtures/rails_project2/app/assets/images/sprite_images/buttons/btn-green-onclick-edge.png +0 -0
- data/spec/fixtures/rails_project2/app/assets/images/sprite_images/buttons/btn-green-onclick.png +0 -0
- data/spec/fixtures/rails_project2/app/assets/images/sprite_images/buttons/btn-green-rollover-cap.png +0 -0
- data/spec/fixtures/rails_project2/app/assets/images/sprite_images/buttons/btn-green-rollover-drop.png +0 -0
- data/spec/fixtures/rails_project2/app/assets/images/sprite_images/buttons/btn-green-rollover-edge.png +0 -0
- data/spec/fixtures/rails_project2/app/assets/images/sprite_images/buttons/btn-green-rollover.png +0 -0
- data/spec/fixtures/{rails_project1/app/assets/images/sprite_images/buttons/dark_background/btn-green-default-cap.png → rails_project2/app/assets/images/sprite_images/buttons/btn-red-default-cap.png} +0 -0
- data/spec/fixtures/rails_project2/app/assets/images/sprite_images/buttons/btn-red-default-drop.png +0 -0
- data/spec/fixtures/rails_project2/app/assets/images/sprite_images/buttons/btn-red-default-edge.png +0 -0
- data/spec/fixtures/rails_project2/app/assets/images/sprite_images/buttons/btn-red-default.png +0 -0
- data/spec/fixtures/{rails_project1/app/assets/images/sprite_images/buttons/dark_background/btn-green-onclick-cap.png → rails_project2/app/assets/images/sprite_images/buttons/btn-red-onclick-cap.png} +0 -0
- data/spec/fixtures/rails_project2/app/assets/images/sprite_images/buttons/btn-red-onclick-drop.png +0 -0
- data/spec/fixtures/rails_project2/app/assets/images/sprite_images/buttons/btn-red-onclick-edge.png +0 -0
- data/spec/fixtures/rails_project2/app/assets/images/sprite_images/buttons/btn-red-onclick.png +0 -0
- data/spec/fixtures/rails_project2/app/assets/images/sprite_images/buttons/btn-red-rollover-cap.png +0 -0
- data/spec/fixtures/rails_project2/app/assets/images/sprite_images/buttons/btn-red-rollover-drop.png +0 -0
- data/spec/fixtures/rails_project2/app/assets/images/sprite_images/buttons/btn-red-rollover-edge.png +0 -0
- data/spec/fixtures/rails_project2/app/assets/images/sprite_images/buttons/btn-red-rollover.png +0 -0
- data/spec/fixtures/rails_project2/app/assets/images/sprite_images/buttons/btn-trans-default-cap.png +0 -0
- data/spec/fixtures/rails_project2/app/assets/images/sprite_images/buttons/btn-trans-default-drop.png +0 -0
- data/spec/fixtures/rails_project2/app/assets/images/sprite_images/buttons/btn-trans-default-edge.png +0 -0
- data/spec/fixtures/rails_project2/app/assets/images/sprite_images/buttons/btn-trans-default.png +0 -0
- data/spec/fixtures/rails_project2/app/assets/images/sprite_images/buttons/btn-trans-onclick-cap.png +0 -0
- data/spec/fixtures/rails_project2/app/assets/images/sprite_images/buttons/btn-trans-onclick-drop.png +0 -0
- data/spec/fixtures/rails_project2/app/assets/images/sprite_images/buttons/btn-trans-onclick-edge.png +0 -0
- data/spec/fixtures/rails_project2/app/assets/images/sprite_images/buttons/btn-trans-onclick.png +0 -0
- data/spec/fixtures/rails_project2/app/assets/images/sprite_images/buttons/btn-trans-rollover-cap.png +0 -0
- data/spec/fixtures/rails_project2/app/assets/images/sprite_images/buttons/btn-trans-rollover-drop.png +0 -0
- data/spec/fixtures/rails_project2/app/assets/images/sprite_images/buttons/btn-trans-rollover-edge.png +0 -0
- data/spec/fixtures/rails_project2/app/assets/images/sprite_images/buttons/btn-trans-rollover.png +0 -0
- data/spec/fixtures/rails_project2/app/assets/images/sprite_images/buttons/btn-white-default-cap.png +0 -0
- data/spec/fixtures/rails_project2/app/assets/images/sprite_images/buttons/btn-white-default-drop.png +0 -0
- data/spec/fixtures/rails_project2/app/assets/images/sprite_images/buttons/btn-white-default-edge.png +0 -0
- data/spec/fixtures/rails_project2/app/assets/images/sprite_images/buttons/btn-white-default.png +0 -0
- data/spec/fixtures/{rails_project1/app/assets/images/sprite_images/buttons/dark_background/btn-blue-rollover.png → rails_project2/app/assets/images/sprite_images/buttons/btn-white-onclick-cap.png} +0 -0
- data/spec/fixtures/rails_project2/app/assets/images/sprite_images/buttons/btn-white-onclick-drop.png +0 -0
- data/spec/fixtures/rails_project2/app/assets/images/sprite_images/buttons/btn-white-onclick-edge.png +0 -0
- data/spec/fixtures/rails_project2/app/assets/images/sprite_images/buttons/btn-white-onclick.png +0 -0
- data/spec/fixtures/rails_project2/app/assets/images/sprite_images/buttons/btn-white-rollover-cap.png +0 -0
- data/spec/fixtures/rails_project2/app/assets/images/sprite_images/buttons/btn-white-rollover-drop.png +0 -0
- data/spec/fixtures/rails_project2/app/assets/images/sprite_images/buttons/btn-white-rollover-edge.png +0 -0
- data/spec/fixtures/rails_project2/app/assets/images/sprite_images/buttons/btn-white-rollover.png +0 -0
- data/spec/fixtures/rails_project2/app/assets/images/sprite_images/buttons/btn-yellow-default-cap.png +0 -0
- data/spec/fixtures/rails_project2/app/assets/images/sprite_images/buttons/btn-yellow-default-drop.png +0 -0
- data/spec/fixtures/rails_project2/app/assets/images/sprite_images/buttons/btn-yellow-default-edge.png +0 -0
- data/spec/fixtures/rails_project2/app/assets/images/sprite_images/buttons/btn-yellow-default.png +0 -0
- data/spec/fixtures/{rails_project1/app/assets/images/sprite_images/buttons/dark_background → rails_project2/app/assets/images/sprite_images/buttons}/btn-yellow-onclick-cap.png +0 -0
- data/spec/fixtures/rails_project2/app/assets/images/sprite_images/buttons/btn-yellow-onclick-drop.png +0 -0
- data/spec/fixtures/rails_project2/app/assets/images/sprite_images/buttons/btn-yellow-onclick-edge.png +0 -0
- data/spec/fixtures/rails_project2/app/assets/images/sprite_images/buttons/btn-yellow-onclick.png +0 -0
- data/spec/fixtures/{rails_project1/app/assets/images/sprite_images/buttons/dark_background → rails_project2/app/assets/images/sprite_images/buttons}/btn-yellow-rollover-cap.png +0 -0
- data/spec/fixtures/rails_project2/app/assets/images/sprite_images/buttons/btn-yellow-rollover-drop.png +0 -0
- data/spec/fixtures/rails_project2/app/assets/images/sprite_images/buttons/btn-yellow-rollover-edge.png +0 -0
- data/spec/fixtures/rails_project2/app/assets/images/sprite_images/buttons/btn-yellow-rollover.png +0 -0
- data/spec/fixtures/rails_project2/config/application.rb +61 -0
- data/spec/fixtures/rails_project2/config/boot.rb +6 -0
- data/spec/fixtures/rails_project2/config/environment.rb +7 -0
- data/spec/fixtures/rails_project2/config/sprites.rb +93 -0
- data/spec/fixtures/rails_project2/log/test.log +0 -0
- data/spec/integration/rails/rails_spec.rb +9 -1
- data/spec/lib/sprites/application_spec.rb +2 -12
- data/spec/lib/sprites/autoloader_spec.rb +21 -0
- data/spec/lib/sprites/configuration_spec.rb +7 -4
- data/spec/lib/sprites/sprite_generators/chunky_png_generator_spec.rb +4 -3
- data/spec/lib/sprites/sprite_piece_spec.rb +30 -6
- data/spec/lib/sprites/sprite_pieces_spec.rb +9 -7
- data/spec/lib/sprites/sprite_spec.rb +10 -64
- data/spec/lib/sprites/sprites_spec.rb +16 -16
- data/spec/lib/sprites/stylesheet_spec.rb +4 -5
- data/spec/lib/sprites/test/sprite_generator_tester_spec.rb +3 -3
- data/spec/lib/sprites_spec.rb +1 -1
- data/spec/spec_helper.rb +2 -1
- data/spec/support/sprites_helper.rb +142 -142
- metadata +229 -117
- data/lib/sprites/rails/railtie.rb +0 -10
- data/spec/fixtures/rails_project1/app/assets/images/sprite_images/buttons/dark_background/btn-black-default-28.png +0 -0
- data/spec/fixtures/rails_project1/app/assets/images/sprite_images/buttons/dark_background/btn-black-default-cap-28.png +0 -0
- data/spec/fixtures/rails_project1/app/assets/images/sprite_images/buttons/dark_background/btn-black-onclick-28.png +0 -0
- data/spec/fixtures/rails_project1/app/assets/images/sprite_images/buttons/dark_background/btn-black-onclick-cap-28.png +0 -0
- data/spec/fixtures/rails_project1/app/assets/images/sprite_images/buttons/dark_background/btn-black-rollover-28.png +0 -0
- data/spec/fixtures/rails_project1/app/assets/images/sprite_images/buttons/dark_background/btn-black-rollover-cap-28.png +0 -0
- data/spec/fixtures/rails_project1/app/assets/images/sprite_images/buttons/dark_background/btn-blue-default-cap.png +0 -0
- data/spec/fixtures/rails_project1/app/assets/images/sprite_images/buttons/dark_background/btn-blue-default.png +0 -0
- data/spec/fixtures/rails_project1/app/assets/images/sprite_images/buttons/dark_background/btn-blue-onclick-cap.png +0 -0
- data/spec/fixtures/rails_project1/app/assets/images/sprite_images/buttons/dark_background/btn-blue-onclick.png +0 -0
- data/spec/fixtures/rails_project1/app/assets/images/sprite_images/buttons/dark_background/btn-blue-rollover-cap.png +0 -0
- data/spec/fixtures/rails_project1/app/assets/images/sprite_images/buttons/dark_background/btn-green-default-drop.png +0 -0
- data/spec/fixtures/rails_project1/app/assets/images/sprite_images/buttons/dark_background/btn-green-default-edge.png +0 -0
- data/spec/fixtures/rails_project1/app/assets/images/sprite_images/buttons/dark_background/btn-green-default.png +0 -0
- data/spec/fixtures/rails_project1/app/assets/images/sprite_images/buttons/dark_background/btn-green-onclick-drop.png +0 -0
- data/spec/fixtures/rails_project1/app/assets/images/sprite_images/buttons/dark_background/btn-green-onclick-edge.png +0 -0
- data/spec/fixtures/rails_project1/app/assets/images/sprite_images/buttons/dark_background/btn-green-onclick.png +0 -0
- data/spec/fixtures/rails_project1/app/assets/images/sprite_images/buttons/dark_background/btn-green-rollover-cap.png +0 -0
- data/spec/fixtures/rails_project1/app/assets/images/sprite_images/buttons/dark_background/btn-green-rollover-drop.png +0 -0
- data/spec/fixtures/rails_project1/app/assets/images/sprite_images/buttons/dark_background/btn-green-rollover-edge.png +0 -0
- data/spec/fixtures/rails_project1/app/assets/images/sprite_images/buttons/dark_background/btn-green-rollover.png +0 -0
- data/spec/fixtures/rails_project1/app/assets/images/sprite_images/buttons/dark_background/btn-red-default.png +0 -0
- data/spec/fixtures/rails_project1/app/assets/images/sprite_images/buttons/dark_background/btn-red-onclick-cap.png +0 -0
- data/spec/fixtures/rails_project1/app/assets/images/sprite_images/buttons/dark_background/btn-red-onclick.png +0 -0
- data/spec/fixtures/rails_project1/app/assets/images/sprite_images/buttons/dark_background/btn-red-rollover-cap.png +0 -0
- data/spec/fixtures/rails_project1/app/assets/images/sprite_images/buttons/dark_background/btn-red-rollover.png +0 -0
- data/spec/fixtures/rails_project1/app/assets/images/sprite_images/buttons/dark_background/btn-trans-default-cap.png +0 -0
- data/spec/fixtures/rails_project1/app/assets/images/sprite_images/buttons/dark_background/btn-trans-default-drop.png +0 -0
- data/spec/fixtures/rails_project1/app/assets/images/sprite_images/buttons/dark_background/btn-trans-default-edge.png +0 -0
- data/spec/fixtures/rails_project1/app/assets/images/sprite_images/buttons/dark_background/btn-trans-default.png +0 -0
- data/spec/fixtures/rails_project1/app/assets/images/sprite_images/buttons/dark_background/btn-trans-onclick-cap.png +0 -0
- data/spec/fixtures/rails_project1/app/assets/images/sprite_images/buttons/dark_background/btn-trans-onclick-drop.png +0 -0
- data/spec/fixtures/rails_project1/app/assets/images/sprite_images/buttons/dark_background/btn-trans-onclick-edge.png +0 -0
- data/spec/fixtures/rails_project1/app/assets/images/sprite_images/buttons/dark_background/btn-trans-onclick.png +0 -0
- data/spec/fixtures/rails_project1/app/assets/images/sprite_images/buttons/dark_background/btn-trans-rollover-cap.png +0 -0
- data/spec/fixtures/rails_project1/app/assets/images/sprite_images/buttons/dark_background/btn-trans-rollover-drop.png +0 -0
- data/spec/fixtures/rails_project1/app/assets/images/sprite_images/buttons/dark_background/btn-trans-rollover-edge.png +0 -0
- data/spec/fixtures/rails_project1/app/assets/images/sprite_images/buttons/dark_background/btn-trans-rollover.png +0 -0
- data/spec/fixtures/rails_project1/app/assets/images/sprite_images/buttons/dark_background/btn-white-default.png +0 -0
- data/spec/fixtures/rails_project1/app/assets/images/sprite_images/buttons/dark_background/btn-white-onclick.png +0 -0
- data/spec/fixtures/rails_project1/app/assets/images/sprite_images/buttons/dark_background/btn-white-rollover.png +0 -0
- data/spec/fixtures/rails_project1/app/assets/images/sprite_images/buttons/dark_background/btn-yellow-default-cap.png +0 -0
- data/spec/fixtures/rails_project1/app/assets/images/sprite_images/buttons/dark_background/btn-yellow-default.png +0 -0
- data/spec/fixtures/rails_project1/app/assets/images/sprite_images/buttons/dark_background/btn-yellow-onclick.png +0 -0
- data/spec/fixtures/rails_project1/app/assets/images/sprite_images/buttons/dark_background/btn-yellow-rollover.png +0 -0
data/README.md
CHANGED
@@ -0,0 +1,18 @@
|
|
1
|
+
# Sprites
|
2
|
+
|
3
|
+
Sprites is a library that let's you define the sprites for your application with configuration or convention. Sprites will generate your sprites, and a corresponding stylesheet for each using either the cli or from within a Rails application.
|
4
|
+
|
5
|
+
## Project Structure
|
6
|
+
|
7
|
+
|
|
8
|
+
|\_config
|
9
|
+
| \_sprites.rb
|
10
|
+
\_public
|
11
|
+
\_images
|
12
|
+
\_sprite_images
|
13
|
+
|\_sprite_name1
|
14
|
+
| |\_blue_icon.png
|
15
|
+
| \_green_icon.png
|
16
|
+
\_sprite_name2
|
17
|
+
|\_blue_icon.png
|
18
|
+
\_green_icon.png
|
data/lib/sprites/application.rb
CHANGED
@@ -18,8 +18,7 @@ module Sprites
|
|
18
18
|
# === Example
|
19
19
|
# sprites = Sprites.new
|
20
20
|
def initialize(configuration = ::Sprites.configuration)
|
21
|
-
@
|
22
|
-
@sprites = Sprites.new
|
21
|
+
@sprites = Sprites.new(configuration)
|
23
22
|
end
|
24
23
|
|
25
24
|
# The +define+ method provides access to the dsl
|
@@ -33,12 +32,29 @@ module Sprites
|
|
33
32
|
|
34
33
|
|
35
34
|
# The +sprite+ method adds sprites to the application
|
35
|
+
#
|
36
36
|
# === Example
|
37
37
|
# Sprites.application.define do
|
38
|
-
#
|
38
|
+
# sprite :foo
|
39
39
|
# end
|
40
|
-
|
41
|
-
|
40
|
+
#
|
41
|
+
# options:
|
42
|
+
# => :orientation - sprite orientation
|
43
|
+
# default: :vertical
|
44
|
+
# => :path - path to sprite relative to config.sprites_path
|
45
|
+
# default: public/images/sprites/{name}.png
|
46
|
+
# => :stylesheet_path - path to stylesheet
|
47
|
+
# default: public/stylesheets/sprites/{name}.css
|
48
|
+
# => :url - path to use in background attribute in stylesheet
|
49
|
+
# default: /images/sprites/{name}.png
|
50
|
+
# => :auto_define - whether or not to auto-define the sprite based on directory contents
|
51
|
+
# default: true
|
52
|
+
# => :class_prefix - a css string to prepend to all css classes define or autogenerated
|
53
|
+
# examples: '.icon', '.contacts '
|
54
|
+
# default: ''
|
55
|
+
#
|
56
|
+
def sprite(name, options = {}, &blk)
|
57
|
+
sprites.add(name, options, &blk)
|
42
58
|
end
|
43
59
|
end
|
44
60
|
end
|
@@ -0,0 +1 @@
|
|
1
|
+
::Sprites::Autoloader.new.autoload
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'sprites/sprite'
|
2
|
+
|
3
|
+
module Sprites
|
4
|
+
class Autoloader
|
5
|
+
def initialize(configuration = ::Sprites.configuration)
|
6
|
+
@configuration = configuration
|
7
|
+
end
|
8
|
+
|
9
|
+
def autoload
|
10
|
+
Dir[File.join(@configuration.sprite_pieces_path, '*')].each do |sprite_path|
|
11
|
+
sprite = Sprite.new(File.basename(sprite_path).intern).configure
|
12
|
+
::Sprites.application.sprites.add(sprite) if File.directory?(sprite_path)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -8,8 +8,14 @@ module Sprites
|
|
8
8
|
'sprite_pieces_path' => 'public/images/sprite_images'
|
9
9
|
}
|
10
10
|
|
11
|
+
attr_accessor *FIELDS
|
12
|
+
|
11
13
|
def initialize
|
12
|
-
DEFAULT_CONFIGURATION.each {|k,v| self.send(k, v)}
|
14
|
+
DEFAULT_CONFIGURATION.each {|k,v| self.send(:"#{k}=", v)}
|
15
|
+
end
|
16
|
+
|
17
|
+
def config
|
18
|
+
self
|
13
19
|
end
|
14
20
|
|
15
21
|
def configure(&blk)
|
@@ -23,26 +29,11 @@ module Sprites
|
|
23
29
|
end
|
24
30
|
end
|
25
31
|
|
26
|
-
FIELDS.each do |meth|
|
27
|
-
eval <<-EVAL
|
28
|
-
def #{meth}(*args)
|
29
|
-
val, *_ = args
|
30
|
-
|
31
|
-
if val
|
32
|
-
@#{meth} = val
|
33
|
-
return self
|
34
|
-
end
|
35
|
-
|
36
|
-
@#{meth}
|
37
|
-
end
|
38
|
-
EVAL
|
39
|
-
end
|
40
|
-
|
41
32
|
def self.new_for_command_line_options(options)
|
42
33
|
config = new
|
43
34
|
options.each do |k, v|
|
44
35
|
if FIELDS.include?(k.to_s)
|
45
|
-
config.send(k, v)
|
36
|
+
config.send(:"#{k}=", v)
|
46
37
|
end
|
47
38
|
end
|
48
39
|
config
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'sprites/autoloader'
|
2
|
+
|
3
|
+
module Sprites
|
4
|
+
unless defined?(Sprites::Railtie)
|
5
|
+
raise 'Require "sprites/rails" before requiring "sprites/rails/autoload"'
|
6
|
+
end
|
7
|
+
|
8
|
+
class Railtie
|
9
|
+
initializer 'sprites.autoload' do
|
10
|
+
Sprites::Autoloader.new.autoload
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -5,14 +5,6 @@ include Sprites
|
|
5
5
|
|
6
6
|
desc "Generate sprites and stylesheets"
|
7
7
|
task :sprites => :environment do
|
8
|
-
assets_root = Rails.application.config.assets[:enabled] ? 'app/assets' : 'public'
|
9
|
-
|
10
|
-
::Sprites.configure do
|
11
|
-
sprites_path Rails.root.join(assets_root, 'images/sprites')
|
12
|
-
sprite_stylesheets_path Rails.root.join(assets_root, 'stylesheets/sprites')
|
13
|
-
sprite_pieces_path Rails.root.join(assets_root, 'images/sprite_images')
|
14
|
-
end unless ::Sprites.configuration.configured?
|
15
|
-
|
16
8
|
unless (def_file_path = Rails.root.join('config/sprites.rb')).exist?
|
17
9
|
raise CliApplication::DefinitionFileNotFound
|
18
10
|
end
|
data/lib/sprites/rails.rb
CHANGED
@@ -1,3 +1,19 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
require 'rails/railtie'
|
2
|
+
|
3
|
+
module Sprites
|
4
|
+
class Railtie < ::Rails::Railtie
|
5
|
+
rake_tasks do
|
6
|
+
load File.expand_path('../rails/sprites.rake', __FILE__)
|
7
|
+
end
|
8
|
+
|
9
|
+
initializer 'sprites._rails-configuration' do
|
10
|
+
assets_root = Rails.application.config.assets[:enabled] ? 'app/assets' : 'public'
|
11
|
+
|
12
|
+
::Sprites.configure do
|
13
|
+
config.sprites_path = Rails.root.join(assets_root, 'images/sprites')
|
14
|
+
config.sprite_stylesheets_path = Rails.root.join(assets_root, 'stylesheets/sprites')
|
15
|
+
config.sprite_pieces_path = Rails.root.join(assets_root, 'images/sprite_images')
|
16
|
+
end unless ::Sprites.configuration.configured?
|
17
|
+
end
|
18
|
+
end
|
3
19
|
end
|
data/lib/sprites/sprite.rb
CHANGED
@@ -1,6 +1,5 @@
|
|
1
1
|
require 'fileutils'
|
2
|
-
require 'active_support/core_ext
|
3
|
-
require 'active_support/core_ext/object/try'
|
2
|
+
require 'active_support/core_ext'
|
4
3
|
require 'sprites/sprite_pieces'
|
5
4
|
require 'sprites/sprite_piece'
|
6
5
|
require 'sprites/stylesheet'
|
@@ -13,48 +12,56 @@ module Sprites
|
|
13
12
|
HORIZONTAL = 2
|
14
13
|
end
|
15
14
|
|
16
|
-
OPTIONS = [:orientation]
|
17
|
-
|
18
15
|
DEFAULT_OPTIONS = {
|
19
|
-
:orientation => Orientations::VERTICAL
|
16
|
+
:orientation => Orientations::VERTICAL,
|
17
|
+
:path => lambda {|sprite| "#{sprite.name}.png" },
|
18
|
+
:stylesheet_path => lambda {|sprite| sprite.stylesheet.path },
|
19
|
+
:url => lambda {|sprite| sprite.stylesheet.url },
|
20
|
+
:auto_define => true,
|
21
|
+
:css_prefix => ''
|
20
22
|
}
|
21
23
|
|
22
24
|
attr_reader :name, :sprite_pieces, :stylesheet
|
25
|
+
attr_writer :path, :stylesheet_path, :url, :auto_define, :css_prefix
|
23
26
|
|
24
|
-
def initialize(name)
|
25
|
-
@name = name
|
27
|
+
def initialize(name, configuration = ::Sprites.configuration)
|
28
|
+
@name, @configuration = name, configuration
|
26
29
|
@sprite_pieces = SpritePieces.new
|
27
|
-
@
|
28
|
-
set_options
|
30
|
+
@stylesheet = Stylesheet.new(self)
|
29
31
|
end
|
30
32
|
|
31
|
-
def
|
32
|
-
|
33
|
-
@
|
34
|
-
@stylesheet ||= Stylesheet.new(css_path, self)
|
35
|
-
@options.delete(@path.to_s)
|
36
|
-
set_options
|
37
|
-
|
38
|
-
instance_eval(&blk) if block_given?
|
39
|
-
self
|
33
|
+
def orientation=(val)
|
34
|
+
raise InvalidOrientation unless [Orientations::VERTICAL, Orientations::HORIZONTAL].include?(val)
|
35
|
+
@orientation = val
|
40
36
|
end
|
41
37
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
38
|
+
[:path, :stylesheet_path, :url].each do |attribute|
|
39
|
+
eval <<-EVAL
|
40
|
+
def #{attribute}
|
41
|
+
val = @#{attribute} || DEFAULT_OPTIONS[:#{attribute}]
|
42
|
+
if val.respond_to?(:call)
|
43
|
+
val.call(self)
|
44
|
+
else
|
45
|
+
val
|
46
|
+
end
|
47
|
+
end
|
48
|
+
EVAL
|
48
49
|
end
|
49
50
|
|
50
|
-
def
|
51
|
-
|
52
|
-
|
51
|
+
def method_missing(meth, *args)
|
52
|
+
unless [:orientation, :auto_define?, :css_prefix].include?(meth)
|
53
|
+
super
|
54
|
+
else
|
55
|
+
instance_variable_get(:"@#{meth.to_s.chomp('?')}") || DEFAULT_OPTIONS[:"#{meth.to_s.chomp('?')}"]
|
56
|
+
end
|
53
57
|
end
|
54
58
|
|
55
|
-
def
|
56
|
-
|
57
|
-
|
59
|
+
def configure(options = {}, &blk)
|
60
|
+
options.symbolize_keys!.assert_valid_keys(*DEFAULT_OPTIONS.keys)
|
61
|
+
options.each {|k,v| send(:"#{k}=", v)}
|
62
|
+
auto_define! if auto_define?
|
63
|
+
instance_eval(&blk) if block_given?
|
64
|
+
self
|
58
65
|
end
|
59
66
|
|
60
67
|
def write_stylesheet(configuration, sprite_pieces = @sprite_pieces)
|
@@ -65,26 +72,8 @@ module Sprites
|
|
65
72
|
end
|
66
73
|
end
|
67
74
|
|
68
|
-
def
|
69
|
-
|
70
|
-
@stylesheet.path
|
71
|
-
end
|
72
|
-
|
73
|
-
def sprite_piece(options)
|
74
|
-
@sprite_pieces.add(options)
|
75
|
-
end
|
76
|
-
|
77
|
-
def orientation(*args)
|
78
|
-
val, *_ = args
|
79
|
-
if val
|
80
|
-
unless [Orientations::VERTICAL, Orientations::HORIZONTAL].include?(val)
|
81
|
-
raise InvalidOrientation
|
82
|
-
end
|
83
|
-
@orientation = val
|
84
|
-
return self
|
85
|
-
end
|
86
|
-
|
87
|
-
@orientation
|
75
|
+
def sprite_piece(path, css_class, options = {})
|
76
|
+
@sprite_pieces.add(path, css_class, options)
|
88
77
|
end
|
89
78
|
|
90
79
|
def self.sprite_full_path(configuration, sprite)
|
@@ -95,31 +84,14 @@ module Sprites
|
|
95
84
|
"/#{sprite_full_path(configuration, sprite)}"
|
96
85
|
end
|
97
86
|
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
@paths && @paths.last || @path.to_s.gsub(/png$/, 'css')
|
102
|
-
end
|
103
|
-
|
104
|
-
def paths_for_options(options)
|
105
|
-
@paths ||= options.find {|k,v| k.is_a?(String) }
|
106
|
-
end
|
107
|
-
|
108
|
-
def path_for_arguments(options, *args)
|
109
|
-
if args.first.is_a?(Symbol) || (args.empty? && !paths_for_options(options).try(:first))
|
110
|
-
"#{args.first || @name}.png"
|
111
|
-
elsif args.first.is_a?(String)
|
112
|
-
args.first
|
113
|
-
else
|
114
|
-
path = paths_for_options(options).first
|
115
|
-
raise ArgumentError, "Path is not a string. See usage." unless path.is_a?(String)
|
116
|
-
path
|
87
|
+
def auto_define!
|
88
|
+
Dir[File.join(@configuration.sprite_pieces_path, name.to_s, '*.png')].each do |path|
|
89
|
+
sprite_piece "#{name}/#{File.basename(path)}", ".#{File.basename(path, File.extname(path))}"
|
117
90
|
end
|
118
91
|
end
|
119
92
|
|
120
|
-
def
|
121
|
-
|
122
|
-
@options.each {|k,v| send(k,v) if Sprite::OPTIONS.include?(k) }
|
93
|
+
def stylesheet_path
|
94
|
+
@stylesheet_path || path.to_s.gsub(/png$/, 'css')
|
123
95
|
end
|
124
96
|
end
|
125
97
|
end
|
@@ -79,8 +79,8 @@ module Sprites
|
|
79
79
|
image_list = sprite_pieces.map do |sp|
|
80
80
|
sprite_piece_path = SpritePiece.sprite_piece_full_path(@configuration, sp)
|
81
81
|
sp_image = ChunkyPNG::Image.from_file(sprite_piece_path)
|
82
|
-
sp.
|
83
|
-
sp.
|
82
|
+
sp.left = orientation == Sprite::Orientations::VERTICAL ? 0 : width
|
83
|
+
sp.top = orientation == Sprite::Orientations::VERTICAL ? height : 0
|
84
84
|
sp.width = sp_image.width
|
85
85
|
sp.height = sp_image.height
|
86
86
|
|
@@ -96,10 +96,13 @@ module Sprites
|
|
96
96
|
@sprite = ChunkyPNG::Image.new(width, height, ChunkyPNG::Color::TRANSPARENT)
|
97
97
|
|
98
98
|
image_list.each_with_index do |image, i|
|
99
|
-
@sprite.replace!(image, sprite_pieces.element_at(i).
|
99
|
+
@sprite.replace!(image, sprite_pieces.element_at(i).left, sprite_pieces.element_at(i).top)
|
100
100
|
# $stdout << '.' if verbose
|
101
101
|
end
|
102
102
|
# $stdout << "\n" if verbose
|
103
|
+
# rescue
|
104
|
+
# debugger
|
105
|
+
# raise
|
103
106
|
end
|
104
107
|
|
105
108
|
def write(path, quality = nil)
|
data/lib/sprites/sprite_piece.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
module Sprites
|
2
2
|
class SpritePiece
|
3
3
|
attr_reader :path
|
4
|
-
attr_accessor :sprite, :css_selector, :x, :y, :width, :height
|
4
|
+
attr_accessor :sprite, :css_selector, :x, :y, :width, :height, :top, :left
|
5
5
|
alias_method :selector, :css_selector
|
6
6
|
|
7
7
|
def initialize(path)
|
@@ -21,7 +21,7 @@ module Sprites
|
|
21
21
|
display:block;
|
22
22
|
width:#{width}px;
|
23
23
|
height:#{height}px;
|
24
|
-
background:url('#{sprite_css_path || Sprite.sprite_css_path(configuration, sprite)}') no-repeat #{negative_pixelize(
|
24
|
+
background:url('#{sprite_css_path || Sprite.sprite_css_path(configuration, sprite)}') no-repeat #{x || negative_pixelize(left)} #{y || negative_pixelize(top)};
|
25
25
|
}
|
26
26
|
CSS
|
27
27
|
end
|
@@ -2,26 +2,32 @@ require 'active_support/ordered_hash'
|
|
2
2
|
|
3
3
|
module Sprites
|
4
4
|
class SpritePieces
|
5
|
+
include Enumerable
|
6
|
+
|
5
7
|
def initialize
|
6
8
|
@sprite_pieces = ActiveSupport::OrderedHash.new do |sprite_pieces, path|
|
7
9
|
sprite_pieces[path] = SpritePiece.new(path)
|
8
10
|
end
|
9
11
|
end
|
10
12
|
|
11
|
-
def add(options)
|
12
|
-
path, css_selector = options.find {|k,v| k.is_a?(String)}
|
13
|
+
def add(path, css_selector, options = {})
|
13
14
|
@sprite_pieces[path].css_selector = css_selector
|
14
|
-
@sprite_pieces[path]
|
15
|
+
options.each {|k,v| @sprite_pieces[path].send(:"#{k}=", v) }
|
16
|
+
self
|
15
17
|
end
|
16
18
|
|
17
|
-
def
|
18
|
-
|
19
|
+
def each(*args, &blk)
|
20
|
+
all.each(*args, &blk)
|
19
21
|
end
|
20
22
|
|
21
23
|
def empty?
|
22
24
|
@sprite_pieces.empty?
|
23
25
|
end
|
24
26
|
|
27
|
+
def all
|
28
|
+
@sprite_pieces.values
|
29
|
+
end
|
30
|
+
|
25
31
|
def [](val)
|
26
32
|
@sprite_pieces.has_key?(val) ?
|
27
33
|
@sprite_pieces[val] :
|
@@ -32,14 +38,6 @@ module Sprites
|
|
32
38
|
@sprite_pieces.values[index]
|
33
39
|
end
|
34
40
|
|
35
|
-
def map(*args, &blk)
|
36
|
-
@sprite_pieces.values.map(*args, &blk)
|
37
|
-
end
|
38
|
-
|
39
|
-
def find(*args, &blk)
|
40
|
-
@sprite_pieces.values.find(*args, &blk)
|
41
|
-
end
|
42
|
-
|
43
41
|
def css(configuration = ::Sprites.configuration, sprite = @sprite)
|
44
42
|
@sprite_pieces.values.map {|sp| sp.css(configuration, sprite)}.join("\n")
|
45
43
|
end
|
data/lib/sprites/sprites.rb
CHANGED
@@ -2,9 +2,10 @@ require 'sprites/sprite'
|
|
2
2
|
|
3
3
|
module Sprites
|
4
4
|
class Sprites
|
5
|
-
def initialize
|
5
|
+
def initialize(configuration)
|
6
|
+
@configuration = configuration
|
6
7
|
@sprites = Hash.new do |sprites, name|
|
7
|
-
sprites[name] = Sprite.new(name)
|
8
|
+
sprites[name] = Sprite.new(name, configuration)
|
8
9
|
end
|
9
10
|
end
|
10
11
|
|
@@ -27,35 +28,20 @@ module Sprites
|
|
27
28
|
end
|
28
29
|
|
29
30
|
def count
|
30
|
-
@sprites.
|
31
|
+
@sprites.count
|
31
32
|
end
|
32
33
|
|
33
|
-
def add(
|
34
|
-
|
35
|
-
|
36
|
-
@sprites[name]
|
37
|
-
|
38
|
-
@sprites[
|
34
|
+
def add(name_or_sprite, options = {}, &blk)
|
35
|
+
sprite = case name_or_sprite
|
36
|
+
when Sprite
|
37
|
+
@sprites[name_or_sprite.name] = name_or_sprite
|
38
|
+
when Symbol, String
|
39
|
+
@sprites[name_or_sprite.to_sym]
|
39
40
|
else
|
40
|
-
raise ArgumentError
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
private
|
45
|
-
|
46
|
-
def sprite_name(*args)
|
47
|
-
return args.first if args.first.is_a?(Symbol)
|
48
|
-
|
49
|
-
path = case args.first
|
50
|
-
when String
|
51
|
-
args.first
|
52
|
-
when Hash
|
53
|
-
# This is for when sprite is used like,
|
54
|
-
# sprite 'path_to_sprite' => 'path_to_stylesheet', :option => value
|
55
|
-
args.first.find {|k,v| k.is_a?(String)}.first
|
41
|
+
raise ArgumentError
|
56
42
|
end
|
57
43
|
|
58
|
-
|
44
|
+
sprite.configure(options, &blk)
|
59
45
|
end
|
60
46
|
end
|
61
47
|
end
|
data/lib/sprites/stylesheet.rb
CHANGED
@@ -5,8 +5,12 @@ module Sprites
|
|
5
5
|
attr_reader :path
|
6
6
|
attr_accessor :sprite_pieces
|
7
7
|
|
8
|
-
def initialize(
|
9
|
-
@
|
8
|
+
def initialize(sprite)
|
9
|
+
@sprite = sprite
|
10
|
+
end
|
11
|
+
|
12
|
+
def path
|
13
|
+
@sprite.stylesheet_path
|
10
14
|
end
|
11
15
|
|
12
16
|
def self.stylesheet_full_path(configuration, stylesheet)
|
@@ -24,12 +24,12 @@ module Sprites
|
|
24
24
|
end
|
25
25
|
|
26
26
|
private
|
27
|
-
def test_generate
|
27
|
+
def test_generate(gem_root = GEM_ROOT)
|
28
28
|
sprite_pieces = @sprite.sprite_pieces
|
29
29
|
sprite_image = Image.read(Sprite.sprite_full_path(configuration, sprite)).first
|
30
30
|
|
31
31
|
stylesheet_path = Stylesheet.stylesheet_full_path(configuration, sprite.stylesheet)
|
32
|
-
stylesheet_absolute_path =
|
32
|
+
stylesheet_absolute_path = gem_root.join(stylesheet_path)
|
33
33
|
parser = CssParser::Parser.new
|
34
34
|
parser.load_file!(File.basename(stylesheet_absolute_path), File.dirname(stylesheet_absolute_path), :screen)
|
35
35
|
|
@@ -52,7 +52,7 @@ module Sprites
|
|
52
52
|
percent_diferences = sprite_pieces_with_selector_data.map do |sp, selector_data|
|
53
53
|
begin
|
54
54
|
raise selector_data.inspect if sp.nil?
|
55
|
-
sprite_piece_path =
|
55
|
+
sprite_piece_path = gem_root.join(SpritePiece.sprite_piece_full_path(configuration, sp))
|
56
56
|
sprite_piece_image = Image.read(sprite_piece_path).first
|
57
57
|
|
58
58
|
curr_sprite_image = sprite_image.crop(
|
@@ -61,6 +61,7 @@ module Sprites
|
|
61
61
|
selector_data.width,
|
62
62
|
selector_data.height
|
63
63
|
)
|
64
|
+
|
64
65
|
diff_iamge, pd = curr_sprite_image.compare_channel(sprite_piece_image, MeanSquaredErrorMetric)
|
65
66
|
pd
|
66
67
|
ensure
|
data/lib/sprites/version.rb
CHANGED
data/lib/sprites.rb
CHANGED
@@ -1,8 +1,17 @@
|
|
1
|
+
require 'active_support'
|
2
|
+
require 'active_support/core_ext'
|
1
3
|
require "sprites/version"
|
2
|
-
require 'sprites/application'
|
3
|
-
require 'sprites/configuration'
|
4
4
|
|
5
5
|
module Sprites
|
6
|
+
extend ActiveSupport::Autoload
|
7
|
+
|
8
|
+
autoload :Application
|
9
|
+
autoload :Configuration
|
10
|
+
autoload :Sprites
|
11
|
+
autoload :Sprite
|
12
|
+
autoload :SpritePieces
|
13
|
+
autoload :SpritePiece
|
14
|
+
autoload :Stylesheet
|
6
15
|
autoload :ChunkyPngGenerator, 'sprites/sprite_generators/chunky_png_generator'
|
7
16
|
|
8
17
|
class << self
|
@@ -10,15 +19,15 @@ module Sprites
|
|
10
19
|
@application ||= Application.new(configuration)
|
11
20
|
end
|
12
21
|
|
22
|
+
def define(&blk)
|
23
|
+
application.define(&blk)
|
24
|
+
end
|
25
|
+
|
13
26
|
def configure(&blk)
|
14
27
|
@configuration ||= Configuration.new
|
15
28
|
@configuration.configure(&blk) if block_given?
|
16
29
|
@configuration
|
17
30
|
end
|
18
31
|
alias_method :configuration, :configure
|
19
|
-
|
20
|
-
def gem_root
|
21
|
-
Pathname.new(File.expand_path('../..', __FILE__))
|
22
|
-
end
|
23
32
|
end
|
24
33
|
end
|