Skip to content

Commit

Permalink
feat: refactor code, update dependencies and drop tslint
Browse files Browse the repository at this point in the history
  • Loading branch information
armano2 committed Dec 23, 2019
1 parent 7320786 commit ca34379
Show file tree
Hide file tree
Showing 79 changed files with 4,239 additions and 5,366 deletions.
1 change: 1 addition & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ indent_size = 2
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true
quote_type = single
4 changes: 4 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.github
test/resource/**/*
dist
types
16 changes: 16 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
module.exports = {
parser: '@typescript-eslint/parser',
plugins: ['@typescript-eslint'],
extends: [
'eslint:recommended',
'plugin:@typescript-eslint/eslint-recommended',
'plugin:@typescript-eslint/recommended',
],
rules: {
// TODO: enable rules
'@typescript-eslint/interface-name-prefix': ['off'],
'@typescript-eslint/explicit-function-return-type': ['off'],
'@typescript-eslint/no-inferrable-types': ['off'],
'@typescript-eslint/no-explicit-any': ['off'],
},
};
1 change: 0 additions & 1 deletion .github/ISSUE_TEMPLATE/feature_request.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
---
name: Feature request
about: Suggest an idea for this project

---

**Is your feature request related to a problem? Please describe.**
Expand Down
4 changes: 4 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.github
test/resource/**/*
dist
types
3 changes: 3 additions & 0 deletions .prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"trailingComma": "all"
}
20 changes: 10 additions & 10 deletions CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,21 @@ appearance, race, religion, or sexual identity and orientation.
Examples of behavior that contributes to creating a positive environment
include:

* Using welcoming and inclusive language
* Being respectful of differing viewpoints and experiences
* Gracefully accepting constructive criticism
* Focusing on what is best for the community
* Showing empathy towards other community members
- Using welcoming and inclusive language
- Being respectful of differing viewpoints and experiences
- Gracefully accepting constructive criticism
- Focusing on what is best for the community
- Showing empathy towards other community members

Examples of unacceptable behavior by participants include:

* The use of sexualized language or imagery and unwelcome sexual attention or
- The use of sexualized language or imagery and unwelcome sexual attention or
advances
* Trolling, insulting/derogatory comments, and personal or political attacks
* Public or private harassment
* Publishing others' private information, such as a physical or electronic
- Trolling, insulting/derogatory comments, and personal or political attacks
- Public or private harassment
- Publishing others' private information, such as a physical or electronic
address, without explicit permission
* Other conduct which could reasonably be considered inappropriate in a
- Other conduct which could reasonably be considered inappropriate in a
professional setting

