Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/fouber/fis-parser-ejs

a parser plugin for fis to compile ejs file
https://github.com/fouber/fis-parser-ejs

Last synced: 5 days ago
JSON representation

a parser plugin for fis to compile ejs file

Awesome Lists containing this project

README

        

# fis-parser-ejs

a parser plugin for fis to compile ejs file

## usage

1. install

```bash
npm install -g fis-parser-ejs
```

1. configure

```javascript
//tell fis that `.ejs` is a js file
fis.config.set('roadmap.ext.ejs', 'js');
//tell fis that parse `.ejs` file by using `fis-parser-ejs` plugin
fis.config.set('modules.parser.ejs', 'ejs');
//set options if you need
//@see https://github.com/visionmedia/ejs#options
fis.config.set('settings.parser.ejs', {
open : '<#',
close : '#>'
});
```

1. inline ejs file

* source:

```javascript
/**********************************
* tpl.ejs content:
**********************************
<% if (user) { %>

<%= user.name %>


<% } %>
**********************************/
var tpl = __inline('tpl.ejs');
var data = {
user : {
name : 'foo'
}
};
var html = tpl(data);
console.log(html);
```

* release:

```javascript
var tpl = [function(locals,filters,escape,rethrow){function rethrow(e,n,a,t){var r=n.split("\n"),s=Math.max(t-3,0),c=Math.min(r.length,t+3),i=r.slice(s,c).map(function(e,n){var a=n+s+1;return(a==t?" >> ":" ")+a+"| "+e}).join("\n");throw e.path=a,e.message=(a||"ejs")+":"+t+"\n"+i+"\n\n"+e.message,e}escape=escape||function(e){return String(e).replace(/&(?!#?[a-zA-Z0-9]+;)/g,"&").replace(//g,">").replace(/'/g,"'").replace(/"/g,""")};var __stack={lineno:1,input:"<% if (user) { %>\n

<%= user.name %>

\n<% } %>",filename:"a.ejs"};try{var buf=[];with(locals||{})!function(){buf.push(""),__stack.lineno=1,user&&(buf.push("\n

",escape((__stack.lineno=2,user.name)),"

\n"),__stack.lineno=3),buf.push("")}();return buf.join("")}catch(err){rethrow(err,__stack.input,__stack.filename,__stack.lineno)}}][0];
var data = {
user : {
name : 'foo'
}
};
var html = tpl(data);
console.log(html);
```