Created
February 22, 2010 00:33
-
-
Save frekw/310648 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
var Template = function(markup){ this.markup = markup; var reg_exp = /(\$[a-zA-Z0-9]+)/i } | |
Template.prototype.compile = function(vars){ | |
this.markup = this.markup.replace(this.reg_exp, function(match){ | |
var key = match.substr(1, match.length-1) | |
return vars[key] | |
}) | |
return this.markup | |
} | |
/* Usage */ | |
var t = new Template("<div class='$klass'>$content</div>") | |
alert(t.compile({ | |
klass: 'hidden', | |
content: 'foo!' | |
})) | |
$('body').append(t.markup) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment