svg-sprite
Advanced tools
Comparing version 1.3.3 to 1.3.4
@@ -172,3 +172,3 @@ #!/usr/bin/env node | ||
var JSONConfigContent = fs.readFileSync(path.resolve(file)); | ||
mergeConfig(JSON.parse(JSONConfigContent), config); | ||
var externalConfig = JSON.parse(JSONConfigContent); | ||
@@ -180,2 +180,17 @@ // Make a clone of initial config for options removal checks | ||
} | ||
// Expand shorthand mode definitions | ||
if (('mode' in externalConfig) && _.isObject(externalConfig.mode)) { | ||
for (var emode in externalConfig.mode) { | ||
if (externalConfig.mode[emode] === true) { | ||
externalConfig.mode[emode] = JSONConfig.mode[emode] = { | ||
render: { | ||
css: true | ||
} | ||
}; | ||
} | ||
} | ||
} | ||
mergeConfig(externalConfig, config); | ||
} catch (e) { | ||
@@ -182,0 +197,0 @@ console.error('[ERROR] Skipping --config file due to errors ("%s")', e.message.trim()); |
@@ -0,1 +1,7 @@ | ||
## 1.3.4 Bugfix release (2016-08-12) | ||
* Updated dependencies | ||
* Extended the ID generator callback signature ([#176](https://github.com/jkphl/svg-sprite/issues/176)) | ||
* Improved usage pattern example ([#177](https://github.com/jkphl/svg-sprite/issues/177)) | ||
* Added support for mode shorthand definitions in CLI mode ([#183](https://github.com/jkphl/svg-sprite/issues/183)) | ||
## 1.3.3 Bugfix release (2016-04-28) | ||
@@ -2,0 +8,0 @@ * Fixed CLI regression bug ([#173](https://github.com/jkphl/svg-sprite/issues/173)) |
@@ -104,3 +104,3 @@ svg-sprite [![NPM version][npm-image]][npm-url] [![Build Status][travis-image]][travis-url] [![Coverage Status][coveralls-image]][coveralls-url] [![Dependency Status][depstat-image]][depstat-url] [![Development Dependency Status][devdepstat-image]][devdepstat-url] | ||
`shape.id.separator` | String | `"--"` | Separator for traversing a directory structure into a shape ID | | ||
`shape.id.generator` | Function∣String | See desc. | Callback for translating the local part of a shape's file name into a shape ID. The callback's signature is `function(name) { /* ... */ return id; }`. By default, the file extension `".svg"` is stripped off and directory structures get traversed using the `id.separator` as replacement for the directory separator. You may also provide a template string (e.g. `"icon-%s"`), in which case the placeholder `"%s"` gets substituted with the traversed local file name. If the string doesn't contain any placeholder, it is used as a prefix to the local file name. | | ||
`shape.id.generator` | Function∣String | See desc. | Callback for translating the local part of a shape's file name into a shape ID. The callback's signature is `function(name, file) { /* ... */ return id; }`, where `name` is the relative path of the source file within the base directory and `file` the original [vinyl](https://github.com/wearefractal/vinyl) file object. By default, the file extension `".svg"` is stripped off the `name` value and directory structures are traversed using the `id.separator` as replacement for the directory separator. You may also provide a template string (e.g. `"icon-%s"`), in which case the placeholder `"%s"` gets substituted with the traversed local file name. If the string doesn't contain any placeholder, it is used as a prefix to the local file name. | | ||
`shape.id.pseudo` | String | `"~"` | String separator for pseudo CSS classes in file names. Example: `my-icon.svg` and `my-icon~hover.svg` for an icon with a regular and a `:hover` state. | | ||
@@ -107,0 +107,0 @@ `shape.id.whitespace` | String | `"_"` | Replacement string for whitespace characters in file names during shape ID generation. Example: By default, `My Custom Icon.svg` will result in the shape ID `my_custom_icon`. | |
@@ -84,22 +84,30 @@ 'use strict'; | ||
file = _.trim(file); | ||
name = _.trimStart(_.trim(name), path.sep + '.') || path.basename(file); | ||
svg = _.trim(svg); | ||
// Argument validation | ||
var error = null; | ||
if (arguments.length < 3) { | ||
error = 'SVGSpriter.add: You must provide 3 arguments'; | ||
} | ||
if (!file.length) { | ||
error = util.format('SVGSpriter.add: "%s" is not a valid absolute file name', file); | ||
} | ||
if (!name.length) { | ||
// If the name part of the file path is absolute | ||
if (path.isAbsolute(name)) { | ||
error = util.format('SVGSpriter.add: "%s" is not a valid relative file name', name); | ||
// Else | ||
} else { | ||
name = _.trimStart(_.trim(name), path.sep + '.') || path.basename(file); | ||
svg = _.trim(svg); | ||
// Argument validation | ||
var error = null; | ||
if (arguments.length < 3) { | ||
error = 'SVGSpriter.add: You must provide 3 arguments'; | ||
} | ||
if (!file.length) { | ||
error = util.format('SVGSpriter.add: "%s" is not a valid absolute file name', file); | ||
} | ||
if (!name.length) { | ||
error = util.format('SVGSpriter.add: "%s" is not a valid relative file name', name); | ||
} | ||
if (!svg.length) { | ||
error = 'SVGSpriter.add: You must provide SVG contents'; | ||
} | ||
if (file.substr(-name.length) !== name) { | ||
error = util.format('SVGSpriter.add: "%s" is not the local part of "%s"', name, file); | ||
} | ||
} | ||
if (!svg.length) { | ||
error = 'SVGSpriter.add: You must provide SVG contents'; | ||
} | ||
if (file.substr(-name.length) !== name) { | ||
error = util.format('SVGSpriter.add: "%s" is not the local part of "%s"', name, file); | ||
} | ||
@@ -106,0 +114,0 @@ // In case of an error: Throw it! |
@@ -34,5 +34,13 @@ 'use strict'; | ||
createIdGenerator = function(template) { | ||
return function(name) { | ||
/** | ||
* ID generator | ||
* | ||
* @param {String} name Relative file path | ||
* @param {File} file Original vinyl file | ||
* @returns {String} Shape ID | ||
*/ | ||
var generator = function(name, file) { | ||
return util.format(template || '%s', path.basename(name.split(path.sep).join(this.separator).replace(/\s+/g, this.whitespace), '.svg')); | ||
}; | ||
return generator; | ||
}, | ||
@@ -149,3 +157,3 @@ /** | ||
this.id = this.config.id.generator(this.name); | ||
this.id = this.config.id.generator(this.name, this.source); | ||
this.state = this.id.split(this.config.id.pseudo); | ||
@@ -152,0 +160,0 @@ this.base = this.state.shift(); |
{ | ||
"name": "svg-sprite", | ||
"version": "1.3.3", | ||
"version": "1.3.4", | ||
"author": "Joschi Kuphal <joschi@kuphal.net> (https://jkphl.is)", | ||
@@ -39,4 +39,4 @@ "description": "SVG sprites & stacks galore — A low-level Node.js module that takes a bunch of SVG files, optimizes them and bakes them into SVG sprites of several types along with suitable stylesheet resources (e.g. CSS, Sass, LESS, Stylus, etc.)", | ||
"mkdirp": "^0.5.1", | ||
"async": "^2.0.0-rc.6", | ||
"lodash": "^4.13.1", | ||
"async": "^2.0.1", | ||
"lodash": "^4.15.0", | ||
"lodash.pluck": "^3.1.2", | ||
@@ -46,11 +46,11 @@ "glob": "^7.0.5", | ||
"xpath": "^0.0.23", | ||
"vinyl": "^1.1.1", | ||
"vinyl": "^1.2.0", | ||
"svgo": "0.6.6", | ||
"cssom": "^0.3.1", | ||
"css-selector-parser": "^1.1.0", | ||
"phantomjs-prebuilt": "^2.1.7", | ||
"phantomjs-prebuilt": "^2.1.12", | ||
"cssmin": "^0.4.3", | ||
"mustache": "^2.2.1", | ||
"js-yaml": "^3.6.1", | ||
"yargs": "^4.7.1", | ||
"yargs": "^4.8.1", | ||
"winston": "^2.2.0", | ||
@@ -68,3 +68,3 @@ "prettysize": "^0.0.3" | ||
"svg2png": "jkphl/svg2png", | ||
"image-diff": "^1.6.0", | ||
"image-diff": "^1.6.3", | ||
"node-sass": "^3.8.0", | ||
@@ -71,0 +71,0 @@ "less": "^2.7.1", |
272954
3415
Updatedasync@^2.0.1
Updatedlodash@^4.15.0
Updatedphantomjs-prebuilt@^2.1.12
Updatedvinyl@^1.2.0
Updatedyargs@^4.8.1