Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

spritesheet-templates

Package Overview
Dependencies
Maintainers
1
Versions
52
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

spritesheet-templates - npm Package Compare versions

Comparing version 8.3.0 to 8.4.0

2

CHANGELOG.md
# spritesheet-templates changelog
8.4.0 - Reverted `8.3.0` to remove breaking changes
8.3.0 - Added `variableNameTransforms`/`strings` for Mustache templates. Fixes #37

@@ -3,0 +5,0 @@

82

lib/spritesheet-templates.js

@@ -5,3 +5,2 @@ // Load in our dependencies

var _ = require('underscore');
var _s = require('underscore.string');
var mustache = require('mustache');

@@ -47,10 +46,9 @@ var jsonContentDemux = require('json-content-demux');

var spritesheet = JSON.parse(JSON.stringify(params.spritesheet));
spritesheet.name = options.spritesheetName || 'spritesheet';
// Add on extra data to spritesheet and each item
templater.escapeImage(spritesheet);
templater.ensureTemplateVariables(spritesheet);
templater.ensureOffsetAndPx(spritesheet);
items.forEach(function addExtraData (item) {
templater.addSpritesheetProperties(item, spritesheet);
templater.ensureTemplateVariables(item);
templater.ensureOffsetAndPx(item);
});

@@ -62,3 +60,3 @@

spritesheet: spritesheet,
spritesheet_name: spritesheet.name,
spritesheet_name: options.spritesheetName || 'spritesheet',
options: options.formatOpts || {}

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

