Socket
Socket
Sign inDemoInstall

grunt-node-sprite-mixings

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

grunt-node-sprite-mixings - npm Package Compare versions

Comparing version 0.1.2 to 0.1.3

test/fixtures/bar.json

18

Gruntfile.js

@@ -29,14 +29,16 @@ /*

node_sprite_mixings: {
mixing: {
jsonFile: ['test/fixtures/mixing/*.json'],
dest: 'test/expected',
name: 'global'
basicAndExtras: {
files: {
'test/expected/bar.styl': ['test/fixtures/bar.json'],
'test/expected/foo.styl': ['test/fixtures/foo.json']
}
},
mixings: {
jsonFile: ['test/fixtures/mixings/*.json'],
dest: 'test/expected'
},
files: {
dest: 'test/expected/global.styl',
src: ['test/fixtures/*.json']
}
},
nodeunit: {

@@ -43,0 +45,0 @@ tests: ['test/*_test.js'],

{
"name": "grunt-node-sprite-mixings",
"description": "Generator mixings for stylus. Based on lib node-sprites",
"version": "0.1.2",
"version": "0.1.3",
"homepage": "https://github.com/SauloSilva/grunt-node-sprite-mixings",

@@ -6,0 +6,0 @@ "author": {

# grunt-node-sprite-mixings [![Build Status](https://travis-ci.org/SauloSilva/grunt-node-sprite-mixings.png?branch=master)](https://travis-ci.org/SauloSilva/grunt-node-sprite-mixings)
> Mixing generator for stylus from a json that contains the coordinates of the images on the sprite.
> Mixing generator for stylus, from a json that contains the coordinates of the images on the sprite.

@@ -33,8 +33,5 @@ ## Requirements

node_sprite_mixings: {
mixing: {
// Task-specific for one mixings.
},
mixings: {
// Task-specific for many mixings.
},
files: {
// task specifics
}
},

@@ -44,31 +41,18 @@ });

### Options
Before run the grunt-node-sprite-mixings task you must make sure that the sprite and json has been generated.
#### mixing.jsonFile or mixings.jsonFile
### Options
jsonFile: `Array` -
Specifies the path to the json file
This task has just one option.
#### mixing.dest or mixings.dest
#### jsonRemove
dest: `String` -
Specifies the path where the mixing must be generated
jsonRemove: `Boolean` -
By `default` is `false`, should you wish to delete the jsons after generation of the mixings.
#### mixing.autoRemove or mixings.autoRemove
autoRemove: `Boolean` -
By `default` is `false`, deletes the json file after generate the mixings
#### mixing.name
name: `String` -
Specifies the name of the mixing which shall be generated. For a group of mixings this option is not a valid because the name is inherited from the name of the sprite. For this reason he is only necessary to inside the **mixing** property.
### Usage Examples
#### One mixing
#### One file per sprites
Coming together of all sprites into a single mixing
Coming together of all json sprites into a single mixing.

@@ -78,7 +62,5 @@ ```js

node_sprite_mixings: {
mixing: {
jsonFile: ['public/images/*.json'],
dest: 'public/stylesheets/mixings',
name: 'example',
autoRemove: true
files: {
dest: 'public/stylesheets/mixings/example.styl',
src: ['public/images/*.json']
}

@@ -89,3 +71,3 @@ },

#### Many mixing
#### Multiple files per sprites

@@ -97,7 +79,8 @@ Mixings separated for every sprite.

node_sprite_mixings: {
mixings: {
jsonFile: ['public/images/*.json'],
dest: 'public/stylesheets/mixings',
autoRemove: true
}
basicAndExtras: {
files: {
'public/stylesheets/mixings/bar.styl': ['public/images/bar.json'],
'public/stylesheets/mixings/foo.styl': ['public/images/foo.json']
}
},
},

@@ -107,3 +90,3 @@ });

## Structural mixing / STYL
## Structural mixing expected / STYL

@@ -135,5 +118,6 @@ This is the format that is generated by mixing task:

## Structural Sprite Information / JSON
## Structural Sprite Information required / JSON
The json that was specified in jsonFile, should be in this structure.
To learn how to produce this automatic json lib check out the [node-sprite](https://github.com/naltatis/node-sprite#usage), and see how to utilize.

@@ -163,4 +147,5 @@

## Release History
* 2013-03-05 **v0.1.3** Improvements remove json and code refactors
* 2013-03-05 **v0.1.2** First released
Task submitted by [Saulo S. Santiago](http://www.linkedin.com/profile/view?id=119242632&trk=nav_responsive_tab_profile)

@@ -13,65 +13,36 @@ /*

module.exports = function(grunt) {
var src = [],
dest = [],
removeJson = false,
codes = '',
_ = grunt.util._;
var parserMixing = function(options) {
if (!optionsValidate(options, 'mixing')) {
var parserMixings = function() {
if (!validate()) {
return
}
var files = grunt.file.expand(options.jsonFile),
code = '';
files.forEach(function(file) {
var data = grunt.file.readJSON(file);
code += codeGenerator(data)
if (options.autoRemove) {
removeJson(file)
}
dest.forEach(function(path, i) {
src[i].forEach(function(file) {
codeGenerator(file)
})
mixingCreate(path)
codes = ''
})
var mixingPath = options.dest + '/' + options.name + '.styl'
stylMixingGenerator(mixingPath, code)
}
var parserMixings = function(options) {
if (!optionsValidate(options, 'mixings')) {
return
if (removeJson) {
remove()
}
var files = grunt.file.expand(options.jsonFile)
files.forEach(function(file) {
var code = '',
data = grunt.file.readJSON(file);
code = codeGenerator(data)
var mixingPath = options.dest + '/' + fileNameParse(file) + '.styl'
stylMixingGenerator(mixingPath, code)
if (options.autoRemove) {
removeJson(file)
}
})
}
var fileNameParse = function(file) {
return file.split('/')
.pop()
.split('.')
.shift()
}
var optionsValidate = function(options, type) {
var validate = function() {
switch (false) {
case typeof(options.jsonFile) === 'object':
grunt.log.warn('jsonFile not found.');
case !_.isEmpty(src):
grunt.log.warn('src not found!')
return false
break;
case options.dest !== '':
grunt.log.warn('dest not found.');
case !_.isEmpty(dest):
grunt.log.warn('dest not found!')
return false
break;
case !(options.name === '' && type === 'mixing'):
grunt.log.warn('name not found.');
return false
break;
default:

@@ -82,37 +53,39 @@ return true

var removeJson = function(file) {
grunt.file.delete(file)
grunt.log.ok(file + ' has been successfully deleted.')
var mixingCreate = function(path) {
var created = grunt.file.write(path, codes)
if (created) {
grunt.log.writeln(chalk.cyan(path) + ' has been created successfully.')
}
}
var stylMixingGenerator = function(path, code) {
grunt.file.write(path, code)
grunt.log.ok(path + ' has been created successfully.')
var remove = function() {
var paths = _.flatten(src)
paths.forEach(function(path) {
var deleted = grunt.file.delete(path)
if (deleted) {
grunt.log.writeln(chalk.cyan(path) + ' has been successfully deleted.')
}
})
}
var codeGenerator = function(data) {
var images = data.images,
var codeGenerator = function(file) {
var data = grunt.file.readJSON(file),
images = data.images,
shortName = data.shortsum,
name = data.name,
content = '';
name = data.name;
images.forEach(function(element, i) {
content += element.name.replace('_', '-') + "(repeat='no-repeat', x-offset=0, y-offset=0)\n background url('" + name + "-" + shortName + ".png') repeat (" + element.positionX + " + x-offset) (" + element.positionY + " + y-offset) transparent\n"
codes += element.name.replace('_', '-') + "(repeat='no-repeat', x-offset=0, y-offset=0)\n background url('" + name + "-" + shortName + ".png') repeat (" + element.positionX + " + x-offset) (" + element.positionY + " + y-offset) transparent\n"
})
return content
}
grunt.registerMultiTask('node_sprite_mixings', 'Generator mixings for stylus. Based on lib node-sprites', function() {
switch (false) {
case this.target !== 'mixing':
parserMixing(this.data)
break;
case this.target !== 'mixings':
parserMixings(this.data)
break;
default:
grunt.log.warn('Target mixing or mixings not found.');
}
this.files.forEach(function(file) {
dest.push(file.dest)
src.push(file.src)
removeJson = this.data.removeJson
}.bind(this))
parserMixings()
});
};
'use strict';
var grunt = require('grunt'),
_ = require('underscore');
_ = grunt.util._;
exports.node_sprite_mixings = {
mixing: function(test) {
test.expect(9);
global: function(test) {
test.expect(19);
var pathStyl = './test/expected/global.styl',
pathJson = './test/fixtures/mixing/example.json',
globalJson = grunt.file.readJSON(pathJson),
pathJson = './test/fixtures/',
jsons = ['bar.json', 'foo.json', 'example.json'],
globalStyl = grunt.file.read(pathStyl);
test.equal(grunt.file.exists(pathStyl), true, 'Should file exist')
test.notEqual(globalStyl.indexOf(_.first(globalJson.images).name), -1, 'Should contain the name of mixing, the same json of the file');
test.notEqual(globalStyl.indexOf(_.last(globalJson.images).name), -1, 'Should contain the name of mixing, the same json of the file');
test.notEqual(globalStyl.indexOf('background'), -1, 'Should contain the background of mixing');
test.notEqual(globalStyl.indexOf("url('" + globalJson.name + '-' + globalJson.shortsum + ".png')"), -1, 'Should contain the url of mixing');
jsons.forEach(function(json) {
var jsonParsed = grunt.file.readJSON(pathJson + json)
test.equal(grunt.file.exists(pathStyl), true, 'Should file exist')
test.notEqual(globalStyl.indexOf(_.first(jsonParsed.images).name), -1, 'Should contain the name of mixing, the same json of the file');
test.notEqual(globalStyl.indexOf(_.last(jsonParsed.images).name), -1, 'Should contain the name of mixing, the same json of the file');
test.notEqual(globalStyl.indexOf('background'), -1, 'Should contain the background of mixing');
test.notEqual(globalStyl.indexOf("url('" + jsonParsed.name + '-' + jsonParsed.shortsum + ".png')"), -1, 'Should contain the url of mixing');
})
test.notEqual(globalStyl.indexOf('repeat'), -1, 'Should contain the repeat of mixing');

@@ -26,25 +31,25 @@ test.notEqual(globalStyl.indexOf('y-offset'), -1, 'Should contain the y-offset of mixing');

mixings: function(test) {
test.expect(16);
var jsonPaths = ['./test/fixtures/mixings/foo.json', './test/fixtures/mixings/bar.json'],
stylPaths = ['./test/expected/foo.styl', './test/expected/bar.styl'],
filesJsons = [grunt.file.readJSON(_.first(jsonPaths)), grunt.file.readJSON(_.last(jsonPaths))],
filesStyl = [grunt.file.read(_.first(stylPaths)), grunt.file.read(_.last(stylPaths))];
basicAndExtra: function(test) {
test.expect(18);
var pathStyl = './test/expected/',
pathJson = './test/fixtures/',
files = ['foo', 'bar'];
filesStyl.forEach(function(element, i) {
test.equal(grunt.file.exists(jsonPaths[i]), true, 'Should file exist')
test.notEqual(element.indexOf(filesJsons[i].name), -1, 'Should contain the name of mixing, the same json of the file');
test.notEqual(element.indexOf('background'), -1, 'Should contain the background of mixing');
test.notEqual(element.indexOf("url('" + filesJsons[i].name + '-' + filesJsons[i].shortsum + ".png')"), -1, 'Should contain the url of mixing');
test.notEqual(element.indexOf('repeat'), -1, 'Should contain the repeat of mixing');
test.notEqual(element.indexOf('y-offset'), -1, 'Should contain the y-offset of mixing');
test.notEqual(element.indexOf('x-offset'), -1, 'Should contain the y-offset of mixing');
test.notEqual(element.indexOf('transparent'), -1, 'Should contain the transparent of mixing');
files.forEach(function(file) {
var styl = grunt.file.read(pathStyl + file + '.styl'),
jsonParsed = grunt.file.readJSON(pathJson + file + '.json');
test.notEqual(styl.indexOf(_.first(jsonParsed.images).name), -1, 'Should contain the name of mixing, the same json of the file');
test.notEqual(styl.indexOf(_.last(jsonParsed.images).name), -1, 'Should contain the name of mixing, the same json of the file');
test.notEqual(styl.indexOf('background'), -1, 'Should contain the background of mixing');
test.notEqual(styl.indexOf("url('" + jsonParsed.name + '-' + jsonParsed.shortsum + ".png')"), -1, 'Should contain the url of mixing');
test.equal(grunt.file.exists(pathStyl + file + '.styl'), true, 'Should file exist')
test.notEqual(styl.indexOf('repeat'), -1, 'Should contain the repeat of mixing');
test.notEqual(styl.indexOf('y-offset'), -1, 'Should contain the y-offset of mixing');
test.notEqual(styl.indexOf('x-offset'), -1, 'Should contain the y-offset of mixing');
test.notEqual(styl.indexOf('transparent'), -1, 'Should contain the transparent of mixing');
})
test.done();
},
fails: function(test) {
test.done();
}
};
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc