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.
Files changed (192) hide show
  1. data/README.md +18 -0
  2. data/features/step_definitions/common_steps.rb +1 -1
  3. data/lib/sprites/application.rb +21 -5
  4. data/lib/sprites/autoload.rb +1 -0
  5. data/lib/sprites/autoloader.rb +16 -0
  6. data/lib/sprites/configuration.rb +8 -17
  7. data/lib/sprites/rails/autoload.rb +13 -0
  8. data/lib/sprites/rails/sprites.rake +0 -8
  9. data/lib/sprites/rails.rb +18 -2
  10. data/lib/sprites/sprite.rb +44 -72
  11. data/lib/sprites/sprite_generators/chunky_png_generator.rb +6 -3
  12. data/lib/sprites/sprite_piece.rb +2 -2
  13. data/lib/sprites/sprite_pieces.rb +11 -13
  14. data/lib/sprites/sprites.rb +12 -26
  15. data/lib/sprites/stylesheet.rb +6 -2
  16. data/lib/sprites/test/sprite_generator_tester.rb +4 -3
  17. data/lib/sprites/version.rb +1 -1
  18. data/lib/sprites.rb +15 -6
  19. data/spec/fixtures/project1/config/sprites.rb +142 -142
  20. data/spec/fixtures/project1/public/images/sprite_images/foo/bar.png +0 -0
  21. data/spec/fixtures/project2/public/images/sprite_images/bas/bar.png +0 -0
  22. data/spec/fixtures/project2/public/images/sprite_images/bas/bas.png +0 -0
  23. data/spec/fixtures/project2/public/images/sprite_images/bas/bkgd_main_copy.png +0 -0
  24. data/spec/fixtures/project2/public/images/sprite_images/bas/foo.png +0 -0
  25. data/spec/fixtures/project2/public/images/sprite_images/bas/fubar.png +0 -0
  26. data/spec/fixtures/rails_project1/app/assets/images/sprite_images/bas/bar.png +0 -0
  27. data/spec/fixtures/rails_project1/app/assets/images/sprite_images/bas/bas.png +0 -0
  28. data/spec/fixtures/rails_project1/app/assets/images/sprite_images/bas/bkgd_main_copy.png +0 -0
  29. data/spec/fixtures/rails_project1/app/assets/images/sprite_images/bas/foo.png +0 -0
  30. data/spec/fixtures/rails_project1/app/assets/images/sprite_images/bas/fubar.png +0 -0
  31. data/spec/fixtures/rails_project1/config/application.rb +3 -0
  32. data/spec/fixtures/rails_project1/config/environment.rb +2 -1
  33. data/spec/fixtures/rails_project1/config/sprites.rb +90 -142
  34. data/spec/fixtures/rails_project2/Rakefile +5 -0
  35. data/spec/fixtures/rails_project2/app/assets/images/sprite_images/bas/bar.png +0 -0
  36. data/spec/fixtures/rails_project2/app/assets/images/sprite_images/bas/bas.png +0 -0
  37. data/spec/fixtures/rails_project2/app/assets/images/sprite_images/bas/bkgd_main_copy.png +0 -0
  38. data/spec/fixtures/rails_project2/app/assets/images/sprite_images/bas/foo.png +0 -0
  39. data/spec/fixtures/rails_project2/app/assets/images/sprite_images/bas/fubar.png +0 -0
  40. data/spec/fixtures/rails_project2/app/assets/images/sprite_images/buttons/btn-black-default-28.png +0 -0
  41. data/spec/fixtures/rails_project2/app/assets/images/sprite_images/buttons/btn-black-default-cap-28.png +0 -0
  42. data/spec/fixtures/rails_project2/app/assets/images/sprite_images/buttons/btn-black-default-cap-long.png +0 -0
  43. data/spec/fixtures/rails_project2/app/assets/images/sprite_images/buttons/btn-black-default.png +0 -0
  44. data/spec/fixtures/rails_project2/app/assets/images/sprite_images/buttons/btn-black-onclick-28.png +0 -0
  45. 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
  46. data/spec/fixtures/rails_project2/app/assets/images/sprite_images/buttons/btn-black-onclick-cap-long.png +0 -0
  47. data/spec/fixtures/rails_project2/app/assets/images/sprite_images/buttons/btn-black-onclick.png +0 -0
  48. data/spec/fixtures/rails_project2/app/assets/images/sprite_images/buttons/btn-black-rollover-28.png +0 -0
  49. data/spec/fixtures/rails_project2/app/assets/images/sprite_images/buttons/btn-black-rollover-cap-28.png +0 -0
  50. data/spec/fixtures/rails_project2/app/assets/images/sprite_images/buttons/btn-black-rollover-cap-long.png +0 -0
  51. data/spec/fixtures/rails_project2/app/assets/images/sprite_images/buttons/btn-black-rollover.png +0 -0
  52. data/spec/fixtures/rails_project2/app/assets/images/sprite_images/buttons/btn-blackarrow-default.png +0 -0
  53. data/spec/fixtures/rails_project2/app/assets/images/sprite_images/buttons/btn-blackarrow-onclick.png +0 -0
  54. data/spec/fixtures/rails_project2/app/assets/images/sprite_images/buttons/btn-blackarrow-rollover.png +0 -0
  55. data/spec/fixtures/rails_project2/app/assets/images/sprite_images/buttons/btn-blue-default-cap.png +0 -0
  56. data/spec/fixtures/rails_project2/app/assets/images/sprite_images/buttons/btn-blue-default-drop.png +0 -0
  57. 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
  58. data/spec/fixtures/rails_project2/app/assets/images/sprite_images/buttons/btn-blue-default.png +0 -0
  59. data/spec/fixtures/rails_project2/app/assets/images/sprite_images/buttons/btn-blue-onclick-cap.png +0 -0
  60. data/spec/fixtures/rails_project2/app/assets/images/sprite_images/buttons/btn-blue-onclick-drop.png +0 -0
  61. 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
  62. data/spec/fixtures/rails_project2/app/assets/images/sprite_images/buttons/btn-blue-onclick.png +0 -0
  63. data/spec/fixtures/rails_project2/app/assets/images/sprite_images/buttons/btn-blue-rollover-cap.png +0 -0
  64. data/spec/fixtures/rails_project2/app/assets/images/sprite_images/buttons/btn-blue-rollover-drop.png +0 -0
  65. 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
  66. data/spec/fixtures/rails_project2/app/assets/images/sprite_images/buttons/btn-blue-rollover.png +0 -0
  67. data/spec/fixtures/rails_project2/app/assets/images/sprite_images/buttons/btn-green-default-cap.png +0 -0
  68. data/spec/fixtures/rails_project2/app/assets/images/sprite_images/buttons/btn-green-default-drop.png +0 -0
  69. data/spec/fixtures/rails_project2/app/assets/images/sprite_images/buttons/btn-green-default-edge.png +0 -0
  70. data/spec/fixtures/rails_project2/app/assets/images/sprite_images/buttons/btn-green-default.png +0 -0
  71. data/spec/fixtures/rails_project2/app/assets/images/sprite_images/buttons/btn-green-onclick-cap.png +0 -0
  72. data/spec/fixtures/rails_project2/app/assets/images/sprite_images/buttons/btn-green-onclick-drop.png +0 -0
  73. data/spec/fixtures/rails_project2/app/assets/images/sprite_images/buttons/btn-green-onclick-edge.png +0 -0
  74. data/spec/fixtures/rails_project2/app/assets/images/sprite_images/buttons/btn-green-onclick.png +0 -0
  75. data/spec/fixtures/rails_project2/app/assets/images/sprite_images/buttons/btn-green-rollover-cap.png +0 -0
  76. data/spec/fixtures/rails_project2/app/assets/images/sprite_images/buttons/btn-green-rollover-drop.png +0 -0
  77. data/spec/fixtures/rails_project2/app/assets/images/sprite_images/buttons/btn-green-rollover-edge.png +0 -0
  78. data/spec/fixtures/rails_project2/app/assets/images/sprite_images/buttons/btn-green-rollover.png +0 -0
  79. 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
  80. data/spec/fixtures/rails_project2/app/assets/images/sprite_images/buttons/btn-red-default-drop.png +0 -0
  81. data/spec/fixtures/rails_project2/app/assets/images/sprite_images/buttons/btn-red-default-edge.png +0 -0
  82. data/spec/fixtures/rails_project2/app/assets/images/sprite_images/buttons/btn-red-default.png +0 -0
  83. 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
  84. data/spec/fixtures/rails_project2/app/assets/images/sprite_images/buttons/btn-red-onclick-drop.png +0 -0
  85. data/spec/fixtures/rails_project2/app/assets/images/sprite_images/buttons/btn-red-onclick-edge.png +0 -0
  86. data/spec/fixtures/rails_project2/app/assets/images/sprite_images/buttons/btn-red-onclick.png +0 -0
  87. data/spec/fixtures/rails_project2/app/assets/images/sprite_images/buttons/btn-red-rollover-cap.png +0 -0
  88. data/spec/fixtures/rails_project2/app/assets/images/sprite_images/buttons/btn-red-rollover-drop.png +0 -0
  89. data/spec/fixtures/rails_project2/app/assets/images/sprite_images/buttons/btn-red-rollover-edge.png +0 -0
  90. data/spec/fixtures/rails_project2/app/assets/images/sprite_images/buttons/btn-red-rollover.png +0 -0
  91. data/spec/fixtures/rails_project2/app/assets/images/sprite_images/buttons/btn-trans-default-cap.png +0 -0
  92. data/spec/fixtures/rails_project2/app/assets/images/sprite_images/buttons/btn-trans-default-drop.png +0 -0
  93. data/spec/fixtures/rails_project2/app/assets/images/sprite_images/buttons/btn-trans-default-edge.png +0 -0
  94. data/spec/fixtures/rails_project2/app/assets/images/sprite_images/buttons/btn-trans-default.png +0 -0
  95. data/spec/fixtures/rails_project2/app/assets/images/sprite_images/buttons/btn-trans-onclick-cap.png +0 -0
  96. data/spec/fixtures/rails_project2/app/assets/images/sprite_images/buttons/btn-trans-onclick-drop.png +0 -0
  97. data/spec/fixtures/rails_project2/app/assets/images/sprite_images/buttons/btn-trans-onclick-edge.png +0 -0
  98. data/spec/fixtures/rails_project2/app/assets/images/sprite_images/buttons/btn-trans-onclick.png +0 -0
  99. data/spec/fixtures/rails_project2/app/assets/images/sprite_images/buttons/btn-trans-rollover-cap.png +0 -0
  100. data/spec/fixtures/rails_project2/app/assets/images/sprite_images/buttons/btn-trans-rollover-drop.png +0 -0
  101. data/spec/fixtures/rails_project2/app/assets/images/sprite_images/buttons/btn-trans-rollover-edge.png +0 -0
  102. data/spec/fixtures/rails_project2/app/assets/images/sprite_images/buttons/btn-trans-rollover.png +0 -0
  103. data/spec/fixtures/rails_project2/app/assets/images/sprite_images/buttons/btn-white-default-cap.png +0 -0
  104. data/spec/fixtures/rails_project2/app/assets/images/sprite_images/buttons/btn-white-default-drop.png +0 -0
  105. data/spec/fixtures/rails_project2/app/assets/images/sprite_images/buttons/btn-white-default-edge.png +0 -0
  106. data/spec/fixtures/rails_project2/app/assets/images/sprite_images/buttons/btn-white-default.png +0 -0
  107. 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
  108. data/spec/fixtures/rails_project2/app/assets/images/sprite_images/buttons/btn-white-onclick-drop.png +0 -0
  109. data/spec/fixtures/rails_project2/app/assets/images/sprite_images/buttons/btn-white-onclick-edge.png +0 -0
  110. data/spec/fixtures/rails_project2/app/assets/images/sprite_images/buttons/btn-white-onclick.png +0 -0
  111. data/spec/fixtures/rails_project2/app/assets/images/sprite_images/buttons/btn-white-rollover-cap.png +0 -0
  112. data/spec/fixtures/rails_project2/app/assets/images/sprite_images/buttons/btn-white-rollover-drop.png +0 -0
  113. data/spec/fixtures/rails_project2/app/assets/images/sprite_images/buttons/btn-white-rollover-edge.png +0 -0
  114. data/spec/fixtures/rails_project2/app/assets/images/sprite_images/buttons/btn-white-rollover.png +0 -0
  115. data/spec/fixtures/rails_project2/app/assets/images/sprite_images/buttons/btn-yellow-default-cap.png +0 -0
  116. data/spec/fixtures/rails_project2/app/assets/images/sprite_images/buttons/btn-yellow-default-drop.png +0 -0
  117. data/spec/fixtures/rails_project2/app/assets/images/sprite_images/buttons/btn-yellow-default-edge.png +0 -0
  118. data/spec/fixtures/rails_project2/app/assets/images/sprite_images/buttons/btn-yellow-default.png +0 -0
  119. 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
  120. data/spec/fixtures/rails_project2/app/assets/images/sprite_images/buttons/btn-yellow-onclick-drop.png +0 -0
  121. data/spec/fixtures/rails_project2/app/assets/images/sprite_images/buttons/btn-yellow-onclick-edge.png +0 -0
  122. data/spec/fixtures/rails_project2/app/assets/images/sprite_images/buttons/btn-yellow-onclick.png +0 -0
  123. 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
  124. data/spec/fixtures/rails_project2/app/assets/images/sprite_images/buttons/btn-yellow-rollover-drop.png +0 -0
  125. data/spec/fixtures/rails_project2/app/assets/images/sprite_images/buttons/btn-yellow-rollover-edge.png +0 -0
  126. data/spec/fixtures/rails_project2/app/assets/images/sprite_images/buttons/btn-yellow-rollover.png +0 -0
  127. data/spec/fixtures/rails_project2/config/application.rb +61 -0
  128. data/spec/fixtures/rails_project2/config/boot.rb +6 -0
  129. data/spec/fixtures/rails_project2/config/environment.rb +7 -0
  130. data/spec/fixtures/rails_project2/config/sprites.rb +93 -0
  131. data/spec/fixtures/rails_project2/log/test.log +0 -0
  132. data/spec/integration/rails/rails_spec.rb +9 -1
  133. data/spec/lib/sprites/application_spec.rb +2 -12
  134. data/spec/lib/sprites/autoloader_spec.rb +21 -0
  135. data/spec/lib/sprites/configuration_spec.rb +7 -4
  136. data/spec/lib/sprites/sprite_generators/chunky_png_generator_spec.rb +4 -3
  137. data/spec/lib/sprites/sprite_piece_spec.rb +30 -6
  138. data/spec/lib/sprites/sprite_pieces_spec.rb +9 -7
  139. data/spec/lib/sprites/sprite_spec.rb +10 -64
  140. data/spec/lib/sprites/sprites_spec.rb +16 -16
  141. data/spec/lib/sprites/stylesheet_spec.rb +4 -5
  142. data/spec/lib/sprites/test/sprite_generator_tester_spec.rb +3 -3
  143. data/spec/lib/sprites_spec.rb +1 -1
  144. data/spec/spec_helper.rb +2 -1
  145. data/spec/support/sprites_helper.rb +142 -142
  146. metadata +229 -117
  147. data/lib/sprites/rails/railtie.rb +0 -10
  148. data/spec/fixtures/rails_project1/app/assets/images/sprite_images/buttons/dark_background/btn-black-default-28.png +0 -0
  149. data/spec/fixtures/rails_project1/app/assets/images/sprite_images/buttons/dark_background/btn-black-default-cap-28.png +0 -0
  150. data/spec/fixtures/rails_project1/app/assets/images/sprite_images/buttons/dark_background/btn-black-onclick-28.png +0 -0
  151. data/spec/fixtures/rails_project1/app/assets/images/sprite_images/buttons/dark_background/btn-black-onclick-cap-28.png +0 -0
  152. data/spec/fixtures/rails_project1/app/assets/images/sprite_images/buttons/dark_background/btn-black-rollover-28.png +0 -0
  153. data/spec/fixtures/rails_project1/app/assets/images/sprite_images/buttons/dark_background/btn-black-rollover-cap-28.png +0 -0
  154. data/spec/fixtures/rails_project1/app/assets/images/sprite_images/buttons/dark_background/btn-blue-default-cap.png +0 -0
  155. data/spec/fixtures/rails_project1/app/assets/images/sprite_images/buttons/dark_background/btn-blue-default.png +0 -0
  156. data/spec/fixtures/rails_project1/app/assets/images/sprite_images/buttons/dark_background/btn-blue-onclick-cap.png +0 -0
  157. data/spec/fixtures/rails_project1/app/assets/images/sprite_images/buttons/dark_background/btn-blue-onclick.png +0 -0
  158. data/spec/fixtures/rails_project1/app/assets/images/sprite_images/buttons/dark_background/btn-blue-rollover-cap.png +0 -0
  159. data/spec/fixtures/rails_project1/app/assets/images/sprite_images/buttons/dark_background/btn-green-default-drop.png +0 -0
  160. data/spec/fixtures/rails_project1/app/assets/images/sprite_images/buttons/dark_background/btn-green-default-edge.png +0 -0
  161. data/spec/fixtures/rails_project1/app/assets/images/sprite_images/buttons/dark_background/btn-green-default.png +0 -0
  162. data/spec/fixtures/rails_project1/app/assets/images/sprite_images/buttons/dark_background/btn-green-onclick-drop.png +0 -0
  163. data/spec/fixtures/rails_project1/app/assets/images/sprite_images/buttons/dark_background/btn-green-onclick-edge.png +0 -0
  164. data/spec/fixtures/rails_project1/app/assets/images/sprite_images/buttons/dark_background/btn-green-onclick.png +0 -0
  165. data/spec/fixtures/rails_project1/app/assets/images/sprite_images/buttons/dark_background/btn-green-rollover-cap.png +0 -0
  166. data/spec/fixtures/rails_project1/app/assets/images/sprite_images/buttons/dark_background/btn-green-rollover-drop.png +0 -0
  167. data/spec/fixtures/rails_project1/app/assets/images/sprite_images/buttons/dark_background/btn-green-rollover-edge.png +0 -0
  168. data/spec/fixtures/rails_project1/app/assets/images/sprite_images/buttons/dark_background/btn-green-rollover.png +0 -0
  169. data/spec/fixtures/rails_project1/app/assets/images/sprite_images/buttons/dark_background/btn-red-default.png +0 -0
  170. data/spec/fixtures/rails_project1/app/assets/images/sprite_images/buttons/dark_background/btn-red-onclick-cap.png +0 -0
  171. data/spec/fixtures/rails_project1/app/assets/images/sprite_images/buttons/dark_background/btn-red-onclick.png +0 -0
  172. data/spec/fixtures/rails_project1/app/assets/images/sprite_images/buttons/dark_background/btn-red-rollover-cap.png +0 -0
  173. data/spec/fixtures/rails_project1/app/assets/images/sprite_images/buttons/dark_background/btn-red-rollover.png +0 -0
  174. data/spec/fixtures/rails_project1/app/assets/images/sprite_images/buttons/dark_background/btn-trans-default-cap.png +0 -0
  175. data/spec/fixtures/rails_project1/app/assets/images/sprite_images/buttons/dark_background/btn-trans-default-drop.png +0 -0
  176. data/spec/fixtures/rails_project1/app/assets/images/sprite_images/buttons/dark_background/btn-trans-default-edge.png +0 -0
  177. data/spec/fixtures/rails_project1/app/assets/images/sprite_images/buttons/dark_background/btn-trans-default.png +0 -0
  178. data/spec/fixtures/rails_project1/app/assets/images/sprite_images/buttons/dark_background/btn-trans-onclick-cap.png +0 -0
  179. data/spec/fixtures/rails_project1/app/assets/images/sprite_images/buttons/dark_background/btn-trans-onclick-drop.png +0 -0
  180. data/spec/fixtures/rails_project1/app/assets/images/sprite_images/buttons/dark_background/btn-trans-onclick-edge.png +0 -0
  181. data/spec/fixtures/rails_project1/app/assets/images/sprite_images/buttons/dark_background/btn-trans-onclick.png +0 -0
  182. data/spec/fixtures/rails_project1/app/assets/images/sprite_images/buttons/dark_background/btn-trans-rollover-cap.png +0 -0
  183. data/spec/fixtures/rails_project1/app/assets/images/sprite_images/buttons/dark_background/btn-trans-rollover-drop.png +0 -0
  184. data/spec/fixtures/rails_project1/app/assets/images/sprite_images/buttons/dark_background/btn-trans-rollover-edge.png +0 -0
  185. data/spec/fixtures/rails_project1/app/assets/images/sprite_images/buttons/dark_background/btn-trans-rollover.png +0 -0
  186. data/spec/fixtures/rails_project1/app/assets/images/sprite_images/buttons/dark_background/btn-white-default.png +0 -0
  187. data/spec/fixtures/rails_project1/app/assets/images/sprite_images/buttons/dark_background/btn-white-onclick.png +0 -0
  188. data/spec/fixtures/rails_project1/app/assets/images/sprite_images/buttons/dark_background/btn-white-rollover.png +0 -0
  189. data/spec/fixtures/rails_project1/app/assets/images/sprite_images/buttons/dark_background/btn-yellow-default-cap.png +0 -0
  190. data/spec/fixtures/rails_project1/app/assets/images/sprite_images/buttons/dark_background/btn-yellow-default.png +0 -0
  191. data/spec/fixtures/rails_project1/app/assets/images/sprite_images/buttons/dark_background/btn-yellow-onclick.png +0 -0
  192. 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
