Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gradients1 #209

Merged
merged 5 commits into from Jul 31, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions lib/nib.js
Expand Up @@ -27,6 +27,8 @@ try {
// ignore // ignore
} }


var vendorHelpers = require('./nodes/vendor-helpers')

/** /**
* Library version. * Library version.
*/ */
Expand Down Expand Up @@ -64,5 +66,7 @@ function plugin() {
} else { } else {
style.define('has-canvas', nodes.false); style.define('has-canvas', nodes.false);
} }

style.define('gradients-syntax-fix', vendorHelpers);
} }
} }
37 changes: 26 additions & 11 deletions lib/nib/vendor.styl
Expand Up @@ -45,30 +45,37 @@ literal-join(string, literals)
return result return result


/* /*
* Prepend matched argument with given prefix * Modify matched arguments
* set strict to false to check as “begin with” * set strict to false to check as “begin with”
*/ */


prepend-args(args, prefix, argument, strict = true) modify-args(args, argument, prefix = '', postfix = '', replace = false, strict = true)
result = () result = ()
argument = unquote(argument) if type(argument) == 'string'
prefix = unquote(prefix)
postfix = unquote(postfix)

// Checking if there are values divided by comma // Checking if there are values divided by comma
if is-comma-list(args) if is-comma-list(args)
for subargs in args for subargs in args
subresult = () subresult = ()
for arg in subargs for arg in subargs
if (arg == argument and strict) or (match('^'+s('%s',argument),''+arg) and !strict) if (arg == argument and strict) or (match(''+s('%s',argument),''+arg) and !strict)
arg = s('%s%s',unquote(prefix),arg) arg = s('%s%s%s', prefix, replace ? replace : arg, postfix)
push(subresult, arg) push(subresult, arg) if arg != unquote('')
subresult = literal-join(' ', subresult) if length(subresult) > 1 subresult = literal-join(' ', subresult) if length(subresult) > 1
push(result, subresult) push(result, subresult)
result = literal-join(', ', result) result = literal-join(', ', result)
else else
for arg in args for arg in args
if (arg == argument and strict) or (match('^'+s('%s',argument),''+arg) and !strict) if (arg == argument and strict) or (match(''+s('%s',argument),''+arg) and !strict)
arg = s('%s%s',unquote(prefix),arg) arg = s('%s%s%s', prefix, replace ? replace : arg, postfix)
push(result, arg) push(result, arg) if arg != unquote('')
return result return result


remove-args(args, argument, strict = true)
return modify-args(args, argument, replace: unquote(''), strict: strict)

/* /*
* Vendor support for the given prop / arguments, * Vendor support for the given prop / arguments,
* optionally specifying the only prefixes to utilize, * optionally specifying the only prefixes to utilize,
Expand All @@ -82,11 +89,19 @@ vendor(prop, args, only = null, ignore = null, vendor-property = true)
{prop}: args {prop}: args
else else
newargs = args newargs = args
// Adjusting the args if needed
// Transforms in transitions need the prefixes
if prop in ('transition' 'transition-property') if prop in ('transition' 'transition-property')
newargs = prepend-args(args, '-' + prefix + '-', transform) newargs = modify-args(newargs, transform, '-' + prefix + '-')

// Adding prefixes for gradients
if prop in ('border-image' 'background' 'background-image' 'cursor' 'list-style' 'list-style-image') if prop in ('border-image' 'background' 'background-image' 'cursor' 'list-style' 'list-style-image')
newargs = prepend-args(args, '-' + prefix + '-', linear-gradient, false) newargs = modify-args(newargs, "-gradient\(", '-' + prefix + '-', strict: false)

// Removing the `fill` from prefixed border-images
if prop in ('border-image' 'border-image-slice')
newargs = remove-args(newargs, fill)

newprop = prop newprop = prop
newprop = '-' + prefix + '-' + prop if vendor-property newprop = '-' + prefix + '-' + prop if vendor-property
// TODO: make the adjustments for differences // TODO: make the adjustments for differences
Expand Down
20 changes: 20 additions & 0 deletions lib/nodes/vendor-helpers.js
@@ -0,0 +1,20 @@

/**
* Module dependencies.
*/

var stylus = require('stylus')
, nodes = stylus.nodes
, utils = stylus.utils

/**
* Expose `gradients-syntax-fix`.
*/

module.exports = function(value) {
if (value) {
return 'Hello ' + value.toString().toUpperCase()
} else {
return 'Hello World'
}
}
6 changes: 6 additions & 0 deletions test/cases/linear-gradient.css
Expand Up @@ -53,6 +53,12 @@ body {
-o-border-image: -o-linear-gradient(top, #fff 0, #000 100%) 20% stretch stretch; -o-border-image: -o-linear-gradient(top, #fff 0, #000 100%) 20% stretch stretch;
border-image: linear-gradient(top, #fff 0, #000 100%) 20% stretch stretch; border-image: linear-gradient(top, #fff 0, #000 100%) 20% stretch stretch;
} }
body {
-webkit-border-image: -webkit-linear-gradient(top, #fff 0, #000 100%) 20% stretch stretch;
-moz-border-image: -moz-linear-gradient(top, #fff 0, #000 100%) 20% stretch stretch;
-o-border-image: -o-linear-gradient(top, #fff 0, #000 100%) 20% stretch stretch;
border-image: linear-gradient(top, #fff 0, #000 100%) 20% fill stretch stretch;
}
body { body {
cursor: -webkit-linear-gradient(40deg, #f00 0, #0f0 100%); cursor: -webkit-linear-gradient(40deg, #f00 0, #0f0 100%);
cursor: -moz-linear-gradient(40deg, #f00 0, #0f0 100%); cursor: -moz-linear-gradient(40deg, #f00 0, #0f0 100%);
Expand Down
3 changes: 3 additions & 0 deletions test/cases/linear-gradient.styl
Expand Up @@ -28,6 +28,9 @@ body
body body
border-image: linear-gradient(top, #fff, #000) 20% stretch stretch; border-image: linear-gradient(top, #fff, #000) 20% stretch stretch;


body
border-image: linear-gradient(top, #fff, #000) 20% fill stretch stretch;

gradient-var = linear-gradient(40deg, red, lime) gradient-var = linear-gradient(40deg, red, lime)


body body
Expand Down
6 changes: 6 additions & 0 deletions test/cases/vendor.css
Expand Up @@ -150,6 +150,12 @@ section {
-moz-border-image: url("image.png") 20% stretch stretch; -moz-border-image: url("image.png") 20% stretch stretch;
border-image: url("image.png") 20% stretch stretch; border-image: url("image.png") 20% stretch stretch;
} }
section {
-o-border-image: url("image.png") 20% stretch stretch;
-webkit-border-image: url("image.png") 20% stretch stretch;
-moz-border-image: url("image.png") 20% stretch stretch;
border-image: url("image.png") 20% fill stretch stretch;
}
p { p {
-webkit-hyphens: auto; -webkit-hyphens: auto;
-moz-hyphens: auto; -moz-hyphens: auto;
Expand Down
3 changes: 3 additions & 0 deletions test/cases/vendor.styl
Expand Up @@ -79,6 +79,9 @@ button
section section
border-image: url("image.png") 20% stretch stretch; border-image: url("image.png") 20% stretch stretch;


section
border-image: url("image.png") 20% fill stretch stretch;

p p
hyphens: auto hyphens: auto


Expand Down