assemble-yaml
Advanced tools
Comparing version 0.1.6 to 0.1.7
{ | ||
"name": "assemble-yaml", | ||
"version": "0.1.6", | ||
"version": "0.1.7", | ||
"repo": "https://github.com/assemble/assemble-yaml.git", | ||
@@ -10,3 +10,8 @@ "main": [ | ||
"js-yaml": "~2.1.0", | ||
"lodash": "~1.3.1" | ||
"lodash": "~1.3.1", | ||
"iconv-lite": "~0.2.11", | ||
"chalk": "~0.2.1", | ||
"globule": "~0.1.0", | ||
"to": "~0.2.9", | ||
"sort-object": "0.0.2" | ||
}, | ||
@@ -13,0 +18,0 @@ "devDependencies": { |
@@ -11,6 +11,20 @@ /* | ||
var yaml = require('js-yaml'); | ||
var fs = require('fs'); | ||
var _ = require('lodash'); | ||
// Node.js | ||
var path = require('path'); | ||
var fs = require('fs'); | ||
// node_modules | ||
var iconv = require('iconv-lite'); | ||
var chalk = require('chalk'); | ||
var glob = require('globule'); | ||
var yaml = require('js-yaml'); | ||
var YAML = require('to').format.yaml; | ||
var _ = require('lodash'); | ||
// Local utils. | ||
var file = require('./utils/file'); | ||
var sortObject = require('sort-object'); | ||
var yamlOptions = ['filename', 'strict', 'schema']; | ||
@@ -32,3 +46,2 @@ | ||
var options = _.extend({}, {fromFile: true}, opts); | ||
var data = { | ||
@@ -78,3 +91,3 @@ originalContent: '', | ||
data.content = data.originalContent.substring(eoy + delim.length).replace(/^(\s*)/, ''); | ||
data.content = data.originalContent.substring(eoy + delim.length); | ||
return data; | ||
@@ -84,3 +97,51 @@ }; | ||
/** | ||
* Add and/or extend YFM with given properties or patterns. | ||
* @param {[type]} dest [description] | ||
* @param {[type]} src [description] | ||
* @param {[type]} options [description] | ||
* @return {[type]} [description] | ||
*/ | ||
exports.extend = function(dest, src, options) { | ||
options = options || {}; | ||
return glob.find(src, options).map(function (path) { | ||
var context = exports.extract(path, options).context; | ||
context = _.extend({}, options.props, context); | ||
// Optionally sort keys | ||
if(options.sort === true) { | ||
context = YAML.stringify(sortObject(context)); | ||
} else { | ||
context = YAML.stringify(context); | ||
} | ||
var content = exports.extract(path, options).content; | ||
return { | ||
path: path, | ||
context: context, | ||
content: content | ||
}; | ||
}).map(function (obj) { | ||
function fencedYAML(metadata, content) { | ||
return '---\n' + metadata + '\n---\n' + content; | ||
} | ||
var name = path.basename(obj.path); | ||
var page = fencedYAML(obj.context, obj.content); | ||
file.write(path.join(dest, name), page, function (err) { | ||
if (err) {throw err;} | ||
console.log(chalk.cyan('It\'s saved!')); | ||
}); | ||
}).join('\n'); | ||
}; | ||
/** | ||
* Convenience method for extracting YAML front matter only. | ||
@@ -91,2 +152,3 @@ */ | ||
}; | ||
exports.readYFM = exports.extractJSON; | ||
@@ -93,0 +155,0 @@ |
{ | ||
"name": "assemble-yaml", | ||
"version": "0.1.6", | ||
"version": "0.1.7", | ||
"description": "Utility library for working with YAML front matter. Works with or without Assemble.", | ||
@@ -48,3 +48,8 @@ "author": { | ||
"js-yaml": "~2.1.0", | ||
"lodash": "~1.3.1" | ||
"lodash": "~1.3.1", | ||
"iconv-lite": "~0.2.11", | ||
"chalk": "~0.2.1", | ||
"globule": "~0.1.0", | ||
"to": "~0.2.9", | ||
"sort-object": "0.0.2" | ||
}, | ||
@@ -51,0 +56,0 @@ "keywords": [ |
@@ -78,4 +78,4 @@ # assemble-yaml [![NPM version](https://badge.fury.io/js/assemble-yaml.png)](http://badge.fury.io/js/assemble-yaml) [![Build Status](https://travis-ci.org/assemble/assemble-yaml.png)](https://travis-ci.org/assemble/assemble-yaml) | ||
* 2013-08-11 v0.1.0 Initial setup - Migrated from main Assemble repo | ||
## Author | ||
@@ -82,0 +82,0 @@ |
@@ -31,3 +31,3 @@ /* | ||
originalContent: "---\nfoo: bar\nversion: 2\n---\n\n<span class=\"alert alert-info\">This is an alert</span>\n", | ||
content: "<span class=\"alert alert-info\">This is an alert</span>\n" | ||
content: "\n\n<span class=\"alert alert-info\">This is an alert</span>\n" | ||
}; | ||
@@ -84,3 +84,3 @@ | ||
originalContent: "---\nfoo: bar\nversion: 2\n---\n\n<span class=\"alert alert-info\">This is an alert</span>\n", | ||
content: "<span class=\"alert alert-info\">This is an alert</span>\n" | ||
content: "\n\n<span class=\"alert alert-info\">This is an alert</span>\n" | ||
}; | ||
@@ -87,0 +87,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
19167
24
365
7
2
+ Addedchalk@~0.2.1
+ Addedglobule@~0.1.0
+ Addediconv-lite@~0.2.11
+ Addedsort-object@0.0.2
+ Addedto@~0.2.9
+ Addedansi-styles@0.2.0(transitive)
+ Addedchalk@0.2.1(transitive)
+ Addedglob@3.1.21(transitive)
+ Addedglobule@0.1.0(transitive)
+ Addedgraceful-fs@1.2.3(transitive)
+ Addedhandy@0.0.13(transitive)
+ Addedhas-color@0.1.7(transitive)
+ Addedhtmlparser@1.7.7(transitive)
+ Addediconv-lite@0.2.11(transitive)
+ Addedinherits@1.0.2(transitive)
+ Addedlodash@1.0.2(transitive)
+ Addedlodash._basecreatecallback@2.2.1(transitive)
+ Addedlodash._createbound@2.2.1(transitive)
+ Addedlodash._createobject@2.2.1(transitive)
+ Addedlodash._noop@2.2.1(transitive)
+ Addedlodash._objecttypes@2.2.1(transitive)
+ Addedlodash._renative@2.2.1(transitive)
+ Addedlodash._setbinddata@2.2.1(transitive)
+ Addedlodash._shimkeys@2.2.1(transitive)
+ Addedlodash.assign@2.2.1(transitive)
+ Addedlodash.bind@2.2.1(transitive)
+ Addedlodash.identity@2.2.1(transitive)
+ Addedlodash.isfunction@2.2.1(transitive)
+ Addedlodash.isobject@2.2.1(transitive)
+ Addedlodash.keys@2.2.1(transitive)
+ Addedlodash.support@2.2.1(transitive)
+ Addedlru-cache@2.7.3(transitive)
+ Addedminimatch@0.2.14(transitive)
+ Addedminimist@0.0.10(transitive)
+ Addedoptimist@0.6.1(transitive)
+ Addedsigmund@1.0.1(transitive)
+ Addedsort-object@0.0.2(transitive)
+ Addedto@0.2.9(transitive)
+ Addedwordwrap@0.0.3(transitive)