dbot/modules/project/pages.js
Douglas Gardner 47d5404f38 Add beginnings of translation progress API
* Add totally legit and optimised code to find the number of strings in
  each language.
* Add this as an API call
* Add strings for ``na'vi``, ``es`` and ``nl`` for their own language
  names
* Optimise CSS a bit
* Add classes for the languages, for testing purposes
2013-04-21 12:18:24 +00:00

108 lines
3.9 KiB
JavaScript

var exec = require('child_process').exec,
request = require('request'),
_ = require('underscore');
var pages = function(dbot) {
var quoteCat = dbot.db.quoteArrs[dbot.config.name],
rev, diff, branch, credit, authors = [];
exec("git log --format='%cN¬' | sort -u | tr -d '\n'", function (error, stdout, sderr) {
var credit = stdout.split("¬"); // nobody uses ¬, do they?
for (var i = 0; i < credit.length; i++) {
if ((credit[i].split(" ").length) == 2){
console.log(credit[i]);
authors.push(credit[i]);
}
}
});
var trans = [];
// THIS IS TOTALLY LEGIT AND OPTIMISED CODE
/* for (var j = 0; j < Object.keys(dbot.strings).length; j++) {
var str = dbot.strings.j;
for (var k = 0; k < Object.keys(dbot.strings.str).length; k++) {
var lang = str.lang;
trans[lang]++;
}
} */
exec("git rev-list --all | wc -l", function(error, stdout, stderr) {
rev = stdout;
});
exec("git rev-parse --abbrev-ref HEAD", function(error, stdout, stderr) {
branch = stdout
});
exec("git log -1", function(error, stdout, stderr) {
diff = stdout
});
/* TODO: merge back into github module */
var milestones;
request("https://api.github.com/repos/" + dbot.config.github.defaultrepo + "/milestones?state=open", function(error, response, body){
milestones = JSON.parse(body);
});
return {
'/project': function(req, res) {
var quote = dbot.config.name;
if(quoteCat) {
quote = quoteCat[Math.floor(Math.random()*quoteCat.length)];
}
res.render('project', {
"translation": dbot.modules.project.api.translationProgress(),
"configList": dbot.modules.project.api.configList(),
"authors": authors, //dbot.modules.project.api.getAuthors(),
"credits": dbot.t("credits"),
"thanks": dbot.t("thanks"),
"name": dbot.config.name,
"intro": dbot.t("dbotintro", {
"botname": dbot.config.name
}),
"curr839": dbot.config.language,
"repo": dbot.config.github.defaultrepo,
"branch": dbot.t("branch",{
"branch": branch
}),
"currver": dbot.config.version,
"currlang": dbot.t("dbotspeaks",{
"lang839": dbot.config.language,
"langen": dbot.strings[dbot.config.language]["en"],
"lang": dbot.t(dbot.config.language),
"name": dbot.config.name
}),
"projectstatus": dbot.t("projectstatus"),
"revnum": dbot.t("revnum",{
"name": dbot.config.name,
"rev": rev
}),
"modules": dbot.config.moduleNames,
"loadmod": dbot.t("loadedmodules"),
"debugmode": dbot.t("debugmode-" + dbot.config.debugMode),
"milestones": milestones,
"milestoneprog": dbot.t("milestoneprog"),
"config": dbot.t("configoptions"),
"milestonename": dbot.t("milestonename"),
"openmilestone": dbot.t("openmilestone"),
"closedmilestone": dbot.t("closedmilestone"),
"development": dbot.t("development"),
"dquote": quote,
"diff": diff,
"pagetitle": dbot.t("pagetitle", {
"botname": dbot.config.name
}),
"git": dbot.t("git"),
"milestonehead": dbot.t("milestones"),
"propaganda": dbot.t("propaganda")
});
},
};
};
exports.fetch = function(dbot) {
return pages(dbot);
};