Skip to content

Instantly share code, notes, and snippets.

@hisasann
Created August 19, 2010 03:57
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 hisasann/536988 to your computer and use it in GitHub Desktop.
Save hisasann/536988 to your computer and use it in GitHub Desktop.
(function($) {
/*
* jTemplate
*
* Copyright (c) 2010 hisasann
*
* Example:
* var temp01 = $.jTemplate("<div id='hoge'>${hoge}</div>");
* var html = temp01.evaluate({
* hoge: "ほげ"
* });
* print html // <div id='hoge'>ほげ</div>
*/
$.jTemplate = function(html){
return {
evaluate: function(json){
return html.replace(/\$\{([a-zA-Z0-9]+)\}/g,function(m,prop){
return json[prop];
})
}
}
}
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment