Created
September 12, 2014 15:28
-
-
Save elrrrrrrr/175de2b90c430840bba6 to your computer and use it in GitHub Desktop.
heredoc实现模版渲染
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function heredoc(fn) { | |
| return fn.toString().split('\n').slice(1,-1).join('\n') + '\n' | |
| } | |
| var a = heredoc(function(){/* | |
| <%data.forEach(function(e){%> | |
| <a class="item" href="pizzahut-detail.html?version=*&id=<%=e.pic%>"> | |
| <div class="cnt"> | |
| <img src="img/0<%=e.pic%>.jpg"> | |
| <div class="wrap"> | |
| <div class="wrap2"> | |
| <div class="content"> | |
| <div class="title"> <%=e.name%></div> | |
| <div class="price">¥<em><%=e.prize.substring(1, e.prize.length-1)%></em>起</div> | |
| </div> | |
| </div> | |
| </div> | |
| </div> | |
| </a> | |
| <%})%> | |
| */}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var fs = require('fs'); | |
| var _ =require('lodash'); | |
| //out | |
| console.log(_.template(a, {data: item})) | |
| fs.writeFile('./t.html',_.template(a, {data: item})) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment