native location hash implementation

This commit is contained in:
Radek Stepan 2013-08-18 20:16:47 +01:00
parent 06cf101400
commit b09e68dac9
5 changed files with 35 additions and 27 deletions

View File

@ -1,23 +1,20 @@
#!/usr/bin/env coffee #!/usr/bin/env coffee
async = require 'async' async = require 'async'
{ _ } = require 'lodash' { _ } = require 'lodash'
Router = require 'route66'
config = require './modules/config' config = require './modules/config'
render = require './modules/render' render = require './modules/render'
{ Repo } = require './modules/repo' { Repo } = require './modules/repo'
module.exports = -> route = ->
# Show info notice? if match = window.location.hash.match /^#!\/(.+)\/(.+)$/
render 'body', 'info' unless location.hash repo = match[1..3].join('/')
# A new router. # We are loading.
new Router().path render 'body', 'loading', { repo }
'/:user/:repo': ->
repo = _.toArray(arguments).join('/')
# Get config/cache. # Get config/cache.
async.waterfall [ config return async.waterfall [ config
# Instantiate. # Instantiate.
, (conf, cb) -> , (conf, cb) ->
cb null, new Repo _.extend { repo }, conf cb null, new Repo _.extend { repo }, conf
@ -26,3 +23,12 @@ module.exports = ->
repo.render cb repo.render cb
], (err) -> ], (err) ->
render 'body', 'error', { text: err.toString() } if err render 'body', 'error', { text: err.toString() } if err
# Info notice for you.
render 'body', 'info'
module.exports = ->
# Detect route changes.
window.addEventListener 'hashchange', route, no
# And route now.
do route

View File

@ -7,7 +7,6 @@
"caolan/async": "*", "caolan/async": "*",
"mbostock/d3": "*", "mbostock/d3": "*",
"visionmedia/superagent": "*", "visionmedia/superagent": "*",
"pazguille/route66": "*",
"necolas/normalize.css": "*" "necolas/normalize.css": "*"
}, },
"scripts": [ "scripts": [
@ -24,6 +23,7 @@
"templates/graph.eco", "templates/graph.eco",
"templates/info.eco", "templates/info.eco",
"templates/label.eco", "templates/label.eco",
"templates/loading.eco",
"templates/progress.eco" "templates/progress.eco"
], ],
"styles": [ "styles": [

View File

@ -21,8 +21,11 @@ h2
color: #FFF color: #FFF
box-shadow: 2px 4px 6px rgba(0,0,0,0.2) box-shadow: 2px 4px 6px rgba(0,0,0,0.2)
&.info, &.error, &.success &.generic, &.info, &.error, &.success
border-top: 4px solid #E2E2E2 border-top: 4px solid #E2E2E2
padding: 20px
width: 50%
margin: 0 auto
&.info &.info
border-top-color: #96CFFB border-top-color: #96CFFB
@ -30,11 +33,6 @@ h2
&.error &.error
border-top-color: #FE5D55 border-top-color: #FE5D55
&.info, &.error
padding: 20px
width: 50%
margin: 0 auto
&.success &.success
border-top-color: #4ACAB4 border-top-color: #4ACAB4

View File

@ -1,4 +1,4 @@
<div class="box info" id="info"> <div class="box info">
<h2>GitHub Burndown Chart</h2> <h2>GitHub Burndown Chart</h2>
<p>Use your browser's location hash to specify a repo: <a href="#!/radekstepan/disposable">#!/radekstepan/disposable</a>.</p> <p>Use your browser's location hash to specify a repo: <a href="#!/radekstepan/disposable">#!/radekstepan/disposable</a>.</p>
</div> </div>

View File

@ -0,0 +1,4 @@
<div class="box generic">
<h2>GitHub Burndown Chart</h2>
<p>Loading <a href="#!/<%- @repo %>">#!/<%- @repo %></a>.</p>
</div>