compass 0.10.6 → 0.11.alpha.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (182) hide show
  1. data/Rakefile +6 -6
  2. data/VERSION.yml +3 -3
  3. data/examples/blueprint_default/parts/forms.html.haml +8 -0
  4. data/examples/css3/src/main.scss +4 -0
  5. data/features/command_line.feature +20 -3
  6. data/features/step_definitions/command_line_steps.rb +7 -1
  7. data/frameworks/blueprint/stylesheets/_blueprint.scss +2 -12
  8. data/frameworks/blueprint/stylesheets/blueprint/_buttons.scss +34 -34
  9. data/frameworks/blueprint/stylesheets/blueprint/_colors.scss +32 -28
  10. data/frameworks/blueprint/stylesheets/blueprint/_debug.scss +3 -3
  11. data/frameworks/blueprint/stylesheets/blueprint/_fancy-type.scss +2 -2
  12. data/frameworks/blueprint/stylesheets/blueprint/_form.scss +14 -16
  13. data/frameworks/blueprint/stylesheets/blueprint/_grid.scss +39 -37
  14. data/frameworks/blueprint/stylesheets/blueprint/_ie.scss +17 -15
  15. data/frameworks/blueprint/stylesheets/blueprint/_interaction.scss +53 -44
  16. data/frameworks/blueprint/stylesheets/blueprint/_liquid.scss +26 -26
  17. data/frameworks/blueprint/stylesheets/blueprint/_print.scss +13 -20
  18. data/frameworks/blueprint/stylesheets/blueprint/_rtl.scss +32 -44
  19. data/frameworks/blueprint/stylesheets/blueprint/_scaffolding.scss +10 -12
  20. data/frameworks/blueprint/stylesheets/blueprint/_typography.scss +18 -32
  21. data/frameworks/blueprint/stylesheets/blueprint/reset/_utilities.scss +50 -25
  22. data/frameworks/compass/stylesheets/compass/_css3.scss +1 -15
  23. data/frameworks/compass/stylesheets/compass/_layout.scss +1 -0
  24. data/frameworks/compass/stylesheets/compass/_support.scss +4 -0
  25. data/frameworks/compass/stylesheets/compass/css3/_box-shadow-v2.scss +98 -0
  26. data/frameworks/compass/stylesheets/compass/css3/_box-shadow.scss +7 -40
  27. data/frameworks/compass/stylesheets/compass/css3/_box.scss +0 -1
  28. data/frameworks/compass/stylesheets/compass/css3/_columns.scss +23 -18
  29. data/frameworks/compass/stylesheets/compass/css3/_font-face.scss +2 -3
  30. data/frameworks/compass/stylesheets/compass/css3/_gradient.scss +66 -42
  31. data/frameworks/compass/stylesheets/compass/css3/_images.scss +52 -0
  32. data/frameworks/compass/stylesheets/compass/css3/_shared.scss +1 -1
  33. data/frameworks/compass/stylesheets/compass/css3/_text-shadow-v2.scss +72 -0
  34. data/frameworks/compass/stylesheets/compass/css3/_transform-v2.scss +584 -0
  35. data/frameworks/compass/stylesheets/compass/css3/_version-1.scss +16 -0
  36. data/frameworks/compass/stylesheets/compass/css3/_version-2.scss +16 -0
  37. data/frameworks/compass/stylesheets/compass/layout/_stretching.scss +24 -0
  38. data/frameworks/compass/stylesheets/compass/utilities/general/_hacks.scss +4 -4
  39. data/frameworks/compass/stylesheets/compass/utilities/lists/_horizontal-list.scss +5 -1
  40. data/frameworks/compass/stylesheets/compass/utilities/lists/_inline-list.scss +7 -1
  41. data/frameworks/compass/stylesheets/compass/utilities/tables/_borders.scss +7 -1
  42. data/lib/compass/actions.rb +1 -1
  43. data/lib/compass/app_integration/rails/actionpack3/railtie.rb +18 -0
  44. data/lib/compass/app_integration/rails/configuration_defaults.rb +22 -0
  45. data/lib/compass/app_integration/rails/installer.rb +77 -34
  46. data/lib/compass/app_integration/rails/runtime.rb +3 -0
  47. data/lib/compass/app_integration/stand_alone/configuration_defaults.rb +1 -1
  48. data/lib/compass/commands/print_version.rb +1 -1
  49. data/lib/compass/commands/update_project.rb +2 -2
  50. data/lib/compass/commands/write_configuration.rb +10 -1
  51. data/lib/compass/compiler.rb +1 -5
  52. data/lib/compass/configuration.rb +2 -1
  53. data/lib/compass/configuration/adapters.rb +2 -1
  54. data/lib/compass/configuration/comments.rb +34 -1
  55. data/lib/compass/configuration/helpers.rb +3 -7
  56. data/lib/compass/configuration/paths.rb +1 -1
  57. data/lib/compass/exec/project_options_parser.rb +4 -0
  58. data/lib/compass/installers/base.rb +1 -1
  59. data/lib/compass/logger.rb +4 -2
  60. data/lib/compass/sass_extensions/functions.rb +6 -3
  61. data/lib/compass/sass_extensions/functions/colors.rb +58 -0
  62. data/lib/compass/sass_extensions/functions/constants.rb +1 -1
  63. data/lib/compass/sass_extensions/functions/display.rb +4 -2
  64. data/lib/compass/sass_extensions/functions/gradient_support.rb +343 -25
  65. data/lib/compass/sass_extensions/functions/if.rb +9 -0
  66. data/lib/compass/sass_extensions/functions/inline_image.rb +9 -3
  67. data/lib/compass/sass_extensions/functions/trig.rb +27 -0
  68. data/lib/compass/version.rb +6 -1
  69. data/lib/rails/init.rb +2 -0
  70. data/test/command_line_test.rb +6 -9
  71. data/test/compass_test.rb +2 -0
  72. data/test/configuration_test.rb +20 -0
  73. data/test/fixtures/stylesheets/blueprint/css/ie.css +16 -0
  74. data/test/fixtures/stylesheets/blueprint/css/screen.css +37 -34
  75. data/test/fixtures/stylesheets/blueprint/css/single-imports/colors.css +5 -5
  76. data/test/fixtures/stylesheets/blueprint/css/single-imports/form.css +7 -5
  77. data/test/fixtures/stylesheets/blueprint/css/single-imports/grid.css +5 -5
  78. data/test/fixtures/stylesheets/blueprint/css/single-imports/ie.css +16 -0
  79. data/test/fixtures/stylesheets/blueprint/css/single-imports/interaction.css +12 -9
  80. data/test/fixtures/stylesheets/blueprint/css/single-imports/reset-utilities.css +23 -64
  81. data/test/fixtures/stylesheets/blueprint/css/single-imports/reset.css +13 -37
  82. data/test/fixtures/stylesheets/blueprint/css/single-imports/rtl.css +5 -5
  83. data/test/fixtures/stylesheets/blueprint/css/single-imports/scaffolding.css +4 -4
  84. data/test/fixtures/stylesheets/blueprint/css/single-imports/typography.css +12 -15
  85. data/test/fixtures/stylesheets/compass/config.rb +2 -0
  86. data/test/fixtures/stylesheets/compass/css/box.css +6 -13
  87. data/test/fixtures/stylesheets/compass/css/box_shadow.css +17 -0
  88. data/test/fixtures/stylesheets/compass/css/columns.css +47 -0
  89. data/test/fixtures/stylesheets/compass/css/gradients.css +240 -25
  90. data/test/fixtures/stylesheets/compass/css/lists.css +12 -4
  91. data/test/fixtures/stylesheets/compass/css/print.css +1 -1
  92. data/test/fixtures/stylesheets/compass/css/reset.css +2 -2
  93. data/test/fixtures/stylesheets/compass/css/stretching.css +66 -0
  94. data/test/fixtures/stylesheets/compass/css/transform.css +305 -0
  95. data/test/fixtures/stylesheets/compass/sass/box_shadow.scss +5 -0
  96. data/test/fixtures/stylesheets/compass/sass/columns.scss +10 -0
  97. data/test/fixtures/stylesheets/compass/sass/gradients.sass +151 -19
  98. data/test/fixtures/stylesheets/compass/sass/stretching.sass +34 -0
  99. data/test/fixtures/stylesheets/compass/sass/transform.scss +87 -0
  100. data/test/sass_extensions_test.rb +44 -0
  101. metadata +42 -96
  102. data/frameworks/_blueprint_deprecated_imports/stylesheets/_blueprint.sass +0 -2
  103. data/frameworks/_blueprint_deprecated_imports/stylesheets/blueprint/_buttons.sass +0 -2
  104. data/frameworks/_blueprint_deprecated_imports/stylesheets/blueprint/_colors.sass +0 -2
  105. data/frameworks/_blueprint_deprecated_imports/stylesheets/blueprint/_debug.sass +0 -2
  106. data/frameworks/_blueprint_deprecated_imports/stylesheets/blueprint/_fancy_type.sass +0 -2
  107. data/frameworks/_blueprint_deprecated_imports/stylesheets/blueprint/_form.sass +0 -2
  108. data/frameworks/_blueprint_deprecated_imports/stylesheets/blueprint/_grid.sass +0 -2
  109. data/frameworks/_blueprint_deprecated_imports/stylesheets/blueprint/_ie.sass +0 -2
  110. data/frameworks/_blueprint_deprecated_imports/stylesheets/blueprint/_interaction.sass +0 -2
  111. data/frameworks/_blueprint_deprecated_imports/stylesheets/blueprint/_link_icons.sass +0 -2
  112. data/frameworks/_blueprint_deprecated_imports/stylesheets/blueprint/_liquid.sass +0 -2
  113. data/frameworks/_blueprint_deprecated_imports/stylesheets/blueprint/_print.sass +0 -2
  114. data/frameworks/_blueprint_deprecated_imports/stylesheets/blueprint/_reset.sass +0 -2
  115. data/frameworks/_blueprint_deprecated_imports/stylesheets/blueprint/_rtl.sass +0 -2
  116. data/frameworks/_blueprint_deprecated_imports/stylesheets/blueprint/_scaffolding.sass +0 -2
  117. data/frameworks/_blueprint_deprecated_imports/stylesheets/blueprint/_screen.sass +0 -2
  118. data/frameworks/_blueprint_deprecated_imports/stylesheets/blueprint/_typography.sass +0 -2
  119. data/frameworks/_blueprint_deprecated_imports/stylesheets/blueprint/_utilities.sass +0 -2
  120. data/frameworks/_blueprint_deprecated_imports/stylesheets/blueprint/modules/_buttons.sass +0 -2
  121. data/frameworks/_blueprint_deprecated_imports/stylesheets/blueprint/modules/_colors.sass +0 -2
  122. data/frameworks/_blueprint_deprecated_imports/stylesheets/blueprint/modules/_debug.sass +0 -2
  123. data/frameworks/_blueprint_deprecated_imports/stylesheets/blueprint/modules/_fancy_type.sass +0 -2
  124. data/frameworks/_blueprint_deprecated_imports/stylesheets/blueprint/modules/_form.sass +0 -2
  125. data/frameworks/_blueprint_deprecated_imports/stylesheets/blueprint/modules/_grid.sass +0 -2
  126. data/frameworks/_blueprint_deprecated_imports/stylesheets/blueprint/modules/_interaction.sass +0 -2
  127. data/frameworks/_blueprint_deprecated_imports/stylesheets/blueprint/modules/_link_icons.sass +0 -2
  128. data/frameworks/_blueprint_deprecated_imports/stylesheets/blueprint/modules/_liquid.sass +0 -2
  129. data/frameworks/_blueprint_deprecated_imports/stylesheets/blueprint/modules/_reset.sass +0 -2
  130. data/frameworks/_blueprint_deprecated_imports/stylesheets/blueprint/modules/_rtl.sass +0 -2
  131. data/frameworks/_blueprint_deprecated_imports/stylesheets/blueprint/modules/_scaffolding.sass +0 -2
  132. data/frameworks/_blueprint_deprecated_imports/stylesheets/blueprint/modules/_typography.sass +0 -2
  133. data/frameworks/_blueprint_deprecated_imports/stylesheets/blueprint/modules/_utilities.sass +0 -2
  134. data/frameworks/_compass_deprecated_imports/stylesheets/_compass.sass +0 -2
  135. data/frameworks/_compass_deprecated_imports/stylesheets/compass/_css3.sass +0 -2
  136. data/frameworks/_compass_deprecated_imports/stylesheets/compass/_layout.sass +0 -2
  137. data/frameworks/_compass_deprecated_imports/stylesheets/compass/_misc.sass +0 -1
  138. data/frameworks/_compass_deprecated_imports/stylesheets/compass/_misc.scss +0 -22
  139. data/frameworks/_compass_deprecated_imports/stylesheets/compass/_reset.sass +0 -2
  140. data/frameworks/_compass_deprecated_imports/stylesheets/compass/_utilities.sass +0 -2
  141. data/frameworks/_compass_deprecated_imports/stylesheets/compass/css3/_background_clip.sass +0 -2
  142. data/frameworks/_compass_deprecated_imports/stylesheets/compass/css3/_background_origin.sass +0 -2
  143. data/frameworks/_compass_deprecated_imports/stylesheets/compass/css3/_background_size.sass +0 -2
  144. data/frameworks/_compass_deprecated_imports/stylesheets/compass/css3/_border_radius.sass +0 -2
  145. data/frameworks/_compass_deprecated_imports/stylesheets/compass/css3/_box_shadow.sass +0 -2
  146. data/frameworks/_compass_deprecated_imports/stylesheets/compass/css3/_box_sizing.sass +0 -2
  147. data/frameworks/_compass_deprecated_imports/stylesheets/compass/css3/_columns.sass +0 -2
  148. data/frameworks/_compass_deprecated_imports/stylesheets/compass/css3/_font_face.sass +0 -2
  149. data/frameworks/_compass_deprecated_imports/stylesheets/compass/css3/_gradient.sass +0 -2
  150. data/frameworks/_compass_deprecated_imports/stylesheets/compass/css3/_inline_block.sass +0 -2
  151. data/frameworks/_compass_deprecated_imports/stylesheets/compass/css3/_opacity.sass +0 -2
  152. data/frameworks/_compass_deprecated_imports/stylesheets/compass/css3/_text_shadow.sass +0 -2
  153. data/frameworks/_compass_deprecated_imports/stylesheets/compass/css3/_transform.sass +0 -2
  154. data/frameworks/_compass_deprecated_imports/stylesheets/compass/css3/_transition.sass +0 -2
  155. data/frameworks/_compass_deprecated_imports/stylesheets/compass/layout/_sticky_footer.sass +0 -2
  156. data/frameworks/_compass_deprecated_imports/stylesheets/compass/utilities/_general.sass +0 -2
  157. data/frameworks/_compass_deprecated_imports/stylesheets/compass/utilities/_links.sass +0 -2
  158. data/frameworks/_compass_deprecated_imports/stylesheets/compass/utilities/_lists.sass +0 -2
  159. data/frameworks/_compass_deprecated_imports/stylesheets/compass/utilities/_print.sass +0 -2
  160. data/frameworks/_compass_deprecated_imports/stylesheets/compass/utilities/_sprites.sass +0 -2
  161. data/frameworks/_compass_deprecated_imports/stylesheets/compass/utilities/_tables.sass +0 -2
  162. data/frameworks/_compass_deprecated_imports/stylesheets/compass/utilities/_text.sass +0 -2
  163. data/frameworks/_compass_deprecated_imports/stylesheets/compass/utilities/general/_clearfix.sass +0 -2
  164. data/frameworks/_compass_deprecated_imports/stylesheets/compass/utilities/general/_float.sass +0 -2
  165. data/frameworks/_compass_deprecated_imports/stylesheets/compass/utilities/general/_hacks.sass +0 -2
  166. data/frameworks/_compass_deprecated_imports/stylesheets/compass/utilities/general/_min.sass +0 -2
  167. data/frameworks/_compass_deprecated_imports/stylesheets/compass/utilities/general/_reset.sass +0 -2
  168. data/frameworks/_compass_deprecated_imports/stylesheets/compass/utilities/general/_tabs.sass +0 -0
  169. data/frameworks/_compass_deprecated_imports/stylesheets/compass/utilities/general/_tag_cloud.sass +0 -2
  170. data/frameworks/_compass_deprecated_imports/stylesheets/compass/utilities/links/_hover_link.sass +0 -2
  171. data/frameworks/_compass_deprecated_imports/stylesheets/compass/utilities/links/_link_colors.sass +0 -2
  172. data/frameworks/_compass_deprecated_imports/stylesheets/compass/utilities/links/_unstyled_link.sass +0 -2
  173. data/frameworks/_compass_deprecated_imports/stylesheets/compass/utilities/lists/_bullets.sass +0 -2
  174. data/frameworks/_compass_deprecated_imports/stylesheets/compass/utilities/lists/_horizontal_list.sass +0 -2
  175. data/frameworks/_compass_deprecated_imports/stylesheets/compass/utilities/lists/_inline_list.sass +0 -2
  176. data/frameworks/_compass_deprecated_imports/stylesheets/compass/utilities/sprites/_sprite_img.sass +0 -2
  177. data/frameworks/_compass_deprecated_imports/stylesheets/compass/utilities/tables/_alternating_rows_and_columns.sass +0 -2
  178. data/frameworks/_compass_deprecated_imports/stylesheets/compass/utilities/tables/_borders.sass +0 -2
  179. data/frameworks/_compass_deprecated_imports/stylesheets/compass/utilities/tables/_scaffolding.sass +0 -2
  180. data/frameworks/_compass_deprecated_imports/stylesheets/compass/utilities/text/_ellipsis.sass +0 -2
  181. data/frameworks/_compass_deprecated_imports/stylesheets/compass/utilities/text/_nowrap.sass +0 -2
  182. data/frameworks/_compass_deprecated_imports/stylesheets/compass/utilities/text/_replacement.sass +0 -2
@@ -36,7 +36,8 @@ module Compass
36
36
  :asset_cache_buster,
37
37
  :line_comments,
38
38
  :color_output,
39
- :preferred_syntax
39
+ :preferred_syntax,
40
+ :disable_warnings
40
41
  ].flatten
41
42
 
42
43
  end
@@ -11,7 +11,7 @@ module Compass
11
11
  locations = []
12
12
  locations << [sass_path, css_path] if sass_path && css_path
13
13
  Compass::Frameworks::ALL.each do |framework|
14
- locations << [framework.stylesheets_directory, css_path || css_dir || "."]
14
+ locations << [framework.stylesheets_directory, File.join(css_path || css_dir || ".", framework.name)]
15
15
  end
16
16
  resolve_additional_import_paths.each do |additional_path|
17
17
  locations << [additional_path, File.join(css_path || css_dir || ".", File.basename(additional_path))]
@@ -46,6 +46,7 @@ module Compass
46
46
  engine_opts[:line_comments] = line_comments
47
47
  engine_opts[:cache] = cache
48
48
  engine_opts[:cache_location] = cache_path
49
+ engine_opts[:quiet] = disable_warnings if disable_warnings
49
50
  engine_opts.merge!(sass_options || {})
50
51
  end
51
52
 
@@ -8,7 +8,7 @@ module Compass
8
8
  end
9
9
 
10
10
  def comment_for_relative_assets
11
- unless relative_assets
11
+ unless top_level.relative_assets
12
12
  %q{# To enable relative paths to assets via compass helper functions. Uncomment:
13
13
  # relative_assets = true
14
14
  }
@@ -17,6 +17,39 @@ module Compass
17
17
  end
18
18
  end
19
19
 
20
+ def comment_for_line_comments
21
+ if top_level.line_comments
22
+ %q{# To disable debugging comments that display the original location of your selectors. Uncomment:
23
+ # line_comments = false
24
+ }
25
+ else
26
+ ""
27
+ end
28
+ end
29
+
30
+ def comment_for_output_style
31
+ unless top_level.output_style_without_default
32
+ %Q{# You can select your preferred output style here (can be overridden via the command line):
33
+ # output_style = :expanded or :nested or :compact or :compressed
34
+ }
35
+ else
36
+ ""
37
+ end
38
+ end
39
+
40
+ def comment_for_preferred_syntax
41
+ if top_level.preferred_syntax == :scss && top_level.sass_dir
42
+ %Q{
43
+ # If you prefer the indented syntax, you might want to regenerate this
44
+ # project again passing --syntax sass, or you can uncomment this:
45
+ # preferred_syntax = :sass
46
+ # and then run:
47
+ # sass-convert -R --from scss --to sass #{top_level.sass_dir} scss && rm -rf sass && mv scss sass
48
+ }
49
+ else
50
+ ""
51
+ end
52
+ end
20
53
  end
