Permalink
Browse files

Simplifying the context

  • Loading branch information...
1 parent 95be311 commit 56ef12ccf78651760ed529152b282d82e6ca0d9f @zmoazeni committed May 11, 2012
Showing with 127 additions and 234 deletions.
  1. +43 −83 coffee/site.coffee
  2. +84 −151 js/site.js
View
126 coffee/site.coffee
@@ -115,127 +115,87 @@ class Event extends Spine.Model
viewInfo: ->
view = @viewType()
- switch view
+ context = switch view
+ when "repository", "watch"
+ {}
when "item"
- [view, id:@id, title:@type, date:@created_at_short_string()]
+ {title:@type}
when "gist"
- [view, id:@id, url:@payload.gist.html_url, date:@created_at_short_string()]
+ {url:@payload.gist.html_url}
when "issue"
- [view,
- id:@id
+ {
url:@payload.issue.html_url
title:@payload.issue.title
comment:@payload.issue.body
- repo_url:"https://github.com/#{@repo.name}"
- repo:@repo.name
- date:@created_at_short_string(),
- ]
+ }
when "issue_comment"
- [view,
- id:@id
+ {
url:@payload.issue.html_url
comment:@payload.comment.body
- repo_url:"https://github.com/#{@repo.name}"
- repo:@repo.name
- date:@created_at_short_string(),
- ]
- when "pull_request_comment"
- [view,
- id:@id
- url:@payload.comment._links.html.href
- comment:@payload.comment.body
- repo_url:"https://github.com/#{@repo.name}"
- repo:@repo.name
- date:@created_at_short_string(),
- ]
+ }
when "commit_comment"
- [view,
- id:@id
+ {
url:@payload.comment.html_url
comment:@payload.comment.body
- repo_url:"https://github.com/#{@repo.name}"
- repo:@repo.name
- date:@created_at_short_string(),
- ]
+ }
+ when "pull_request_comment"
+ {
+ url:@payload.comment._links.html.href
+ comment:@payload.comment.body
+ }
when "pull_request"
- [view,
- id:@id
+ {
url:@payload.pull_request._links.html.href
comment:@payload.pull_request.body
- repo_url:"https://github.com/#{@repo.name}"
- repo:@repo.name
- date:@created_at_short_string(),
- ]
+ }
when "fork"
- [view,
- id:@id
+ {
fork_url:@payload.forkee.html_url
fork_name:"#{@actor.login}/#{@payload.forkee.name}"
description:@payload.forkee.description
- repo_url:"https://github.com/#{@repo.name}"
- repo:@repo.name
- date:@created_at_short_string()
- ]
+ }
when "follow"
- [view,
- id:@id
+ {
url:@payload.target.html_url
name:@payload.target.name
gravatar:@payload.target.avatar_url
- date:@created_at_short_string()
- ]
- when "watch"
- [view,
- id:@id
- repo:@repo.name
- repo_url:"https://github.com/#{@repo.name}"
- date:@created_at_short_string()
- ]
- when "repository"
- [view,
- id:@id
- repo:@repo.name
- repo_url:"https://github.com/#{@repo.name}"
- date:@created_at_short_string()
- ]
+ }
when "tag", "branch"
- [view,
- id:@id,
- name:@payload.ref,
+ {
+ name:@payload.ref
url:"https://github.com/#{@repo.name}/tree/#{@payload.ref}"
- date:@created_at_short_string()
- repo_url:"https://github.com/#{@repo.name}",
- repo:@repo.name
- ]
+ }
when "push"
commits = @commits.map (c, i) =>
commit:c.sha.slice(0, 5)
commit_url:"https://github.com/#{@repo.name}/commit/#{c.sha}"
message:c.message.split("\n")[0]
hidden:i > 2
- [view,
- id:@id,
- login:@actor.login,
- num:commits.length,
- commits:commits,
- repo_url:"https://github.com/#{@repo.name}",
- repo:@repo.name
- date:@created_at_short_string(),
+ {
+ login:@actor.login
+ num:commits.length
+ commits:commits
more:commits.length > 3
- ]
+ }
when "gollum"
pages = @payload.pages.map((p, i) => {title:p.title, url:p.html_url, action:p.action, hidden:i > 2})
- [view,
- id:@id
- repo:@repo.name
- repo_url:"https://github.com/#{@repo.name}"
+ {
pages:pages
num:pages.length
- date:@created_at_short_string()
more:pages.length > 3
- ]
- else []
+ }
+ else null
+
+ if context
+ [view, $.extend(context,
+ id:@id
+ repo:@repo.name
+ repo_url:"https://github.com/#{@repo.name}"
+ date:@created_at_short_string()
+ )]
+ else
+ []
window.Github = {User:User, Repo:Repo, Event:Event}
View
235 js/site.js
@@ -247,177 +247,110 @@
};
Event.prototype.viewInfo = function() {
- var commits, pages, view,
- _this = this;
+ var commits, context, pages, view;
view = this.viewType();
- switch (view) {
- case "item":
- return [
- view, {
- id: this.id,
- title: this.type,
- date: this.created_at_short_string()
- }
- ];
- case "gist":
- return [
- view, {
- id: this.id,
- url: this.payload.gist.html_url,
- date: this.created_at_short_string()
- }
- ];
- case "issue":
- return [
- view, {
- id: this.id,
+ context = (function() {
+ var _this = this;
+ switch (view) {
+ case "repository":
+ case "watch":
+ return {};
+ case "item":
+ return {
+ title: this.type
+ };
+ case "gist":
+ return {
+ url: this.payload.gist.html_url
+ };
+ case "issue":
+ return {
url: this.payload.issue.html_url,
title: this.payload.issue.title,
- comment: this.payload.issue.body,
- repo_url: "https://github.com/" + this.repo.name,
- repo: this.repo.name,
- date: this.created_at_short_string()
- }
- ];
- case "issue_comment":
- return [
- view, {
- id: this.id,
+ comment: this.payload.issue.body
+ };
+ case "issue_comment":
+ return {
url: this.payload.issue.html_url,
- comment: this.payload.comment.body,
- repo_url: "https://github.com/" + this.repo.name,
- repo: this.repo.name,
- date: this.created_at_short_string()
- }
- ];
- case "pull_request_comment":
- return [
- view, {
- id: this.id,
- url: this.payload.comment._links.html.href,
- comment: this.payload.comment.body,
- repo_url: "https://github.com/" + this.repo.name,
- repo: this.repo.name,
- date: this.created_at_short_string()
- }
- ];
- case "commit_comment":
- return [
- view, {
- id: this.id,
+ comment: this.payload.comment.body
+ };
+ case "commit_comment":
+ return {
url: this.payload.comment.html_url,
- comment: this.payload.comment.body,
- repo_url: "https://github.com/" + this.repo.name,
- repo: this.repo.name,
- date: this.created_at_short_string()
- }
- ];
- case "pull_request":
- return [
- view, {
- id: this.id,
+ comment: this.payload.comment.body
+ };
+ case "pull_request_comment":
+ return {
+ url: this.payload.comment._links.html.href,
+ comment: this.payload.comment.body
+ };
+ case "pull_request":
+ return {
url: this.payload.pull_request._links.html.href,
- comment: this.payload.pull_request.body,
- repo_url: "https://github.com/" + this.repo.name,
- repo: this.repo.name,
- date: this.created_at_short_string()
- }
- ];
- case "fork":
- return [
- view, {
- id: this.id,
+ comment: this.payload.pull_request.body
+ };
+ case "fork":
+ return {
fork_url: this.payload.forkee.html_url,
fork_name: "" + this.actor.login + "/" + this.payload.forkee.name,
- description: this.payload.forkee.description,
- repo_url: "https://github.com/" + this.repo.name,
- repo: this.repo.name,
- date: this.created_at_short_string()
- }
- ];
- case "follow":
- return [
- view, {
- id: this.id,
+ description: this.payload.forkee.description
+ };
+ case "follow":
+ return {
url: this.payload.target.html_url,
name: this.payload.target.name,
- gravatar: this.payload.target.avatar_url,
- date: this.created_at_short_string()
- }
- ];
- case "watch":
- return [
- view, {
- id: this.id,
- repo: this.repo.name,
- repo_url: "https://github.com/" + this.repo.name,
- date: this.created_at_short_string()
- }
- ];
- case "repository":
- return [
- view, {
- id: this.id,
- repo: this.repo.name,
- repo_url: "https://github.com/" + this.repo.name,
- date: this.created_at_short_string()
- }
- ];
- case "tag":
- case "branch":
- return [
- view, {
- id: this.id,
- name: this.payload.ref,
- url: "https://github.com/" + this.repo.name + "/tree/" + this.payload.ref,
- date: this.created_at_short_string(),
- repo_url: "https://github.com/" + this.repo.name,
- repo: this.repo.name
- }
- ];
- case "push":
- commits = this.commits.map(function(c, i) {
+ gravatar: this.payload.target.avatar_url
+ };
+ case "tag":
+ case "branch":
return {
- commit: c.sha.slice(0, 5),
- commit_url: "https://github.com/" + _this.repo.name + "/commit/" + c.sha,
- message: c.message.split("\n")[0],
- hidden: i > 2
+ name: this.payload.ref,
+ url: "https://github.com/" + this.repo.name + "/tree/" + this.payload.ref
};
- });
- return [
- view, {
- id: this.id,
+ case "push":
+ commits = this.commits.map(function(c, i) {
+ return {
+ commit: c.sha.slice(0, 5),
+ commit_url: "https://github.com/" + _this.repo.name + "/commit/" + c.sha,
+ message: c.message.split("\n")[0],
+ hidden: i > 2
+ };
+ });
+ return {
login: this.actor.login,
num: commits.length,
commits: commits,
- repo_url: "https://github.com/" + this.repo.name,
- repo: this.repo.name,
- date: this.created_at_short_string(),
more: commits.length > 3
- }
- ];
- case "gollum":
- pages = this.payload.pages.map(function(p, i) {
- return {
- title: p.title,
- url: p.html_url,
- action: p.action,
- hidden: i > 2
};
- });
- return [
- view, {
- id: this.id,
- repo: this.repo.name,
- repo_url: "https://github.com/" + this.repo.name,
+ case "gollum":
+ pages = this.payload.pages.map(function(p, i) {
+ return {
+ title: p.title,
+ url: p.html_url,
+ action: p.action,
+ hidden: i > 2
+ };
+ });
+ return {
pages: pages,
num: pages.length,
- date: this.created_at_short_string(),
more: pages.length > 3
- }
- ];
- default:
- return [];
+ };
+ default:
+ return null;
+ }
+ }).call(this);
+ if (context) {
+ return [
+ view, $.extend(context, {
+ id: this.id,
+ repo: this.repo.name,
+ repo_url: "https://github.com/" + this.repo.name,
+ date: this.created_at_short_string()
+ })
+ ];
+ } else {
+ return [];
}
};

0 comments on commit 56ef12c

Please sign in to comment.