Created
August 19, 2010 03:57
-
-
Save hisasann/536988 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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