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 #67
  • Loading branch information
kizu authored and notslang committed Jul 30, 2013
1 parent 82310f6 commit 8f8231a
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 30 deletions.
35 changes: 9 additions & 26 deletions lib/nib/gradients.styl
Original file line number Diff line number Diff line change
Expand Up @@ -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)

/*
Expand Down
44 changes: 41 additions & 3 deletions lib/nib/vendor.styl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
Expand Down Expand Up @@ -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
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 8f8231a

Please sign in to comment.