From: Andrew Otto Date: Thu, 19 Apr 2012 18:14:39 +0000 (-0400) Subject: controllers/graph.co - using switch instead of if for index/ format conditional X-Git-Url: http://git.less.ly:3516/?a=commitdiff_plain;h=59f3d538f8b87db246d06e53ca28a3a70d386d52;p=limn-bak.git controllers/graph.co - using switch instead of if for index/ format conditional --- diff --git a/lib/server/controllers/graph.co b/lib/server/controllers/graph.co index 7dcea18..91efa70 100644 --- a/lib/server/controllers/graph.co +++ b/lib/server/controllers/graph.co @@ -37,6 +37,7 @@ class GraphController extends Controller -> super ... + toFile: (id) -> "#{@dataDir}/#id.json" /** @@ -62,20 +63,21 @@ class GraphController extends Controller catch err console.error "GraphController.autoload(#id, #{typeof cb}) -->\nerr" cb err - + # GET /graphs.:format? index: (req, res) -> # if format is json, then return the graph JSON - if (req.params.format == 'json') - pattern = @dataDir + "/*.json" - Seq() - # find list of data/graph/*.json files, send back the objects - .seq -> readJSONFilesAsync pattern, this - # remove filepath info - .seq (graphs) -> res.send _.values graphs - else - res.render 'graph/index' - + switch req.format + case 'json' + pattern = @dataDir + "/*.json" + Seq() + # find list of data/graph/*.json files, send back the objects + .seq -> readJSONFilesAsync pattern, this + # remove filepath info + .seq (graphs) -> res.send _.values graphs + default + res.render 'graph/index' + # GET /graphs/:graph show: (req, res) -> if req.format is 'json'