2 Copyright (c) 2012, Yahoo! Inc. All rights reserved.
3 Copyrights licensed under the New BSD License. See the accompanying LICENSE file for terms.
6 var util = require('util'),
7 EventEmitter = require('events').EventEmitter;
9 function extend(cons, proto) {
10 Object.keys(proto).forEach(function (k) {
11 cons.prototype[k] = proto[k];
16 * abstract interfaces for writing content
17 * @class ContentWriter
22 //abstract interface for writing content
23 function ContentWriter() {
26 ContentWriter.prototype = {
28 * writes the specified string as-is
30 * @param {String} str the string to write
32 write: /* istanbul ignore next: abstract method */ function (/* str */) {
33 throw new Error('write: must be overridden');
36 * writes the specified string with a newline at the end
38 * @param {String} str the string to write
40 println: function (str) { this.write(str + '\n'); }
44 * abstract interface for writing files and assets. The caller is expected to
45 * call `done` on the writer after it has finished writing all the required
46 * files. The writer is an event-emitter that emits a `done` event when `done`
47 * is called on it *and* all files have successfully been written.
53 EventEmitter.call(this);
56 util.inherits(Writer, EventEmitter);
60 * allows writing content to a file using a callback that is passed a content writer
62 * @param {String} file the name of the file to write
63 * @param {Function} callback the callback that is called as `callback(contentWriter)`
65 writeFile: /* istanbul ignore next: abstract method */ function (/* file, callback */) {
66 throw new Error('writeFile: must be overridden');
69 * copies a file from source to destination
71 * @param {String} source the file to copy, found on the file system
72 * @param {String} dest the destination path
74 copyFile: /* istanbul ignore next: abstract method */ function (/* source, dest */) {
75 throw new Error('copyFile: must be overridden');
78 * marker method to indicate that the caller is done with this writer object
79 * The writer is expected to emit a `done` event only after this method is called
80 * and it is truly done.
83 done: /* istanbul ignore next: abstract method */ function () {
84 throw new Error('done: must be overridden');
90 ContentWriter: ContentWriter