21
54
  end
22
55
  end
@@ -54,21 +54,17 @@ module Compass
54
54
  end
55
55
 
56
56
  def configure_sass_plugin!
57
- return if sass_plugin_configured?
58
57
  require 'sass/plugin'
59
- @sass_plugin_configured = true
60
58
  config = sass_plugin_configuration
61
59
  locations = config.delete(:template_location)
62
60
  Sass::Plugin.options.merge!(config)
63
61
  locations.each do |sass_dir, css_dir|
64
- Sass::Plugin.add_template_location sass_dir, css_dir
62
+ unless Sass::Plugin.engine_options[:load_paths].include?(sass_dir)
63
+ Sass::Plugin.add_template_location sass_dir, css_dir
64
+ end
65
65
  end
66
66
  end
67
67
 
68
- def sass_plugin_configured?
69
- @sass_plugin_configured
70
- end
71
-
72
68
  def sass_engine_options
73
69
  configuration.to_sass_engine_options
74
70
  end
@@ -8,7 +8,7 @@ module Compass::Configuration::Paths
8
8
  class_eval %Q{
9
9
  def #{attr} # def css_dir
10
10
  path = #{attr}_with_trailing_separator # path = css_dir_with_trailing_separator
11
- if path =~ TRAILING_SEPARATOR # if path =~ TRAILING_SEPARATOR
11
+ if path.to_s =~ TRAILING_SEPARATOR # if path =~ TRAILING_SEPARATOR
12
12
  path = path[0..-($1.length+1)] # path = path[0..-($1.length+1)]
13
13
  end # end
14
14
  path # path
@@ -49,6 +49,10 @@ module Compass::Exec::ProjectOptionsParser
49
49
  opts.on('--relative-assets', :NONE, 'Make compass asset helpers generate relative urls to assets.') do
50
50
  self.options[:relative_assets] = true
51
51
  end
52
+
53
+ opts.on('--no-line-comments', :NONE, 'Disable line comments.') do
54
+ self.options[:line_comments] = false
55
+ end
52
56
  end
53
57
 
54
58
  end
@@ -84,7 +84,7 @@ module Compass
84
84
  to = targetize(install_location_for_stylesheet(to, options))
85
85
  contents = File.new(from).read
86
86
  if preferred_syntax.to_s != from[-4..-1]
87
- logger.record :convert, basename(from)
87
+ # logger.record :convert, basename(from)
88
88
  tree = Sass::Engine.new(contents, Compass.sass_engine_options.merge(:syntax => from[-4..-1].intern)).to_tree
89
89
  contents = tree.send("to_#{preferred_syntax}")
90
90
  to[-4..-1] = preferred_syntax.to_s
@@ -16,7 +16,8 @@ module Compass
16
16
  :exists => :green,
17
17
  :directory => :green,
18
18
  :identical => :green,
19
- :convert => :green
19
+ :convert => :green,
20
+ :unchanged => :yellow
20
21
  }
21
22
 
22
23
 
@@ -32,8 +33,9 @@ module Compass
32
33
  def record(action, *arguments)
