Handle list arguments to prefixes

This commit is contained in:
Chris Eppstein 2010-11-27 12:17:52 -08:00
parent 6e30099473
commit dd921ea363
3 changed files with 64 additions and 20 deletions

View File

@ -141,18 +141,26 @@ module Compass::SassExtensions::Functions::GradientSupport
%w(webkit moz o ms svg pie).each do |prefix| %w(webkit moz o ms svg pie).each do |prefix|
class_eval <<-RUBY, __FILE__, __LINE__ + 1 class_eval <<-RUBY, __FILE__, __LINE__ + 1
def _#{prefix}(*args) def _#{prefix}(*args)
List.new(*args.map! do |a| List.new(*args.map! {|a| add_prefix(:to_#{prefix}, a)}, :comma)
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)
end end
RUBY RUBY
end end
protected 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) def color_stop?(arg)
parse_color_stop(arg) parse_color_stop(arg)
rescue rescue
@ -219,7 +227,12 @@ module Compass::SassExtensions::Functions::GradientSupport
# Returns a comma-delimited list after removing any non-true values # Returns a comma-delimited list after removing any non-true values
def compact(*args) 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 end
# Returns a list object from a value that was passed. # 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. # Check if any of the arguments passed have a tendency towards vendor prefixing.
def prefixed(prefix, *args) def prefixed(prefix, *args)
method = prefix.value.sub(/^-/,"to_").to_sym 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)}) Sass::Script::Bool.new(args.any?{|a| a.respond_to?(method)})
end end
%w(webkit moz o ms svg pie).each do |prefix| %w(webkit moz o ms svg pie).each do |prefix|
class_eval <<-RUBY, __FILE__, __LINE__ + 1 class_eval <<-RUBY, __FILE__, __LINE__ + 1
def _#{prefix}(*args) def _#{prefix}(*args)
Sass::Script::List.new(args.map! do |a| Sass::Script::List.new(args.map! {|a| add_prefix(:to_#{prefix}, a)}, :comma)
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)
end end
RUBY RUBY
end end
protected 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) def color_stop?(arg)
arg.is_a?(ColorStop) || arg.is_a?(ColorStop) ||
(arg.is_a?(Sass::Script::List) && ColorStop.new(*arg.value)) || (arg.is_a?(Sass::Script::List) && ColorStop.new(*arg.value)) ||

View File

@ -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 { .bg-simple-image {
background-image: url("foo.png"); } background-image: url("foo.png"); }
@ -46,7 +61,7 @@
list-style-image: url('/images/4x6.png?busted=true'); } list-style-image: url('/images/4x6.png?busted=true'); }
.shorthand-list-image-plain { .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 { .direct-list-image-with-gradient {
list-style-image: -moz-radial-gradient(#00ff00, #ff0000 10px); list-style-image: -moz-radial-gradient(#00ff00, #ff0000 10px);

View File

@ -1,6 +1,15 @@
@import compass/css3/images, compass/css3/gradient @import compass/css3/images, compass/css3/gradient
$experimental-support-for-svg: true $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 .bg-simple-image
+background-image(url('foo.png')) +background-image(url('foo.png'))