Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Assume UTF-8 encoding for .markdown and .haml - using new Git.readFile functionality #31

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 6 additions & 9 deletions lib/wheat/data.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@ var Git = require('git-fs'),
QueryString = require('querystring');

function preProcessMarkdown(markdown) {
if (!(typeof markdown === 'string')) {
markdown = markdown.toString();
}
var props = { };

// Parse out headers
Expand Down Expand Up @@ -80,7 +77,7 @@ function sandbox(snippet) {
stdout.on('data', function(data) {
snippet.output += data.toString();
});

var env = {
clear: function () { snippet.output = ""; },
require: fakeRequire,
Expand Down Expand Up @@ -123,7 +120,7 @@ function activateSnippets(version, snippets, canExecute, callback) {
}
var group = this.group();
snippets.forEach(function (snippet) {
Git.readFile(version, "articles/" + snippet.filename, group());
Git.readFile(version, "articles/" + snippet.filename, "utf8", group());
});
},
function (err, files) {
Expand Down Expand Up @@ -181,7 +178,7 @@ var Data = module.exports = {
filename = path.substr(0, match.index);
}
url = "/" + (version === "fs" ? "" : version + "/") + filename;
Git.readFile(version, "articles/" + filename, this);
Git.readFile(version, "articles/" + filename, "utf8", this);
},
function (err, code) {
if (err) { error(err); return; }
Expand All @@ -208,7 +205,7 @@ var Data = module.exports = {
var props;
Step(
function getArticleMarkdown() {
Git.readFile(version, Path.join("articles", name + ".markdown"), this);
Git.readFile(version, Path.join("articles", name + ".markdown"), "utf8", this);
},
function (err, markdown) {
if (err) { callback(err); return; }
Expand All @@ -228,7 +225,7 @@ var Data = module.exports = {
props.author = author;

if(props.categories != undefined){
props.categories = props.categories.split(',').map(function(element){
props.categories = props.categories.split(',').map(function(element){
return QueryString.escape(element.trim());
});
}
Expand Down Expand Up @@ -286,7 +283,7 @@ var Data = module.exports = {
callback(new Error("name is required"));
return;
}
Git.readFile(version, Path.join("authors", name + ".markdown"), this);
Git.readFile(version, Path.join("authors", name + ".markdown"), "utf8", this);
},
function process(err, markdown) {
if (err) { callback(err); return; }
Expand Down
24 changes: 11 additions & 13 deletions lib/wheat/renderers.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,15 +108,15 @@ var Renderers = module.exports = {
function loadData(err, head) {
if (err) { callback(err); return; }
Data.articles(version, this.parallel());
Git.readFile(head, "description.markdown", this.parallel());
Data.categories(version, this.parallel());
Git.readFile(head, "description.markdown", "utf8", this.parallel());
Data.categories(version, this.parallel());
},
function applyTemplate(err, articles, description, categories) {
if (err) { callback(err); return; }
Tools.render("index", {
articles: articles,
description: description,
categories: categories
categories: categories
}, this);
},
function callPostProcess(err, buffer) {
Expand Down Expand Up @@ -174,7 +174,7 @@ var Renderers = module.exports = {
if (err) { callback(err); return; }
article = props;
insertSnippets(article.markdown, article.snippets, this.parallel());
Git.readFile(head, "description.markdown", this.parallel());
Git.readFile(head, "description.markdown", "utf8", this.parallel());
},
function applyTemplate(err, markdown, description) {
if (err) { callback(err); return; }
Expand Down Expand Up @@ -204,20 +204,20 @@ var Renderers = module.exports = {
function loadData(err, head) {
if (err) { callback(err); return; }
Data.articles(version, this.parallel());
Git.readFile(head, "description.markdown", this.parallel());
Data.categories(version, this.parallel());
Git.readFile(head, "description.markdown", "utf8", this.parallel());
Data.categories(version, this.parallel());
},
function applyTemplate(err, articles, description, categories) {
if (err) { callback(err); return; }

var articlesForCategory = articles.reduce(function (start, element){
return element.categories && element.categories.indexOf(category) >= 0 ? start.concat(element) : start;
}, []);

Tools.render("index", {
articles: articlesForCategory,
description: description,
categories: categories
categories: categories
}, this);
},
function callPostProcess(err, buffer) {
Expand All @@ -241,15 +241,13 @@ var Renderers = module.exports = {
}
return data;
},
function processFile(err, string) {
function processFile(err, data) {
if (err) { callback(err); return; }
var headers = {
"Content-Type": getMime(path),
"Cache-Control": "public, max-age=32000000"
};
var buffer = new Buffer(string.length);
buffer.write(string, 'binary');
postProcess(headers, buffer, version, path, this);
postProcess(headers, data, version, path, this);
},
callback
);
Expand Down
2 changes: 1 addition & 1 deletion lib/wheat/tools.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ function stringToBuffer(string) {
var loadTemplate = Git.safe(function loadTemplate(version, name, callback) {
Step(
function loadHaml() {
Git.readFile(version, "skin/" + name + ".haml", this);
Git.readFile(version, "skin/" + name + ".haml", "utf8", this);
},
function compileTemplate(err, haml) {
if (err) { callback(err); return; }
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"engines": ["node >= 0.4.0"],
"main": "lib/wheat.js",
"dependencies": {
"git-fs": ">=0.0.5",
"git-fs": ">=0.0.7",
"simple-mime": ">=0.0.1",
"haml": ">=0.2.5",
"step": ">=0.0.3",
Expand Down