diff --git a/lib/compass/sass_extensions/functions/gradient_support.rb b/lib/compass/sass_extensions/functions/gradient_support.rb index f1388111..2bf163c0 100644 --- a/lib/compass/sass_extensions/functions/gradient_support.rb +++ b/lib/compass/sass_extensions/functions/gradient_support.rb @@ -141,18 +141,26 @@ module Compass::SassExtensions::Functions::GradientSupport %w(webkit moz o ms svg pie).each do |prefix| class_eval <<-RUBY, __FILE__, __LINE__ + 1 def _#{prefix}(*args) - List.new(*args.map! do |a| - if a.is_a?(List) - a.class.new(*a.values.map{|v| v.respond_to?(:to_#{prefix}) ? v.to_#{prefix} : v}) - else - a.respond_to?(:to_#{prefix}) ? a.to_#{prefix} : a - end - end) + List.new(*args.map! {|a| add_prefix(:to_#{prefix}, a)}, :comma) end RUBY end protected + + def add_prefix(prefix_method, object) + if object.is_a?(List) + object.class.new(object.value.map{|e| + add_prefix(prefix_method, e) + }) + elsif object.respond_to?(prefix_method) + object.options = options + object.send(prefix_method) + else + object + end + end + def color_stop?(arg) parse_color_stop(arg) rescue @@ -219,7 +227,12 @@ module Compass::SassExtensions::Functions::GradientSupport # Returns a comma-delimited list after removing any non-true values def compact(*args) - Sass::Script::List.new(args.reject{|a| !a.to_bool}, :comma) + sep = :comma + if args.size == 1 && args.first.is_a?(Sass::Script::List) + args = args.first.value + sep = args.first.separator + end + Sass::Script::List.new(args.reject{|a| !a.to_bool}, sep) end # Returns a list object from a value that was passed. @@ -259,28 +272,35 @@ module Compass::SassExtensions::Functions::GradientSupport # Check if any of the arguments passed have a tendency towards vendor prefixing. def prefixed(prefix, *args) method = prefix.value.sub(/^-/,"to_").to_sym - args.map!{|a| a.is_a?(Sass::Script::List) ? a.value : a}.flatten! + 2.times do + args.map!{|a| a.is_a?(Sass::Script::List) ? a.value : a}.flatten! + end Sass::Script::Bool.new(args.any?{|a| a.respond_to?(method)}) end %w(webkit moz o ms svg pie).each do |prefix| class_eval <<-RUBY, __FILE__, __LINE__ + 1 def _#{prefix}(*args) - Sass::Script::List.new(args.map! do |a| - a.options = options - if a.is_a?(Sass::Script::List) - Sass::Script::List.new(a.value.map do |v| - v.respond_to?(:to_#{prefix}) ? v.to_#{prefix} : v - end, a.separator) - else - a.respond_to?(:to_#{prefix}) ? a.to_#{prefix} : a - end - end, :comma) + Sass::Script::List.new(args.map! {|a| add_prefix(:to_#{prefix}, a)}, :comma) end RUBY end protected + + def add_prefix(prefix_method, object) + if object.is_a?(Sass::Script::List) + Sass::Script::List.new(object.value.map{|e| + add_prefix(prefix_method, e) + }, object.separator) + elsif object.respond_to?(prefix_method) + object.options = options + object.send(prefix_method) + else + object + end + end + def color_stop?(arg) arg.is_a?(ColorStop) || (arg.is_a?(Sass::Script::List) && ColorStop.new(*arg.value)) || diff --git a/test/fixtures/stylesheets/compass/css/gradients.css b/test/fixtures/stylesheets/compass/css/gradients.css index 58ee72f3..721003bc 100644 --- a/test/fixtures/stylesheets/compass/css/gradients.css +++ b/test/fixtures/stylesheets/compass/css/gradients.css @@ -1,3 +1,18 @@ +.bg-shortcut-simple-image { + background: white url("foo.png"); } + +.bg-shortcut-linear-gradient { + background: white url('data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0idXRmLTgiPz4gPHN2ZyB2ZXJzaW9uPSIxLjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+PGRlZnM+PGxpbmVhckdyYWRpZW50IGlkPSJncmFkIiB4MT0iMCUiIHkxPSIwJSIgeDI9IjEwMCUiIHkyPSIxMDAlIj48c3RvcCBvZmZzZXQ9IjAlIiBzdG9wLWNvbG9yPSIjZGRkZGRkIi8+PHN0b3Agb2Zmc2V0PSIxMDAlIiBzdG9wLWNvbG9yPSIjYWFhYWFhIi8+PC9saW5lYXJHcmFkaWVudD48L2RlZnM+PHJlY3QgeD0iMCIgeT0iMCIgd2lkdGg9IjEwMCUiIGhlaWdodD0iMTAwJSIgZmlsbD0idXJsKCNncmFkKSIgLz48L3N2Zz4g'); + background: white -webkit-gradient(linear, 0% 0%, 100% 100%, color-stop(0%, #dddddd), color-stop(100%, #aaaaaa)); + background: white -moz-linear-gradient(top left, #dddddd, #aaaaaa); + background: white linear-gradient(top left, #dddddd, #aaaaaa); } + +.bg-shortcut-radial-gradient { + background: white url('data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0idXRmLTgiPz4gPHN2ZyB2ZXJzaW9uPSIxLjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+PGRlZnM+PHJhZGlhbEdyYWRpZW50IGlkPSJncmFkIiBncmFkaWVudFVuaXRzPSJ1c2VyU3BhY2VPblVzZSIgY3g9IjUwJSIgY3k9IjUwJSIgcj0iMTAwIj48c3RvcCBvZmZzZXQ9IjAlIiBzdG9wLWNvbG9yPSIjZGRkZGRkIi8+PHN0b3Agb2Zmc2V0PSIxMDAlIiBzdG9wLWNvbG9yPSIjYWFhYWFhIi8+PC9yYWRpYWxHcmFkaWVudD48L2RlZnM+PHJlY3QgeD0iMCIgeT0iMCIgd2lkdGg9IjEwMCUiIGhlaWdodD0iMTAwJSIgZmlsbD0idXJsKCNncmFkKSIgLz48L3N2Zz4g'); + background: white -webkit-gradient(radial, 50% 50%, 0, 50% 50%, 100, color-stop(0%, #dddddd), color-stop(100%, #aaaaaa)); + background: white -moz-radial-gradient(center center, #dddddd, #aaaaaa 100px); + background: white radial-gradient(center center, #dddddd, #aaaaaa 100px); } + .bg-simple-image { background-image: url("foo.png"); } @@ -46,7 +61,7 @@ list-style-image: url('/images/4x6.png?busted=true'); } .shorthand-list-image-plain { - list-style-image: outside url("/images/4x6.png?busted=true"); } + list-style-image: outside url('/images/4x6.png?busted=true'); } .direct-list-image-with-gradient { list-style-image: -moz-radial-gradient(#00ff00, #ff0000 10px); diff --git a/test/fixtures/stylesheets/compass/sass/gradients.sass b/test/fixtures/stylesheets/compass/sass/gradients.sass index 4369b300..8c8a656c 100644 --- a/test/fixtures/stylesheets/compass/sass/gradients.sass +++ b/test/fixtures/stylesheets/compass/sass/gradients.sass @@ -1,6 +1,15 @@ @import compass/css3/images, compass/css3/gradient $experimental-support-for-svg: true +.bg-shortcut-simple-image + +background(#fff url('foo.png')) + +.bg-shortcut-linear-gradient + +background(#fff linear-gradient(top left, #ddd, #aaa)) + +.bg-shortcut-radial-gradient + +background(#fff radial-gradient(center center, #ddd, #aaa 100px)) + .bg-simple-image +background-image(url('foo.png'))