compass 0.12.2 → 0.13.alpha.4

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.
Files changed (257) hide show
  1. data/README.markdown +5 -5
  2. data/Rakefile +14 -9
  3. data/VERSION.yml +5 -4
  4. data/features/command_line.feature +8 -50
  5. data/features/step_definitions/command_line_steps.rb +3 -2
  6. data/frameworks/compass/stylesheets/compass/_css3.scss +3 -0
  7. data/frameworks/compass/stylesheets/compass/_support.scss +4 -4
  8. data/frameworks/compass/stylesheets/compass/css3/_animation.scss +121 -0
  9. data/frameworks/compass/stylesheets/compass/css3/_appearance.scss +14 -9
  10. data/frameworks/compass/stylesheets/compass/css3/_background-clip.scss +32 -36
  11. data/frameworks/compass/stylesheets/compass/css3/_background-origin.scss +32 -35
  12. data/frameworks/compass/stylesheets/compass/css3/_background-size.scss +12 -15
  13. data/frameworks/compass/stylesheets/compass/css3/_border-radius.scss +27 -48
  14. data/frameworks/compass/stylesheets/compass/css3/_box-shadow.scss +22 -35
  15. data/frameworks/compass/stylesheets/compass/css3/_box-sizing.scss +12 -8
  16. data/frameworks/compass/stylesheets/compass/css3/_box.scss +58 -83
  17. data/frameworks/compass/stylesheets/compass/css3/_columns.scss +113 -71
  18. data/frameworks/compass/stylesheets/compass/css3/_filter.scss +38 -18
  19. data/frameworks/compass/stylesheets/compass/css3/_flexbox.scss +294 -0
  20. data/frameworks/compass/stylesheets/compass/css3/_hyphenation.scss +13 -22
  21. data/frameworks/compass/stylesheets/compass/css3/_images.scss +45 -48
  22. data/frameworks/compass/stylesheets/compass/css3/_inline-block.scss +1 -1
  23. data/frameworks/compass/stylesheets/compass/css3/_regions.scss +12 -8
  24. data/frameworks/compass/stylesheets/compass/css3/_selection.scss +31 -0
  25. data/frameworks/compass/stylesheets/compass/css3/_shared.scss +226 -2
  26. data/frameworks/compass/stylesheets/compass/css3/_text-shadow.scss +21 -26
  27. data/frameworks/compass/stylesheets/compass/css3/_transform-legacy.scss +3 -3
  28. data/frameworks/compass/stylesheets/compass/css3/_transform.scss +8 -8
  29. data/frameworks/compass/stylesheets/compass/css3/_transition.scss +3 -3
  30. data/frameworks/compass/stylesheets/compass/css3/_user-interface.scss +43 -4
  31. data/frameworks/compass/stylesheets/compass/typography/_units.scss +152 -0
  32. data/frameworks/compass/stylesheets/compass/typography/_vertical_rhythm.scss +180 -102
  33. data/frameworks/compass/stylesheets/compass/typography/lists/_horizontal-list.scss +5 -3
  34. data/frameworks/compass/stylesheets/compass/typography/lists/_inline-list.scss +6 -3
  35. data/frameworks/compass/stylesheets/compass/typography/text/_ellipsis.scss +1 -1
  36. data/frameworks/compass/stylesheets/compass/utilities/general/_float.scss +7 -3
  37. data/frameworks/compass/stylesheets/compass/utilities/general/_hacks.scss +2 -2
  38. data/frameworks/compass/stylesheets/compass/utilities/sprites/_base.scss +32 -13
  39. data/frameworks/compass/stylesheets/compass/utilities/tables/_borders.scss +14 -9
  40. data/lib/compass/actions.rb +5 -1
  41. data/lib/compass/commands/project_base.rb +7 -1
  42. data/lib/compass/commands/update_project.rb +2 -3
  43. data/lib/compass/commands/watch_project.rb +11 -113
  44. data/lib/compass/commands.rb +1 -1
  45. data/lib/compass/compiler.rb +6 -0
  46. data/lib/compass/configuration/data.rb +1 -1
  47. data/lib/compass/configuration/helpers.rb +2 -0
  48. data/lib/compass/exec/global_options_parser.rb +1 -1
  49. data/lib/compass/exec/project_options_parser.rb +13 -1
  50. data/lib/compass/logger.rb +2 -0
  51. data/lib/compass/sass_extensions/functions/cross_browser_support.rb +1 -1
  52. data/lib/compass/sass_extensions/functions/env.rb +18 -0
  53. data/lib/compass/sass_extensions/functions/gradient_support.rb +101 -29
  54. data/lib/compass/sass_extensions/functions/image_size.rb +2 -1
  55. data/lib/compass/sass_extensions/functions/math.rb +14 -2
  56. data/lib/compass/sass_extensions/functions/sprites.rb +82 -22
  57. data/lib/compass/sass_extensions/functions/urls.rb +37 -6
  58. data/lib/compass/sass_extensions/functions/utility.rb +10 -0
  59. data/lib/compass/sass_extensions/sprites/engines/chunky_png_engine.rb +5 -1
  60. data/lib/compass/sass_extensions/sprites/engines.rb +3 -3
  61. data/lib/compass/sass_extensions/sprites/image.rb +7 -2
  62. data/lib/compass/sass_extensions/sprites/image_methods.rb +5 -1
  63. data/lib/compass/sass_extensions/sprites/images.rb +29 -0
  64. data/lib/compass/sass_extensions/sprites/layout/diagonal.rb +42 -0
  65. data/lib/compass/sass_extensions/sprites/layout/horizontal.rb +66 -0
  66. data/lib/compass/sass_extensions/sprites/layout/smart.rb +33 -0
  67. data/lib/compass/sass_extensions/sprites/layout/vertical.rb +68 -0
  68. data/lib/compass/sass_extensions/sprites/layout.rb +39 -0
  69. data/lib/compass/sass_extensions/sprites/layout_methods.rb +9 -115
  70. data/lib/compass/sass_extensions/sprites/sprite_map.rb +5 -1
  71. data/lib/compass/sass_extensions/sprites/sprite_methods.rb +9 -14
  72. data/lib/compass/sass_extensions/sprites.rb +2 -0
  73. data/lib/compass/sprite_importer/content.erb +29 -24
  74. data/lib/compass/sprite_importer.rb +7 -11
  75. data/lib/compass/watcher/compiler.rb +59 -0
  76. data/lib/compass/watcher/project_watcher.rb +111 -0
  77. data/lib/compass/watcher/watch.rb +33 -0
  78. data/lib/compass/watcher.rb +11 -0
  79. data/lib/compass.rb +2 -2
  80. data/test/fixtures/sprites/public/images/numeric/200.png +0 -0
  81. data/test/fixtures/stylesheets/busted_font_urls/config.rb +32 -0
  82. data/test/fixtures/stylesheets/busted_font_urls/css/screen.css +7 -0
  83. data/test/fixtures/stylesheets/busted_font_urls/fonts/grid.ttf +0 -0
  84. data/test/fixtures/stylesheets/busted_font_urls/fonts/sub/dk.ttf +0 -0
  85. data/test/fixtures/stylesheets/busted_font_urls/sass/screen.sass +11 -0
  86. data/test/fixtures/stylesheets/busted_font_urls/tmp/screen.css +7 -0
  87. data/test/fixtures/stylesheets/compass/css/animation-with-legacy-ie.css +33 -0
  88. data/test/fixtures/stylesheets/compass/css/animation.css +33 -0
  89. data/test/fixtures/stylesheets/compass/css/background-clip.css +5 -0
  90. data/test/fixtures/stylesheets/compass/css/background-origin.css +15 -0
  91. data/test/fixtures/stylesheets/compass/css/background-size.css +24 -0
  92. data/test/fixtures/stylesheets/compass/css/columns.css +32 -61
  93. data/test/fixtures/stylesheets/compass/css/flexbox.css +121 -0
  94. data/test/fixtures/stylesheets/compass/css/gradients.css +65 -37
  95. data/test/fixtures/stylesheets/compass/css/grid_background.css +10 -17
  96. data/test/fixtures/stylesheets/compass/css/hyphenation.css +4 -2
  97. data/test/fixtures/stylesheets/compass/css/lists.css +5 -5
  98. data/test/fixtures/stylesheets/compass/css/pie.css +0 -3
  99. data/test/fixtures/stylesheets/compass/css/regions.css +4 -2
  100. data/test/fixtures/stylesheets/compass/css/selection.css +13 -0
  101. data/test/fixtures/stylesheets/compass/css/sprites.css +251 -250
  102. data/test/fixtures/stylesheets/compass/css/text_shadow.css +6 -6
  103. data/test/fixtures/stylesheets/compass/css/transition.css +6 -0
  104. data/test/fixtures/stylesheets/compass/css/units.css +30 -0
  105. data/test/fixtures/stylesheets/compass/css/user-interface.css +22 -1
  106. data/test/fixtures/stylesheets/compass/css/utilities.css +15 -0
  107. data/test/fixtures/stylesheets/compass/css/vertical_rhythm.css +196 -27
  108. data/test/fixtures/stylesheets/compass/images/flag-s5b4f509715.png +0 -0
  109. data/test/fixtures/stylesheets/compass/sass/animation-with-legacy-ie.scss +19 -0
  110. data/test/fixtures/stylesheets/compass/sass/animation.scss +13 -0
  111. data/test/fixtures/stylesheets/compass/sass/background-clip.scss +4 -2
  112. data/test/fixtures/stylesheets/compass/sass/background-origin.scss +10 -0
  113. data/test/fixtures/stylesheets/compass/sass/background-size.scss +12 -0
  114. data/test/fixtures/stylesheets/compass/sass/columns.scss +10 -9
  115. data/test/fixtures/stylesheets/compass/sass/flexbox.scss +44 -0
  116. data/test/fixtures/stylesheets/compass/sass/gradients.sass +32 -3
  117. data/test/fixtures/stylesheets/compass/sass/selection.scss +13 -0
  118. data/test/fixtures/stylesheets/compass/sass/transition.scss +1 -1
  119. data/test/fixtures/stylesheets/compass/sass/units.scss +45 -0
  120. data/test/fixtures/stylesheets/compass/sass/user-interface.scss +13 -1
  121. data/test/fixtures/stylesheets/compass/sass/utilities.scss +10 -0
  122. data/test/fixtures/stylesheets/compass/sass/vertical_rhythm.scss +208 -7
  123. data/test/fixtures/stylesheets/envtest/css/env.css +8 -0
  124. data/test/fixtures/stylesheets/envtest/sass/env.scss +16 -0
  125. data/test/fixtures/stylesheets/envtest/tmp/env.css +4 -4
  126. data/test/fixtures/stylesheets/valid/css/simple.css +4 -0
  127. data/test/helpers/diff.rb +1 -1
  128. data/test/integrations/compass_test.rb +23 -14
  129. data/test/integrations/sprites_test.rb +305 -63
  130. data/test/test_helper.rb +4 -13
  131. data/test/units/command_line_test.rb +0 -2
  132. data/test/units/compass_module_test.rb +1 -1
  133. data/test/units/configuration_test.rb +12 -0
  134. data/test/units/regressions_test.rb +8 -8
  135. data/test/units/sass_extensions_test.rb +13 -11
  136. data/test/units/sass_extenstions/gradients_test.rb +33 -0
  137. data/test/units/sprites/image_test.rb +5 -0
  138. data/test/units/sprites/images_test.rb +46 -0
  139. data/test/units/sprites/layout_test.rb +29 -4
  140. data/test/units/watcher/compiler_test.rb +39 -0
  141. data/test/units/watcher/project_watcher_test.rb +73 -0
  142. data/test/units/watcher/watch_test.rb +42 -0
  143. metadata +137 -241
  144. data/examples/compass/images/emblem-a043c4f148.png +0 -0
  145. data/examples/compass/images/flag-03c3b29b35.png +0 -0
  146. data/examples/compass/images/flag-21cfbfbfc8.png +0 -0
  147. data/examples/css3/extensions/fancy-fonts/templates/project/Prociono.otf +0 -0
  148. data/examples/css3/extensions/fancy-fonts/templates/project/bgrove.otf +0 -0
  149. data/frameworks/blueprint/stylesheets/_blueprint.scss +0 -37
  150. data/frameworks/blueprint/stylesheets/blueprint/_buttons.scss +0 -101
  151. data/frameworks/blueprint/stylesheets/blueprint/_colors.scss +0 -36
  152. data/frameworks/blueprint/stylesheets/blueprint/_debug.scss +0 -28
  153. data/frameworks/blueprint/stylesheets/blueprint/_fancy-type.scss +0 -88
  154. data/frameworks/blueprint/stylesheets/blueprint/_form.scss +0 -66
  155. data/frameworks/blueprint/stylesheets/blueprint/_grid.scss +0 -258
  156. data/frameworks/blueprint/stylesheets/blueprint/_ie.scss +0 -111
  157. data/frameworks/blueprint/stylesheets/blueprint/_interaction.scss +0 -66
  158. data/frameworks/blueprint/stylesheets/blueprint/_link-icons.scss +0 -37
  159. data/frameworks/blueprint/stylesheets/blueprint/_liquid.scss +0 -152
  160. data/frameworks/blueprint/stylesheets/blueprint/_print.scss +0 -86
  161. data/frameworks/blueprint/stylesheets/blueprint/_reset.scss +0 -3
  162. data/frameworks/blueprint/stylesheets/blueprint/_rtl.scss +0 -121
  163. data/frameworks/blueprint/stylesheets/blueprint/_scaffolding.scss +0 -52
  164. data/frameworks/blueprint/stylesheets/blueprint/_typography.scss +0 -90
  165. data/frameworks/blueprint/stylesheets/blueprint/_utilities.scss +0 -37
  166. data/frameworks/blueprint/stylesheets/blueprint/reset/_utilities.scss +0 -83
  167. data/frameworks/blueprint/templates/basic/grid.png +0 -0
  168. data/frameworks/blueprint/templates/basic/ie.sass +0 -4
  169. data/frameworks/blueprint/templates/basic/manifest.rb +0 -30
  170. data/frameworks/blueprint/templates/basic/partials/_base.sass +0 -10
  171. data/frameworks/blueprint/templates/basic/print.sass +0 -4
  172. data/frameworks/blueprint/templates/basic/screen.sass +0 -12
  173. data/frameworks/blueprint/templates/buttons/buttons/cross.png +0 -0
  174. data/frameworks/blueprint/templates/buttons/buttons/key.png +0 -0
  175. data/frameworks/blueprint/templates/buttons/buttons/tick.png +0 -0
  176. data/frameworks/blueprint/templates/buttons/buttons.sass +0 -49
  177. data/frameworks/blueprint/templates/buttons/manifest.rb +0 -17
  178. data/frameworks/blueprint/templates/link_icons/link_icons/doc.png +0 -0
  179. data/frameworks/blueprint/templates/link_icons/link_icons/email.png +0 -0
  180. data/frameworks/blueprint/templates/link_icons/link_icons/external.png +0 -0
  181. data/frameworks/blueprint/templates/link_icons/link_icons/feed.png +0 -0
  182. data/frameworks/blueprint/templates/link_icons/link_icons/im.png +0 -0
  183. data/frameworks/blueprint/templates/link_icons/link_icons/pdf.png +0 -0
  184. data/frameworks/blueprint/templates/link_icons/link_icons/visited.png +0 -0
  185. data/frameworks/blueprint/templates/link_icons/link_icons/xls.png +0 -0
  186. data/frameworks/blueprint/templates/link_icons/link_icons.sass +0 -13
  187. data/frameworks/blueprint/templates/link_icons/manifest.rb +0 -23
  188. data/frameworks/blueprint/templates/project/grid.png +0 -0
  189. data/frameworks/blueprint/templates/project/ie.sass +0 -16
  190. data/frameworks/blueprint/templates/project/manifest.rb +0 -30
  191. data/frameworks/blueprint/templates/project/partials/_base.sass +0 -11
  192. data/frameworks/blueprint/templates/project/print.sass +0 -8
  193. data/frameworks/blueprint/templates/project/screen.sass +0 -46
  194. data/frameworks/blueprint/templates/semantic/grid.png +0 -0
  195. data/frameworks/blueprint/templates/semantic/ie.sass +0 -16
  196. data/frameworks/blueprint/templates/semantic/manifest.rb +0 -33
  197. data/frameworks/blueprint/templates/semantic/partials/_base.sass +0 -10
  198. data/frameworks/blueprint/templates/semantic/partials/_form.sass +0 -6
  199. data/frameworks/blueprint/templates/semantic/partials/_page.sass +0 -17
  200. data/frameworks/blueprint/templates/semantic/partials/_two_col.sass +0 -38
  201. data/frameworks/blueprint/templates/semantic/print.sass +0 -5
  202. data/frameworks/blueprint/templates/semantic/screen.sass +0 -14
  203. data/lib/compass/commands/generate_grid_background.rb +0 -96
  204. data/lib/compass/grid_builder.rb +0 -102
  205. data/test/fixtures/stylesheets/blueprint/config.rb +0 -14
  206. data/test/fixtures/stylesheets/blueprint/css/ie.css +0 -76
  207. data/test/fixtures/stylesheets/blueprint/css/print.css +0 -56
  208. data/test/fixtures/stylesheets/blueprint/css/screen.css +0 -815
  209. data/test/fixtures/stylesheets/blueprint/css/single-imports/buttons.css +0 -56
  210. data/test/fixtures/stylesheets/blueprint/css/single-imports/colors.css +0 -80
  211. data/test/fixtures/stylesheets/blueprint/css/single-imports/debug.css +0 -11
  212. data/test/fixtures/stylesheets/blueprint/css/single-imports/fancy-type.css +0 -30
  213. data/test/fixtures/stylesheets/blueprint/css/single-imports/form.css +0 -42
  214. data/test/fixtures/stylesheets/blueprint/css/single-imports/grid.css +0 -435
  215. data/test/fixtures/stylesheets/blueprint/css/single-imports/ie.css +0 -76
  216. data/test/fixtures/stylesheets/blueprint/css/single-imports/interaction.css +0 -46
  217. data/test/fixtures/stylesheets/blueprint/css/single-imports/link-icons.css +0 -40
  218. data/test/fixtures/stylesheets/blueprint/css/single-imports/liquid.css +0 -651
  219. data/test/fixtures/stylesheets/blueprint/css/single-imports/print.css +0 -60
  220. data/test/fixtures/stylesheets/blueprint/css/single-imports/reset-utilities.css +0 -69
  221. data/test/fixtures/stylesheets/blueprint/css/single-imports/reset.css +0 -42
  222. data/test/fixtures/stylesheets/blueprint/css/single-imports/rtl.css +0 -437
  223. data/test/fixtures/stylesheets/blueprint/css/single-imports/scaffolding.css +0 -45
  224. data/test/fixtures/stylesheets/blueprint/css/single-imports/typography.css +0 -146
  225. data/test/fixtures/stylesheets/blueprint/css/single-imports/utilities.css +0 -35
  226. data/test/fixtures/stylesheets/blueprint/images/grid.png +0 -0
  227. data/test/fixtures/stylesheets/blueprint/images/link_icons/doc.png +0 -0
  228. data/test/fixtures/stylesheets/blueprint/images/link_icons/email.png +0 -0
  229. data/test/fixtures/stylesheets/blueprint/images/link_icons/external.png +0 -0
  230. data/test/fixtures/stylesheets/blueprint/images/link_icons/feed.png +0 -0
  231. data/test/fixtures/stylesheets/blueprint/images/link_icons/im.png +0 -0
  232. data/test/fixtures/stylesheets/blueprint/images/link_icons/pdf.png +0 -0
  233. data/test/fixtures/stylesheets/blueprint/images/link_icons/visited.png +0 -0
  234. data/test/fixtures/stylesheets/blueprint/images/link_icons/xls.png +0 -0
  235. data/test/fixtures/stylesheets/blueprint/sass/ie.sass +0 -3
  236. data/test/fixtures/stylesheets/blueprint/sass/print.sass +0 -3
  237. data/test/fixtures/stylesheets/blueprint/sass/screen.sass +0 -18
  238. data/test/fixtures/stylesheets/blueprint/sass/single-imports/buttons.scss +0 -4
  239. data/test/fixtures/stylesheets/blueprint/sass/single-imports/colors.scss +0 -34
  240. data/test/fixtures/stylesheets/blueprint/sass/single-imports/debug.scss +0 -3
  241. data/test/fixtures/stylesheets/blueprint/sass/single-imports/fancy-type.scss +0 -3
  242. data/test/fixtures/stylesheets/blueprint/sass/single-imports/form.scss +0 -5
  243. data/test/fixtures/stylesheets/blueprint/sass/single-imports/grid.scss +0 -3
  244. data/test/fixtures/stylesheets/blueprint/sass/single-imports/ie.scss +0 -3
  245. data/test/fixtures/stylesheets/blueprint/sass/single-imports/interaction.scss +0 -3
  246. data/test/fixtures/stylesheets/blueprint/sass/single-imports/link-icons.scss +0 -13
  247. data/test/fixtures/stylesheets/blueprint/sass/single-imports/liquid.scss +0 -3
  248. data/test/fixtures/stylesheets/blueprint/sass/single-imports/print.scss +0 -5
  249. data/test/fixtures/stylesheets/blueprint/sass/single-imports/reset-utilities.scss +0 -5
  250. data/test/fixtures/stylesheets/blueprint/sass/single-imports/reset.scss +0 -1
  251. data/test/fixtures/stylesheets/blueprint/sass/single-imports/rtl.scss +0 -3
  252. data/test/fixtures/stylesheets/blueprint/sass/single-imports/scaffolding.scss +0 -5
  253. data/test/fixtures/stylesheets/blueprint/sass/single-imports/typography.scss +0 -3
  254. data/test/fixtures/stylesheets/blueprint/sass/single-imports/utilities.scss +0 -3
  255. data/test/fixtures/stylesheets/compass/images/flag-s4798b5a210.png +0 -0
  256. data/test/units/compass_png_test.rb +0 -46
  257. /data/{examples/css3/extensions/fancy-fonts/templates/project/bgrove.ttf → test/fixtures/stylesheets/busted_font_urls/fonts/feed.ttf} +0 -0
