Browse files

Moved whole logic from the gradient function to the vendor ones, rewr…

…iting the background, background-image etc. Fixes #67
  • Loading branch information...
1 parent 82310f6 commit 8f8231ae15c8cff60dd2b9c88aa14b688b853a8b @kizu kizu committed with slang800 May 25, 2012
Showing with 52 additions and 30 deletions.
  1. +9 −26 lib/nib/gradients.styl
  2. +41 −3 lib/nib/vendor.styl
  3. +2 −1 test/cases/linear-gradient.styl
View
35 lib/nib/gradients.styl
@@ -85,35 +85,18 @@ std-stop(color, pos)
linear-gradient(start, stops...)
error('color stops required') unless length(stops)
- prop = current-property[0]
- val = current-property[1]
-
- if start is a 'color'
- unshift(stops, start)
- start = top
+ // 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)
-
- // gradient image
- 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]
-
- // legacy webkit
- end = grad-point(opposite-position(start))
- webkit-legacy = '-webkit-gradient(linear, %s, %s, %s)' % (grad-point(start) end join-stops(stops, webkit-stop))
- add-property(prop, replace(val, '__CALL__', webkit-legacy))
-
- // 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
'linear-gradient(%s, %s)' % (start stops)
/*
View
44 lib/nib/vendor.styl
@@ -75,7 +75,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
@@ -85,9 +85,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.
@@ -584,3 +588,37 @@ placeholder()
else if pair is not null && pair[0] is not null
{pair[0]}: type(pair[1]) == 'string' ? s(pair[1]) : pair[1]
input-placeholder = placeholder
+
+/*
+ * 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
View
3 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
+ background: linear-gradient(top, white, black), white

0 comments on commit 8f8231a

Please sign in to comment.