## Our Responsibilities
Expand Down
141 changes: 74 additions & 67 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,19 @@ Freemarker Parser is a javascript implementation of the Freemarker (https://free
This project contains **experimental version** of parser ftl to ast tree

## Installation

You can install `freemarker-parser` using [npm](https://npmjs.com):

```bash
$ npm install freemarker-parser --save-dev
```

## Usage

Require `freemarker-parser` inside of your JavaScript:

### Parser
### Parser

```ftl
<#assign f=1>
Expand All @@ -31,17 +34,19 @@ Require `freemarker-parser` inside of your JavaScript:
${f} < 0
</#if>
```

```ts
const freemarker = require("freemarker-parser")
const freemarker = require('freemarker-parser');

const parser = new freemarker.Parser()
const data = parser.parse(template)
const parser = new freemarker.Parser();
const data = parser.parse(template);

console.log(data.ast)
console.log(data.tokens)
console.log(data.ast);
console.log(data.tokens);
```

### Parser (bracket style)

```ftl
[#assign f=1]
Expand All @@ -51,74 +56,76 @@ console.log(data.tokens)
${f} < 0
[/#if]
```

```ts
const freemarker = require("freemarker-parser")
const freemarker = require('freemarker-parser');

const parser = new freemarker.Parser()
const parser = new freemarker.Parser();
const data = parser.parse(template, {
useSquareTags: true,
parseLocation : true,
})
parseLocation: true,
});

console.log(data.ast)
console.log(data.tokens)
console.log(data.ast);
console.log(data.tokens);
```

## Currently supported:
- interpolations `${foo}`
- methods, i.e. `${avg(3, 5)}`
- executing macro
- directives https://freemarker.apache.org/docs/ref_directives.html:
- [`#attempt`](https://freemarker.apache.org/docs/ref_directive_attempt.html)
* `#recover`
- [`#assign`](https://freemarker.apache.org/docs/ref_directive_assign.html)
- [`#global`](https://freemarker.apache.org/docs/ref_directive_global.html)
- [`#local`](https://freemarker.apache.org/docs/ref_directive_local.html)
- [`#if`](https://freemarker.apache.org/docs/ref_directive_if.html)
* `#elseif`
* `#else`
- [`#list`](https://freemarker.apache.org/docs/ref_directive_list.html)
* `#else`
* `#break`
* `#continue`
- [`#include`](https://freemarker.apache.org/docs/ref_directive_include.html)
- [`#import`](https://freemarker.apache.org/docs/ref_directive_import.html)
- [`#macro`](https://freemarker.apache.org/docs/ref_directive_macro.html)
- [`#switch`](https://freemarker.apache.org/docs/ref_directive_switch.html)
* `#case`
* `#default`
* `#break`
- [`#compress`](https://freemarker.apache.org/docs/ref_directive_compress.html)
- [`#function`](https://freemarker.apache.org/docs/ref_directive_function.html)
* `#return`
- [`#parse`](https://freemarker.apache.org/docs/ref_directive_parse.html)
- [`#noparse`](https://freemarker.apache.org/docs/ref_directive_noparse.html)
- [`#stop`](https://freemarker.apache.org/docs/ref_directive_stop.html)
- [`#setting`](https://freemarker.apache.org/docs/ref_directive_setting.html)
- [`#lt`](https://freemarker.apache.org/docs/ref_directive_lt.html)
- [`#t`](https://freemarker.apache.org/docs/ref_directive_t.html)
- [`#nt`](https://freemarker.apache.org/docs/ref_directive_nt.html)
- [`#rt`](https://freemarker.apache.org/docs/ref_directive_rt.html)
- [`#flush`](https://freemarker.apache.org/docs/ref_directive_flush.html)
- [`#escape`](https://freemarker.apache.org/docs/ref_directive_escape.html)
* `#noescape`
- [`#autoesc`](https://freemarker.apache.org/docs/ref_directive_autoesc.html)
- [`#noautoesc`](https://freemarker.apache.org/docs/ref_directive_noautoesc.html)
- [`#outputformat`](https://freemarker.apache.org/docs/ref_directive_outputformat.html)
- [`#ftl`](https://freemarker.apache.org/docs/ref_directive_ftl.html)
- comments `<#-- -->`
- built-ins:
- `?toUpperCase`
- `?toLowerCase`
- `?capitalize`
- `?length`
- `?string("yes", "no")`
- support default values, i.e. `${user!"Anonymous"}`

- interpolations `${foo}`
- methods, i.e. `${avg(3, 5)}`
- executing macro
- directives https://freemarker.apache.org/docs/ref_directives.html:
- [`#attempt`](https://freemarker.apache.org/docs/ref_directive_attempt.html)
- `#recover`
- [`#assign`](https://freemarker.apache.org/docs/ref_directive_assign.html)
- [`#global`](https://freemarker.apache.org/docs/ref_directive_global.html)
- [`#local`](https://freemarker.apache.org/docs/ref_directive_local.html)
- [`#if`](https://freemarker.apache.org/docs/ref_directive_if.html)
- `#elseif`
- `#else`
- [`#list`](https://freemarker.apache.org/docs/ref_directive_list.html)
- `#else`
- `#break`
- `#continue`
- [`#include`](https://freemarker.apache.org/docs/ref_directive_include.html)
- [`#import`](https://freemarker.apache.org/docs/ref_directive_import.html)
- [`#macro`](https://freemarker.apache.org/docs/ref_directive_macro.html)
- [`#switch`](https://freemarker.apache.org/docs/ref_directive_switch.html)
- `#case`
- `#default`
- `#break`
- [`#compress`](https://freemarker.apache.org/docs/ref_directive_compress.html)
- [`#function`](https://freemarker.apache.org/docs/ref_directive_function.html)
- `#return`
- [`#parse`](https://freemarker.apache.org/docs/ref_directive_parse.html) - [`#noparse`](https://freemarker.apache.org/docs/ref_directive_noparse.html)
- [`#stop`](https://freemarker.apache.org/docs/ref_directive_stop.html)
- [`#setting`](https://freemarker.apache.org/docs/ref_directive_setting.html)
- [`#lt`](https://freemarker.apache.org/docs/ref_directive_lt.html)
- [`#t`](https://freemarker.apache.org/docs/ref_directive_t.html)
- [`#nt`](https://freemarker.apache.org/docs/ref_directive_nt.html)
- [`#rt`](https://freemarker.apache.org/docs/ref_directive_rt.html)
- [`#flush`](https://freemarker.apache.org/docs/ref_directive_flush.html)
- [`#escape`](https://freemarker.apache.org/docs/ref_directive_escape.html)
- `#noescape`
- [`#autoesc`](https://freemarker.apache.org/docs/ref_directive_autoesc.html)
- [`#noautoesc`](https://freemarker.apache.org/docs/ref_directive_noautoesc.html)
- [`#outputformat`](https://freemarker.apache.org/docs/ref_directive_outputformat.html)
- [`#ftl`](https://freemarker.apache.org/docs/ref_directive_ftl.html)
- comments `<#-- -->`
- built-ins:
- `?toUpperCase`
- `?toLowerCase`
- `?capitalize`
- `?length`
- `?string("yes", "no")`
- support default values, i.e. `${user!"Anonymous"}`

## TODO:
- directives:
- `#fallback`
- `#nested`
- `#recurse`
- `#visit`
- `#items`

- directives:
- `#fallback`
- `#nested`
- `#recurse`
- `#visit`
- `#items`
Loading

0 comments on commit ca34379

Please sign in to comment.