@@ -15,7 +15,7 @@ Given(/^it contains sprite images$/) do
15
15
  end
16
16
 
17
17
  When(/^I run the executable "([^"]*)"$/) do |bin|
18
- `#{Sprites.gem_root}/bin/#{bin}`
18
+ `#{GEM_ROOT}/bin/#{bin}`
19
19
  $?.to_i.should be(0)
20
20
  end
21
21
 
@@ -18,8 +18,7 @@ module Sprites
18
18
  # === Example
19
19
  # sprites = Sprites.new
20
20
  def initialize(configuration = ::Sprites.configuration)
21
- @configuration = configuration
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
- def sprite(*args, &blk)
41
- sprites.add(*args, &blk)
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
- module Sprites
2
- require 'sprites/rails/railtie'
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
@@ -1,6 +1,5 @@
1
1
  require 'fileutils'
2
- require 'active_support/core_ext/array/extract_options'
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
- @options = DEFAULT_OPTIONS.dup
28
- set_options
30
+ @stylesheet = Stylesheet.new(self)
29
31
  end
30
32
 
31
- def define(*args, &blk)
32
- @options = @options.merge args.extract_options!
33
- @path ||= Pathname(path_for_arguments(@options, *args))
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
- def define!
43
- define unless is_defined?
44
- end
45
-
46
- def is_defined?
47
- !@stylesheet.nil?
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 path
51
- define!
52
- @path
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 stylesheet
56
- define!
57
- @stylesheet
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 stylesheet_path
69
- define!
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
- private
99
-
100
- def css_path
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 set_options
121
- return unless @options
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.x = orientation == Sprite::Orientations::VERTICAL ? 0 : width
83
- sp.y = orientation == Sprite::Orientations::VERTICAL ? height : 0
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).x, sprite_pieces.element_at(i).y)
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)
@@ -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(x)} #{negative_pixelize(y)};
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 count
18
- @sprite_pieces.size
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
@@ -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.size
31
+ @sprites.count
31
32
  end
32
33
 
33
- def add(*args, &blk)
34
- if block_given?
35
- name = sprite_name(*args)
36
- @sprites[name].define(*args, &blk)
37
- elsif args.first.is_a?(Sprite)
38
- @sprites[args.first.name] = args.first
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, "You need to supply a block or a Sprites::Sprite"
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
- File.basename(path, File.extname(path)).intern
44
+ sprite.configure(options, &blk)
59
45
  end
60
46
  end
61
47
  end
@@ -5,8 +5,12 @@ module Sprites
5
5
  attr_reader :path
6
6
  attr_accessor :sprite_pieces
7
7
 
8
- def initialize(path, sprite = nil)
9
- @path, @sprite = path, sprite
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 = ::Sprites.gem_root.join(stylesheet_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 = ::Sprites.gem_root.join(SpritePiece.sprite_piece_full_path(configuration, sp))
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
@@ -1,3 +1,3 @@
1
1
  module Sprites
2
- VERSION = "0.0.1.pre3"
2
+ VERSION = "0.0.1.rc1"
3
3
  end
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