stylus-spritesmith-brunch
Adds Stylus support to Brunch with automatic sprite sheet generation.
Usage
Install the plugin via npm with npm install --save stylus-spritemith-brunch
.
Or, do manual install:
- Add
"stylus-spritesmith-brunch": "x.y.z"
to package.json
of your Brunch app. - If you want to use the
master
branch of the plugin, add "stylus-spritesmith-brunch": "git+ssh://git@github.com:jas/stylus-spritesmith-brunch.git"
.
Note: This plugin is a replacement for stylus-brunch
.
Using Sprites
This plugin defines Stylus mixins, variables, and functions that make using sprites in your stylesheets almost effortless.
Just drop images into app/assets/images/sprites
, and a sprite sheet will be compiled to public/images/spritesheets/default.png
.
If you need to configure the input and output directories, reference the Plugin Options section.
Mixin
The sprite
mixin is the easiest way to use a sprite image. To use the mixin, you must first import it into your stylesheets.
@import "sprites"
Then use it like so...
.logo {
sprite('logo.png') // finds "icon-star.png" in default sprite sheet
}
If you have multiple sprite sheets, a second argument can be given to specify the sprite sheet to which the image belongs.
.icon-star {
sprite('icon-star.png', 'icons') // finds "icon-star.png" in sprite sheet named "icons"
}
Variables and Functions
The following variables and functions are also available for use in your stylesheets.
Variable | Type | Description |
---|
sprite-sheets | List | List of sprite sheets generated |
default-sprite-sheet | String | Value of config option plugins.sprites.defaultSheet |
extend-sprite-sheets | Boolean | Value of config option plugins.sprites.useExtendDirective |
Sprite Sheet Functions
These functions return values about a given sprite-sheet
.
Function | Description |
---|
sprite-sheet-path | String — absolute path to the sprite sheet image |
sprite-sheet-width | Unit, px — width of an entire sprite sheet |
sprite-sheet-height | Unit, px — height of an entire sprite sheet |
Sprite Images
These functions return values about a given image
. A second, optional sprite-sheet
argument can be given to specify the sprite sheet to which the image belongs.
Function | Description |
---|
sprite-image-width | Unit, px — width of an individual sprite image |
sprite-image-height | Unit, px — height of an individual sprite image |
sprite-image-x | Unit, px — x-position of a sprite |
sprite-image-y | Unit, px — y-position of a sprite |
Plugin Options
Options for Stylus and Spritesmith can be set in the plugins
object in your brunch-config
. All values below are the defaults.
Stylus
plugins: {
stylus: {
compress: false,
firebug: false,
lineNumbers: false,
includeCss: false
}
}
Sprites
plugins: {
sprites: {
enabled: true,
outputDir: 'images/spritesheets',
outputFile: '{{name}}.png',
includeMixins: true,
useExtendDirective: false,
defaultSheet: 'default',
spriteSheets: {
'default': /^app\/assets\/images\/sprites\/(.*)\.png$/
},
engine: 'auto',
algoritm: 'binary-tree',
padding: 0,
exportOpts: {
format: 'png',
quality: 75,
timeout: 10000
},
engineOpts: {},
}
}
License
The MIT License (MIT)
Copyright (c) 2013 Jason Sandmeyer
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.