Git Product home page Git Product logo

broccoli-sprite's Introduction

A BroccoliJs plugin for sprite generation

Use this plugin in a project built using BroccoliJs to add CSS image sprites to it. Includes instructions for how to integrate into an ember-cli also included, and direct support is planned.

Supported stylesheet formats: SCSS, SASS, LESS, Stylus, CSS

broccoli-sprite NPM

npm install --save broccoli-sprite

Installation dependencies

You will need to install at least one of the following, before installing broccoli-sprite.

  • GraphicsMagick
  • node canvas
    • Ensure that you have NodeJs version is v0.10.29 (>= v0.11.x will not work)
    • On Ubuntu:
      • sudo apt-get install libcairo2-dev libjpeg8-dev libpango1.0-dev libgif-dev build-essential g++
      • npm install -g canvas

Usage

In Brocfile.js, add the following:

var broccoliSprite = require('broccoli-sprite');
var spritesTree = broccoliSprite('public', {
  src: [ 'public/images/sprites/*.png' ],
  spritePath: 'assets/sprites.png',
  stylesheetPath: 'assets/sprites.css',
  stylesheet: 'css',
  stylesheetOptions: {
    prefix: 'sprite-',
    spritePath: '/assets/sprites.png',
  },
});

โ€ฆ and be sure to merge spritesTree into the main tree.

Note that it is important to specify stylesheetOptions.spritePath, as otherwise a relative path will be used, and this will not work with fingerprinting, which is enabled by default in when building with environment=production.

Usage in ember-cli apps

It used to be rather complicated, but now ember-cli's addon/ plugin system has more features, and thus it is really as simple as npm installing a module.

You will, however, need to install a different package: ember-sprite. Look for a one-liner installation instruction there!

Configuration Options

broccoli-sprite wraps around the excellent node-sprite-generator library.

When you call broccoliSprite, it accepts two arguments: tree and options.

tree

This is any broccoli tree. In an ember-cli app, this would most likely be 'public'.

options

These options are passed into node-sprite-generator, so follow the options specified here.

There are a few things to note though:

src is the full path, not the path within the tree. Notice that in the example above, the tree is 'public', and "public" is repeated in the path within src.

The same is not true for output paths though, spritePath and stylesheetPath, which must be specified relative to the tree. Notice that "public" is not repeated within these paths.

Time Line

  • Make work with live-reload
  • Make it work as an ember-cli registry plugin, so that there is no need to extend EmberApp in Brocfile.js
  • Integrate into EmberApp.styles() such that CSS for sprites is concatenated and minifed together with CSS of app
    • Generated sprite images exported into style tree
    • Works in conjunction with registry plugin system, so that there is no need to extend EmberApp in Brocfile.js
  • Add caching to speed up incremental builds

Contributors

Maintained by bguiz.

Additional contributions from:

Licence

GPL v3

broccoli-sprite's People

Contributors

adriaandotcom avatar bguiz avatar connorhd avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.