33
34
  msg = ""
34
35
  msg << color(ACTION_COLORS[action]) if Compass.configuration.color_output
35
- msg << "#{action_padding(action)}#{action} #{arguments.join(' ')}"
36
+ msg << "#{action_padding(action)}#{action}"
36
37
  msg << color(:clear) if Compass.configuration.color_output
38
+ msg << " #{arguments.join(' ')}"
37
39
  log msg
38
40
  end
39
41
 
@@ -2,9 +2,9 @@ module Compass::SassExtensions::Functions
2
2
  end
3
3
 
4
4
  %w(
5
- selectors enumerate urls display
6
- inline_image image_size gradient_support
7
- font_files constants lists
5
+ selectors enumerate urls display if
6
+ inline_image image_size constants gradient_support
7
+ font_files lists colors trig
8
8
  ).each do |func|
9
9
  require "compass/sass_extensions/functions/#{func}"
10
10
  end
@@ -20,6 +20,9 @@ module Sass::Script::Functions
20
20
  include Compass::SassExtensions::Functions::FontFiles
21
21
  include Compass::SassExtensions::Functions::Constants
22
22
  include Compass::SassExtensions::Functions::Lists
23
+ include Compass::SassExtensions::Functions::Colors
24
+ include Compass::SassExtensions::Functions::Trig
25
+ include Compass::SassExtensions::Functions::If
23
26
  end
24
27
 
25
28
  # Wierd that this has to be re-included to pick up sub-modules. Ruby bug?
@@ -0,0 +1,58 @@
1
+ module Compass::SassExtensions::Functions::Colors
2
+ if defined?(Sass::Util)
3
+ include Sass::Util
4
+ else
5
+ include Haml::Util
6
+ end
7
+
8
+ # a genericized version of lighten/darken so that negative values can be used.
9
+ def adjust_lightness(color, amount)
10
+ assert_type color, :Color
11
+ assert_type amount, :Number
12
+ color.with(:lightness => restrict(color.lightness + amount.value, 0..100))
13
+ end
14
+
15
+ # Scales a color's lightness by some percentage.
16
+ # If the amount is negative, the color is scaled darker, if positive, it is scaled lighter.
17
+ # This will never return a pure light or dark color unless the amount is 100%.
18
+ def scale_lightness(color, amount)
19
+ assert_type color, :Color
20
+ assert_type amount, :Number
21
+ color.with(:lightness => scale_color_value(color.lightness, amount.value))
22
+ end
23
+
24
+ # a genericized version of saturation/desaturate so that negative values can be used.
25
+ def adjust_saturation(color, amount)
26
+ assert_type color, :Color
27
+ assert_type amount, :Number
28
+ color.with(:saturation => restrict(color.saturation + amount.value, 0..100))
29
+ end
30
+
31
+ # Scales a color's saturation by some percentage.
32
+ # If the amount is negative, the color is desaturated, if positive, it is saturated.
33
+ # This will never return a pure saturated or desaturated color unless the amount is 100%.
34
+ def scale_saturation(color, amount)
35
+ assert_type color, :Color
36
+ assert_type amount, :Number
37
+ color.with(:saturation => scale_color_value(color.saturation, amount.value))
38
+ end
39
+
40
+ # returns an IE hex string for a color with an alpha channel
41
+ # suitable for passing to IE filters.
42
+ def ie_hex_str(color)
43
+ assert_type color, :Color
44
+ alpha = (color.alpha * 255).round
45
+ alphastr = alpha.to_s(16).rjust(2, '0')
46
+ Sass::Script::String.new("##{alphastr}#{color.send(:hex_str)[1..-1]}".upcase)
47
+ end
48
+
49
+ private
50
+ def scale_color_value(value, amount)
51
+ if amount > 0
52
+ value += (100 - value) * (amount / 100.0)
53
+ elsif amount < 0
54
+ value += value * amount / 100.0
55
+ end
56
+ value
57
+ end
58
+ end
@@ -9,7 +9,7 @@ module Compass::SassExtensions::Functions::Constants
9
9
  when "right" then "left"
10
10
  when "center" then "center"
11
11
  else
12
- raise Sass::SyntaxError, "Cannot determine the opposite of #{pos}"
12
+ pos
13
13
  end
14
14
  end
15
15
  Sass::Script::String.new(opposite.join(" "), position.type)
@@ -2,7 +2,8 @@ module Compass::SassExtensions::Functions::Display
2
2
  DEFAULT_DISPLAY = {
3
3
  :block => %w{address blockquote center dir div dd dl dt fieldset form
4
4
  frameset h1 h2 h3 h4 h5 h6 hr isindex menu noframes
5
- noscript ol p pre ul},
5
+ noscript ol p pre ul
6
+ article aside dialog figure footer header hgroup nav section},
6
7
  :inline => %w{a abbr acronym b basefont bdo big br cite code dfn em
7
8
  font i img input kbd label q s samp select small span
8
9
  strike strong sub sup textarea tt u var},
@@ -12,7 +13,8 @@ module Compass::SassExtensions::Functions::Display
12
13
  :"table-header-group" => %w{thead},
13
14
  :"table-footer-group" => %w{tfoot},
14
15
  :"table-row" => %w{tr},
15
- :"table-cell" => %w{th td}
16
+ :"table-cell" => %w{th td},
17
+ :html5 => %w{article aside dialog figure footer header hgroup nav section}
16
18
  }
17
19
 
18
20
  # returns a comma delimited string for all the
@@ -5,17 +5,32 @@ module Compass::SassExtensions::Functions::GradientSupport
5
5
  def initialize(*values)
6
6
  self.values = values
7
7
  end
8
+ def join_with
9
+ ", "
10
+ end
8
11
  def inspect
9
- values.map{|v| v.inspect}.join(", ")
12
+ to_s
10
13
  end
11
14
  def to_s
12
- inspect
15
+ values.map {|v| v.to_s }.join(join_with)
16
+ end
17
+ def size
18
+ values.size
19
+ end
20
+ end
21
+
22
+ class SpaceList < List
23
+ def join_with
24
+ " "
13
25
  end
14
26
  end
15
27
 
16
28
  class ColorStop < Sass::Script::Literal
17
29
  attr_accessor :color, :stop
18
30
  def initialize(color, stop = nil)
31
+ unless Sass::Script::Color === color || Sass::Script::Funcall === color
32
+ raise Sass::SyntaxError, "Expected a color. Got: #{color}"
33
+ end
19
34
  self.color, self.stop = color, stop
20
35
  end
21
36
  def inspect
@@ -35,9 +50,135 @@ module Compass::SassExtensions::Functions::GradientSupport
35
50
  end
36
51
  end
37
52
 
53
+ class RadialGradient < Sass::Script::Literal
54
+ attr_accessor :position_and_angle, :shape_and_size, :color_stops
55
+ def initialize(position_and_angle, shape_and_size, color_stops)
56
+ unless color_stops.values.size >= 2
57
+ raise Sass::SyntaxError, "At least two color stops are required for a radial-gradient"
58
+ end
59
+ self.position_and_angle = position_and_angle
60
+ self.shape_and_size = shape_and_size
61
+ self.color_stops = color_stops
62
+ end
63
+ def inspect
64
+ to_s
65
+ end
66
+ def to_s
67
+ s = "radial-gradient("
68
+ s << position_and_angle.to_s << ", " if position_and_angle
69
+ s << shape_and_size.to_s << ", " if shape_and_size
70
+ s << color_stops.to_s
71
+ s << ")"
72
+ end
73
+ def to_webkit
74
+ args = [
75
+ grad_point(position_and_angle || Sass::Script::String.new("center center")),
76
+ "0",
77
+ grad_point(position_and_angle || Sass::Script::String.new("center center")),
78
+ grad_end_position(color_stops, Sass::Script::Bool.new(true)),
79
+ grad_color_stops(color_stops)
80
+ ]
81
+ Sass::Script::String.new("-webkit-gradient(radial, #{args.join(', ')})")
82
+
83
+ end
84
+ def to_moz
85
+ Sass::Script::String.new("-moz-#{to_s}")
86
+ end
87
+ def to_svg
88
+ # XXX Add shape support if possible
89
+ radial_svg_gradient(color_stops, position_and_angle || Sass::Script::String.new("center center"))
90
+ end
91
+ end
92
+
93
+ class LinearGradient < Sass::Script::Literal
94
+ attr_accessor :color_stops, :position_and_angle
95
+ def initialize(position_and_angle, color_stops)
96
+ unless color_stops.values.size >= 2
97
+ raise Sass::SyntaxError, "At least two color stops are required for a linear-gradient"
98
+ end
99
+ self.position_and_angle = position_and_angle
100
+ self.color_stops = color_stops
101
+ end
102
+ def inspect
103
+ to_s
104
+ end
105
+ def to_s
106
+ s = "linear-gradient("
107
+ s << position_and_angle.to_s << ", " if position_and_angle
108
+ s << color_stops.to_s
109
+ s << ")"
110
+ end
111
+ def to_webkit
112
+ args = []
113
+ args << grad_point(position_and_angle || Sass::Script::String.new("top"))
114
+ args << grad_point(opposite_position(position_and_angle || Sass::Script::String.new("top")))
115
+ args << grad_color_stops(color_stops)
116
+ Sass::Script::String.new("-webkit-gradient(linear, #{args.join(', ')})")
117
+ end
118
+ def to_moz
119
+ Sass::Script::String.new("-moz-#{to_s}")
120
+ end
121
+ def to_svg
122
+ linear_svg_gradient(color_stops, position_and_angle || Sass::Script::String.new("top"))
123
+ end
124
+ end
125
+
38
126
  module Functions
127
+
128
+ def radial_gradient(position_and_angle, shape_and_size, *color_stops)
129
+ # Have to deal with variable length/meaning arguments.
130
+ if color_stop?(shape_and_size)
131
+ color_stops.unshift(shape_and_size)
132
+ shape_and_size = nil
133
+ elsif list_of_color_stops?(shape_and_size)
134
+ # Support legacy use of the color-stops() function
135
+ color_stops = shape_and_size.values + color_stops
136
+ shape_and_size = nil
137
+ end
138
+ shape_and_size = nil if shape_and_size && !shape_and_size.to_bool # nil out explictly passed falses
139
+ # ditto for position_and_angle
140
+ if color_stop?(position_and_angle)
141
+ color_stops.unshift(position_and_angle)
142
+ position_and_angle = nil
143
+ elsif list_of_color_stops?(position_and_angle)
144
+ color_stops = position_and_angle.values + color_stops
145
+ position_and_angle = nil
146
+ end
147
+ position_and_angle = nil if position_and_angle && !position_and_angle.to_bool
148
+
149
+ # Support legacy use of the color-stops() function
150
+ if color_stops.size == 1 && list_of_color_stops?(color_stops.first)
151
+ color_stops = color_stops.first.values
152
+ end
153
+ RadialGradient.new(position_and_angle, shape_and_size, send(:color_stops, *color_stops))
154
+ end
155
+
156
+ def linear_gradient(position_and_angle, *color_stops)
157
+ if color_stop?(position_and_angle)
158
+ color_stops.unshift(position_and_angle)
159
+ position_and_angle = nil
160
+ elsif list_of_color_stops?(position_and_angle)
161
+ color_stops = position_and_angle.values + color_stops
162
+ position_and_angle = nil
163
+ end
164
+ position_and_angle = nil if position_and_angle && !position_and_angle.to_bool
165
+
166
+ # Support legacy use of the color-stops() function
167
+ if color_stops.size == 1 && list_of_color_stops?(color_stops.first)
168
+ color_stops = color_stops.first.values
169
+ end
170
+ LinearGradient.new(position_and_angle, send(:color_stops, *color_stops))
171
+ end
172
+
39
173
  # returns color-stop() calls for use in webkit.
40
174
  def grad_color_stops(color_list)
175
+ stops = color_stops_in_percentages(color_list).map do |stop, color|
176
+ "color-stop(#{stop.inspect}, #{color.inspect})"
177
+ end
178
+ Sass::Script::String.new(stops.join(", "))
179
+ end
180
+
181
+ def color_stops_in_percentages(color_list)
41
182
  assert_list(color_list)
42
183
  normalize_stops!(color_list)
43
184
  max = color_list.values.last.stop
@@ -45,16 +186,14 @@ module Compass::SassExtensions::Functions::GradientSupport
45
186
  color_stops = color_list.values.map do |pos|
46
187
  # have to convert absolute units to percentages for use in color stop functions.
47
188
  stop = pos.stop
48
- stop = stop.div(max).times(Sass::Script::Number.new(100,["%"])) if stop.numerator_units == max.numerator_units
189
+ stop = stop.div(max).times(Sass::Script::Number.new(100,["%"])) if stop.numerator_units == max.numerator_units && max.numerator_units != ["%"]
49
190
  # Make sure the color stops are specified in the right order.
50
191
  if last_value && last_value.value > stop.value
51
192
  raise Sass::SyntaxError.new("Color stops must be specified in increasing order")
52
193
  end
53
194
  last_value = stop
54
- "color-stop(#{stop.inspect}, #{pos.color.inspect})"
195
+ [stop, pos.color]
55
196
  end
56
-
57
- Sass::Script::String.new(color_stops.join(", "))
58
197
  end
59
198
 
60
199
  # returns the end position of the gradient from the color stop
@@ -102,9 +241,11 @@ module Compass::SassExtensions::Functions::GradientSupport
102
241
  else
103
242
  case position
104
243
  when /top|bottom/
105
- "left #{position}"
244
+ "center #{position}"
106
245
  when /left|right/
107
- "#{position} top"
246
+ "#{position} center"
247
+ when /center/
248
+ "center center"
108
249
  else
109
250
  position
110
251
  end
@@ -120,35 +261,144 @@ module Compass::SassExtensions::Functions::GradientSupport
120
261
  def color_stops(*args)
121
262
  List.new(*args.map do |arg|
122
263
  case arg
264
+ when ColorStop
265
+ arg
123
266
  when Sass::Script::Color
124
267
  ColorStop.new(arg)
125
268
  when Sass::Script::String
126
269
  # We get a string as the result of concatenation
127
270
  # So we have to reparse the expression
128
- color = stop = nil
271
+ parse_color_stop(arg)
272
+ else
273
+ raise Sass::SyntaxError, "Not a valid color stop: #{arg.class.name}: #{arg}"
274
+ end
275
+ end)
276
+ end
277
+
278
+ def linear_svg_gradient(color_stops, start)
279
+ x1, y1 = grad_point(start).to_s.split
280
+ x2, y2 = grad_point(opposite_position(start)).to_s.split
281
+ stops = color_stops_in_percentages(color_stops)
282
+
283
+ svg = linear_svg(stops, x1, y1, x2, y2)
284
+ inline_image_string(svg.gsub(/\s+/, ' '), 'image/svg+xml')
285
+ end
286
+
287
+ def radial_svg_gradient(color_stops, center)
288
+ cx, cy = grad_point(center).to_s.split
289
+ r = grad_end_position(color_stops, Sass::Script::Bool.new(true))
290
+ stops = color_stops_in_percentages(color_stops)
291
+
292
+ svg = radial_svg(stops, cx, cy, r)
293
+ inline_image_string(svg.gsub(/\s+/, ' '), 'image/svg+xml')
294
+ end
295
+
296
+ # Returns a comma-delimited list after removing any non-true values
297
+ def compact(*args)
298
+ List.new(*args.reject{|a| !a.to_bool})
299
+ end
300
+
301
+ # Returns a list object from a value that was passed.
302
+ # This can be used to unpack a space separated list that got turned
303
+ # into a string by sass before it was passed to a mixin.
304
+ def _compass_list(arg)
305
+ return arg if arg.is_a?(List)
306
+ values = case arg
307
+ when Sass::Script::String
129
308
  expr = Sass::Script::Parser.parse(arg.value, 0, 0)
130
- case expr
131
- when Sass::Script::Color
132
- color = expr
133
- when Sass::Script::Funcall
134
- color = expr
135
- when Sass::Script::Operation
136
- unless expr.instance_variable_get("@operator") == :concat
137
- # This should never happen.
138
- raise Sass::SyntaxError, "Couldn't parse a color stop from: #{arg.value}"
139
- end
140
- color = expr.instance_variable_get("@operand1")
141
- stop = expr.instance_variable_get("@operand2")
309
+ if expr.is_a?(Sass::Script::Operation)
310
+ extract_list_values(expr)
311
+ elsif expr.is_a?(Sass::Script::Funcall)
312
+ expr.perform(Sass::Environment.new) #we already evaluated the args in context so no harm in using a fake env
142
313
  else
143
- raise Sass::SyntaxError, "Couldn't parse a color stop from: #{arg.value}"
314
+ [arg]
144
315
  end
145
- ColorStop.new(color, stop)
146
316
  else
147
- raise Sass::SyntaxError, "Not a valid color stop: #{arg}"
317
+ [arg]
148
318
  end
