From c619e276074df31341575ca99bb452d5b1ff6f65 Mon Sep 17 00:00:00 2001 From: Ryan McGrath Date: Thu, 23 Jun 2011 02:55:19 +0900 Subject: [PATCH 1/3] Readme --- readme.md | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 readme.md diff --git a/readme.md b/readme.md new file mode 100644 index 0000000..1d886f9 --- /dev/null +++ b/readme.md @@ -0,0 +1,38 @@ +GitStatus - A Simple Repository Feed Widget +==================================================================================================== +I was surpised that this didn't already exist, but eh, whatever. + +This is a widget that provides a feed of recent commits on a repository +using the Github API. It's completely client-side, so it won't work on +private repositories, but that's a small price to pay. + +The one thing to note about this widget is that it technically has to make +two requests to GitHub to get all the information it needs. This is due to +how the GitHub API works; it's less than ideal, but overall not too bad. + +Example usage is as follows: + +``` html +
+ + +``` + +Uncommenting the "disable_all_styles" option will do exactly that - no default styling will be applied +and you can then style the widget to your needs from the ground up. + + +Questions, Comments, Praise, etc? +------------------------------------------------------------------------------------------------------- +This was built in the space of... 2 hours, so it's not perfect. It's totally open source, though, so feel +free to hack/fork/do whatever with it. + +I'm available on Twitter as @ryanmcgrath, or via email at ryan [at] venodesigns (.) net. Hit me up! From 6841a5e5d86f7b9140f98e5ee49e51d173e3c87f Mon Sep 17 00:00:00 2001 From: Ryan McGrath Date: Thu, 23 Jun 2011 03:02:10 +0900 Subject: [PATCH 2/3] Here --- index.html | 2 +- js/gitstatus.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/index.html b/index.html index 7518e64..22108d7 100644 --- a/index.html +++ b/index.html @@ -71,7 +71,7 @@ var x = parseInt(Math.random() * 100000); c.innerHTML = [ '<div id="gitstatus_' + x + '"></div>\n', - '<script type="text/javascript" src=""></script>\n', + '<script type="text/javascript" src="http://ryanmcgrath.github.com/gitstatus/js/gitstatus.min.js"></script>\n', '<script type="text/javascript">\n', 'new GitStatus({\n', ' id: "gitstatus_' + x + '",\n', diff --git a/js/gitstatus.js b/js/gitstatus.js index e4658b0..2f613e6 100644 --- a/js/gitstatus.js +++ b/js/gitstatus.js @@ -204,7 +204,7 @@ * @returns String, parsed/replaced template. */ render: function(template, context) { - for(x in context) template = template.replace(new RegExp('{{' + x + '}}', 'g'), context[x]); + for(x in context) template = template.replace(new RegExp('{{' + x + '}}', 'g'), context[x].replace('<', '<').replace('>', '>')); return template; } }; From 8e3fc15c1de4fccd5f86574f17accf70c215109e Mon Sep 17 00:00:00 2001 From: Ryan McGrath Date: Thu, 23 Jun 2011 03:06:03 +0900 Subject: [PATCH 3/3] Final --- js/gitstatus.min.js | 1 + 1 file changed, 1 insertion(+) create mode 100644 js/gitstatus.min.js diff --git a/js/gitstatus.min.js b/js/gitstatus.min.js new file mode 100644 index 0000000..c30751b --- /dev/null +++ b/js/gitstatus.min.js @@ -0,0 +1 @@ +(function(b){if(b!=="undefined"){return}var a=window.GitStatus=function a(c){this.opts=c;if(typeof this.opts.no_of_commits==="undefined"){this.opts.no_of_commits=5}};a.util={DEBUG:false,bind:function(c,d){return function(){return d.apply(c,arguments)}},loadScript:function(e,d){var c=document.createElement("script");c.type="text/javascript";c.setAttribute("src",e);c.setAttribute("async","true");if(c.readyState){c.onreadystatechange=function(){if(/loaded|complete/.test(c.readyState)){c.onreadystatechange=null;if(typeof d!=="undefined"){d()}!a.util.DEBUG&&c&&document.documentElement.firstChild.removeChild(c)}}}else{c.addEventListener("load",function(){if(typeof d!=="undefined"){d()}!a.util.DEBUG&&c&&document.documentElement.firstChild.removeChild(c)},false)}document.documentElement.firstChild.appendChild(c)},jsonp:function(i,c,f,e){var j=typeof f!=="undefined"?a.util.bind(f,c):c,h=typeof e!=="undefined"?e:"GitStatusJSONPCallback_"+parseInt(Math.random()*100000),g=i+(i.indexOf("?")>-1?"&callback=":"?callback=")+h,d=null;d=a.util.bind(this,function(k){j(k);try{delete window[h]}catch(l){window[h]=null}});window[h]=d;a.util.loadScript(g)},createGravatarURL:function(c){return"http://www.gravatar.com/avatar/"+c+"?s=50&d=mm"},render:function(d,c){for(x in c){d=d.replace(new RegExp("{{"+x+"}}","g"),c[x].replace("<","<").replace(">",">"))}return d}};a.prototype={opts:null,node:null,api_base_url:"https://github.com",base_structure:['
','Recent Commits on {{repo_name}}',"
",'
',"{{history}}","
",'"].join(""),commit_structure:['
','','
','','
',"

{{commit_msg}}

","
",'
','By {{login}} on {{date}}',"
","
","
"].join(""),default_style:[".gitstatus_container { -webkit-border-radius: 2px; -moz-border-radius: 2px; border-radius: 2px; }",".gitstatus_container a, .gitstatus_container a:visited { color: #307ace; text-decoration: none; border-bottom: 1px solid dotted #307ace; }",".gitstatus_header { text-align: right; padding: 5px; color: #f9f9f9; background-color: #010101; background-image: -webkit-gradient(linear, left top, left bottom, from(#333), to(#010101)); -moz-border-radius: 2px 2px 0 0; -webkit-border-radius: 2px 2px 0 0; border-radius: 2px 2px 0 0; }",".gitstatus_commit_history { font-size: 11px; border-left: 1px solid #c9c9c9; border-right: 1px solid #c9c9c9; }",".gitstatus_commit_row { padding: 5px 5px 5px 63px; position: relative; background-color: #f5f5f5; border-bottom: 1px solid #c9c9c9; -webkit-box-shadow: inset 2px 2px 2px #e9e9e9; -moz-box-shadow: inset 2px 2px 2px #e9e9e9; box-shadow: inset 2px 2px 2px #e9e9e9;}",".gitstatus_row_even { background-color: #f9f9f9 !important; }",".gitstatus_commit_row_meta { color: #b2b2b2; }",".gitstatus_commit_row_meta a, .gitstatus_commit_row_meta a:visited { color: #a2a2a2 !important; border-color: #a2a2a2 !important; }",".gitstatus_gravatar { -webkit-border-radius: 2px; -moz-border-radius: 2px; border-radius: 2px; position: absolute; top: 7px; left: 5px; }",".gitstatus_footer { font-size: 10px !important; padding: 3px 5px 5px; text-align: right; color: #f9f9f9; background-color: #010101; background-image: -webkit-gradient(linear, left top, left bottom, from(#333), to(#010101)); -moz-border-radius: 0 0 2px 2px; -webkit-border-radius: 0 0 2px 2px; border-radius: 0 0 2px 2px; }"].join(""),show:function(){this.api_base_url+="/"+this.opts.github_username+"/"+this.opts.github_repository+"/";a.util.jsonp(this.api_base_url+"network_meta",this._getRepoNetworkData,this);return this},_getRepoNetworkData:function(e){var d=e.nethash,c=e.focus,f=this.api_base_url+"network_data_chunk?nethash="+d+"&start="+(c-this.opts.no_of_commits)+"&end="+c;a.util.jsonp(f,this._build,this)},_build:function(d){if(this.node===null){this.node=document.getElementById(this.opts.id)}var j=document.createDocumentFragment(),c=document.createElement("div"),g="",h=d.commits,e=h.length;c.className="gitstatus_container";j.appendChild(c);while(e--){g+=a.util.render(this.commit_structure,{even_or_odd:(e%2===0?"gitstatus_row_even":"gitstatus_row_odd"),gravatar:a.util.createGravatarURL(h[e].gravatar),sha_link:"https://github.com/"+this.opts.github_username+"/"+this.opts.github_repository+"/commit/"+h[e].id,sha:"Commit #"+h[e].id.substr(0,7),commit_msg:h[e].message,login:h[e].login,date:h[e].date})}c.innerHTML=a.util.render(this.base_structure,{repo_name:this.opts.github_repository,repo_url:this.api_base_url,history:g});if(typeof this.opts.disable_default_styles==="undefined"){var f=document.createElement("style");f.type="text/css";if(f.styleSheet){f.styleSheet.cssText=this.default_style}else{f.appendChild(document.createTextNode(this.default_style))}document.documentElement.firstChild.appendChild(f)}this.node.appendChild(j)}}})(typeof window.GitStatus); \ No newline at end of file