// Helper function to ensure offset values exist as well as values with pixels in the name
templater.ensureTemplateVariables = function (item) {
templater.ensureOffsetAndPx = function (item) {
// Guarantee offsets exist

@@ -114,52 +112,2 @@ if (item.x !== undefined) {

templater.ensureMustacheVariables = function (item, transformFn) {
// Define strings in the appropriate case
item.strings = {};
// If we have a name, add on name keys
if (item.name) {
_.extend(item.strings, {
// icon-home
name: transformFn(item.name),
// icon-home-name
name_name: transformFn(item.name + '-name'),
// icon-home-x
name_x: transformFn(item.name + '-x'),
// icon-home-y
name_y: transformFn(item.name + '-y'),
// icon-home-offset-x
name_offset_x: transformFn(item.name + '-offset-x'),
// icon-home-offset-y
name_offset_y: transformFn(item.name + '-offset-y'),
// icon-home-width
name_width: transformFn(item.name + '-width'),
// icon-home-height
name_height: transformFn(item.name + '-height'),
// icon-home-total-width
name_total_width: transformFn(item.name + '-total-width'),
// icon-home-total-height
name_total_height: transformFn(item.name + '-total-height'),
// icon-home-image
name_image: transformFn(item.name + '-image'),
// icon-home-sprites
name_sprites: transformFn(item.name + '-sprites')
});
}
// Bare strings for maps
_.extend(item.strings, {
bare_name: transformFn('name'),
bare_x: transformFn('x'),
bare_y: transformFn('y'),
bare_offset_x: transformFn('offset-x'),
bare_offset_y: transformFn('offset-y'),
bare_width: transformFn('width'),
bare_height: transformFn('height'),
bare_total_width: transformFn('total-width'),
bare_total_height: transformFn('total-height'),
bare_image: transformFn('image'),
bare_sprites: transformFn('sprites')
});
};
// Add template store and helper methods to add new templates

@@ -181,24 +129,2 @@ templater.templates = {};

// If we want to transform our variables, then transform them
var transformFn = _.identity;
var variableNameTransforms = itemObj.options.variableNameTransforms;
if (variableNameTransforms) {
assert(Array.isArray(variableNameTransforms),
'`options.variableNameTransforms` was expected to be an array but it was not');
transformFn = function (str) {
var strObj = _s(str);
variableNameTransforms.forEach(function runTransform (transformKey) {
strObj = strObj[transformKey]();
});
return strObj.value();
};
}
// Generate strings for our variables
templater.ensureMustacheVariables(itemObj, transformFn);
templater.ensureMustacheVariables(itemObj.spritesheet, transformFn);
itemObj.items.forEach(function addMustacheVariables (item) {
templater.ensureMustacheVariables(item, transformFn);
});
// Render the items via the template

@@ -205,0 +131,0 @@ var retStr = mustache.render(tmpl, itemObj);

{
"name": "spritesheet-templates",
"description": "Convert spritesheet data into CSS or CSS pre-processor data",
"version": "8.3.0",
"version": "8.4.0",
"homepage": "https://github.com/twolfson/spritesheet-templates",

@@ -37,4 +37,3 @@ "author": {

"mustache": "~0.7.0",
"underscore": "~1.4.2",
"underscore.string": "~3.0.3"
"underscore": "~1.4.2"
},

@@ -41,0 +40,0 @@ "devDependencies": {

@@ -191,8 +191,2 @@ # spritesheet-templates [![Build status](https://travis-ci.org/twolfson/spritesheet-templates.svg?branch=master)](https://travis-ci.org/twolfson/spritesheet-templates)

- By default this is `true` (mixins will be included)
- variableNameTransforms `String[]` - Array of `underscore.string` methods to run on variable names
- For example, `['camelize']` would transform `icon-home-x` to `iconHomeX`
- By default, this is `['dasherize']` which yields a `dash-case` name
- `underscore.string`: http://epeli.github.io/underscore.string/#api
- We use `chain` which allows for `toUpperCase` and `toLowerCase`
- http://epeli.github.io/underscore.string/#s-string-gt-chain

@@ -226,8 +220,2 @@ **Example:**

- By default this is `true` (mixins will be included)
- variableNameTransforms `String[]` - Array of `underscore.string` methods to run on variable names
- For example, `['camelize']` would transform `icon-home-x` to `iconHomeX`
- By default, this is `['dasherize']` which yields a `dash-case` name
- `underscore.string`: http://epeli.github.io/underscore.string/#api
- We use `chain` which allows for `toUpperCase` and `toLowerCase`
- http://epeli.github.io/underscore.string/#s-string-gt-chain

@@ -261,8 +249,2 @@ **Example:**

- By default this is `true` (mixins will be included)
- variableNameTransforms `String[]` - Array of `underscore.string` methods to run on variable names
- For example, `['camelize']` would transform `icon-home-x` to `iconHomeX`
- By default, this is `['dasherize']` which yields a `dash-case` name
- `underscore.string`: http://epeli.github.io/underscore.string/#api
- We use `chain` which allows for `toUpperCase` and `toLowerCase`
- http://epeli.github.io/underscore.string/#s-string-gt-chain

@@ -296,8 +278,2 @@ **Example:**

- By default this is `true` (mixins will be included)
- variableNameTransforms `String[]` - Array of `underscore.string` methods to run on variable names
- For example, `['camelize']` would transform `icon-home-x` to `iconHomeX`
- By default, this is `['underscored']` which yields a `snake_case` name
- `underscore.string`: http://epeli.github.io/underscore.string/#api
- We use `chain` which allows for `toUpperCase` and `toLowerCase`
- http://epeli.github.io/underscore.string/#s-string-gt-chain

@@ -330,8 +306,2 @@ **Example:**

- By default this is `true` (mixins will be included)
- variableNameTransforms `String[]` - Array of `underscore.string` methods to run on variable names
- For example, `['camelize']` would transform `icon-home-x` to `iconHomeX`
- By default, this is `['underscored']` which yields a `snake_case` name
- `underscore.string`: http://epeli.github.io/underscore.string/#api
- We use `chain` which allows for `toUpperCase` and `toLowerCase`
- http://epeli.github.io/underscore.string/#s-string-gt-chain

@@ -389,3 +359,2 @@ **Example:**

- spritesheet `Object` - Information about spritesheet
- name `String` - Name for spritesheet
- width `Number` - Horizontal length of image in pixels

@@ -403,69 +372,2 @@ - height `Number` - Vertical length of image in pixels

###### Mustache template data
We provide an extra set of data for `mustache` templates for variable/string names.
- params.items[*].strings `Object` - Container for sprite-relevant variable/string names
- Each of these strings will be transformed via `variableNameTransforms`
- name `String` - Transformed name of sprite (e.g. `icon-home`)
- name_name `String` - Transformed combination of sprite name and `-name` string (e.g. `icon-home-name`)
- name_x `String` - Transformed combination of sprite name and `-x` string (e.g. `icon-home-x`)
- name_y `String` - Transformed combination of sprite name and `-y` string (e.g. `icon-home-y`)
- name_offset_x `String` - Transformed combination of sprite name and `-offset-x` string (e.g. `icon-home-offset-x`)
- name_offset_y `String` - Transformed combination of sprite name and `-offset-y` string (e.g. `icon-home-offset-y`)
- name_width `String` - Transformed combination of sprite name and `-width` string (e.g. `icon-home-width`)
- name_height `String` - Transformed combination of sprite name and `-height` string (e.g. `icon-home-height`)
- name_total_width `String` - Transformed combination of sprite name and `-total-width` string (e.g. `icon-home-total-width`)
- name_total_height `String` - Transformed combination of sprite name and `-total-height` string (e.g. `icon-home-total-height`)
- name_image `String` - Transformed combination of sprite name and `-image` string (e.g. `icon-home-image`)
- name_sprites `String` - Transformed combination of sprite name and `-sprites` string (e.g. `icon-home-sprites`)
- bare_name `String` - Transformed word for `name`
- bare_x `String` - Transformed word for `x`
- bare_y `String` - Transformed word for `y`
- bare_offset_x `String` - Transformed word for `offset-x`
- bare_offset_y `String` - Transformed word for `offset-y`
- bare_width `String` - Transformed word for `width`
- bare_height `String` - Transformed word for `height`
- bare_total_width `String` - Transformed word for `total-width`
- bare_total_height `String` - Transformed word for `total-height`
- bare_image `String` - Transformed word for `image`
- bare_sprites `String` - Transformed word for `sprites`
- params.spritesheet.strings `Object` - Container for spritesheet-relevant variable/string names
- Each of these strings will be transformed via `variableNameTransforms`
- name `String` - Transformed name of sprite (e.g. `icon-home`)
- name_name `String` - Transformed combination of sprite name and `-name` string (e.g. `icon-home-name`)
- name_x `String` - Transformed combination of sprite name and `-x` string (e.g. `icon-home-x`)
- name_y `String` - Transformed combination of sprite name and `-y` string (e.g. `icon-home-y`)
- name_offset_x `String` - Transformed combination of sprite name and `-offset-x` string (e.g. `icon-home-offset-x`)
- name_offset_y `String` - Transformed combination of sprite name and `-offset-y` string (e.g. `icon-home-offset-y`)
- name_width `String` - Transformed combination of sprite name and `-width` string (e.g. `icon-home-width`)
- name_height `String` - Transformed combination of sprite name and `-height` string (e.g. `icon-home-height`)
- name_total_width `String` - Transformed combination of sprite name and `-total-width` string (e.g. `icon-home-total-width`)
- name_total_height `String` - Transformed combination of sprite name and `-total-height` string (e.g. `icon-home-total-height`)
- name_image `String` - Transformed combination of sprite name and `-image` string (e.g. `icon-home-image`)
- name_sprites `String` - Transformed combination of sprite name and `-sprites` string (e.g. `icon-home-sprites`)
- bare_name `String` - Transformed word for `name`
- bare_x `String` - Transformed word for `x`
- bare_y `String` - Transformed word for `y`
- bare_offset_x `String` - Transformed word for `offset-x`
- bare_offset_y `String` - Transformed word for `offset-y`
- bare_width `String` - Transformed word for `width`
- bare_height `String` - Transformed word for `height`
- bare_total_width `String` - Transformed word for `total-width`
- bare_total_height `String` - Transformed word for `total-height`
- bare_image `String` - Transformed word for `image`
- bare_sprites `String` - Transformed word for `sprites`
- params.strings `Object` - Container for generic strings
- Each of these strings will be transformed via `variableNameTransforms`
- bare_name `String` - Transformed word for `name`
- bare_x `String` - Transformed word for `x`
- bare_y `String` - Transformed word for `y`
- bare_offset_x `String` - Transformed word for `offset-x`
- bare_offset_y `String` - Transformed word for `offset-y`
- bare_width `String` - Transformed word for `width`
- bare_height `String` - Transformed word for `height`
- bare_total_width `String` - Transformed word for `total-width`
- bare_total_height `String` - Transformed word for `total-height`
- bare_image `String` - Transformed word for `image`
- bare_sprites `String` - Transformed word for `sprites`
##### `templater.addTemplate(name, fn)`

@@ -472,0 +374,0 @@ Method to define a custom template under the format of `name`.

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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