Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Some small tweaks to make JSLINT happy.

  • Loading branch information...
commit c33632cc409457aa97a23447a024e9f5e535bfc5 1 parent 54a0a7d
@thatismatt authored
View
11 lib/josi/actionresults.js
@@ -64,11 +64,12 @@ this.ContentResult = ContentResult = ActionResult.extend({
self.headers['Content-Length'] = stat.size;
self.headers['ETag'] = etag;
var first = true;
- var stream = fs.createReadStream(filename)
+ var stream = fs.createReadStream(filename);
stream
.addListener('error', function(err) {
- if (first)
+ if (first) {
return error(err).execute(req, res);
+ }
stream.destroy();
req.end();
})
@@ -120,11 +121,7 @@ this.notModified = notModified = function() {
};
this.error = error = function(err) {
- if (err instanceof Error) {
- var msg = err.message + '\r\n' + err.stack;
- } else {
- var msg = err;
- }
+ var msg = err instanceof Error ? err.message + '\r\n' + err.stack : err;
return new ActionResult(msg, { 'Content-Type': 'text/plain' }, 500);
};
View
2  lib/josi/routing.js
@@ -69,7 +69,7 @@ this.ControllerRouter = ControllerRouter = FunctionRouter.extend({
}
if (controllerObj[action]) {
var result = controllerObj[action];
- var context = context.slice(2);
+ context = context.slice(2);
context.controller = controller;
context.action = action;
return {
View
7 lib/josi/server.js
@@ -54,13 +54,14 @@ this.Server = function(dir) {
actionContext.params.action = actionContext.route.action;
}
try {
+ var actionResult;
if (routeResult instanceof RouteResult) {
if (routeResult instanceof MissingRouteResult) {
- var actionResult = actionresults.notFound(routeResult.message || 'No route matched the url: ' + parsedUrl.pathname);
+ actionResult = actionresults.notFound(routeResult.message || 'No route matched the url: ' + parsedUrl.pathname);
} else if (routeResult instanceof ErrorRouteResult) {
- var actionResult = actionresults.error(routeResult.error);
+ actionResult = actionresults.error(routeResult.error);
} else {
- var actionResult = routeResult.action.apply(actionContext);
+ actionResult = routeResult.action.apply(actionContext);
}
} else {
throw new Error('Result from router not an instance of RouteResult.');
View
4 lib/josi/tasks/create.js
@@ -54,8 +54,8 @@ this.task = {
return;
}
}
- },
-}
+ }
+};
var createApp = function(appName) {
fs.mkdirSync(appName, 0777);
View
2  lib/josi/tasks/test.js
@@ -11,7 +11,7 @@ this.task = {
opts: 'suite - the suite to run',
execute: function(opts) {
if (!utilities.fileOrDirectoryExists('tests')) {
- sys.puts('This josi app contains no tests.')
+ sys.puts('This josi app contains no tests.');
return;
}
var tests = fs.readdirSync('tests')
View
80 lib/josi/templating.js
@@ -73,51 +73,51 @@ this.MicroTemplatingEngine = TemplatingEngine.extend({
this.jQueryTemplatingEngine = TemplatingEngine.extend({
compile: function(str) {
var tmplcmd = {
- 'each': {
- _default: [null, "$i"],
- prefix: "$1.forEach(function($2){with(this){",
- suffix: "}});"
- },
- 'if': {
- prefix: "if($1){",
- suffix: "}"
- },
- 'else': {
- prefix: "}else{"
- },
- 'html': {
- prefix: "_.push(typeof $1==='function'?$1.call(this):$1);"
- },
- '=': {
- _default: ["this"],
- prefix: "_.push(typeof $1==='function'?$1.call(this):$1);"
+ 'each': {
+ _default: [null, "$i"],
+ prefix: "$1.forEach(function($2){with(this){",
+ suffix: "}});"
+ },
+ 'if': {
+ prefix: "if($1){",
+ suffix: "}"
+ },
+ 'else': {
+ prefix: "}else{"
+ },
+ 'html': {
+ prefix: "_.push(typeof $1==='function'?$1.call(this):$1);"
+ },
+ '=': {
+ _default: ["this"],
+ prefix: "_.push(typeof $1==='function'?$1.call(this):$1);"
// prefix: "_.push($.encode(typeof $1==='function'?$1.call(this):$1));"
- }
- };
- var fn = new Function("$data",
- "var _=[];_.data=$data;" +
+ }
+ };
+ var fn = new Function("$data",
+ "var _=[];_.data=$data;" +
- // Introduce the data as local variables using with(){}
- "with($data){_.push('" +
+ // Introduce the data as local variables using with(){}
+ "with($data){_.push('" +
- // Convert the template into pure JavaScript
- str
- .replace(/[\r\t\n]/g, " ")
- .replace(/\${([^}]*)}/g, "{{= $1}}")
- .replace(/{{(\/?)(\w+|.)(?:\((.*?)\))?(?: (.*?))?}}/g, function(all, slash, type, fnargs, args) {
- var tmpl = tmplcmd[type];
+ // Convert the template into pure JavaScript
+ str
+ .replace(/[\r\t\n]/g, " ")
+ .replace(/\${([^}]*)}/g, "{{= $1}}")
+ .replace(/{{(\/?)(\w+|.)(?:\((.*?)\))?(?: (.*?))?}}/g, function(all, slash, type, fnargs, args) {
+ var tmpl = tmplcmd[type];
- if (!tmpl) {
- throw "Template command not found: " + type;
- }
+ if (!tmpl) {
+ throw "Template command not found: " + type;
+ }
- var def = tmpl._default;
+ var def = tmpl._default;
- return "');" + tmpl[slash ? "suffix" : "prefix"]
- .split("$1").join(args || (def ? def[0] : ''))
- .split("$2").join(fnargs || (def ? def[1] : '')) + "_.push('";
- })
- + "');}return _.join('');");
- return fn;
+ return "');" + tmpl[slash ? "suffix" : "prefix"]
+ .split("$1").join(args || (def ? def[0] : ''))
+ .split("$2").join(fnargs || (def ? def[1] : '')) + "_.push('";
+ })
+ + "');}return _.join('');");
+ return fn;
}
});
View
12 lib/josi/utilities.js
@@ -5,7 +5,9 @@ this.merge = function() {
var result = {};
for (var a in arguments) {
var arg = arguments[a];
- for (var i in arg) result[i] = arg[i];
+ for (var i in arg) {
+ result[i] = arg[i];
+ }
}
return result;
};
@@ -16,7 +18,7 @@ this.argumentsToArray = function(args) {
arr.push(args[a]);
}
return arr;
-}
+};
this.fileOrDirectoryExists = fileOrDirectoryExists = function(fileOrDirectory) {
try {
@@ -37,7 +39,7 @@ this.cwdContainsApp = function() {
this.processARGV = function(argv) {
var task = (argv[2] && /^\w+$/.test(argv[2])) ? argv[2] : '';
- var optsRE = /-{0,2}(\w+)=(\w+)/
+ var optsRE = /-{0,2}(\w+)=(\w+)/;
var opts = {};
var args = [];
argv
@@ -65,10 +67,10 @@ this.stripExtension = function(filename) {
this.extension = function (filename) {
var index = filename.lastIndexOf('.');
return index < 0 ? '' : filename.substring(index);
-}
+};
this.mime = mime = {
- lookup : function(ext, fallback) {
+ lookup: function(ext, fallback) {
return mime.types[ext.toLowerCase()] || fallback || mime.defaultType;
},
defaultType: 'application/octet-stream',
Please sign in to comment.
Something went wrong with that request. Please try again.