@@ -1,5 +1,6 @@
1
1
  module Compass::SassExtensions::Functions::Sprites
2
2
  ZERO = Sass::Script::Number::new(0)
3
+ BOOL_FALSE = Sass::Script::Bool::new(false)
3
4
  VALID_SELECTORS = %w(hover active target)
4
5
  # Provides a consistent interface for getting a variable in ruby
5
6
  # from a keyword argument hash that accounts for underscores/dash equivalence
@@ -10,15 +11,37 @@ module Compass::SassExtensions::Functions::Sprites
10
11
  end
11
12
  end
12
13
 
13
- #Returns a list of all sprite names
14
+ # Returns the width of the generated sprite map
15
+ def sprite_width(map, sprite=nil)
16
+ verify_map(map, 'sprite-width')
17
+ file = get_sprite_file(map, sprite)
18
+ width, _ = image_dimensions(file)
19
+ Sass::Script::Number.new(width, ["px"])
20
+ end
21
+ Sass::Script::Functions.declare :sprite_width, [:map]
22
+ Sass::Script::Functions.declare :sprite_width, [:map, :sprite]
23
+
24
+ # Returns the height of the generated sprite map
25
+ def sprite_height(map, sprite=nil)
26
+ verify_map(map, 'sprite-height')
27
+ file = get_sprite_file(map, sprite)
28
+ _, height = image_dimensions(file)
29
+ Sass::Script::Number.new(height, ["px"])
30
+ end
31
+ Sass::Script::Functions.declare :sprite_height, [:map]
32
+ Sass::Script::Functions.declare :sprite_height, [:map, :sprite]
33
+
34
+ # Returns a list of all sprite names
14
35
  def sprite_names(map)
