Merge pull request #22 from NumEricR/Profile

Modifications on profile description
This commit is contained in:
David Coallier
2012-09-04 15:22:48 -07:00
4 changed files with 255 additions and 133 deletions

View File

@@ -87,8 +87,18 @@ var run = function() {
var res = github_user(username, function(data) {
data = data.data;
var sinceDate = new Date(data.created_at);
since = sinceDate.getFullYear();
var sinceMonth = sinceDate.getMonth();
var since = sinceDate.getFullYear();
var sinceMonth = sinceDate.getMonth();
var currentYear = (new Date).getFullYear();
switch (since) {
case currentYear-1:
since = 'last year';
break;
case currentYear:
since = 'this year';
break;
}
var addHttp = '';
if (data.blog && data.blog.indexOf('http') < 0) {
@@ -112,12 +122,12 @@ var run = function() {
followers: data.followers,
followersLabel: data.followers > 1 ? 'followers' : 'follower',
username: username,
userStatus: 'Github user',
userStatus: 'GitHub user',
since: since,
resume_url: window.location
};
// We consider a limit of 4 months since the Github opening (Feb 2008) to be considered as an early adopter
// We consider a limit of 4 months since the GitHub opening (Feb 2008) to be considered as an early adopter
if (since == '2008' && sinceMonth <= 5) {
view.earlyAdopter = 1;
}
@@ -151,22 +161,22 @@ var run = function() {
}
if (statusScore == FIRST_STEP) {
return 'Inactive Github user';
return 'Inactive GitHub user';
}
else if (statusScore > FIRST_STEP && statusScore <= SECOND_STEP) {
return 'Newbie Github user';
return 'Newbie GitHub user';
}
else if (statusScore > SECOND_STEP && statusScore <= THIRD_STEP) {
return 'Regular Github user';
return 'Regular GitHub user';
}
else if (statusScore > THIRD_STEP && statusScore <= FOURTH_STEP) {
return 'Advanced Github user';
return 'Advanced GitHub user';
}
else if (statusScore > FOURTH_STEP && statusScore <= FIFTH_STEP) {
return 'Enthusiastic Github user';
return 'Enthusiastic GitHub user';
}
else if (statusScore > FIFTH_STEP) {
return 'Passionate Github user';
return 'Passionate GitHub user';
}
};

View File

@@ -1,12 +1,7 @@
/*
Shameless port of http://github.com/defunkt/mustache
by Jan Lehnardt <jan@apache.org>,
Alexander Lang <alex@upstream-berlin.com>,
Sebastian Cohnen <sebastian.cohnen@googlemail.com>
mustache.js — Logic-less templates in JavaScript
Thanks @defunkt for the awesome code.
See http://github.com/defunkt/mustache for more info.
See http://mustache.github.com/ for more info.
*/
var Mustache = function() {
@@ -17,11 +12,20 @@ var Mustache = function() {
ctag: "}}",
pragmas: {},
buffer: [],
pragmas_parsed: false,
pragmas_implemented: {
"IMPLICIT-ITERATOR": true
},
context: {},
render: function(template, context, partials, in_recursion) {
// reset buffer & set context
if(!in_recursion) {
this.context = context;
this.buffer = []; // TODO: make this non-lazy
}
// fail fast
if(template.indexOf(this.otag) == -1) {
if(!this.includes("", template)) {
if(in_recursion) {
return template;
} else {
@@ -30,13 +34,7 @@ var Mustache = function() {
}
}
if(!in_recursion) {
this.buffer = [];
}
if(!this.pragmas_parsed) {
template = this.render_pragmas(template);
}
template = this.render_pragmas(template);
var html = this.render_section(template, context, partials);
if(in_recursion) {
return this.render_tags(html, context, partials, in_recursion);
@@ -46,8 +44,8 @@ var Mustache = function() {
},
/*
Sends parsed lines
*/
Sends parsed lines
*/
send: function(line) {
if(line != "") {
this.buffer.push(line);
@@ -55,19 +53,23 @@ var Mustache = function() {
},
/*
Looks for %PRAGMAS
*/
Looks for %PRAGMAS
*/
render_pragmas: function(template) {
this.pragmas_parsed = true;
// no pragmas
if(template.indexOf(this.otag + "%") == -1) {
if(!this.includes("%", template)) {
return template;
}
var that = this;
var regex = new RegExp(this.otag + "%([\\w_-]+) ?([\\w]+=[\\w]+)?"
+ this.ctag);
var regex = new RegExp(this.otag + "%([\\w-]+) ?([\\w]+=[\\w]+)?" +
this.ctag);
return template.replace(regex, function(match, pragma, options) {
if(!that.pragmas_implemented[pragma]) {
throw({message:
"This implementation of mustache doesn't understand the '" +
pragma + "' pragma"});
}
that.pragmas[pragma] = {};
if(options) {
var opts = options.split("=");
@@ -79,85 +81,106 @@ var Mustache = function() {
},
/*
Tries to find a partial in the global scope and render it
*/
Tries to find a partial in the curent scope and render it
*/
render_partial: function(name, context, partials) {
if(typeof(context[name]) != "object") {
throw({message: "subcontext for '" + name + "' is not an object"});
}
if(!partials || !partials[name]) {
name = this.trim(name);
if(!partials || partials[name] === undefined) {
throw({message: "unknown_partial '" + name + "'"});
}
if(typeof(context[name]) != "object") {
return this.render(partials[name], context, partials, true);
}
return this.render(partials[name], context[name], partials, true);
},
/*
Renders boolean and enumerable sections
*/
Renders inverted (^) and normal (#) sections
*/
render_section: function(template, context, partials) {
if(template.indexOf(this.otag + "#") == -1) {
if(!this.includes("#", template) && !this.includes("^", template)) {
return template;
}
var that = this;
// CSW - Added "+?" so it finds the tighest bound, not the widest
var regex = new RegExp(this.otag + "\\#(.+)" + this.ctag +
"\\s*([\\s\\S]+?)" + this.otag + "\\/\\1" + this.ctag + "\\s*", "mg");
var regex = new RegExp(this.otag + "(\\^|\\#)\\s*(.+)\\s*" + this.ctag +
"\n*([\\s\\S]+?)" + this.otag + "\\/\\s*\\2\\s*" + this.ctag +
"\\s*", "mg");
// for each {{#foo}}{{/foo}} section do...
return template.replace(regex, function(match, name, content) {
return template.replace(regex, function(match, type, name, content) {
var value = that.find(name, context);
if(that.is_array(value)) { // Enumerable, Let's loop!
return that.map(value, function(row) {
return that.render(content, that.merge(context,
that.create_context(row)), partials, true);
}).join("");
} else if(value) { // boolean section
return that.render(content, context, partials, true);
} else {
return "";
if(type == "^") { // inverted section
if(!value || that.is_array(value) && value.length === 0) {
// false or empty list, render it
return that.render(content, context, partials, true);
} else {
return "";
}
} else if(type == "#") { // normal section
if(that.is_array(value)) { // Enumerable, Let's loop!
return that.map(value, function(row) {
return that.render(content, that.create_context(row),
partials, true);
}).join("");
} else if(that.is_object(value)) { // Object, Use it as subcontext!
return that.render(content, that.create_context(value),
partials, true);
} else if(typeof value === "function") {
// higher order section
return value.call(context, content, function(text) {
return that.render(text, context, partials, true);
});
} else if(value) { // boolean section
return that.render(content, context, partials, true);
} else {
return "";
}
}
});
},
/*
Replace {{foo}} and friends with values from our view
*/
Replace {{foo}} and friends with values from our view
*/
render_tags: function(template, context, partials, in_recursion) {
// tit for tat
var that = this;
var new_regex = function() {
return new RegExp(that.otag + "(=|!|>|\\{|%)?([^\/#]+?)\\1?" +
return new RegExp(that.otag + "(=|!|>|\\{|%)?([^\\/#\\^]+?)\\1?" +
that.ctag + "+", "g");
};
var regex = new_regex();
var tag_replace_callback = function(match, operator, name) {
switch(operator) {
case "!": // ignore comments
return "";
case "=": // set new delimiters, rebuild the replace regexp
that.set_delimiters(name);
regex = new_regex();
return "";
case ">": // render partial
return that.render_partial(name, context, partials);
case "{": // the triple mustache is unescaped
return that.find(name, context);
default: // escape the value
return that.escape(that.find(name, context));
}
};
var lines = template.split("\n");
for (var i=0; i < lines.length; i++) {
lines[i] = lines[i].replace(regex, function(match, operator, name) {
switch(operator) {
case "!": // ignore comments
return match;
case "=": // set new delimiters, rebuild the replace regexp
that.set_delimiters(name);
regex = new_regex();
return "";
case ">": // render partial
return that.render_partial(name, context, partials);
case "{": // the triple mustache is unescaped
return that.find(name, context);
default: // escape the value
return that.escape(that.find(name, context));
}
}, this);
if(!in_recursion) {
this.send(lines[i]);
}
}
for(var i = 0; i < lines.length; i++) {
lines[i] = lines[i].replace(regex, tag_replace_callback, this);
if(!in_recursion) {
this.send(lines[i]);
}
}
if(in_recursion) {
return lines.join("\n");
}
if(in_recursion) {
return lines.join("\n");
}
},
set_delimiters: function(delimiters) {
@@ -177,20 +200,33 @@ var Mustache = function() {
'(\\' + specials.join('|\\') + ')', 'g'
);
}
return text.replace(arguments.callee.sRE, '\\$1');
return text.replace(arguments.callee.sRE, '\\$1');
},
/*
find `name` in current `context`. That is find me a value
from the view object
*/
find `name` in current `context`. That is find me a value
from the view object
*/
find: function(name, context) {
name = this.trim(name);
if(typeof context[name] === "function") {
return context[name].apply(context);
// Checks whether a value is thruthy or false or 0
function is_kinda_truthy(bool) {
return bool === false || bool === 0 || bool;
}
if(context[name] !== undefined) {
return context[name];
var value;
if(is_kinda_truthy(context[name])) {
value = context[name];
} else if(is_kinda_truthy(this.context[name])) {
value = this.context[name];
}
if(typeof value === "function") {
return value.apply(context);
}
if(value !== undefined) {
return value;
}
// silently ignore unkown variables
return "";
@@ -198,49 +234,39 @@ var Mustache = function() {
// Utility methods
/*
Does away with nasty characters
*/
escape: function(s) {
return ((s == null) ? "" : s).toString().replace(/[&"<>\\]/g, function(s) {
switch(s) {
case "&": return "&amp;";
case "\\": return "\\\\";;
case '"': return '\"';;
case "<": return "&lt;";
case ">": return "&gt;";
default: return s;
}
});
/* includes tag */
includes: function(needle, haystack) {
return haystack.indexOf(this.otag + needle) != -1;
},
/*
Merges all properties of object `b` into object `a`.
`b.property` overwrites a.property`
*/
merge: function(a, b) {
var _new = {};
for(var name in a) {
if(a.hasOwnProperty(name)) {
_new[name] = a[name];
Does away with nasty characters
*/
escape: function(s) {
s = String(s === null ? "" : s);
return s.replace(/&(?!\w+;)|["<>\\]/g, function(s) {
switch(s) {
case "&": return "&amp;";
case "\\": return "\\\\";
case '"': return '\"';
case "<": return "&lt;";
case ">": return "&gt;";
default: return s;
}
};
for(var name in b) {
if(b.hasOwnProperty(name)) {
_new[name] = b[name];
}
};
return _new;
});
},
// by @langalex, support for arrays of strings
create_context: function(_context) {
if(this.is_object(_context)) {
return _context;
} else if(this.pragmas["IMPLICIT-ITERATOR"]) {
var iterator = this.pragmas["IMPLICIT-ITERATOR"].iterator || ".";
} else {
var iterator = ".";
if(this.pragmas["IMPLICIT-ITERATOR"]) {
iterator = this.pragmas["IMPLICIT-ITERATOR"].iterator;
}
var ctx = {};
ctx[iterator] = _context
ctx[iterator] = _context;
return ctx;
}
},
@@ -254,22 +280,22 @@ var Mustache = function() {
},
/*
Gets rid of leading and trailing whitespace
*/
Gets rid of leading and trailing whitespace
*/
trim: function(s) {
return s.replace(/^\s*|\s*$/g, "");
},
/*
Why, why, why? Because IE. Cry, cry cry.
*/
Why, why, why? Because IE. Cry, cry cry.
*/
map: function(array, fn) {
if (typeof array.map == "function") {
return array.map(fn)
return array.map(fn);
} else {
var r = [];
var l = array.length;
for(i=0;i<l;i++) {
for(var i = 0; i < l; i++) {
r.push(fn(array[i]));
}
return r;
@@ -279,11 +305,11 @@ var Mustache = function() {
return({
name: "mustache.js",
version: "0.2.3-dev",
version: "0.3.0",
/*
Turns a template and view into HTML
*/
Turns a template and view into HTML
*/
to_html: function(template, view, partials, send_fun) {
var renderer = new Renderer();
if(send_fun) {
@@ -295,4 +321,4 @@ var Mustache = function() {
}
}
});
}();
}();

View File

@@ -41,8 +41,9 @@
{{#location}}
based in <span class="adr locality">{{location}}</span>
{{/location}}
with <a href="https://github.com/{{{username}}}">{{repos}} public {{reposLabel}}</a>{{#followers}}&nbsp;and {{followers}} {{followersLabel}}{{/followers}}.
I've been using github.com since {{since}}{{#blog}}&nbsp;and sometimes I blog at <a href="{{blog}}" id="myblog" class="url" title="my blog">{{blog}}</a>{{/blog}}.
{{#repos}}with <a href="https://github.com/{{{username}}}">{{repos}} public {{reposLabel}}</a>{{/repos}}{{^repos}}without any public repository for now{{/repos}}{{#followers}}&nbsp;and {{followers}} {{followersLabel}}{{/followers}}.
I've been using github.com since {{since}}{{#earlyAdopter}}, therefore I'm an early adopter,{{/earlyAdopter}}
{{#blog}}&nbsp;and sometimes I blog at <a href="{{blog}}" id="myblog" title="my blog">{{blog}}</a>.{{/blog}}
</p>
<p id="languages" class="enlarge"></p>
</div>

85
views/resumeOrgs.html Normal file
View File

@@ -0,0 +1,85 @@
<div id="doc2" class="yui-t7">
<div id="inner">
<div id="hd">
<div class="yui-gc">
<div class="yui-u first">
<hgroup>
<h1>{{name}}</h1>
<h2>Github organization</h2>
</hgroup>
</div>
<div class="yui-u">
<div class="contact-info">
{{#gravatar_id}}
<img src="https://secure.gravatar.com/avatar/{{gravatar_id}}?s=140&amp;d=https://github.com/images/gravatars/gravatar-140.png" alt=""/>
{{/gravatar_id}}
{{#email}}<h3><a href="mailto:{{email}}">{{email}}</a></h3>{{/email}}
</div><!--// .contact-info -->
</div>
</div><!--// .yui-gc -->
</div><!--// hd -->
<div id="bd">
<div id="yui-main">
<div class="yui-b">
<div class="yui-gf">
<div class="yui-u first">
<h2>Github Profile</h2>
</div>
<div class="yui-u">
<p class="enlarge">
We are XX developers gathered in a group
{{#location}}
based in {{location}}
{{/location}}
with <a href="https://github.com/{{{username}}}">{{repos}} public {{reposLabel}}</a>.
We've created this Github group in {{since}}{{#earlyAdopter}}, therefore I'm an early adopter,{{/earlyAdopter}}{{#blog}}&nbsp;and you can find more informations about us at <a href="{{blog}}" id="myblog" title="my blog">{{blog}}</a>{{/blog}}.
</p>
<p id="languages" class="enlarge"></p>
</div>
</div><!--// .yui-gf -->
<div class="yui-gf" id="mylanguages">
<div class="yui-u first">
<h2>Languages</h2>
</div>
<div class="yui-u" id="content-languages">
</div>
</div>
<div class="yui-gf">
<div class="yui-u first">
<h2>Our Popular Repositories</h2>
</div><!--// .yui-u -->
<div class="yui-u" id="jobs">
<span>Loading information...</span><img src="images/loader.gif" />
</div><!--// .yui-u -->
</div><!--// .yui-gf -->
<div class="yui-gf last">
<div class="yui-u first">
<h2>About This R&eacute;sum&eacute;</h2>
</div>
<div class="yui-u">
<p class="enlarge">
This r&eacute;sum&eacute; is generated automatically using information from github. The repositories are
ordered by popularity based on a very simple popularity heuristic that defines the popularity of a repository
by its sum of watchers and forks. Do not hesitate to visit <a href="https://github.com/{{{username}}}" title="My Github page">our github group's page</a>
for more information about our repositories and work.
</p>
</div>
</div><!--// .yui-gf -->
</div><!--// .yui-b -->
</div><!--// yui-main -->
</div><!--// bd -->
<div id="ft">
<p>{{name}} &mdash; {{#email}}<a href="mailto:{{email}}">{{email}}</a> &mdash; {{/email}} <a href="https://github.com/{{username}}" title="Github profile">https://github.com/{{username}}</a></p>
</div><!--// footer -->
</div><!-- // inner -->
</div><!--// doc -->