149
- end)
319
+
320
+ SpaceList.new(*values)
321
+ end
322
+
323
+ def _compass_list_size(list)
324
+ Sass::Script::Number.new(list.size)
325
+ end
326
+
327
+ # Get the nth value from a list
328
+ def _compass_nth(list, place)
329
+ if place.value == "last"
330
+ list.values.last
331
+ elsif place.value == "first"
332
+ list.values.first
333
+ else
334
+ list.values[place.value - 1]
335
+ end
336
+ end
337
+
338
+ def _compass_space_list(list)
339
+ if list.is_a?(List) && !list.is_a?(SpaceList)
340
+ SpaceList.new(*list.values)
341
+ elsif list.is_a?(SpaceList)
342
+ list
343
+ else
344
+ SpaceList.new(list)
345
+ end
346
+ end
347
+
348
+ # slice a sublist from a list
349
+ def _compass_slice(list, start_index, end_index = nil)
350
+ end_index ||= Sass::Script::Number.new(-1)
351
+ start_index = start_index.value
352
+ end_index = end_index.value
353
+ start_index -= 1 unless start_index < 0
354
+ end_index -= 1 unless end_index < 0
355
+ list.class.new *list.values[start_index..end_index]
356
+ end
357
+
358
+ %w(webkit moz o ms svg).each do |prefix|
359
+ class_eval <<-RUBY, __FILE__, __LINE__ + 1
360
+ def _#{prefix}(*args)
361
+ List.new(*args.map! do |a|
362
+ if a.is_a?(List)
363
+ a.class.new(*a.values.map{|v| v.respond_to?(:to_#{prefix}) ? v.to_#{prefix} : v})
364
+ else
365
+ a.respond_to?(:to_#{prefix}) ? a.to_#{prefix} : a
366
+ end
367
+ end)
368
+ end
369
+ RUBY
370
+ end
371
+
372
+ # Check if any of the arguments passed have a tendency towards vendor prefixing.
373
+ def prefixed(prefix, *args)
374
+ method = prefix.value.sub(/^-/,"to_").to_sym
375
+ args.map!{|a| a.is_a?(List) ? a.values : a}.flatten!
376
+ Sass::Script::Bool.new(args.any?{|a| a.respond_to?(method)})
150
377
  end
378
+
151
379
  private
380
+ # After using the sass script parser to parse a string, this reconstructs
381
+ # a list from operands to the space/concat operation
382
+ def extract_list_values(operation)
383
+ left = operation.instance_variable_get("@operand1")
384
+ right = operation.instance_variable_get("@operand2")
385
+ left = extract_list_values(left) if left.is_a?(Sass::Script::Operation)
386
+ right = extract_list_values(right) if right.is_a?(Sass::Script::Operation)
387
+ left = literalize(left) unless left.is_a?(Array)
388
+ right = literalize(right) unless right.is_a?(Array)
389
+ Array(left) + Array(right)
390
+ end
391
+ # Makes a literal from other various script nodes.
392
+ def literalize(node)
393
+ case node
394
+ when Sass::Script::Literal
395
+ node
396
+ when Sass::Script::Funcall
397
+ node.perform(Sass::Environment.new)
398
+ else
399
+ Sass::Script::String.new(node.to_s)
400
+ end
401
+ end
152
402
  def normalize_stops!(color_list)
153
403
  positions = color_list.values
154
404
  # fill in the start and end positions, if unspecified
@@ -182,9 +432,77 @@ module Compass::SassExtensions::Functions::GradientSupport
182
432
  end
183
433
  nil
184
434
  end
435
+
185
436
  def assert_list(value)
186
437
  return if value.is_a?(List)
187
438
  raise ArgumentError.new("#{value.inspect} is not a list of color stops. Expected: color_stops(<color> <number>?, ...)")
188
439
  end
440
+
441
+ def parse_color_stop(arg)
442
+ return ColorStop.new(arg) if arg.is_a?(Sass::Script::Color)
443
+ return nil unless arg.is_a?(Sass::Script::String)
444
+ color = stop = nil
445
+ expr = Sass::Script::Parser.parse(arg.value, 0, 0)
446
+ case expr
447
+ when Sass::Script::Color
448
+ color = expr
449
+ when Sass::Script::Funcall
450
+ color = expr
451
+ when Sass::Script::Operation
452
+ unless [:concat, :space].include?(expr.instance_variable_get("@operator"))
453
+ # This should never happen.
454
+ raise Sass::SyntaxError, "Couldn't parse a color stop from: #{arg.value}"
455
+ end
456
+ color = expr.instance_variable_get("@operand1")
457
+ stop = expr.instance_variable_get("@operand2")
458
+ else
459
+ raise Sass::SyntaxError, "Couldn't parse a color stop from: #{arg.value}"
460
+ end
461
+ ColorStop.new(color, stop)
462
+ end
463
+
464
+ def color_stop?(arg)
465
+ parse_color_stop(arg)
466
+ rescue
467
+ nil
468
+ end
469
+
470
+ def list_of_color_stops?(arg)
471
+ arg.is_a?(List) && arg.values.first.is_a?(ColorStop)
472
+ end
473
+
474
+ def linear_svg(color_stops, x1, y1, x2, y2)
475
+ gradient = %Q{<linearGradient id="grad" x1="#{x1}" y1="#{y1}" x2="#{x2}" y2="#{y2}">#{color_stops_svg(color_stops)}</linearGradient>}
476
+ svg(gradient)
477
+ end
478
+
479
+ def radial_svg(color_stops, cx, cy, r)
480
+ gradient = %Q{<radialGradient id="grad" gradientUnits="userSpaceOnUse" cx="#{cx}" cy="#{cy}" r="#{r}">#{color_stops_svg(color_stops)}</radialGradient>}
481
+ svg(gradient)
482
+ end
483
+
484
+ # color_stops = array of: [stop, color]
485
+ def color_stops_svg(color_stops)
486
+ color_stops.each.map{ |stop, color|
487
+ %{<stop offset="#{stop.to_s}" stop-color="#{color.inspect}"/>}
488
+ }.join
489
+ end
490
+
491
+ def svg(gradient)
492
+ svg = <<-EOS
493
+ <?xml version="1.0" encoding="utf-8"?>
494
+ <svg version="1.1" xmlns="http://www.w3.org/2000/svg"><defs>#{gradient}</defs><rect x="0" y="0" width="100%" height="100%" fill="url(#grad)" /></svg>
495
+ EOS
496
+ end
497
+ end
498
+ class LinearGradient < Sass::Script::Literal
499
+ include Functions
500
+ include Compass::SassExtensions::Functions::Constants
501
+ include Compass::SassExtensions::Functions::InlineImage
502
+ end
503
+ class RadialGradient < Sass::Script::Literal
504
+ include Functions
505
+ include Compass::SassExtensions::Functions::Constants
506
+ include Compass::SassExtensions::Functions::InlineImage
189
507
  end
190
508
  end