Skip to content

Commit

Permalink
Add "resolve url". Fixes #71
Browse files Browse the repository at this point in the history
Update Travis config

Adds Data URI Image Inlining options

Added Authors, Docs, Version bump
  • Loading branch information
vladikoff committed Feb 22, 2014
1 parent 3b20dfc commit 6b1705c
Show file tree
Hide file tree
Showing 15 changed files with 123 additions and 24 deletions.
2 changes: 0 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,3 @@ language: node_js
node_js:
- "0.8"
- "0.10"
before_script:
- npm install -g grunt-cli
17 changes: 16 additions & 1 deletion AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,19 @@ Chris Talkington (http://christalkington.com/)
Jean-Sébastien Ney
Artem Sapegin (http://sapegin.me)
Jason Kuhrt (http://jasonkuhrt.com)
Artem Sapegin (http://sapegin.me)
Tyler Kellen
Kyle Robinson Young
Sindre Sorhus
Vlad Filippov
James Kyle
Dmitry Nikitenko
Vlad Filippov
Spike Brehm
Radko Dinev
Jonathan Dumaine
Joe Fleming
Devric
David Wood
Chris Abrams
Alessandro Zanardi
Adam Hull
30 changes: 30 additions & 0 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,28 @@ module.exports = function(grunt) {
urlfunc: 'embedurl'
}
},
embedurlObj: {
files: {
'tmp/embedurlObj.css': 'test/fixtures/embedurl/embedurl.styl'
},
options: {
urlfunc: {
name: 'embedurl'
}
}
},
urlfuncOpts: {
files: {
'tmp/embedurlOpts.css': 'test/fixtures/embedurl/embedurlOpts.styl'
},
options: {
urlfunc: {
name: 'embedurl',
limit: 10,
paths: []
},
}
},
relative: {
files: {
'tmp/relative.css': 'test/fixtures/relative/relative.styl'
Expand All @@ -96,6 +118,14 @@ module.exports = function(grunt) {
}
}
},
resolveUrl: {
files: {
'tmp/resolveUrl.css': 'test/fixtures/resolveUrl/resolveUrl.styl'
},
options: {
'resolve url': true
}
},
import: {
files: {
'tmp/import.css': 'test/fixtures/import/import.styl'
Expand Down
2 changes: 1 addition & 1 deletion LICENSE-MIT
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright (c) 2013 Eric Woroshow, contributors
Copyright (c) 2014 Eric Woroshow, contributors

Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
Expand Down
22 changes: 16 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# grunt-contrib-stylus v0.12.0 [![Build Status](https://travis-ci.org/gruntjs/grunt-contrib-stylus.png?branch=master)](https://travis-ci.org/gruntjs/grunt-contrib-stylus)
# grunt-contrib-stylus v0.13.0 [![Build Status](https://travis-ci.org/gruntjs/grunt-contrib-stylus.png?branch=master)](https://travis-ci.org/gruntjs/grunt-contrib-stylus)

> Compile Stylus files to CSS.
Expand Down Expand Up @@ -60,9 +60,17 @@ Type: `Object`
Allows you to define global variables in Gruntfile that will be accessible in Stylus files.

#### urlfunc
Type: `String`
Type: `String|Object`

If `String`: specifies function name that should be used for embedding images as Data URI.

If `Object`:
* `name` - Type: `String`. Function name that should be used for embedding images as Data URI.
* [ `limit` ] - Type: `Number|Boolean` Default: `30000`. Bytesize limit defaulting to 30Kb (30000), use false to disable the limit.
* [ `[paths` ] - Type: `Array`, Default: `[]`. Image resolution path(s).

See [url()](http://learnboost.github.io/stylus/docs/functions.url.html) for details.

Specifies function name that should be used for embedding images as Data URI.

#### [use](https://github.com/LearnBoost/stylus/blob/master/docs/js.md#usefn)
Type: `Array`
Expand All @@ -79,13 +87,15 @@ in every single one of said files.
Type: `Boolean`
Default: `false`

When including a css file in your app.styl by using @import "style.css", by default it will not include the full script, use `true` to compile into one script. ( **NOTICE:** the object key contains a space `"include css"` )
When including a css file in your app.styl by using @import "style.css", by default it will not include the full script, use `true` to compile into one script.
( **NOTICE:** the object key contains a space `"include css"` )

#### [resolve url](http://learnboost.github.io/stylus/docs/executable.html#resolving-relative-urls-inside-imports)
Type: `Boolean`
Default: `false`

Telling Stylus to generate `url("bar/baz.png")` in the compiled CSS files accordingly from `@import "bar/bar.styl"` and `url("baz.png")`, which makes relative pathes work in Stylus. ( **NOTICE:** the object key contains a space `"resolve url"` )
Telling Stylus to generate `url("bar/baz.png")` in the compiled CSS files accordingly from `@import "bar/bar.styl"` and `url("baz.png")`, which makes relative pathes work in Stylus.
( **NOTICE:** the object key contains a space `"resolve url"` and Stylus resolves the url only if it finds the provided file )

#### banner
Type: `String`
Expand Down Expand Up @@ -146,4 +156,4 @@ stylus: {

Task submitted by [Eric Woroshow](http://ericw.ca)

*This file was generated on Wed Jan 22 2014 17:42:03.*
*This file was generated on Sat Feb 22 2014 02:45:07.*
18 changes: 14 additions & 4 deletions docs/stylus-options.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,17 @@ Type: `Object`
Allows you to define global variables in Gruntfile that will be accessible in Stylus files.

## urlfunc
Type: `String`
Type: `String|Object`

If `String`: specifies function name that should be used for embedding images as Data URI.

If `Object`:
* `name` - Type: `String`. Function name that should be used for embedding images as Data URI.
* [ `limit` ] - Type: `Number|Boolean` Default: `30000`. Bytesize limit defaulting to 30Kb (30000), use false to disable the limit.
* [ `[paths` ] - Type: `Array`, Default: `[]`. Image resolution path(s).

See [url()](http://learnboost.github.io/stylus/docs/functions.url.html) for details.

Specifies function name that should be used for embedding images as Data URI.

## [use](https://github.com/LearnBoost/stylus/blob/master/docs/js.md#usefn)
Type: `Array`
Expand All @@ -48,13 +56,15 @@ in every single one of said files.
Type: `Boolean`
Default: `false`

When including a css file in your app.styl by using @import "style.css", by default it will not include the full script, use `true` to compile into one script. ( **NOTICE:** the object key contains a space `"include css"` )
When including a css file in your app.styl by using @import "style.css", by default it will not include the full script, use `true` to compile into one script.
( **NOTICE:** the object key contains a space `"include css"` )

## [resolve url](http://learnboost.github.io/stylus/docs/executable.html#resolving-relative-urls-inside-imports)
Type: `Boolean`
Default: `false`

Telling Stylus to generate `url("bar/baz.png")` in the compiled CSS files accordingly from `@import "bar/bar.styl"` and `url("baz.png")`, which makes relative pathes work in Stylus. ( **NOTICE:** the object key contains a space `"resolve url"` )
Telling Stylus to generate `url("bar/baz.png")` in the compiled CSS files accordingly from `@import "bar/bar.styl"` and `url("baz.png")`, which makes relative pathes work in Stylus.
( **NOTICE:** the object key contains a space `"resolve url"` and Stylus resolves the url only if it finds the provided file )

## banner
Type: `String`
Expand Down
11 changes: 4 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "grunt-contrib-stylus",
"description": "Compile Stylus files to CSS.",
"version": "0.12.0",
"version": "0.13.0",
"homepage": "https://github.com/gruntjs/grunt-contrib-stylus",
"author": {
"name": "Grunt Team",
Expand All @@ -28,7 +28,7 @@
"LICENSE-MIT"
],
"scripts": {
"test": "grunt test"
"test": "grunt jshint test"
},
"dependencies": {
"stylus": "~0.42.0",
Expand All @@ -40,16 +40,13 @@
"grunt-contrib-nodeunit": "~0.2.0",
"grunt-contrib-clean": "~0.4.1",
"grunt-contrib-internal": "~0.4.5",
"grunt": "~0.4.1"
"grunt": "~0.4.1",
"grunt-cli": "~0.1.13"
},
"peerDependencies": {
"grunt": "~0.4.0"
},
"keywords": [
"gruntplugin"
],
"files": [
"tasks",
"LICENSE-MIT"
]
}
13 changes: 11 additions & 2 deletions tasks/stylus.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* grunt-contrib-stylus
* http://gruntjs.com/
*
* Copyright (c) 2013 Eric Woroshow, contributors
* Copyright (c) 2014 Eric Woroshow, contributors
* Licensed under the MIT license.
*/

Expand Down Expand Up @@ -79,7 +79,14 @@ module.exports = function(grunt) {
grunt.util._.each(options, function(value, key) {
if (key === 'urlfunc') {
// Custom name of function for embedding images as Data URI
s.define(value, stylus.url());
if (typeof value === 'string') {
s.define(value, stylus.url());
} else {
s.define(value.name, stylus.url({
limit: value.limit ? value.limit : 30000,
paths: value.paths ? value.paths : []
}));
}
} else if (key === 'use') {
value.forEach(function(func) {
if (typeof func === 'function') {
Expand All @@ -94,6 +101,8 @@ module.exports = function(grunt) {
value.forEach(function(stylusModule) {
s.import(stylusModule);
});
} else if (key === 'resolve url') {
s.define('url', stylus.resolver());
} else {
s.set(key, value);
}
Expand Down
2 changes: 2 additions & 0 deletions test/expected/embedurl/embedurlOpts.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.normal{background-image:url("test.png")}
.base64not{background-image:url("test.png")}
1 change: 1 addition & 0 deletions test/expected/resolveUrl/resolveUrl.css
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
body{background:url("child/child.png")}
4 changes: 4 additions & 0 deletions test/fixtures/embedurl/embedurlOpts.styl
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.normal
background-image:url('test.png');
.base64not
background-image:embedurl('test.png');
Binary file added test/fixtures/resolveUrl/child/child.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions test/fixtures/resolveUrl/child/child.styl
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
body
// Stylus fixes the url only if it finds the provided file
background: url("child.png")
1 change: 1 addition & 0 deletions test/fixtures/resolveUrl/resolveUrl.styl
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@import "child/child.styl"
21 changes: 20 additions & 1 deletion test/stylus_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,20 @@ exports.stylus = {
embedurl: function(test) {
'use strict';

test.expect(1);
test.expect(3);

var actual = readFile('tmp/embedurl.css');
var expected = readFile('test/expected/embedurl/embedurl.css');
test.equal(expected, actual, '`embedurl` mixin should embed image as Data URI');

var actual2 = readFile('tmp/embedurlObj.css');
var expected2 = readFile('test/expected/embedurl/embedurl.css');
test.equal(actual2, expected2, '`embedurl` mixin should embed image as Data URI');

var actual3 = readFile('tmp/embedurlOpts.css');
var expected3 = readFile('test/expected/embedurl/embedurlOpts.css');
test.equal(actual3, expected3, '`embedurlOpts` limit should prevent Data URI embed');

test.done();
},
relative: function(test) {
Expand Down Expand Up @@ -115,6 +123,17 @@ exports.stylus = {
var expected = readFile('test/expected/banner/banner.css');
test.equal(expected, actual, 'should prefix with baner');

test.done();
},
resolveUrl: function(test) {
'use strict';

test.expect(1);

var actual = readFile('tmp/resolveUrl.css');
var expected = readFile('test/expected/resolveUrl/resolveUrl.css');
test.equal(expected, actual, 'should resolve import urls');

test.done();
}
};

0 comments on commit 6b1705c

Please sign in to comment.