Skip to content

Commit

Permalink
adding write to view
Browse files Browse the repository at this point in the history
  • Loading branch information
doowb committed Aug 4, 2015
1 parent b9a2874 commit e91eb7e
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/file.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ var util = require('util');
*/

var lazy = require('lazy-cache')(require);
var write = lazy('write');
var clone = lazy('clone-deep');
var omit = lazy('object.omit');

Expand Down
34 changes: 34 additions & 0 deletions lib/view.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ var lazy = require('lazy-cache')(require);
var assign = lazy('assign-value');
var clone = lazy('clone-deep');
var omit = lazy('object.omit');
var write = lazy('write');

/**
* Local dependencies
Expand Down Expand Up @@ -244,6 +245,39 @@ utils.delegate(View.prototype, {
if (typeof view.path === 'undefined') {
utils.error('View#validate `path` is a required field: ', view);
}
},

/**
* Write the item to disk asynchronously.
*
* @param {String} `fp` Destination filepath.
* @param {Function} `cb` Callback function
* @returns {Object} Returns the instance for chaining.
* @api public
*/

write: function (fp, cb) {
if (typeof fp === 'function') {
cb = fp;
fp = null;
}

if (typeof cb !== 'function') {
throw new Error('async `write` was called without a callback function.');
}

var dest = fp || this.dest.path;
var src = this.src.path;
var str = this.content;

if (str) {
write()(dest, str, cb);
} else {
copy()(src, dest, cb);
}

this.emit('write', dest);
return this;
}
});

Expand Down

0 comments on commit e91eb7e

Please # to comment.