From 06cf101400614e51138ff29ffff65d3295ecc3c1 Mon Sep 17 00:00:00 2001 From: Radek Stepan Date: Sun, 18 Aug 2013 19:41:14 +0100 Subject: [PATCH] error messaging --- src/app.coffee | 13 +++---------- src/component.json | 1 + src/modules/render.coffee | 6 ++++++ src/modules/repo.coffee | 12 ++++++++++-- src/templates/error.eco | 5 +++-- 5 files changed, 23 insertions(+), 14 deletions(-) create mode 100644 src/modules/render.coffee diff --git a/src/app.coffee b/src/app.coffee index fb16dad..867425a 100644 --- a/src/app.coffee +++ b/src/app.coffee @@ -4,25 +4,18 @@ async = require 'async' Router = require 'route66' config = require './modules/config' +render = require './modules/render' { Repo } = require './modules/repo' -# Render an eco template into selector. -show = (selector, template, context = {}) -> - tml = require "./templates/#{template}" - document.querySelector(selector).innerHTML = tml context - module.exports = -> # Show info notice? - show 'body', 'info' unless location.hash + render 'body', 'info' unless location.hash # A new router. new Router().path '/:user/:repo': -> repo = _.toArray(arguments).join('/') - # Render the body. - show 'body', 'graph' - # Get config/cache. async.waterfall [ config # Instantiate. @@ -32,4 +25,4 @@ module.exports = -> , (repo, cb) -> repo.render cb ], (err) -> - throw err if err \ No newline at end of file + render 'body', 'error', { text: err.toString() } if err \ No newline at end of file diff --git a/src/component.json b/src/component.json index c92d417..7bcb7a4 100644 --- a/src/component.json +++ b/src/component.json @@ -18,6 +18,7 @@ "modules/milestones.coffee", "modules/regex.coffee", "modules/request.coffee", + "modules/render.coffee", "modules/repo.coffee", "templates/error.eco", "templates/graph.eco", diff --git a/src/modules/render.coffee b/src/modules/render.coffee new file mode 100644 index 0000000..27e91e9 --- /dev/null +++ b/src/modules/render.coffee @@ -0,0 +1,6 @@ +#!/usr/bin/env coffee + +# Render an eco template into a selector. +module.exports = (selector, template, context = {}) -> + tml = require "../templates/#{template}" + document.querySelector(selector).innerHTML = tml context \ No newline at end of file diff --git a/src/modules/repo.coffee b/src/modules/repo.coffee index 4323f03..55536ff 100644 --- a/src/modules/repo.coffee +++ b/src/modules/repo.coffee @@ -7,6 +7,7 @@ issues = require './issues' graph = require './graph' reg = require './regex' req = require './request' +render = require './render' # Eco templates as functions. tml = {} @@ -23,8 +24,10 @@ class exports.Repo async.waterfall [ (cb) -> # Get the current milestone. milestones.get_current self, (err, warn, milestone) -> + return cb err if err + return cb warn if warn self.milestone = milestone - cb err + cb null # Get all issues. (cb) -> @@ -52,8 +55,13 @@ class exports.Repo _.partial(graph.actual, self.issues.closed.data, self.milestone.created_at, total) _.partial(graph.ideal, self.milestone.created_at, self.milestone.due_on, total) ], (err, values) -> - document.querySelector('#progress').innerHTML = tml.progress { progress } + # Render the body. + render 'body', 'graph' + # Render the progress. + render '#progress', 'progress', { progress } + + # Render the chart. graph.render values, cb ], cb \ No newline at end of file diff --git a/src/templates/error.eco b/src/templates/error.eco index e26d2f3..a8ddf0f 100644 --- a/src/templates/error.eco +++ b/src/templates/error.eco @@ -1,3 +1,4 @@ -
-

Hello trouble

+
+

Trouble

+

<%- @text %>

\ No newline at end of file