Skip to content

Commit

Permalink
Simplified file-reader implementation by using named callbacks
Browse files Browse the repository at this point in the history
- Named callbacks where introduced by listen.js v0.4.0
- Added CHANGES.md to packaged files
  • Loading branch information
mantoni committed May 9, 2013
1 parent 758c61f commit afd9b78
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 18 deletions.
26 changes: 11 additions & 15 deletions lib/file-reader.js
Expand Up @@ -82,9 +82,6 @@ function contextAwareFileProperties(context, filePath, suffix, json) {
}


var htmlFiles = ['.html', '.mustache'];


exports.read = function (filePath, context, callback) {

function parseJSON(json) {
Expand All @@ -97,19 +94,18 @@ exports.read = function (filePath, context, callback) {
}
}

var listener = listen();

readFile(filePath + '.json', parseJSON, {}, listener());
function trim(html) {
return html.trim();
}

htmlFiles.forEach(function (htmlFile) {
readFile(filePath + htmlFile, function (html) {
return html.trim();
}, '', listener());
});
var listener = listen();

readFile(filePath + '.json', parseJSON, {}, listener('json'));
readFile(filePath + '.html', trim, '', listener('html'));
readFile(filePath + '.mustache', trim, '', listener('mustache'));
readFile(filePath + '.md', function (markdown) {
return markdown;
}, null, listener());
}, null, listener('md'));

function extractJson(str, json) {
var match = str.match(/^\}/m);
Expand All @@ -129,13 +125,13 @@ exports.read = function (filePath, context, callback) {
callback(err);
} else {
// listen.js returns results in callback creation order:
var json = results[0];
var json = results.json;
var p = filePath.lastIndexOf('/');
var html = results[1] || results[2];
var html = results.html || results.mustache;
if (html) {
json.html = extractJson(html, json);
}
var markdown = results[3];
var markdown = results.md;
if (markdown) {
markdown = extractJson(markdown, json);
json.md = marked(markdown).trim();
Expand Down
6 changes: 3 additions & 3 deletions package.json
Expand Up @@ -2,7 +2,7 @@
"name" : "blogdown",
"version" : "0.7.0",
"description" : "Generate HTML with Mustache and Markdown",
"keywords" : ["html", "generator", "mustache", "markdown"],
"keywords" : ["html", "generator", "mustache", "markdown", "blog"],
"author" : "Maximilian Antoni (http://maxantoni.de)",
"homepage" : "http://github.com/mantoni/blogdown",
"main" : "./lib/blogdown.js",
Expand All @@ -20,7 +20,7 @@
"dependencies" : {
"marked" : "~0.2.8",
"mustache" : "~0.7.2",
"listen" : "~0.3.1",
"listen" : "~0.4.0",
"moment" : "~2.0.0",
"optimist" : "~0.3.7"
},
Expand All @@ -30,5 +30,5 @@
"sinon" : "~1.6.0",
"autolint" : "~1.1.3"
},
"files" : ["bin", "lib", "README.md", "LICENSE"]
"files" : ["bin", "lib", "README.md", "CHANGES.md", "LICENSE"]
}

0 comments on commit afd9b78

Please sign in to comment.