Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // My very own template engine :DD
- function precompile (template) {
- return function (locals) {
- return template.replace(/\#\{([a-z0-9_]+)\}/g, function (_, key) {
- return locals[key];
- });
- }
- };
- var template = [
- '<div class="head">',
- '<h1>#{title}</h1>',
- '<h2>#{subtitle}</h2>',
- '</div>'
- ].join('\n')
- var tpl = precompile(template);
- tpl({ title: 'hello', subtitle: 'world' });
- /*
- "<div class="head">
- <h1>hello</h1>
- <h2>world</h2>
- </div>"
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement