Skip to content

Commit

Permalink
Moved whole logic from the gradient function to the vendor ones, rewr…
Browse files Browse the repository at this point in the history
…iting the background, background-image etc. Fixes stylus#67
  • Loading branch information
kizu committed Aug 13, 2012
1 parent afcad00 commit 988d3de
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 27 deletions.
35 changes: 12 additions & 23 deletions lib/nib/gradients.styl
Original file line number Diff line number Diff line change
Expand Up @@ -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)

/*
Expand Down
44 changes: 41 additions & 3 deletions lib/nib/vendor.styl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
Expand Down Expand Up @@ -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
3 changes: 2 additions & 1 deletion test/cases/linear-gradient.styl
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@

@import 'nib/vendor'
@import 'nib/gradients'

body
Expand All @@ -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 988d3de

Please sign in to comment.