freemarker-parser-next
v2.0.0
Published
Freemarker Parser is a javascript implementation of the Freemarker
Downloads
3
Maintainers
Readme
freemarker-parser-next
Fork from freemarker-parser made by Armano (https://github.com/armano2)
Freemarker Parser is a javascript implementation of the Freemarker (https://freemarker.apache.org).
This project contains experimental version of parser ftl to ast tree
Installation
You can install freemarker-parser
using npm:
$ npm install freemarker-parser --save-dev
Usage
Require freemarker-parser
inside of your JavaScript:
Parser
<#assign f=1>
<#if f gt 0>
${f} > 0
<#else>
${f} < 0
</#if>
const freemarker = require('freemarker-parser');
const parser = new freemarker.Parser();
const data = parser.parse(template);
console.log(data.ast);
console.log(data.tokens);
Parser (bracket style)
[#assign f=1]
[#if f gt 0]
${f} > 0
[#else]
${f} < 0
[/#if]
const freemarker = require('freemarker-parser');
const parser = new freemarker.Parser();
const data = parser.parse(template, {
useSquareTags: true,
parseLocation: true,
});
console.log(data.ast);
console.log(data.tokens);
Currently supported:
- interpolations
${foo}
- methods, i.e.
${avg(3, 5)}
- methods, i.e.
- executing macro
- directives https://freemarker.apache.org/docs/ref_directives.html:
- comments
<#-- -->
- built-ins:
?toUpperCase
?toLowerCase
?capitalize
?length
?string("yes", "no")
- support default values, i.e.
${user!"Anonymous"}
TODO:
- directives:
#fallback
#nested
#recurse
#visit