Skip to content

Commit

Permalink
Typo and Readme updates
Browse files Browse the repository at this point in the history
  • Loading branch information
Reterics committed Oct 14, 2023
1 parent 9bfae67 commit 1bfb6fe
Show file tree
Hide file tree
Showing 6 changed files with 100 additions and 14 deletions.
79 changes: 70 additions & 9 deletions README.md
Expand Up @@ -9,16 +9,13 @@ It should not be used in production environment.
# Features

- Unescaped output with `{{ }}`
- Static caching of templates

## Examples

```
<p>Hello {{world}}</p>
```
- IF statement with `{# }} {/# ]]`
- Maping objects with `{> }} {/> }}`

## Usage

### Node

```javascript
let template = lejs.compile(str, options);
template(data);
Expand All @@ -30,6 +27,70 @@ lejs.render(str, data, options);
lejs.renderFile(filename, data, options);
```

### CLI

**.lejs**
```html
<p>Hello {{world}}</p>
<ul>
{>li}}
<li>Index: {{+index}}. {{+value}}</li>
{/>li}}
</ul>
{#details}}
<details>
{{detail}}
</details>
{/#details}}

```

**JSON data**
```json
{
"world": "World",
"li": [
{
"value": "Line 1"
},
{
"value": "Line 2"
}
],
"details": true,
"detail": "This value is visible, because details is true"
}
```

**Output**
```html
<p>Hello World</p>
<ul>

<li>Index: 0. Line 1</li>

<li>Index: 1. Line 2</li>

</ul>

<details>
This value is visible, because details is true
</details>
```

**CLI call**
```bash
node ./dist/bin/cli.js ./test/files/example.lejs -f ./test/files/example.json
# OR
lejs ./test/files/example.lejs -f ./test/files/example.json
```



### Tags
- `{{` Value output for template
- `}}` End Tag
- `{{ }}` Value output tag
- `{# }}` IF statement start tag
- `{/# }}` IF statement end tag
- `{> }}` MAP start tag
- `{{+ }}` MAP variable tag
- `{/> }}` MAP end tag
5 changes: 3 additions & 2 deletions src/constants.ts
Expand Up @@ -9,13 +9,14 @@ export const REGEXPS: ParserConstants = {
if: {
start: "{#",
end: "}}",
close_start: "{\/#",
regexp: /{#\w*}}[\s\S]*?{\/#\w*}}/g
},
map: {
start: "{>",
end: "}}",
close_start: "{\\>",
regexp: /{>\w*}}[\s\S]*?{\\>\w*}}/g,
close_start: "{\/>",
regexp: /{>\w*}}[\s\S]*?{\/>\w*}}/g,
},
map_variable: {
start: "{{+",
Expand Down
4 changes: 2 additions & 2 deletions src/parsers/if.ts
Expand Up @@ -12,8 +12,8 @@ const renderIfStatement: ParserFunc = (string: string, data: object|null, option

if (data && name && data[name] && data[name] !== "") {
const values = match
.replaceAll(`{#${name}}}`, '')
.replaceAll(`{/#${name}}}`, '');
.replaceAll(`${config.start}${name}${config.end}`, '')
.replaceAll(`${config.close_start}${name}${config.end}`, '');
string = string.replace(match, values);
} else if (options.defaultValue === 'empty' || options.defaultValue === 'default') {
// Remove the matched string from the XML content.
Expand Down
13 changes: 13 additions & 0 deletions test/files/example.json
@@ -0,0 +1,13 @@
{
"world": "World",
"li": [
{
"value": "Line 1"
},
{
"value": "Line 2"
}
],
"details": true,
"detail": "This value is visible, because details is true"
}
11 changes: 11 additions & 0 deletions test/files/example.lejs
@@ -0,0 +1,11 @@
<p>Hello {{world}}</p>
<ul>
{>li}}
<li>Index: {{+index}}. {{+value}}</li>
{/>li}}
</ul>
{#details}}
<details>
{{detail}}
</details>
{/#details}}
2 changes: 1 addition & 1 deletion test/files/map.xml
Expand Up @@ -16,6 +16,6 @@
</productCodes>
<lineExpressionIndicator>true</lineExpressionIndicator>
</line>
{\>invoiceLines}}
{/>invoiceLines}}
</invoiceMain>
</InvoiceData>

0 comments on commit 1bfb6fe

Please sign in to comment.