template-utils
Advanced tools
Comparing version 0.2.0 to 0.3.0
'use strict'; | ||
var _ = require('lodash'); | ||
var path = require('path'); | ||
var extend = require('extend-shallow'); | ||
var matter = require('gray-matter'); | ||
var parsePath = require('parse-filepath'); | ||
var merge = require('merge-deep'); | ||
var pick = require('object.pick'); | ||
var vinylProps = require('./vinylProps'); | ||
var defaultProps = require('./defaultProps'); | ||
@@ -32,43 +33,11 @@ /** | ||
} else if (Buffer.isBuffer(file.contents) || typeof file.contents === 'string') { | ||
o = _.merge({}, o, matter(file.contents.toString())); | ||
o = merge({}, o, matter(file.contents.toString())); | ||
} | ||
_.extend(o, _.pick(file, vinylProps.whitelisted)); | ||
extend(o, pick(file, vinylProps.whitelisted)); | ||
// setup default properties on the template | ||
defaults(o, ['data', 'options', 'locals'], {}); | ||
// add default properties to the template | ||
o.path = o.path || file.path; | ||
o.ext = o.ext || path.extname(o.path); | ||
defaults(o.options, ['engine'], o.ext); | ||
defaults(o.data, ['src', 'dest'], {}); | ||
// add default `src` and `dest` properties to the `data` object | ||
if (typeof o.path !== 'string') { | ||
throw new Error('[template-utils] toTemplate expects `.path` to be a string'); | ||
} | ||
// Parse `file.path` into an object | ||
var parsed = parsePath(o.path); | ||
for (var prop in parsed) { | ||
if (Boolean(parsed[prop])) { | ||
defaults(o.data.src, [prop], parsed[prop]); | ||
defaults(o.data.dest, [prop], parsed[prop]); | ||
} | ||
} | ||
defaults(o.data.src, ['path'], o.path); | ||
defaults(o.data.dest, ['path'], o.data.src.path); | ||
defaults(o.data.dest, ['ext'], parsed.extname); | ||
defaultProps(o); | ||
return o; | ||
}; | ||
function defaults(o, props, fallback) { | ||
var len = props.length; | ||
var i = 0; | ||
while (len--) { | ||
var prop = props[i++]; | ||
o[prop] = o[prop] || fallback; | ||
} | ||
} |
@@ -5,4 +5,2 @@ 'use strict'; | ||
var File = require('vinyl'); | ||
var _ = require('lodash'); | ||
var extend = _.extend; | ||
@@ -22,3 +20,3 @@ /** | ||
module.exports = function toVinyl(template, options) { | ||
module.exports = function toVinyl(template) { | ||
debug('toVinyl: %j', arguments); | ||
@@ -25,0 +23,0 @@ template.locals = template.locals || {}; |
{ | ||
"name": "template-utils", | ||
"description": "Utils for [Template](https://github.com/jonschlinkert/template).", | ||
"version": "0.2.0", | ||
"version": "0.3.0", | ||
"homepage": "https://github.com/jonschlinkert/template-utils", | ||
@@ -17,8 +17,6 @@ "author": { | ||
}, | ||
"licenses": [ | ||
{ | ||
"type": "MIT", | ||
"url": "https://github.com/jonschlinkert/template-utils/blob/master/LICENSE-MIT" | ||
} | ||
], | ||
"license": { | ||
"type": "MIT", | ||
"url": "https://github.com/jonschlinkert/template-utils/blob/master/LICENSE-MIT" | ||
}, | ||
"main": "index.js", | ||
@@ -33,20 +31,17 @@ "engines": { | ||
"async": "^0.9.0", | ||
"chalk": "^0.5.1", | ||
"debug": "^2.1.0", | ||
"escape-delims": "^0.4.0", | ||
"export-files": "^0.1.4", | ||
"extend-shallow": "^0.1.1", | ||
"extend-shallow": "^0.2.0", | ||
"extract-gfm": "^0.1.0", | ||
"globby": "^1.0.0", | ||
"gray-matter": "^0.6.1", | ||
"js-comments": "^0.3.4", | ||
"lodash": "^2.4.1", | ||
"lookup-deps": "^0.2.5", | ||
"gray-matter": "^1.0.2", | ||
"merge-deep": "^0.1.3", | ||
"object.pick": "^1.1.0", | ||
"parse-filepath": "^0.5.0", | ||
"pretty-hrtime": "^0.2.2", | ||
"vinyl": "^0.4.5" | ||
"vinyl": "^0.4.6" | ||
}, | ||
"devDependencies": { | ||
"mocha": "*", | ||
"should": "*" | ||
"should": "*", | ||
"verb": "^0.3.9" | ||
}, | ||
@@ -53,0 +48,0 @@ "keywords": [ |
@@ -28,2 +28,8 @@ # template-utils [![NPM version](https://badge.fury.io/js/template-utils.svg)](http://badge.fury.io/js/template-utils) | ||
### [.defaultProps](lib/utils/defaultProps.js#L14) | ||
* `template` **{Object}**: Template Object to add properties to. | ||
Setup default properties and objects on a template object. | ||
### [.headings](lib/utils/headings.js#L22) | ||
@@ -45,5 +51,10 @@ | ||
### [.parsePath](lib/utils/parsePath.js#L15) | ||
### [.toTemplate](lib/utils/toTemplate.js#L22) | ||
* `template` **{Object}**: Template object | ||
Add parsed `src` and `dest` path properties to the `data` object. | ||
### [.toTemplate](lib/utils/toTemplate.js#L23) | ||
Convert a Vinyl file object to a non-vinyl template object. | ||
@@ -58,3 +69,3 @@ | ||
### [.toVinyl](lib/utils/toVinyl.js#L21) | ||
### [.toVinyl](lib/utils/toVinyl.js#L19) | ||
@@ -72,3 +83,2 @@ Convert a `template` object to a Vinyl file object. | ||
## Contributing | ||
@@ -90,2 +100,2 @@ Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](https://github.com/jonschlinkert/template-utils/issues) | ||
_This file was generated by [verb](https://github.com/assemble/verb) on December 03, 2014._ | ||
_This file was generated by [verb](https://github.com/assemble/verb) on December 20, 2014._ |
@@ -12,3 +12,3 @@ 'use strict'; | ||
basename: 'README.md', | ||
dirname: process.cwd().toLowerCase(), | ||
dirname: process.cwd(), | ||
ext: '.md', | ||
@@ -23,3 +23,3 @@ extSegments: ['.md'], | ||
basename: 'README.md', | ||
dirname: process.cwd().toLowerCase(), | ||
dirname: process.cwd(), | ||
ext: '.md', | ||
@@ -37,3 +37,3 @@ extSegments: ['.md'], | ||
basename: 'README.md', | ||
dirname: process.cwd().toLowerCase(), | ||
dirname: process.cwd(), | ||
ext: '.md', | ||
@@ -48,3 +48,3 @@ extSegments: ['.md'], | ||
basename: 'README.md', | ||
dirname: process.cwd().toLowerCase(), | ||
dirname: process.cwd(), | ||
ext: '.md', | ||
@@ -51,0 +51,0 @@ extSegments: ['.md'], |
@@ -36,16 +36,5 @@ /*! | ||
describe('.toVinyl()', function () { | ||
// compare the full fixture and expected objects in these tests | ||
// to ensure that we catch any changes to the file object | ||
it('should create a vinyl file object:', function () { | ||
var file = utils.toVinyl({}); | ||
file.should.eql({ | ||
_contents: null, | ||
base: process.cwd(), | ||
cwd: process.cwd(), | ||
data: {}, | ||
history: [], | ||
locals: {}, | ||
options: {}, | ||
stat: null | ||
}); | ||
file.should.have.properties(['_contents', 'base', 'cwd', 'data', 'locals']); | ||
}); | ||
@@ -52,0 +41,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
18469
11
29
442
96
3
+ Addedmerge-deep@^0.1.3
+ Addedobject.pick@^1.1.0
+ Addedansi-regex@2.1.1(transitive)
+ Addedansi-styles@2.2.1(transitive)
+ Addedchalk@1.1.3(transitive)
+ Addedclone-deep@0.1.1(transitive)
+ Addedextend-shallow@0.2.01.1.4(transitive)
+ Addedgray-matter@1.3.0(transitive)
+ Addedhas-ansi@2.0.0(transitive)
+ Addedisobject@3.0.1(transitive)
+ Addedkind-of@0.1.21.1.0(transitive)
+ Addedmerge-deep@0.1.5(transitive)
+ Addedmixin-object@0.1.1(transitive)
+ Addedobject.pick@1.3.0(transitive)
+ Addedstrip-ansi@3.0.1(transitive)
+ Addedsupports-color@2.0.0(transitive)
- Removedchalk@^0.5.1
- Removedglobby@^1.0.0
- Removedjs-comments@^0.3.4
- Removedlodash@^2.4.1
- Removedlookup-deps@^0.2.5
- Removedpretty-hrtime@^0.2.2
- Removedansi-regex@0.2.1(transitive)
- Removedansi-styles@1.0.01.1.0(transitive)
- Removedargparse@1.0.10(transitive)
- Removedarray-differ@0.1.01.0.0(transitive)
- Removedarray-union@0.1.01.0.2(transitive)
- Removedarray-uniq@0.1.11.0.3(transitive)
- Removedbalanced-match@1.0.2(transitive)
- Removedbrace-expansion@1.1.11(transitive)
- Removedchalk@0.4.00.5.1(transitive)
- Removedcode-context@0.2.3(transitive)
- Removedcoffee-script@1.12.7(transitive)
- Removedconcat-map@0.0.1(transitive)
- Removeddeep-filter-object@0.1.0(transitive)
- Removedesprima@4.0.1(transitive)
- Removedextend-shallow@0.1.1(transitive)
- Removedextract-comments@0.4.2(transitive)
- Removedfilter-keys@0.1.2(transitive)
- Removedfilter-object@0.1.3(transitive)
- Removedfrep@0.2.3(transitive)
- Removedget-value@0.3.2(transitive)
- Removedglob@4.5.3(transitive)
- Removedglobby@0.1.11.2.0(transitive)
- Removedgray-matter@0.6.2(transitive)
- Removedhas-ansi@0.1.0(transitive)
- Removedhas-color@0.1.7(transitive)
- Removedinflection@1.13.4(transitive)
- Removedinflight@1.0.6(transitive)
- Removedinherits@2.0.4(transitive)
- Removedisobject@0.2.0(transitive)
- Removedjs-comments@0.3.9(transitive)
- Removedjs-comments-template@0.4.2(transitive)
- Removedjs-yaml@3.14.1(transitive)
- Removedline-count@0.1.0(transitive)
- Removedlodash@2.4.23.10.1(transitive)
- Removedlodash-helpers@0.1.0(transitive)
- Removedlook-up@0.1.1(transitive)
- Removedlookup-deps@0.2.5(transitive)
- Removedlru-cache@2.7.3(transitive)
- Removedmap-files@0.1.2(transitive)
- Removedmarkdown-utils@0.1.3(transitive)
- Removedminimatch@1.0.02.0.10(transitive)
- Removedmultimatch@1.0.1(transitive)
- Removednormalize-path@0.3.0(transitive)
- Removedobject-assign@2.1.1(transitive)
- Removedonce@1.4.0(transitive)
- Removedparse-comments@0.3.4(transitive)
- Removedpretty-hrtime@0.2.2(transitive)
- Removedrelative@1.2.0(transitive)
- Removedrepeat-string@0.2.21.6.1(transitive)
- Removedreplacements@0.1.3(transitive)
- Removedsigmund@1.0.1(transitive)
- Removedsort-asc@0.1.0(transitive)
- Removedsort-desc@0.1.1(transitive)
- Removedsort-object@0.3.2(transitive)
- Removedsprintf-js@1.0.3(transitive)
- Removedstrip-ansi@0.1.10.3.0(transitive)
- Removedsupports-color@0.2.0(transitive)
- Removedtoml@2.3.6(transitive)
- Removedverbalize@0.1.2(transitive)
- Removedwrappy@1.0.2(transitive)
Updatedextend-shallow@^0.2.0
Updatedgray-matter@^1.0.2
Updatedvinyl@^0.4.6