light javascript files loader with client side templating feature and late events binding
How to use it :
1 - load the script like that :
<script src="js/lib/require.js" data-main="js/scripts/main"></script>2 - main.js definition :
// paths configuration define(function() { r.baseScripts = "/js/scripts/"; r.baseTemplates = "/js/views/"; });
require(["util", "text!util.html"], function(util, tpl){ let tpl = util.utils(); console.log( template(tpl, { firstname : "David", lastname : "Chabrier" }) ); });
3 - util.js definition :
define(["text!util.html"], function (tpl) { return { utils : function() { return template(tpl, { firstname : "David", lastname : "Chabrier", 'for-customers' : [ { id : 1, lastname : "Chabrier 1", firstname : "David 1" }, { firstname : "David 2", lastname : "Chabrier 2", id :2 }, ] }); } } });
4 - util.html template definition :
firstname : {{identity.firstname}}
lastname : {{identity.lastname}}
Address:
- City : {{identity.address.city}}
- Zipcode : {{identity.address.zipcode}}
-
{{for-identity.customers}}
-
{{identity.customers.firstname}} {{identity.customers.lastname}}
-
{{for-customers.tels}}
- {{customers.tels.type}} {{customers.tels.number}} (perso:{{tels.emails.personnal}} pro:{{tels.emails.pro}}) {{endfor-customers.tels}}
{{endfor-identity.customers}}
-
{{for-customers}}
- {{customers.firstname}} {{customers.lastname}} {{endfor-customers}}