Skip to content

Instantly share code, notes, and snippets.

@frekw
Created February 22, 2010 00:33
Show Gist options
  • Save frekw/310648 to your computer and use it in GitHub Desktop.
Save frekw/310648 to your computer and use it in GitHub Desktop.
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