Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <script id="menu" type="text/html">
- <ul class="menu">
- # for (var i = 0, l = links.length; i < l; ++i) {
- <li><a href="{{ links[i].href }}"{% if (current == links[i].href) { %} class="current"{% } %}>{{ links[i].name }}</a></li>
- # }
- </ul>
- </script>
- <script>
- function template(str) {
- var temp;
- return new Function('context', 'var __p="";with(context){__p+="' +
- str.replace(/\{\{([\s\S]*?)\}\}|\{%([\s\S]*?)%\}|^#(.*)\r?\n?|"|\n/gm, function(m, m1, m2, m3) {
- temp = m1 ? '__p+=' + m1 + ';' : ( m2 ? m2 : ( m3 ? m3 : null ) );
- return temp == null ? (m == '"' ? '\\"' : '\\n') : '";' + temp + '__p+="';
- }) +
- '";}return __p');
- }
- menu = template( val('menu') );
- console.log(menu);
- console.log( menu({
- current: '/',
- links: [
- {href: '/', name: 'Главная'},
- {href: '/articles', name: 'Статьи'},
- {href: '/contactus', name: 'Контакты'}
- ]
- }) );
- </script>
Advertisement
Add Comment
Please, Sign In to add comment