Skip to content

@cmilfont /prototype.js
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
function Engine(template) {
var pattern = /\#\{([^}]+)\}/g;
var _render = function(json){
return template.replace(pattern, function(m, value) {
return json[value];
});
};
this._r = function() {
return _render.apply(this, arguments);
}
};
Engine.prototype = {
render: function(json) { return this._r(json) }
};
var json = { title: "Cadastro", url: "/cursos", desc: "cliqui aqui" };
var template = "<h1>#{title}</h1> " +
"<a href='#{url}'>#{desc}</a>";
new Engine(template).render(json);
Object.defineProperty(String.prototype, 'interpolate', {
value: function(json){
var pattern = /\#\{([^}]+)\}/g;
this.replace(pattern, function() {
console.log(arguments);
return "";
});
}
});
var json = { title: "Cadastro", url: "/cursos", desc: "cliqui aqui" };
var template = "<h1>#{json.title}</h1> " +
"<a href='#{json.url}'>#{json.desc}</a>";
$("#nav").html( template.interpolate(json) );
var Engine = (function(){
var pattern = /\#\{([^}]+)\}/g;
var _render = function(template, json){
return template.replace(pattern, function(m, value) {
return json[value];
});
};
return {
render: _render
};
})();
var json = { title: "Cadastro", url: "/cursos", desc: "cliqui aqui" };
var template = "<h1>#{title}</h1> " +
"<a href='#{url}'>#{desc}</a>";
Engine.render(template, json)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.