1234567891011121314151617181920212223242526272829303132333435363738 |
- <!DOCTYPE HTML>
- <html>
- <head>
- <meta charset="UTF-8">
- <title>helper-demo</title>
- <script src="../dist/template.js"></script>
- </head>
- <body>
- <h1>辅助方法</h1>
- <div id="content"></div>
- <script id="test" type="text/html">
- <%=$ubb2html(text)%>
- </script>
- <script>
- template.helper('$ubb2html', function (content) {
- return content
- .replace(/\[b\]([^\[]*?)\[\/b\]/igm, '<b>$1</b>')
- .replace(/\[i\]([^\[]*?)\[\/i\]/igm, '<i>$1</i>')
- .replace(/\[u\]([^\[]*?)\[\/u\]/igm, '<u>$1</u>')
- .replace(/\[url=([^\]]*)\]([^\[]*?)\[\/url\]/igm, '<a href="$1">$2</a>')
- .replace(/\[img\]([^\[]*?)\[\/img\]/igm, '<img src="$1" />');
- });
- // 如果要访问 Math 则:template.helper('Math', Math)
- var data = {
- text: '我是辅助方法[b]加粗[/b]的'
- };
- var html = template.render('test', data);
- document.getElementById('content').innerHTML = html;
- </script>
- </body>
- </html>
|