Created

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist
View prototype.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
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);
View prototype.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14
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) );
View prototype.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
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.