JSFiddle - React, Tailwind, and code Playground
by luizz
JavaScript
$.fn.templace = function(template, data, omg_alp, func){
var _self = $(this), html ='';
omg_alp = omg_alp || 0;
data = data || {};
function forData(tpl, dataf){
var html_temp = tpl;
var match = html_temp.match(new RegExp('{{([A-z0-9\_]+)}}',"gmi"));
// var beta = html_temp.match(new RegExp('{{([A-z0-9\_]+)}}\.([A-z0-9\_\(\)]?)',"gmi"));
for(var i in match){
i = match[i].replace("{{", "").replace("}}", "");
if(typeof(dataf[i]) !== "undefined"){
if(typeof(func) === "function")dataf[i] = func.call(this, i, dataf[i]);
html_temp = html_temp.replace(new RegExp('{{'+i+'}}',"gm"), dataf[i]);
// function(m, key, value){
//
// var v_match = value.match(new RegExp('{{'+i+'}}\.([A-z0-9\_]+)',"mi"));
// var _datatemp = dataf[i];
//
// if(v_match !== null && v_match['index'] === key){
// try{
// _datatemp = _datatemp[v_match[1]]();
// }catch (e){log(e);}
// }
//
// //console.log(m, key);
// ...