grunt-montage
Advanced tools
Comparing version 0.0.5 to 0.0.6
@@ -34,2 +34,9 @@ module.exports = function (grunt) { | ||
montage: { | ||
defaults: { | ||
files: { | ||
"tmp/defaults": [ | ||
"test/fixtures/*.png" | ||
] | ||
} | ||
}, | ||
basic: { | ||
@@ -42,6 +49,6 @@ files: { | ||
options: { | ||
size: 16, | ||
prefix: ".montage", | ||
outputImage: "montage.png", | ||
outputStylesheet: "montage.css" | ||
size: 24, | ||
prefix: ".test", | ||
outputImage: "test.png", | ||
outputStylesheet: "test.css" | ||
} | ||
@@ -48,0 +55,0 @@ } |
{ | ||
"name": "grunt-montage", | ||
"description": "Generate CSS sprite sheets and the corresponding stylesheet", | ||
"version": "0.0.5", | ||
"version": "0.0.6", | ||
"author": { | ||
@@ -6,0 +6,0 @@ "name": "James Allardice", |
@@ -133,2 +133,7 @@ # montage | ||
## Contributing | ||
In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using [Grunt](http://gruntjs.com/). | ||
In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using [Grunt](http://gruntjs.com/). | ||
## Licensing and Attribution | ||
Grunt Montage is released under the MIT license as detailed in the LICENSE file that should be distributed with this library; the source code is [freely available](http://github.com/globaldev/grunt-montage). | ||
Grunt Montage was developed by [James Allardice](http://jamesallardice.com) during work on [White Label Dating](http://www.whitelabeldating.com/), while employed by [Global Personals Ltd](http://www.globalpersonals.co.uk). Global Personals Ltd have kindly agreed to the extraction and release of this software under the license terms above. |
@@ -14,11 +14,22 @@ module.exports = function (grunt) { | ||
var done = this.async(), | ||
options = this.data.options || {}, | ||
size = options.size || 16, | ||
prefix = options.prefix || ".montage", | ||
outputImage = options.outputImage || "montage.png", | ||
outputStylesheet = options.outputStylesheet || "montage.css", | ||
cliOptions = ""; | ||
cliOptions = "", | ||
options = {}, | ||
defaults = { | ||
size: 16, | ||
prefix: ".montage", | ||
outputImage: "montage.png", | ||
outputStylesheet: "montage.css", | ||
magick: {} | ||
}; | ||
// Configuration | ||
Object.keys(defaults).forEach(function (option) { | ||
if (this.data.options && this.data.options[option] !== undefined) { | ||
options[option] = this.data.options[option]; | ||
} else { | ||
options[option] = defaults[option]; | ||
} | ||
}, this); | ||
// Build ImageMagick montage option string | ||
options.magick = options.magick || {}; | ||
cliOptions = Object.keys(options.magick).map(function (option) { | ||
@@ -39,7 +50,7 @@ return "-" + option + " " + options.magick[option]; | ||
}), | ||
dest = path.join(files.dest, outputImage), | ||
dest = path.join(files.dest, options.outputImage), | ||
sqrt = Math.sqrt(src.length), | ||
rows = Math.floor(sqrt), | ||
cols = Math.ceil(sqrt), | ||
css = prefix + " { background: url('" + outputImage + "') no-repeat; width: " + size + "px; height: " + size + "px; }\n"; | ||
css = options.prefix + " { background: url('" + options.outputImage + "') no-repeat; width: " + options.size + "px; height: " + options.size + "px; }\n"; | ||
@@ -53,4 +64,4 @@ // Create the output directory if necessary (ImageMagick errors if it doesn't exist) | ||
css += src.map(function (image, i) { | ||
var offsetLeft = -size * (i % cols), | ||
offsetTop = -size * Math.floor(i / cols), | ||
var offsetLeft = -options.size * (i % cols), | ||
offsetTop = -options.size * Math.floor(i / cols), | ||
className = path.basename(image).replace(/\.\w+$/, "").replace(rSpecial, "\\$1"); | ||
@@ -66,9 +77,9 @@ | ||
return prefix + "." + className + " { background-position: " + offsetLeft + " " + offsetTop + "; }\n"; | ||
return options.prefix + "." + className + " { background-position: " + offsetLeft + " " + offsetTop + "; }\n"; | ||
}).join(""); | ||
grunt.file.write(path.join(files.dest, outputStylesheet), css); | ||
grunt.file.write(path.join(files.dest, options.outputStylesheet), css); | ||
// Execute the ImageMagick montage tool | ||
exec("montage -tile " + cols + "x -geometry " + size + "x" + size + " " + cliOptions + " " + src.join(" ") + " " + dest, function (err) { | ||
exec("montage -tile " + cols + "x -geometry " + options.size + "x" + options.size + " " + cliOptions + " " + src.join(" ") + " " + dest, function (err) { | ||
done(); | ||
@@ -75,0 +86,0 @@ }); |
@@ -8,6 +8,12 @@ exports.montage = (function () { | ||
return { | ||
defaults: function (test) { | ||
test.expect(2); | ||
test.equal(grunt.file.exists("tmp/defaults/montage.png"), true, "should generate a default montage.png file."); | ||
test.equal(grunt.file.exists("tmp/defaults/montage.css"), true, "should generage a default montage.css file."); | ||
test.done(); | ||
}, | ||
basic: function (test) { | ||
test.expect(2); | ||
test.equal(grunt.file.exists("tmp/basic/montage.png"), true, "should generate a default montage.png file."); | ||
test.equal(grunt.file.exists("tmp/basic/montage.css"), true, "should generage a default montage.css file."); | ||
test.equal(grunt.file.exists("tmp/basic/test.png"), true, "should generate a test.png file."); | ||
test.equal(grunt.file.exists("tmp/basic/test.css"), true, "should generage a test.css file."); | ||
test.done(); | ||
@@ -14,0 +20,0 @@ } |
31505
161
138