From 988d3de467f7f0c1b8875452f2e3092701b43c31 Mon Sep 17 00:00:00 2001 From: kizu Date: Fri, 25 May 2012 17:30:34 +0400 Subject: [PATCH] Moved whole logic from the gradient function to the vendor ones, rewriting the background, background-image etc. Fixes #67 --- lib/nib/gradients.styl | 35 +++++++++----------------- lib/nib/vendor.styl | 44 ++++++++++++++++++++++++++++++--- test/cases/linear-gradient.styl | 3 ++- 3 files changed, 55 insertions(+), 27 deletions(-) diff --git a/lib/nib/gradients.styl b/lib/nib/gradients.styl index ebeaf804..1b9e9b22 100644 --- a/lib/nib/gradients.styl +++ b/lib/nib/gradients.styl @@ -85,29 +85,18 @@ std-stop(color, pos) linear-gradient(start, stops...) error('color stops required') unless length(stops) - if current-property - prop = current-property[0] - val = current-property[1] - stops = normalize-stops(stops) - - // gradient image - // if start is a 'color' - // unshift(stops, start) - // start = top - // if start[0] is a 'unit' - // if has-canvas - // img = linear-gradient-image(start, stops) - // add-property(prop, replace(val, '__CALL__', img)) - // start = start[1] - - // vendor prefixed - stops = join-stops(stops, std-stop) - for prefix in vendor-prefixes - unless prefix == official - gradient = '-%s-linear-gradient(%s, %s)' % (prefix start stops) - add-property(prop, replace(val, '__CALL__', gradient)) - - // standard + // if current-property + // if start is a 'color' + // unshift(stops, start) + // start = top + // if start[0] is a 'unit' + // if has-canvas + // img = linear-gradient-image(start, stops) + // add-property(prop, replace(val, '__CALL__', img)) + // start = start[1] + + stops = normalize-stops(stops) + stops = join-stops(stops, std-stop) 'linear-gradient(%s, %s)' % (start stops) /* diff --git a/lib/nib/vendor.styl b/lib/nib/vendor.styl index 24b08d74..23cf9d58 100644 --- a/lib/nib/vendor.styl +++ b/lib/nib/vendor.styl @@ -62,7 +62,7 @@ prepend-args(args, prefix, argument, strict = true) * or those which should be ignored. */ -vendor(prop, args, only = null, ignore = null) +vendor(prop, args, only = null, ignore = null, vendor-property = true) for prefix in vendor-prefixes unless (only and !(prefix in only)) or (ignore and prefix in ignore) if official == prefix @@ -72,9 +72,13 @@ vendor(prop, args, only = null, ignore = null) // Adjusting the args if needed if prop in ('transition' 'transition-property') newargs = prepend-args(args, '-' + prefix + '-', transform) - if prop in ('border-image') + if prop in ('border-image' 'background' 'background-image' 'cursor' 'list-style' 'list-style-image') newargs = prepend-args(args, '-' + prefix + '-', linear-gradient, false) - {'-' + prefix + '-' + prop}: newargs + newprop = prop + newprop = '-' + prefix + '-' + prop if vendor-property + // TODO: make the adjustments for differences + // between the official syntax and vendor ones + {newprop}: newargs /* * Vendorize the given value. @@ -478,3 +482,37 @@ border-radius() -apply-border-radius(pos) pos = () vendor('border-radius', pos, only: webkit official) unless augmented + +/* + * Vendor background support (gradients). + */ + +background() + if match('-gradient\(', ''+arguments) + vendor('background', arguments, vendor-property: false) + else + background arguments + +background-image() + if match('-gradient\(', ''+arguments) + vendor('background-image', arguments, vendor-property: false) + else + background-image arguments + +cursor() + if match('-gradient\(', ''+arguments) + vendor('cursor', arguments, vendor-property: false) + else + cursor arguments + +list-style() + if match('-gradient\(', ''+arguments) + vendor('list-style', arguments, vendor-property: false) + else + list-style arguments + +list-style-image() + if match('-gradient\(', ''+arguments) + vendor('list-style-image', arguments, vendor-property: false) + else + list-style-image arguments diff --git a/test/cases/linear-gradient.styl b/test/cases/linear-gradient.styl index 692674b3..6237b5fe 100644 --- a/test/cases/linear-gradient.styl +++ b/test/cases/linear-gradient.styl @@ -1,4 +1,5 @@ +@import 'nib/vendor' @import 'nib/gradients' body @@ -22,4 +23,4 @@ body background: linear-gradient(top, white, black) body - background: linear-gradient(top, white, black), white \ No newline at end of file + background: linear-gradient(top, white, black), white