Skip to content

paperscut/xejs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

History

24 Commits

Repository files navigation

XEJS

By @angrykoala

npm versionBuild Statuscodecov

eXtreme EJS

XEJS allows you to render files with a custom tag-based language using EJS

Recursive templating, what could go wrong?

How it works

xejs provides a custom renderer utility on top of ejs, allowing you to define your own tags of the type {{my tag }} with custom delimiters (<< my tag >>).

xejs will then match your custom regex rules (e.g. /[Tt]itle/) and map it to a string to be rendered by ejs.

The original EJS tags of the file (<% %>) will be escaped and won't be rendered by xejs

Usage

varxejs=require('xejs');varfs=require('fs');varoptions={openTag: "{{",closeTag: "}}",tokens: [[/bold\s(.+)/,"- '<b>$1</b>'"]]};varfile=xejs("example/test.ejs",options);fs.writeFileSync('example/prueba.html',file);

This code will render all{{bold [my text] }} into html <b> text

Provided tags

The tag include is already implemented, allowing you to load (and render) another file.

Examples:

Using the tags delimiters {{... }}

  • /[Tt]itle/ - "= title" will translate any tag of the type {{title }} or {{Title}} into a valid <%- title %> ejs tag which will be rendered by ejs.

Warning: Only simple tags allowed, nested tags and html-based tags not supported

About

Recursive templating. What could go wrong?

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript100.0%