0.1.4 • Published 6 years ago

xste v0.1.4

Weekly downloads
2
License
MIT
Repository
github
Last release
6 years ago

xste:custard: Travis Status Coverage Status License: MIT

extra small template engine (under 360bytes, not gzipped)
NPM

recommend using vdom.

THIS ENGINE DOESN'T ESCAPE.
escape on server side recommend.
don't let the client if possible.
for user experience.

xste is beta-release.
the interface could change at any time.

How to use(Browser)

Hello!

  • foo
  • bar
<script src="xste.js"></script>
<script>
//Add Template
xste.add("h3","<h3><%=self.text%></h3>");
xste.add("mbox",`
  <div class="mbox">
    <%=include("h3",{text:self.title})%>
    <ul>
    <!-- don't forget "var"(let, const) -->
    <%for(var i=0,l=self.list.length;i<l;i++){%>
      <li><%=self.list[i]%></li>
    <%}%>
  </div>
`);
//Compile
document.body.innerHTML =
  xste("mbox", {
    title:"Hello!",
    list:["foo", "bar"]
  });
</script>

How to use(node)

const fs = require("fs"):
const xste = require("xste"):

let xste_agent; fs.writeFileSync("./template/a/b/c/test.tpl", "<%=self.hoge%>");

//@Browser-like xste_agent = new xste(); xste_agent.add("test", "<%=self.hoge%>"); const result = await xste_agent.compile("test", {hoge: "foobar"}); assert.strictEqual(result, "foobar");

//@LoadFromFile,Dynamic xste_agent = new xste(); await xste_agent.addSource("./template/"); //DynamicLoad when compile(template_name == filename) const result = await xste_agent.compile("test", {hoge: "foobar"}); assert.strictEqual(result, "foobar");

//@LoadFromFile,Manual xste_agent = new xste(); await xste_agent.load("test", "./template/a/b/c/test.tpl"); const result = await xste_agent.compile("test", {hoge: "foobar"}); assert.strictEqual(result, "foobar");

//@Bundle const bundled_source = await xste.bundle({ mode: "raw", src : "./template/", }); fs.writeFileSync("./bundled.js", bundled_source);

//and more methods...

## Do you need full documentation?
see `/test/**/*.js`, almost cover all methods.
```bash
git clone git@github.com:mochiya98/xste.git
cd xste
npm i
npm test
0.1.4

6 years ago

0.1.3

6 years ago

0.1.2

6 years ago

0.1.1

6 years ago

0.1.0

6 years ago