Merge branch 'develop' of git://github.com/ether/etherpad-lite

Conflicts:
	src/templates/pad.html
	src/templates/timeslider.html
This commit is contained in:
François Boulogne 2012-11-15 20:52:24 +01:00
commit d3ead86db1
87 changed files with 12193 additions and 341 deletions

View file

@ -30,6 +30,7 @@ exports.info = {
block_stack: [],
blocks: {},
file_stack: [],
args: []
};
exports._init = function (b, recursive) {
@ -81,7 +82,8 @@ exports.end_define_block = function () {
exports.end_block = function () {
var name = exports.info.block_stack[exports.info.block_stack.length-1];
var args = {content: exports.end_define_block()};
var renderContext = exports.info.args[exports.info.args.length-1];
var args = {content: exports.end_define_block(), renderContext: renderContext};
hooks.callAll("eejsBlock_" + name, args);
exports.info.buf.push(args.content);
}
@ -118,10 +120,13 @@ exports.require = function (name, args, mod) {
args.e = exports;
args.require = require;
var template = '<% e._init(buf); %>' + fs.readFileSync(ejspath).toString() + '<% e._exit(); %>';
exports.info.args.push(args);
exports.info.file_stack.push({path: ejspath, inherit: []});
var res = ejs.render(template, args);
exports.info.file_stack.pop();
exports.info.args.pop();
return res;
}

View file

@ -619,7 +619,7 @@ exports.updatePadClients = function(pad, callback)
//https://github.com/caolan/async#whilst
//send them all new changesets
async.whilst(
function (){ return sessioninfos[session].rev < pad.getHeadRevisionNumber()},
function (){ return sessioninfos[session] && sessioninfos[session].rev < pad.getHeadRevisionNumber()},
function(callback)
{
var author, revChangeset, currentTime;

View file

@ -0,0 +1,8 @@
var eejs = require('ep_etherpad-lite/node/eejs');
exports.expressCreateServer = function (hook_name, args, cb) {
args.app.get('/admin', function(req, res) {
res.send( eejs.require("ep_etherpad-lite/templates/admin/index.html", {}) );
});
}

View file

@ -0,0 +1,54 @@
var path = require('path');
var eejs = require('ep_etherpad-lite/node/eejs');
var settings = require('ep_etherpad-lite/node/utils/Settings');
var installer = require('ep_etherpad-lite/static/js/pluginfw/installer');
var hooks = require("ep_etherpad-lite/static/js/pluginfw/hooks");
var fs = require('fs');
exports.expressCreateServer = function (hook_name, args, cb) {
args.app.get('/admin/settings', function(req, res) {
var render_args = {
settings: "",
search_results: {},
errors: []
};
res.send( eejs.require("ep_etherpad-lite/templates/admin/settings.html", render_args) );
});
}
exports.socketio = function (hook_name, args, cb) {
var io = args.io.of("/settings");
io.on('connection', function (socket) {
if (!socket.handshake.session.user || !socket.handshake.session.user.is_admin) return;
socket.on("load", function (query) {
fs.readFile('settings.json', 'utf8', function (err,data) {
if (err) {
return console.log(err);
}
else
{
socket.emit("settings", {results: data});
}
});
});
socket.on("saveSettings", function (settings) {
fs.writeFile('settings.json', settings, function (err) {
if (err) throw err;
socket.emit("saveprogress", "saved");
});
});
socket.on("restartServer", function () {
console.log("Admin request to restart server through a socket on /admin/settings");
settings.reloadSettings();
hooks.aCallAll("restartServer", {}, function () {});
});
});
}

View file

@ -12,12 +12,32 @@ exports.expressCreateServer = function (hook_name, args, cb) {
//serve robots.txt
args.app.get('/robots.txt', function(req, res)
{
var filePath = path.normalize(__dirname + "/../../../static/robots.txt");
res.sendfile(filePath);
var filePath = path.normalize(__dirname + "/../../../static/custom/robots.txt");
res.sendfile(filePath, function(err)
{
//there is no custom favicon, send the default robots.txt which dissallows all
if(err)
{
filePath = path.normalize(__dirname + "/../../../static/robots.txt");
res.sendfile(filePath);
}
});
});
//serve favicon.ico
args.app.get('/favicon.ico', function(req, res)
//serve pad.html under /p
args.app.get('/p/:pad', function(req, res, next)
{
res.send(eejs.require("ep_etherpad-lite/templates/pad.html", {req: req}));
});
//serve timeslider.html under /p/$padname/timeslider
args.app.get('/p/:pad/timeslider', function(req, res, next)
{
res.send(eejs.require("ep_etherpad-lite/templates/timeslider.html", {req: req}));
});
//serve favicon.ico from all path levels except as a pad name
args.app.get( /\/favicon.ico$/, function(req, res)
{
var filePath = path.normalize(__dirname + "/../../../static/custom/favicon.ico");
res.sendfile(filePath, function(err)
@ -31,16 +51,5 @@ exports.expressCreateServer = function (hook_name, args, cb) {
});
});
//serve pad.html under /p
args.app.get('/p/:pad', function(req, res, next)
{
res.send(eejs.require("ep_etherpad-lite/templates/pad.html"));
});
//serve timeslider.html under /p/$padname/timeslider
args.app.get('/p/:pad/timeslider', function(req, res, next)
{
res.send(eejs.require("ep_etherpad-lite/templates/timeslider.html"));
});
}

View file

@ -0,0 +1,46 @@
var path = require("path");
var fs = require("fs");
exports.expressCreateServer = function (hook_name, args, cb) {
args.app.get('/tests/frontend/specs_list.js', function(req, res){
fs.readdir('tests/frontend/specs', function(err, files){
if(err){ return res.send(500); }
res.send("var specs_list = " + JSON.stringify(files.sort()) + ";\n");
});
});
var url2FilePath = function(url){
var subPath = url.substr("/tests/frontend".length);
if (subPath == ""){
subPath = "index.html"
}
subPath = subPath.split("?")[0];
var filePath = path.normalize(__dirname + "/../../../../tests/frontend/")
filePath += subPath.replace("..", "");
return filePath;
}
args.app.get('/tests/frontend/specs/*', function (req, res) {
var specFilePath = url2FilePath(req.url);
var specFileName = path.basename(specFilePath);
fs.readFile(specFilePath, function(err, content){
if(err){ return res.send(500); }
content = "describe(" + JSON.stringify(specFileName) + ", function(){ " + content + " });";
res.send(content);
});
});
args.app.get('/tests/frontend/*', function (req, res) {
var filePath = url2FilePath(req.url);
res.sendfile(filePath);
});
args.app.get('/tests/frontend', function (req, res) {
res.redirect('/tests/frontend/');
});
}

33
src/node/hooks/i18n.js Normal file
View file

@ -0,0 +1,33 @@
var Globalize = require('globalize')
, fs = require('fs')
, path = require('path')
, express = require('express')
var localesPath = __dirname+"/../../locales";
var localeIndex = '[*]\r\n@import url(locales/en.ini)\r\n';
exports.availableLangs = {en: 'English'};
fs.readdir(localesPath, function(er, files) {
files.forEach(function(locale) {
locale = locale.split('.')[0]
if(locale.toLowerCase() == 'en') return;
// build locale index
localeIndex += '['+locale+']\r\n@import url(locales/'+locale+'.ini)\r\n'
require('globalize/lib/cultures/globalize.culture.'+locale+'.js')
var culture = Globalize.cultures[locale];
exports.availableLangs[culture.name] = culture.nativeName;
})
})
exports.expressCreateServer = function(n, args) {
args.app.use('/locales', express.static(localesPath));
args.app.get('/locales.ini', function(req, res) {
res.send(localeIndex);
})
}

View file

@ -29,6 +29,16 @@ var vm = require('vm');
/* Root path of the installation */
exports.root = path.normalize(path.join(npm.dir, ".."));
/**
* The app title, visible e.g. in the browser window
*/
exports.title = "Etherpad Lite";
/**
* The app favicon fully specified url, visible e.g. in the browser window
*/
exports.favicon = "favicon.ico";
/**
* The IP ep-lite should listen to
*/
@ -102,50 +112,58 @@ exports.abiwordAvailable = function()
}
}
// Discover where the settings file lives
var settingsFilename = argv.settings || "settings.json";
settingsFilename = path.resolve(path.join(root, settingsFilename));
var settingsStr;
try{
//read the settings sync
settingsStr = fs.readFileSync(settingsFilename).toString();
} catch(e){
console.warn('No settings file found. Continuing using defaults!');
}
// try to parse the settings
var settings;
try {
if(settingsStr) {
settings = vm.runInContext('exports = '+settingsStr, vm.createContext(), "settings.json");
exports.reloadSettings = function reloadSettings() {
// Discover where the settings file lives
var settingsFilename = argv.settings || "settings.json";
settingsFilename = path.resolve(path.join(root, settingsFilename));
var settingsStr;
try{
//read the settings sync
settingsStr = fs.readFileSync(settingsFilename).toString();
} catch(e){
console.warn('No settings file found. Continuing using defaults!');
}
}catch(e){
console.error('There was an error processing your settings.json file: '+e.message);
process.exit(1);
}
//loop trough the settings
for(var i in settings)
{
//test if the setting start with a low character
if(i.charAt(0).search("[a-z]") !== 0)
// try to parse the settings
var settings;
try {
if(settingsStr) {
settings = vm.runInContext('exports = '+settingsStr, vm.createContext(), "settings.json");
}
}catch(e){
console.error('There was an error processing your settings.json file: '+e.message);
process.exit(1);
}
//loop trough the settings
for(var i in settings)
{
console.warn("Settings should start with a low character: '" + i + "'");
//test if the setting start with a low character
if(i.charAt(0).search("[a-z]") !== 0)
{
console.warn("Settings should start with a low character: '" + i + "'");
}
//we know this setting, so we overwrite it
//or it's a settings hash, specific to a plugin
if(exports[i] !== undefined || i.indexOf('ep_')==0)
{
exports[i] = settings[i];
}
//this setting is unkown, output a warning and throw it away
else
{
console.warn("Unknown Setting: '" + i + "'. This setting doesn't exist or it was removed");
}
}
//we know this setting, so we overwrite it
if(exports[i] !== undefined)
{
exports[i] = settings[i];
}
//this setting is unkown, output a warning and throw it away
else
{
console.warn("Unknown Setting: '" + i + "'. This setting doesn't exist or it was removed");
if(exports.dbType === "dirty"){
console.warn("DirtyDB is used. This is fine for testing but not recommended for production.")
}
}
if(exports.dbType === "dirty"){
console.warn("DirtyDB is used. This is fine for testing but not recommended for production.")
}
// initially load settings
exports.reloadSettings();