Created
November 15, 2011 07:31
-
-
Save milesplit/1366395 to your computer and use it in GitHub Desktop.
Zepto Simple Template Plugin
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
// Template | |
// (c) 2011 Jason Byrne, MileSplit | |
// May be freely distributed under the MIT license, with attribution. | |
// | |
// ** Usage ** | |
// | |
// HTML: | |
// <script type="text/html" id="tmplArticle"><h1>${Title}</h1></script> | |
// | |
// JavaScript: | |
// $('#tmplArticle').tmpl(data).appendTo($item); | |
// | |
(function($){ | |
$.fn.tmpl = function(d) { | |
var s = $(this[0]).html().trim(); | |
if (d) { | |
for (k in d) { | |
s = s.replace(new RegExp('\\${' + k + '}', 'g'), d[k]); | |
} | |
} | |
return $(s); | |
}; | |
})(Zepto); |
Author
milesplit
commented
Nov 15, 2011
$.fn.tmpl = function(d) {
var s = $(this[0]).html().trim();
if (d) {
for (k in d) {
s = s.replace('${' + k + '}', d[k]);
}
}
return $(s);
};
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment