Skip to content

Commit

Permalink
better interface
Browse files Browse the repository at this point in the history
  • Loading branch information
1000ch committed May 10, 2015
1 parent 732c820 commit c82e93f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 11 deletions.
6 changes: 3 additions & 3 deletions bin/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ stats.parse(function (error, result) {
encoding: 'utf8'
}));

format.toTemplate(function (text) {
format.parseTemplate(function (text) {
console.log(text);
});

Expand All @@ -97,12 +97,12 @@ stats.parse(function (error, result) {
});
break;
case 'html':
format.toDefaultTemplate('../assets/html.hbs', function (html) {
format.toHTML(function (html) {
console.log(html);
});
break;
case 'md':
format.toDefaultTemplate('../assets/markdown.hbs', function (md) {
format.toMarkdown(function (md) {
console.log(md);
});
break;
Expand Down
23 changes: 15 additions & 8 deletions lib/format.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,28 @@ Format.prototype.setTemplate = function (templateString) {
this.template = new Template(templateString, prettify(this.data));
};

Format.prototype.toTemplate = function (callback) {
Format.prototype.parseTemplate = function (callback) {
if (!this.template) {
throw new Error('Template is not set');
} else {
this.template.parse(callback);
}
};

// toHTML and toMarkdown
Format.prototype.toDefaultTemplate = function (filePath, callback) {
var templatePath = path.join(__dirname, filePath);
var templateString = fs.readFileSync(templatePath, {
Format.prototype.toMarkdown = function (callback) {
var file = path.join(__dirname, '../assets/markdown.hbs');
this.setTemplate(fs.readFileSync(file, {
encoding: 'utf8'
});
this.template = new Template(templateString, prettify(this.data));
this.template.parse(callback);
}));
this.parseTemplate(callback);
};

Format.prototype.toHTML = function (callback) {
var file = path.join(__dirname, '../assets/html.hbs');
this.setTemplate(fs.readFileSync(file, {
encoding: 'utf8'
}));
this.parseTemplate(callback);
};

Format.prototype.toJSON = function (callback) {
Expand All @@ -52,6 +58,7 @@ Format.prototype.toCSV = function (callback) {
data[key] = data[key].join(' ');
}
});

converter.json2csv(data, function (error, csv) {
if (error) {
throw error;
Expand Down

0 comments on commit c82e93f

Please sign in to comment.