36
+ verify_map(map, 'sprite-names')
15
37
  Sass::Script::List.new(map.sprite_names.map { |f| Sass::Script::String.new(f) }, ' ')
16
38
  end
17
39
  Sass::Script::Functions.declare :sprite_names, [:map]
18
40
 
19
41
  # Returns the system path of the sprite file
20
42
  def sprite_path(map)
21
- Sass::Script::String.new(map.name_and_hash)
43
+ verify_map(map, 'sprite-path')
44
+ Sass::Script::String.new(map.filename)
22
45
  end
23
46
  Sass::Script::Functions.declare :sprite_path, [:map]
24
47
 
@@ -30,7 +53,8 @@ module Compass::SassExtensions::Functions::Sprites
30
53
  def inline_sprite(map)
31
54
  verify_map(map, "sprite-url")
32
55
  map.generate
33
- inline_image(sprite_path(map))
56
+ path = map.filename
57
+ inline_image_string(data(path), compute_mime_type(path))
34
58
  end
35
59
  Sass::Script::Functions.declare :inline_sprite, [:map]
36
60
 
@@ -57,19 +81,24 @@ module Compass::SassExtensions::Functions::Sprites
57
81
  # Becomes:
58
82
  #
59
83
  # background: url('/images/icons.png?12345678') 0 -24px no-repeat;
