Created
June 5, 2012 10:48
-
-
Save usefulthink/2874360 to your computer and use it in GitHub Desktop.
JS µTemplating
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(global) { | |
var tpl = function(template, data) { | |
var proc = function(data) { | |
var ret = template; | |
for (var k in data) { | |
if (data.hasOwnProperty(k)) { | |
ret = ret.replace('#{'+k+'}', data[k]); | |
} | |
} | |
return ret; | |
}; | |
if(data) { return proc(data); } | |
return proc; | |
}; | |
global.tpl = tpl; | |
} (this)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment