Skip to content

Instantly share code, notes, and snippets.

@monjudoh
Created September 9, 2008 06:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save monjudoh/9626 to your computer and use it in GitHub Desktop.
Save monjudoh/9626 to your computer and use it in GitHub Desktop.
(function($,templateStr){
var MiniTemplate = function(template){
this.template = eval(['([\'',template.replace(/\$\{([^${}]+)\}/g,'\',{key:\'$1\'},\''),'\'])'].join(''));
};
MiniTemplate.prototype.merge = function(context){
var template = this.template || [];
var temp = [];
for(var i = 0; i < template.length; i++){
if(typeof template[i] == 'string'){
temp.push(template[i]);
}else if(typeof template[i] == 'object' && typeof template[i]['key'] == 'string'){
temp.push(context[ template[i]['key'] ]);
}
}
return temp.join('');
}
var text = [];
var template = new MiniTemplate(templateStr);
$('#container .doing tr.hentry:visible')
.map(function(){
var entry = $(this);
return {
statusId:entry.attr('id')
,url:entry.find('.entry-date').attr('href')
,userId:entry.find('.content strong a').text()
,message:$.trim(entry.find('.entry-content').text())
};
})
.get()
.sort(function(a,b){
if(a.statusId > b.statusId){
return 1;
}else if(b.statusId > a.statusId){
return -1;
}else{
return 0;
}
}).forEach(function(e){
text.push(template.merge(e));
});
copy(text.join('\n'));
})(jQuery,'|[${url}:title=${userId}]|${message}|');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment