Instantly share code, notes, and snippets.

Embed
What would you like to do?
grunt-spritesmith notes
/*
SCSS variables are information about icon's compiled state, stored under its original file name
.icon-home {
width: $icon-home-width;
}
The large array-like variables contain all information about a single icon
$icon-home: x y offset_x offset_y width height total_width total_height image_path;
At the bottom of this section, we provide information about the spritesheet itself
$spritesheet: width height image $spritesheet-sprites;
*/
i[class*="-ipad-"] {
background-image: url(../images/sprites.png);
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
background-image: url(../images/sprites-2x.png);
}
}
$icons-ipad-rightnav-diagnose-name: 'icons-ipad-rightnav-diagnose';
$icons-ipad-rightnav-diagnose-x: 0px;
$icons-ipad-rightnav-diagnose-y: 0px;
$icons-ipad-rightnav-diagnose-offset-x: 0px;
$icons-ipad-rightnav-diagnose-offset-y: 0px;
$icons-ipad-rightnav-diagnose-width: 24px;
$icons-ipad-rightnav-diagnose-height: 24px;
$icons-ipad-rightnav-diagnose-total-width: 48px;
$icons-ipad-rightnav-diagnose-total-height: 48px;
$icons-ipad-rightnav-diagnose: (0px, 0px, 0px, 0px, 24px, 24px, 48px, 48px, 'icons-ipad-rightnav-diagnose', );
$icons-ipad-rightnav-fav-name: 'icons-ipad-rightnav-fav';
$icons-ipad-rightnav-fav-x: 24px;
$icons-ipad-rightnav-fav-y: 0px;
$icons-ipad-rightnav-fav-offset-x: -24px;
$icons-ipad-rightnav-fav-offset-y: 0px;
$icons-ipad-rightnav-fav-width: 24px;
$icons-ipad-rightnav-fav-height: 24px;
$icons-ipad-rightnav-fav-total-width: 48px;
$icons-ipad-rightnav-fav-total-height: 48px;
$icons-ipad-rightnav-fav: (24px, 0px, -24px, 0px, 24px, 24px, 48px, 48px, 'icons-ipad-rightnav-fav', );
$icons-ipad-rightnav-line-name: 'icons-ipad-rightnav-line';
$icons-ipad-rightnav-line-x: 0px;
$icons-ipad-rightnav-line-y: 24px;
$icons-ipad-rightnav-line-offset-x: 0px;
$icons-ipad-rightnav-line-offset-y: -24px;
$icons-ipad-rightnav-line-width: 24px;
$icons-ipad-rightnav-line-height: 24px;
$icons-ipad-rightnav-line-total-width: 48px;
$icons-ipad-rightnav-line-total-height: 48px;
$icons-ipad-rightnav-line: (0px, 24px, 0px, -24px, 24px, 24px, 48px, 48px, 'icons-ipad-rightnav-line', );
$icons-ipad-rightnav-diagnose-2x-name: 'icons-ipad-rightnav-diagnose@2x';
$icons-ipad-rightnav-diagnose-2x-x: 0px;
$icons-ipad-rightnav-diagnose-2x-y: 0px;
$icons-ipad-rightnav-diagnose-2x-offset-x: 0px;
$icons-ipad-rightnav-diagnose-2x-offset-y: 0px;
$icons-ipad-rightnav-diagnose-2x-width: 48px;
$icons-ipad-rightnav-diagnose-2x-height: 48px;
$icons-ipad-rightnav-diagnose-2x-total-width: 96px;
$icons-ipad-rightnav-diagnose-2x-total-height: 96px;
$icons-ipad-rightnav-diagnose-2x: (0px, 0px, 0px, 0px, 48px, 48px, 96px, 96px, 'icons-ipad-rightnav-diagnose@2x', );
$icons-ipad-rightnav-fav-2x-name: 'icons-ipad-rightnav-fav@2x';
$icons-ipad-rightnav-fav-2x-x: 48px;
$icons-ipad-rightnav-fav-2x-y: 0px;
$icons-ipad-rightnav-fav-2x-offset-x: -48px;
$icons-ipad-rightnav-fav-2x-offset-y: 0px;
$icons-ipad-rightnav-fav-2x-width: 48px;
$icons-ipad-rightnav-fav-2x-height: 48px;
$icons-ipad-rightnav-fav-2x-total-width: 96px;
$icons-ipad-rightnav-fav-2x-total-height: 96px;
$icons-ipad-rightnav-fav-2x: (48px, 0px, -48px, 0px, 48px, 48px, 96px, 96px, 'icons-ipad-rightnav-fav@2x', );
$icons-ipad-rightnav-line-2x-name: 'icons-ipad-rightnav-line@2x';
$icons-ipad-rightnav-line-2x-x: 0px;
$icons-ipad-rightnav-line-2x-y: 48px;
$icons-ipad-rightnav-line-2x-offset-x: 0px;
$icons-ipad-rightnav-line-2x-offset-y: -48px;
$icons-ipad-rightnav-line-2x-width: 48px;
$icons-ipad-rightnav-line-2x-height: 48px;
$icons-ipad-rightnav-line-2x-total-width: 96px;
$icons-ipad-rightnav-line-2x-total-height: 96px;
$icons-ipad-rightnav-line-2x: (0px, 48px, 0px, -48px, 48px, 48px, 96px, 96px, 'icons-ipad-rightnav-line@2x', );
$spritesheet-width: 48px;
$spritesheet-height: 48px;
$spritesheet-sprites: ($icons-ipad-rightnav-diagnose, $icons-ipad-rightnav-fav, $icons-ipad-rightnav-line, );
$spritesheet: (48px, 48px, $spritesheet-sprites, );
$retina-spritesheet-width: 96px;
$retina-spritesheet-height: 96px;
$retina-spritesheet-sprites: ($icons-ipad-rightnav-diagnose-2x, $icons-ipad-rightnav-fav-2x, $icons-ipad-rightnav-line-2x, );
$retina-spritesheet: (96px, 96px, $retina-spritesheet-sprites, );
/*
These "retina group" variables are mappings for the naming and pairing of normal and retina sprites.
The list formatted variables are intended for mixins like `retina-sprite` and `retina-sprites`.
*/
$icons-ipad-rightnav-diagnose-group-name: 'icons-ipad-rightnav-diagnose';
$icons-ipad-rightnav-diagnose-group: ('icons-ipad-rightnav-diagnose', $icons-ipad-rightnav-diagnose, $icons-ipad-rightnav-diagnose-2x, );
$icons-ipad-rightnav-fav-group-name: 'icons-ipad-rightnav-fav';
$icons-ipad-rightnav-fav-group: ('icons-ipad-rightnav-fav', $icons-ipad-rightnav-fav, $icons-ipad-rightnav-fav-2x, );
$icons-ipad-rightnav-line-group-name: 'icons-ipad-rightnav-line';
$icons-ipad-rightnav-line-group: ('icons-ipad-rightnav-line', $icons-ipad-rightnav-line, $icons-ipad-rightnav-line-2x, );
$retina-groups: ($icons-ipad-rightnav-diagnose-group, $icons-ipad-rightnav-fav-group, $icons-ipad-rightnav-line-group, );
/*
The provided mixins are intended to be used with the array-like variables
.icon-home {
@include sprite-width($icon-home);
}
.icon-email {
@include sprite($icon-email);
}
Example usage in HTML:
`display: block` sprite:
<div class="icon-home"></div>
To change `display` (e.g. `display: inline-block;`), we suggest using a common CSS class:
// CSS
.icon {
display: inline-block;
}
// HTML
<i class="icon icon-home"></i>
*/
@mixin sprite-width($sprite) {
width: nth($sprite, 5);
}
@mixin sprite-height($sprite) {
height: nth($sprite, 6);
}
@mixin sprite-position($sprite) {
$sprite-offset-x: nth($sprite, 3);
$sprite-offset-y: nth($sprite, 4);
background-position: $sprite-offset-x $sprite-offset-y;
}
@mixin sprite-image($sprite) {
$sprite-image: nth($sprite, 9);
background-image: url(#{$sprite-image});
}
@mixin sprite($sprite) {
@include sprite-position($sprite);
@include sprite-width($sprite);
@include sprite-height($sprite);
}
/*
The `retina-sprite` mixin sets up rules and a media query for a sprite/retina sprite.
It should be used with a "retina group" variable.
The media query is from CSS Tricks: https://css-tricks.com/snippets/css/retina-display-media-query/
$icon-home-group: ('icon-home', $icon-home, $icon-home-2x, );
.icon-home {
@include retina-sprite($icon-home-group);
}
*/
@mixin sprite-background-size($sprite) {
$sprite-total-width: nth($sprite, 7);
$sprite-total-height: nth($sprite, 8);
background-size: $sprite-total-width $sprite-total-height;
}
@mixin retina-sprite($retina-group) {
$normal-sprite: nth($retina-group, 2);
$retina-sprite: nth($retina-group, 3);
@include sprite($normal-sprite);
@media (-webkit-min-device-pixel-ratio: 2),
(min-resolution: 192dpi) {
@include sprite-background-size($normal-sprite);
}
}
/*
The `sprites` mixin generates identical output to the CSS template
but can be overridden inside of SCSS
@include sprites($spritesheet-sprites);
*/
@mixin sprites($sprites) {
@each $sprite in $sprites {
$sprite-name: nth($sprite, 10);
.#{$sprite-name} {
@include sprite($sprite);
}
}
}
/*
The `retina-sprites` mixin generates a CSS rule and media query for retina groups
This yields the same output as CSS retina template but can be overridden in SCSS
@include retina-sprites($retina-groups);
*/
@mixin retina-sprites($retina-groups) {
@each $retina-group in $retina-groups {
$sprite-name: nth($retina-group, 1);
.#{$sprite-name} {
@include retina-sprite($retina-group);
}
}
}
{
// Default options
'functions': true,
'variableNameTransforms': ['dasherize']
}
{{#block "sprites-comment"}}
/*
SCSS variables are information about icon's compiled state, stored under its original file name
.icon-home {
width: $icon-home-width;
}
The large array-like variables contain all information about a single icon
$icon-home: x y offset_x offset_y width height total_width total_height image_path;
At the bottom of this section, we provide information about the spritesheet itself
$spritesheet: width height image $spritesheet-sprites;
*/
{{/block}}
{{#block "sprites-imageurl"}}
i[class*="-ipad-"] {
background-image: url({{{spritesheet.image}}});
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
background-image: url({{{retina_spritesheet.image}}});
}
}
{{/block}}
{{#block "sprites"}}
{{#each sprites}}
${{strings.name_name}}: '{{name}}';
${{strings.name_x}}: {{px.x}};
${{strings.name_y}}: {{px.y}};
${{strings.name_offset_x}}: {{px.offset_x}};
${{strings.name_offset_y}}: {{px.offset_y}};
${{strings.name_width}}: {{px.width}};
${{strings.name_height}}: {{px.height}};
${{strings.name_total_width}}: {{px.total_width}};
${{strings.name_total_height}}: {{px.total_height}};
${{strings.name}}: ({{px.x}}, {{px.y}}, {{px.offset_x}}, {{px.offset_y}}, {{px.width}}, {{px.height}}, {{px.total_width}}, {{px.total_height}}, '{{name}}', );
{{/each}}
{{/block}}
{{#block "spritesheet"}}
${{spritesheet_info.strings.name_width}}: {{spritesheet.px.width}};
${{spritesheet_info.strings.name_height}}: {{spritesheet.px.height}};
${{spritesheet_info.strings.name_sprites}}: ({{#each sprites}}${{strings.name}}, {{/each}});
${{spritesheet_info.strings.name}}: ({{spritesheet.px.width}}, {{spritesheet.px.height}}, ${{spritesheet_info.strings.name_sprites}}, );
{{/block}}
{{#block "sprite-functions-comment"}}
{{#if options.functions}}
/*
The provided mixins are intended to be used with the array-like variables
.icon-home {
@include sprite-width($icon-home);
}
.icon-email {
@include sprite($icon-email);
}
Example usage in HTML:
`display: block` sprite:
<div class="icon-home"></div>
To change `display` (e.g. `display: inline-block;`), we suggest using a common CSS class:
// CSS
.icon {
display: inline-block;
}
// HTML
<i class="icon icon-home"></i>
*/
{{/if}}
{{/block}}
{{#block "sprite-functions"}}
{{#if options.functions}}
@mixin sprite-width($sprite) {
width: nth($sprite, 5);
}
@mixin sprite-height($sprite) {
height: nth($sprite, 6);
}
@mixin sprite-position($sprite) {
$sprite-offset-x: nth($sprite, 3);
$sprite-offset-y: nth($sprite, 4);
background-position: $sprite-offset-x $sprite-offset-y;
}
@mixin sprite-image($sprite) {
$sprite-image: nth($sprite, 9);
background-image: url(#{$sprite-image});
}
@mixin sprite($sprite) {
@include sprite-position($sprite);
@include sprite-width($sprite);
@include sprite-height($sprite);
}
{{/if}}
{{/block}}
{{#block "spritesheet-functions-comment"}}
{{#if options.functions}}
/*
The `sprites` mixin generates identical output to the CSS template
but can be overridden inside of SCSS
@include sprites($spritesheet-sprites);
*/
{{/if}}
{{/block}}
{{#block "spritesheet-functions"}}
{{#if options.functions}}
@mixin sprites($sprites) {
@each $sprite in $sprites {
$sprite-name: nth($sprite, 10);
.#{$sprite-name} {
@include sprite($sprite);
}
}
}
{{/if}}
{{/block}}
{
// Default options
'functions': true,
'variableNameTransforms': ['dasherize']
}
{{#extend "scss"}}
{{#content "sprites" mode="append"}}
{{#each retina_sprites}}
${{strings.name_name}}: '{{name}}';
${{strings.name_x}}: {{px.x}};
${{strings.name_y}}: {{px.y}};
${{strings.name_offset_x}}: {{px.offset_x}};
${{strings.name_offset_y}}: {{px.offset_y}};
${{strings.name_width}}: {{px.width}};
${{strings.name_height}}: {{px.height}};
${{strings.name_total_width}}: {{px.total_width}};
${{strings.name_total_height}}: {{px.total_height}};
${{strings.name}}: ({{px.x}}, {{px.y}}, {{px.offset_x}}, {{px.offset_y}}, {{px.width}}, {{px.height}}, {{px.total_width}}, {{px.total_height}}, '{{name}}', );
{{/each}}
{{/content}}
{{#content "spritesheet" mode="append"}}
${{retina_spritesheet_info.strings.name_width}}: {{retina_spritesheet.px.width}};
${{retina_spritesheet_info.strings.name_height}}: {{retina_spritesheet.px.height}};
${{retina_spritesheet_info.strings.name_sprites}}: ({{#each retina_sprites}}${{strings.name}}, {{/each}});
${{retina_spritesheet_info.strings.name}}: ({{retina_spritesheet.px.width}}, {{retina_spritesheet.px.height}}, ${{retina_spritesheet_info.strings.name_sprites}}, );
/*
These "retina group" variables are mappings for the naming and pairing of normal and retina sprites.
The list formatted variables are intended for mixins like `retina-sprite` and `retina-sprites`.
*/
{{#each retina_groups}}
${{strings.name_group_name}}: '{{name}}';
${{strings.name_group}}: ('{{name}}', ${{normal.strings.name}}, ${{retina.strings.name}}, );
{{/each}}
${{retina_groups_info.strings.name}}: ({{#each retina_groups}}${{strings.name_group}}, {{/each}});
{{/content}}
{{#content "sprite-functions" mode="append"}}
{{#if options.functions}}
/*
The `retina-sprite` mixin sets up rules and a media query for a sprite/retina sprite.
It should be used with a "retina group" variable.
The media query is from CSS Tricks: https://css-tricks.com/snippets/css/retina-display-media-query/
$icon-home-group: ('icon-home', $icon-home, $icon-home-2x, );
.icon-home {
@include retina-sprite($icon-home-group);
}
*/
@mixin sprite-background-size($sprite) {
$sprite-total-width: nth($sprite, 7);
$sprite-total-height: nth($sprite, 8);
background-size: $sprite-total-width $sprite-total-height;
}
@mixin retina-sprite($retina-group) {
$normal-sprite: nth($retina-group, 2);
$retina-sprite: nth($retina-group, 3);
@include sprite($normal-sprite);
@media (-webkit-min-device-pixel-ratio: 2),
(min-resolution: 192dpi) {
@include sprite-background-size($normal-sprite);
}
}
{{/if}}
{{/content}}
{{#content "spritesheet-functions" mode="append"}}
{{#if options.functions}}
/*
The `retina-sprites` mixin generates a CSS rule and media query for retina groups
This yields the same output as CSS retina template but can be overridden in SCSS
@include retina-sprites($retina-groups);
*/
@mixin retina-sprites($retina-groups) {
@each $retina-group in $retina-groups {
$sprite-name: nth($retina-group, 1);
.#{$sprite-name} {
@include retina-sprite($retina-group);
}
}
}
{{/if}}
{{/content}}
{{/extend}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment