Skip to content

Commit

Permalink
Merge branch 'release/0.9.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
Dhaulagiri committed Nov 7, 2018
2 parents 3cc8944 + a441292 commit 13ebb27
Show file tree
Hide file tree
Showing 4 changed files with 13,456 additions and 31 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@ That is all!

## Configuration

All the configuration options are exactly the same as those in
All the configuration options are pretty much the same as those in
[broccoli-sprite](https://github.com/bguiz/broccoli-sprite).
There is an extra option `removeSrcFiles` which tells addon to remove
source images after the sprite is finished.

The only thing that you need to do in addition is:

Expand All @@ -46,6 +48,7 @@ var app = new EmberApp({
src: [
'images/sprites/**/*.png'
],
removeSrcFiles: true,
spritePath: 'assets/sprites.png',
stylesheetPath: 'assets/sprites.css',
stylesheet: 'css',
Expand Down
71 changes: 45 additions & 26 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
/* eslint-env node */
'use strict';

const util = require('util');
const Funnel = require('broccoli-funnel');
const brocMergeTrees = require('broccoli-merge-trees');
const brocConcat = require('broccoli-concat');
const brocDelete = require('broccoli-file-remover');
const brocPickFiles = require('broccoli-static-compiler');
const concat = require('broccoli-concat');
const brocSprite = require('broccoli-sprite');
const util = require('util');

module.exports = {
name: 'ember-sprite',
Expand All @@ -17,58 +16,73 @@ module.exports = {

function treeFor( /*inTree*/ ) {}

function getAppCSSOutputPath(options) {
let appCssOutputPath = options.outputPaths.app.css.app;

if(appCssOutputPath[0] === '/' ){
appCssOutputPath = appCssOutputPath.substr(1);
}

return appCssOutputPath;
}

function postprocessTree(type, workingTree) {
if (type === 'all' && this.app.options.sprite) {
var self = this;
let self = this;
// retrieves the app CSS output path
const appCssOutputPath = getAppCSSOutputPath(this.app.options);

// for backwards compatibility to previous implementation that
// passed plain object into sprite,
// we push that object into an array we can iterate through to
// process the sprite(s)
if (Object.prototype.toString.call(this.app.options.sprite) ===
'[object Object]') {
var tmp = this.app.options.sprite;

let tmp = this.app.options.sprite;
this.app.options.sprite = [];
this.app.options.sprite.push(tmp);
}

// process each of the sprites that was passed in
this.app.options.sprite.forEach(function eachSprite(sprite) {
workingTree = self._processSprite(sprite, workingTree);
workingTree = self._processSprite(sprite, workingTree, appCssOutputPath);
});
}

return workingTree;
}

function _processSprite(sprite, workingTree) {
var spriteTree = brocPickFiles(workingTree, {
srcDir: '/',
files: sprite.src,
destDir: '/',
function _processSprite(sprite, workingTree, appCssOutputPath) {
let spriteTree = new Funnel(workingTree, {
srcDir: '/',
destDir: '/',
include: [
...sprite.src
],
});

if (!!sprite.debug) {
console.log('spriteTree', util.inspect(workingTree, false, 6, true));
}

spriteTree = brocSprite(spriteTree, sprite);

workingTree = brocMergeTrees([
workingTree,
spriteTree
]);

//sprites.css is appended to app.css,
//so that two separate styles sheets do not need to get linked from index.html
var appCssFile = 'assets/' +
(this.app.name || this.app.project.pkg.name) + '.css';
var spriteCssFile = sprite.stylesheetPath;
var treeConcatCss = brocConcat(workingTree, {

let spriteCssFile = sprite.stylesheetPath;

let treeConcatCss = concat(workingTree, {
inputFiles: [
appCssFile,
spriteCssFile
appCssOutputPath,
spriteCssFile
],
outputFile: '/'+appCssFile,
wrapInFunction: false,
outputFile: "/" + appCssOutputPath
});

workingTree = brocMergeTrees([
Expand All @@ -77,11 +91,16 @@ function _processSprite(sprite, workingTree) {
], {
overwrite: true,
});
workingTree = brocDelete(workingTree, {
files: [
spriteCssFile
],
});

if (sprite.removeSrcFiles) {
workingTree = new Funnel(workingTree, {
exclude: [
spriteCssFile,
...sprite.src
]
});
}


return workingTree;
}
Loading

0 comments on commit 13ebb27

Please sign in to comment.