From b09e68dac9435c17a790cd26c807c4d561a88d3b Mon Sep 17 00:00:00 2001 From: Radek Stepan Date: Sun, 18 Aug 2013 20:16:47 +0100 Subject: [PATCH] native location hash implementation --- src/app.coffee | 44 ++++++++++++++++++++++----------------- src/component.json | 2 +- src/styles/app.styl | 10 ++++----- src/templates/info.eco | 2 +- src/templates/loading.eco | 4 ++++ 5 files changed, 35 insertions(+), 27 deletions(-) create mode 100644 src/templates/loading.eco diff --git a/src/app.coffee b/src/app.coffee index 867425a..946ea44 100644 --- a/src/app.coffee +++ b/src/app.coffee @@ -1,28 +1,34 @@ #!/usr/bin/env coffee async = require 'async' { _ } = require 'lodash' -Router = require 'route66' config = require './modules/config' render = require './modules/render' { Repo } = require './modules/repo' +route = -> + if match = window.location.hash.match /^#!\/(.+)\/(.+)$/ + repo = match[1..3].join('/') + + # We are loading. + render 'body', 'loading', { repo } + + # Get config/cache. + return async.waterfall [ config + # Instantiate. + , (conf, cb) -> + cb null, new Repo _.extend { repo }, conf + # Render. + , (repo, cb) -> + repo.render cb + ], (err) -> + render 'body', 'error', { text: err.toString() } if err + + # Info notice for you. + render 'body', 'info' + module.exports = -> - # Show info notice? - render 'body', 'info' unless location.hash - - # A new router. - new Router().path - '/:user/:repo': -> - repo = _.toArray(arguments).join('/') - - # Get config/cache. - async.waterfall [ config - # Instantiate. - , (conf, cb) -> - cb null, new Repo _.extend { repo }, conf - # Render. - , (repo, cb) -> - repo.render cb - ], (err) -> - render 'body', 'error', { text: err.toString() } if err \ No newline at end of file + # Detect route changes. + window.addEventListener 'hashchange', route, no + # And route now. + do route \ No newline at end of file diff --git a/src/component.json b/src/component.json index 7bcb7a4..69bd6aa 100644 --- a/src/component.json +++ b/src/component.json @@ -7,7 +7,6 @@ "caolan/async": "*", "mbostock/d3": "*", "visionmedia/superagent": "*", - "pazguille/route66": "*", "necolas/normalize.css": "*" }, "scripts": [ @@ -24,6 +23,7 @@ "templates/graph.eco", "templates/info.eco", "templates/label.eco", + "templates/loading.eco", "templates/progress.eco" ], "styles": [ diff --git a/src/styles/app.styl b/src/styles/app.styl index d171a3f..c946cfb 100644 --- a/src/styles/app.styl +++ b/src/styles/app.styl @@ -21,8 +21,11 @@ h2 color: #FFF box-shadow: 2px 4px 6px rgba(0,0,0,0.2) - &.info, &.error, &.success + &.generic, &.info, &.error, &.success border-top: 4px solid #E2E2E2 + padding: 20px + width: 50% + margin: 0 auto &.info border-top-color: #96CFFB @@ -30,11 +33,6 @@ h2 &.error border-top-color: #FE5D55 - &.info, &.error - padding: 20px - width: 50% - margin: 0 auto - &.success border-top-color: #4ACAB4 diff --git a/src/templates/info.eco b/src/templates/info.eco index a3de3c3..ac59a52 100644 --- a/src/templates/info.eco +++ b/src/templates/info.eco @@ -1,4 +1,4 @@ -
+

GitHub Burndown Chart

Use your browser's location hash to specify a repo: #!/radekstepan/disposable.

\ No newline at end of file diff --git a/src/templates/loading.eco b/src/templates/loading.eco new file mode 100644 index 0000000..3b331ab --- /dev/null +++ b/src/templates/loading.eco @@ -0,0 +1,4 @@ +
+

GitHub Burndown Chart

+

Loading #!/<%- @repo %>.

+
\ No newline at end of file