diff --git a/src/app.coffee b/src/app.coffee index 44d15f1..1d4027c 100644 --- a/src/app.coffee +++ b/src/app.coffee @@ -1,14 +1,27 @@ #!/usr/bin/env coffee -{ Repos } = require './repos' +async = require 'async' +{ _ } = require 'lodash' +Router = require 'route66' + +config = require './modules/config' +{ Repo } = require './modules/repo' module.exports = -> - # A new repo collection. - collection = new Repos() - # Get the coll/config. - collection.fetch (err) -> - throw err if err - # Use the head. - repo = collection.at(0) - # Render the repo. - repo.render (err) -> - throw err if err \ No newline at end of file + # A new router. + new Router().path + '/:user/:repo': -> + repo = _.toArray(arguments).join('/') + + # Render the body. + document.querySelector('body').innerHTML = do require('./templates/body') + + # Get config/cache. + async.waterfall [ config + # Instantiate. + , (conf, cb) -> + cb null, new Repo _.extend { repo }, conf + # Render. + , (repo, cb) -> + repo.render cb + ], (err) -> + throw err if err \ No newline at end of file diff --git a/src/component.json b/src/component.json index 7199e74..aada927 100644 --- a/src/component.json +++ b/src/component.json @@ -7,18 +7,21 @@ "caolan/async": "*", "mbostock/d3": "*", "visionmedia/superagent": "*", + "pazguille/route66": "*", "necolas/normalize.css": "*" }, "scripts": [ "app.coffee", + "modules/config.coffee", "modules/graph.coffee", "modules/issues.coffee", "modules/milestones.coffee", "modules/regex.coffee", "modules/request.coffee", - "modules/repos.coffee", + "modules/repo.coffee", "templates/body.eco", - "templates/label.eco" + "templates/label.eco", + "templates/progress.eco" ], "styles": [ "styles/app.styl" diff --git a/src/modules/config.coffee b/src/modules/config.coffee new file mode 100644 index 0000000..caccee5 --- /dev/null +++ b/src/modules/config.coffee @@ -0,0 +1,23 @@ +#!/usr/bin/env coffee +{ _ } = require 'lodash' + +req = require './request' + +config = null +wait = no +queue = [] + +module.exports = (cb) -> + # Have config? + return cb null, config if config + # Enqueue. + queue.push cb + # Load it? + unless wait + wait = yes + req.config (err, result) -> + # Save config? + config = result unless err + # Call back for each. + _.each queue, (cb) -> + cb err, result \ No newline at end of file diff --git a/src/modules/repos.coffee b/src/modules/repo.coffee similarity index 74% rename from src/modules/repos.coffee rename to src/modules/repo.coffee index f0fd154..4323f03 100644 --- a/src/modules/repos.coffee +++ b/src/modules/repo.coffee @@ -9,30 +9,15 @@ reg = require './regex' req = require './request' # Eco templates as functions. -templates = {} ; ( templates[t] = require("./#{t}") for t in [ 'body', 'label' ] ) +tml = {} +( tml[t] = require("../templates/#{t}") for t in [ 'progress' ] ) -class exports.Repos - - constructor: -> - @models = [] - - fetch: (cb) -> - self = @ - req.config (err, { protocol, host, token, repos }) -> - protocol ?= 'https' ; host ?= 'api.github.com' - self.models = ( new Repo({ protocol, host, token, repo: r }) for r in repos ) - cb null - - at: (index) -> - @models[index] - - -class Repo +class exports.Repo constructor: (opts) -> ( @[k] = v for k, v of opts ) - render: (cb) -> + render: (cb) => self = @ async.waterfall [ (cb) -> @@ -67,7 +52,7 @@ class 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('body').innerHTML = templates.body { progress } + document.querySelector('#progress').innerHTML = tml.progress { progress } graph.render values, cb diff --git a/src/modules/request.coffee b/src/modules/request.coffee index ddb51a5..bd38a4f 100644 --- a/src/modules/request.coffee +++ b/src/modules/request.coffee @@ -26,6 +26,9 @@ request = ({ protocol, host, token, repo }, query, path, cb) -> # Make the query params. q = ( "#{k}=#{v}" for k, v of query ).join('&') + host ?= 'api.github.com' + protocol ?= 'https' + req = sa .get("#{protocol}://#{host}/repos/#{repo}/#{path}?#{q}") .set('Content-Type', 'application/json') diff --git a/src/styles/app.styl b/src/styles/app.styl index e7652a8..8e64a30 100644 --- a/src/styles/app.styl +++ b/src/styles/app.styl @@ -5,6 +5,20 @@ body background: #31323A padding: 100px +ul + list-style-type: none + padding: 0 + + li + padding: 0 + +h2 + font-size: 14px + text-transform: uppercase + +#repos + color: #FFF + #box background: #43444f border-radius: 6px @@ -40,8 +54,6 @@ body background: $opened h2 - font-size: 14px - text-transform: uppercase margin: 10px 0 0 0 &.closed diff --git a/src/templates/body.eco b/src/templates/body.eco index 2eae46b..649e0ce 100644 --- a/src/templates/body.eco +++ b/src/templates/body.eco @@ -1,15 +1,5 @@ +
-
-
- <% if @progress is 100: %> -
- <% else: %> -
- <% end %> -
-
-

Closed / <%= Math.floor @progress %>%

-

Open / <%= 100 - Math.floor @progress %>%

-
+
\ No newline at end of file diff --git a/src/templates/progress.eco b/src/templates/progress.eco new file mode 100644 index 0000000..34b4498 --- /dev/null +++ b/src/templates/progress.eco @@ -0,0 +1,10 @@ +
+ <% if @progress is 100: %> +
+ <% else: %> +
+ <% end %> +
+
+

Closed / <%= Math.floor @progress %>%

+

Open / <%= 100 - Math.floor @progress %>%

\ No newline at end of file