60
- def sprite(map, sprite, offset_x = ZERO, offset_y = ZERO)
61
- sprite = convert_sprite_name(sprite)
84
+ #
85
+ # If the `use_percentages` parameter is passed as true, percentages will be
86
+ # used to position the sprite. Example output:
87
+ #
88
+ # background: url('/images/icons.png?12345678') 0 50% no-repeat;
89
+ #
90
+ def sprite(map, sprite, offset_x = ZERO, offset_y = ZERO, use_percentages = BOOL_FALSE)
91
+ sprite = convert_sprite_name(sprite)
62
92
  verify_map(map)
63
- unless sprite.is_a?(Sass::Script::String)
64
- raise Sass::SyntaxError, %Q(The second argument to sprite() must be a sprite name. See http://beta.compass-style.org/help/tutorials/spriting/ for more information.)
65
- end
93
+ verify_sprite(sprite)
66
94
  url = sprite_url(map)
67
- position = sprite_position(map, sprite, offset_x, offset_y)
95
+ position = sprite_position(map, sprite, offset_x, offset_y, use_percentages)
68
96
  Sass::Script::List.new([url] + position.value, :space)
69
97
  end
70
98
  Sass::Script::Functions.declare :sprite, [:map, :sprite]
71
99
  Sass::Script::Functions.declare :sprite, [:map, :sprite, :offset_x]
72
100
  Sass::Script::Functions.declare :sprite, [:map, :sprite, :offset_x, :offset_y]
101
+ Sass::Script::Functions.declare :sprite, [:map, :sprite, :offset_x, :offset_y, :use_percentages]
73
102
 
74
103
  # Returns the name of a sprite map
75
104
  # The name is derived from the folder than contains the sprites.
@@ -115,6 +144,13 @@ module Compass::SassExtensions::Functions::Sprites
115
144
 
116
145
  Sass::Script::Functions.declare :sprite_has_selector, [:map, :sprite, :selector]
117
146
 
147
+ # Determines if the CSS selector is valid
148
+ def sprite_has_valid_selector(selector)
149
+ unless selector.value =~ /\A#{Sass::SCSS::RX::IDENT}\Z/
150
+ raise Sass::SyntaxError, "#{selector} must be a legal css identifier"
151
+ end
152
+ Sass::Script::Bool.new true
153
+ end
118
154
 
119
155
  # Returns a url to the sprite image.
120
156
  def sprite_url(map)
@@ -143,39 +179,63 @@ module Compass::SassExtensions::Functions::Sprites
143
179
  # Would change the above output to:
144
180
  #
145
181
  # background-position: 3px -36px;
146
- def sprite_position(map, sprite = nil, offset_x = ZERO, offset_y = ZERO)
182
+ #
183
+ # If you set the `use_percentages` parameter to true, the position will be
184
+ # expressed in percentages. An example:
185
+ #
186
+ # background-position: sprite-position($icons, new, 0, 0, true);
187
+ #
188
+ # Would result in something like this:
189
+ #
190
+ # background-position: 0 42%;
191
+ #
192
+ def sprite_position(map, sprite = nil, offset_x = ZERO, offset_y = ZERO, use_percentages = BOOL_FALSE)
147
193
  assert_type offset_x, :Number
148
194
  assert_type offset_y, :Number
149
195
  sprite = convert_sprite_name(sprite)
150
196
  verify_map(map, "sprite-position")
151
- unless sprite && sprite.is_a?(Sass::Script::String)
197
+ unless sprite.is_a?(Sass::Script::String) || sprite.is_a?(Sass::Script::Number)
152
198
  raise Sass::SyntaxError, %Q(The second argument to sprite-position must be a sprite name. See http://beta.compass-style.org/help/tutorials/spriting/ for more information.)
153
199
  end
154
200
  image = map.image_for(sprite.value)
155
201
  unless image
156
202
  missing_image!(map, sprite)
157
203
  end
158
- if offset_x.unit_str == "%"
159
- x = offset_x # CE: Shouldn't this be a percentage of the total width?
204
+ if use_percentages.value
205
+ xdivis = map.width - image.width;
206
+ x = (offset_x.value + image.left.to_f) / (xdivis.nonzero? || 1) * 100
207
+ x = Sass::Script::Number.new(x, x == 0 ? [] : ["%"])
208
+ ydivis = map.height - image.height;
209
+ y = (offset_y.value + image.top.to_f) / (ydivis.nonzero? || 1) * 100
210
+ y = Sass::Script::Number.new(y, y == 0 ? [] : ["%"])
160
211
  else
161
- x = offset_x.value - image.left
162
- x = Sass::Script::Number.new(x, x == 0 ? [] : ["px"])
212
+ if offset_x.unit_str == "%"
213
+ x = offset_x # CE: Shouldn't this be a percentage of the total width?
214
+ else
215
+ x = offset_x.value - image.left
216
+ x = Sass::Script::Number.new(x, x == 0 ? [] : ["px"])
217
+ end
218
+ y = offset_y.value - image.top
219
+ y = Sass::Script::Number.new(y, y == 0 ? [] : ["px"])
163
220
  end
164
- y = offset_y.value - image.top
165
- y = Sass::Script::Number.new(y, y == 0 ? [] : ["px"])
166
221
  Sass::Script::List.new([x, y],:space)
167
222
  end
168
223
  Sass::Script::Functions.declare :sprite_position, [:map]
169
224
  Sass::Script::Functions.declare :sprite_position, [:map, :sprite]
170
225
  Sass::Script::Functions.declare :sprite_position, [:map, :sprite, :offset_x]
171
226
  Sass::Script::Functions.declare :sprite_position, [:map, :sprite, :offset_x, :offset_y]
172
-
173
- def sprite_image(*args)
174
- raise Sass::SyntaxError, %Q(The sprite-image() function has been replaced by sprite(). See http://compass-style.org/help/tutorials/spriting/ for more information.)
175
- end
227
+ Sass::Script::Functions.declare :sprite_position, [:map, :sprite, :offset_x, :offset_y, :use_percentages]
176
228
 
177
229
  protected
178
230
 
231
+ def get_sprite_file(map, sprite=nil)
232
+ if sprite
233
+ map.image_for(sprite).file
234
+ else
235
+ map.filename
236
+ end
237
+ end
238
+
179
239
  def reversed_color_names
180
240
  if Sass::Script::Color.const_defined?(:HTML4_COLORS_REVERSE)
181
241
  Sass::Script::Color::HTML4_COLORS_REVERSE
@@ -202,7 +262,7 @@ protected
202
262
  end
203
263
 
204
264
  def verify_sprite(sprite)
205
- unless sprite.is_a?(Sass::Script::String)
265
+ unless sprite.is_a?(Sass::Script::String) || sprite.is_a?(Sass::Script::Number)
206
266
  raise Sass::SyntaxError, %Q(The second argument to sprite() must be a sprite name. See http://beta.compass-style.org/help/tutorials/spriting/ for more information.)
207
267
  end
208
268
  end
@@ -44,9 +44,10 @@ module Compass::SassExtensions::Functions::Urls
44
44
  if base.respond_to?(:declare)
45
45
  base.declare :font_url, [:path]
46
46
  base.declare :font_url, [:path, :only_path]
47
+ base.declare :font_url, [:path, :only_path, :cache_buster]
47
48
  end
48
49
  end
49
- def font_url(path, only_path = Sass::Script::Bool.new(false))
50
+ def font_url(path, only_path = Sass::Script::Bool.new(false), cache_buster = Sass::Script::Bool.new(false))
50
51
  path = path.value # get to the string value of the literal.
51
52
 
52
53
  # Short curcuit if they have provided an absolute url.
@@ -62,7 +63,33 @@ module Compass::SassExtensions::Functions::Urls
62
63
  Compass.configuration.http_fonts_path
63
64
  end
64
65
 
65
- path = "#{http_fonts_path}/#{path}"
66
+ # Compute the real path to the font on the file system if the fonts_dir is set.
67
+ real_path = if Compass.configuration.fonts_dir
68
+ File.join(Compass.configuration.project_path, Compass.configuration.fonts_dir, path)
69
+ end
70
+
71
+ # prepend the path to the font if there's one
72
+ if http_fonts_path
73
+ http_fonts_path = "#{http_fonts_path}/" unless http_fonts_path[-1..-1] == "/"
74
+ path = "#{http_fonts_path}#{path}"
75
+ end
76
+
77
+ # Compute the asset host unless in relative mode.
78
+ asset_host = if !relative? && Compass.configuration.asset_host
79
+ Compass.configuration.asset_host.call(path)
80
+ end
81
+
82
+ # Compute and append the cache buster if there is one.
83
+ if cache_buster.to_bool
84
+ if cache_buster.is_a?(Sass::Script::String)
85
+ path += "?#{cache_buster.value}"
86
+ else
87
+ path = cache_busted_path(path, real_path)
88
+ end
89
+ end
90
+
91
+ # prepend the asset host if there is one.
92
+ path = "#{asset_host}#{'/' unless path[0..0] == "/"}#{path}" if asset_host
66
93
 
67
94
  if only_path.to_bool
68
95
  Sass::Script::String.new(clean_path(path))
@@ -103,8 +130,10 @@ module Compass::SassExtensions::Functions::Urls
103
130
  end
104
131
 
105
132
  # Compute the real path to the image on the file stystem if the images_dir is set.
106
- real_path = if Compass.configuration.images_dir
107
- File.join(Compass.configuration.project_path, Compass.configuration.images_dir, path)
133
+ real_path = if Compass.configuration.images_path
134
+ File.join(Compass.configuration.images_path, path)
135
+ else
136
+ File.join(Compass.configuration.project_path, path)
108
137
  end
109
138
 
110
139
  # prepend the path to the image if there's one
@@ -168,8 +197,10 @@ module Compass::SassExtensions::Functions::Urls
168
197
  end
169
198
 
170
199
  # Compute the real path to the image on the file stystem if the generated_images_dir is set.
171
- real_path = if Compass.configuration.generated_images_dir
172
- File.join(Compass.configuration.project_path, Compass.configuration.generated_images_dir, path)
200
+ real_path = if Compass.configuration.images_path
201
+ File.join(Compass.configuration.images_path, path)
202
+ else
203
+ File.join(Compass.configuration.project_path, path)
173
204
  end
174
205
 
175
206
  # prepend the path to the image if there's one
@@ -0,0 +1,10 @@
1
+ module Compass::SassExtensions::Functions::Utility
2
+
3
+ def file_exists(path_to_file)
4
+ path = path_to_file.respond_to?(:value) ? path_to_file.value : path_to_file
5
+ Sass::Script::Bool.new(File.exists?(path));
6
+ end
7
+
8
+ Sass::Script::Functions.declare :file_exists, [:path_to_file]
9
+
10
+ end
@@ -12,7 +12,11 @@ module Compass
12
12
  def construct_sprite
13
13
  @canvas = ChunkyPNG::Image.new(width, height, ChunkyPNG::Color::TRANSPARENT)
14
14
  images.each do |image|
15
- input_png = ChunkyPNG::Image.from_file(image.file)
15
+ input_png = begin
16
+ ChunkyPNG::Image.from_file(image.file)
17
+ rescue ChunkyPNG::SignatureMismatch
18
+ raise Compass::SpriteException, "You have provided a file that does not have a PNG signature. Only PNG files are supported by the default sprite engine"
19
+ end
16
20
  canvas.replace! input_png, image.left, image.top
17
21
  end
18
22
  end
@@ -9,11 +9,11 @@ module Compass
9
9
  end
10
10
 
11
11
  def construct_sprite
12
- raise ::Compass::Error, "You must impliment construct_sprite"
12
+ raise ::Compass::Error, "You must implement construct_sprite"
13
13
  end
14
14
 
15
15
  def save(filename)
16
- raise ::Compass::Error, "You must impliment save(filename)"
16
+ raise ::Compass::Error, "You must implement save(filename)"
17
17
  end
18
18
 
19
19
  end
@@ -22,4 +22,4 @@ module Compass
22
22
  end
23
23
 
24
24
 
25
- require 'compass/sass_extensions/sprites/engines/chunky_png_engine'
25
+ require 'compass/sass_extensions/sprites/engines/chunky_png_engine'
@@ -8,9 +8,10 @@ module Compass
8
8
  PARENT = %r{(.+)[-_](.+)$}
9
9
 
10
10
  REPEAT_X = 'repeat-x'
11
+ REPEAT_Y = 'repeat-y'
11
12
  NO_REPEAT = 'no-repeat'
12
13
 
13
- VALID_REPEATS = [REPEAT_X, NO_REPEAT]
14
+ VALID_REPEATS = [REPEAT_Y, REPEAT_X, NO_REPEAT]
14
15
 
15
16
  attr_reader :relative_file, :options, :base
16
17
  attr_accessor :top, :left
@@ -50,7 +51,7 @@ module Compass
50
51
 
51
52
  # Basename of the image
52
53
  def name
53
- File.basename(relative_file, '.png')
54
+ @name ||= File.basename(relative_file, '.png')
54
55
  end
55
56
 
56
57
  def get_var_file(var)
@@ -73,6 +74,10 @@ module Compass
73
74
  repeat == REPEAT_X
74
75
  end
75
76
 
77
+ def repeat_y?
78
+ repeat == REPEAT_Y
79
+ end
80
+
76
81
  def no_repeat?
77
82
  repeat == NO_REPEAT
78
83
  end
@@ -4,7 +4,11 @@ module Compass
4
4
  module ImageMethods
5
5
  # Fetches the Sprite::Image object for the supplied name
6
6
  def image_for(name)
7
- @images.detect { |img| img.name == name}
7
+ if name.is_a?(Sass::Script::String)
8
+ name = name.value
9
+ end
10
+ name = name.to_s
11
+ @images.detect { |img| img.name == name}
8
12
  end
9
13
 
10
14
  # Returns true if the image name has a hover selector image
@@ -0,0 +1,29 @@
1
+ module Compass
2
+ module SassExtensions
3
+ module Sprites
4
+ class Images < Array
5
+
6
+ def sort_by!(method)
7
+ invert = false
8
+ if method.to_s[0] == '!'[0] # have todo this for 1.8.7 compat
9
+ method = method.to_s[1..-1]
10
+ invert = true
11
+ end
12
+ method = method.to_sym
13
+ self.sort! do |a, b|
14
+ unless a.send(method) == b.send(method)
15
+ a.send(method) <=> b.send(method)
16
+ else
17
+ other = ([:size, :name] - [method]).first
18
+ a.send(other) <=> b.send(other)
19
+ end
20
+ end
21
+ self.reverse! if invert
22
+ end
23
+
24
+
25
+
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,42 @@
1
+ module Compass
2
+ module SassExtensions
3
+ module Sprites
4
+ module Layout
5
+ class Diagonal < SpriteLayout
6
+
7
+ def layout!
8
+ calculate_width!
9
+ calculate_height!
10
+ calculate_positions!
11
+ end
12
+
13
+ private # ===========================================================================================>
14
+
15
+ def calculate_width!
16
+ @width = @images.inject(0) {|sum, img| sum + img.width}
17
+ end
18
+
19
+ def calculate_height!
20
+ @height = @images.inject(0) {|sum, img| sum + img.height}
21
+ end
22
+
23
+ def calculate_positions!
24
+ previous = nil
25
+ @images.each_with_index do |image, index|
26
+ if previous.nil?
27
+ previous = image
28
+ image.top = @height - image.height
29
+ image.left = 0
30
+ next
31
+ end
32
+ image.top = previous.top - image.height
33
+ image.left = previous.left + previous.width
34
+ previous = image
35
+ end
36
+ end
37
+
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,66 @@
1
+ module Compass
2
+ module SassExtensions
3
+ module Sprites
4
+ module Layout
5
+ class Horizontal < SpriteLayout
6
+
7
+ def layout!
8
+ calculate_height!
9
+ calculate_width!
10
+ calculate_positions!
11
+ tile_images_that_repeat!
12
+ end
13
+
14
+ private # ===========================================================================================>
15
+
16
+ def calculate_height!
17
+ @height = @images.map {|image| image.height + image.offset}.max
18
+ if repeating_images?
19
+ calculate_repeat_extra_height!
20
+ end
21
+ @height
22
+ end
23
+
24
+ def calculate_width!
25
+ @width = @images.inject(0) { |sum, image| sum += (image.width + image.spacing) }
26
+ end
27
+
28
+ def repeating_images?
29
+ @repeating_images ||= @images.any?(&:repeat_y?)
30
+ end
31
+
32
+ def calculate_repeat_extra_height!
33
+ m = @images.inject(1) {|m,img| img.repeat_y? ? m.lcm(img.height) : m }
34
+ remainder = @height % m
35
+ @height += (m - remainder) unless remainder.zero?
36
+ end
37
+
38
+ def calculate_positions!
39
+ @images.each_with_index do |image, index|
40
+ image.top = image.position.unit_str == '%' ? (@height - image.height) * (image.position.value / 100.0) : image.position.value
41
+ next if index == 0
42
+ last_image = @images[index-1]
43
+ image.left = last_image.left + last_image.width + [image.spacing, last_image.spacing].max
44
+ end
45
+ end
46
+
47
+ def tile_images_that_repeat!
48
+ return unless repeating_images?
49
+ @images.map {|img| img if img.repeat_y?}.compact.each do |image|
50
+ y = (image.top + image.height)
51
+ while y < @height do
52
+ begin
53
+ img = image.dup
54
+ img.top = y.to_i
55
+ @images << img
56
+ y += image.height
57
+ end
58
+ end #while
59
+ end
60
+ end
61
+
62
+ end
63
+ end
64
+ end
65
+ end
66
+ end
@@ -0,0 +1,33 @@
1
+ module Compass
2
+ module SassExtensions
3
+ module Sprites
4
+ module Layout
5
+ class Smart < SpriteLayout
6
+
7
+ def layout!
8
+ calculate_positions!
9
+ end
10
+
11
+ private # ===========================================================================================>
12
+
13
+ def calculate_positions!
14
+ fitter = ::Compass::SassExtensions::Sprites::RowFitter.new(@images)
15
+ current_y = 0
16
+ fitter.fit!.each do |row|
17
+ current_x = 0
18
+ row.images.each_with_index do |image, index|
19
+ image.left = current_x
20
+ image.top = current_y
21
+ current_x += image.width
22
+ end
23
+ current_y += row.height
24
+ end
25
+ @width = fitter.width
26
+ @height = fitter.height
27
+ end
28
+
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,68 @@
1
+ module Compass
2
+ module SassExtensions
3
+ module Sprites
4
+ module Layout
5
+ class Vertical < SpriteLayout
6
+
7
+ def layout!
8
+ calculate_width!
9
+ calculate_positions!
10
+ calculate_height!
11
+ tile_images_that_repeat!
12
+ end
13
+
14
+ private # ===========================================================================================>
15
+
16
+ def calculate_width!
17
+ @width = @images.map { |image| image.width + image.offset }.max
18
+ if repeating_images?
19
+ calculate_repeat_extra_width!
20
+ end
21
+
22
+ @width
23
+ end
24
+
25
+ def calculate_height!
26
+ last = @images.last
27
+ @height = last.top + last.height
28
+ end
29
+
30
+ def repeating_images?
31
+ @repeating_images ||= @images.any?(&:repeat_x?)
32
+ end
33
+
34
+ def calculate_repeat_extra_width!
35
+ m = @images.inject(1) {|m,img| img.repeat_x? ? m.lcm(img.width) : m }
36
+ remainder = @width % m
37
+ @width += (m - remainder) unless remainder.zero?
38
+ end
39
+
40
+ def calculate_positions!
41
+ @images.each_with_index do |image, index|
42
+ image.left = (image.position.unit_str == "%" ? (@width - image.width) * (image.position.value / 100.0) : image.position.value).to_i
43
+ next if index == 0
44
+ last_image = @images[index-1]
45
+ image.top = last_image.top + last_image.height + [image.spacing, last_image.spacing].max
46
+ end #each_with_index
47
+ end #method
48
+
49
+ def tile_images_that_repeat!
50
+ return unless repeating_images?
51
+ @images.map {|img| img if img.repeat_x?}.compact.each do |image|
52
+ x = image.left - (image.left / image.width).ceil * image.width
53
+ while x < @width do
54
+ begin
55
+ img = image.dup
56
+ img.top = image.top
57
+ img.left = x.to_i
58
+ @images << img
59
+ x += image.width
60
+ end #begin
61
+ end #while
62
+ end #map
63
+ end #method
64
+ end #Vertical
65
+ end #Layout
66
+ end #Sprites
67
+ end #SassExtensions
68
+ end #Compass
@@ -0,0 +1,39 @@
1
+ require 'rational'
2
+ module Compass
3
+ module SassExtensions
4
+ module Sprites
5
+ module Layout
6
+ class SpriteLayout
7
+
8
+ attr_reader :images, :options
9
+ attr_accessor :height, :width
10
+
11
+ def initialize(images, kwargs={})
12
+ @images = images
13
+ @options = kwargs
14
+ @height = 0
15
+ @width = 0
16
+
17
+ layout!
18
+ end
19
+
20
+ def layout!
21
+ raise Compass::SpriteException, "You must impliment layout!"
22
+ end
23
+
24
+ def properties
25
+ if @width.zero?
26
+ raise Compass::SpriteException, "You must set the width fetching the properties"
27
+ end
28
+ if @height.zero?
29
+ raise Compass::SpriteException, "You must set the height fetching the properties"
30
+ end
31
+
32
+ [@images, @width, @height]
33
+ end
34
+
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end