Skip to content

Commit 418a31b

Browse files
committed
feat: rewrite to support layout and include well
1 parent a07d895 commit 418a31b

91 files changed

Lines changed: 1912 additions & 3225 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.vscode/settings.json

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
{
22
"cSpell.words": [
33
"elif",
4+
"endassign",
5+
"endcall",
6+
"endcomment",
7+
"endmacro",
8+
"endwith",
49
"groupby",
510
"jianjia",
611
"liquidjs",
@@ -54,5 +59,8 @@
5459
"scss",
5560
"pcss",
5661
"postcss"
57-
]
62+
],
63+
"[javascript]": {
64+
"editor.defaultFormatter": "dbaeumer.vscode-eslint"
65+
}
5866
}

README-zh-CN.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
const engine = new Engine()
2828
const { render } = await engine.compile('{{= name }} 苍苍,白露为霜')
2929
const html = await render({ name: '蒹葭' })
30+
3031
document.body.innerHTML = html
3132
```
3233

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
const engine = new Engine()
2828
const { render } = await engine.compile('Hello, {{= name }}!')
2929
const html = await render({ name: 'World' })
30+
3031
document.body.innerHTML = html
3132
```
3233

benchmark/engines/jianjia.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@ export default {
66
ext: 'jianjia',
77
render: async function (templatePath, data) {
88
const template = fs.readFileSync(templatePath, 'utf-8');
9-
return (await(await(await new Engine().initialize(template)).parse()).compile()).render(data);
9+
return (await new Engine().compile(template)).render(data);
1010
},
1111
};

benchmark/readme.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22

33
| Template \ Engine | ejs | eta | handlebars | jianjia | liquidjs |
44
|-------------------|:--------:|:--------:|:--------:|:--------:|:--------:|
5-
| **friends** | 🟡 1.26 | 🟢 0.18 | 🟡 0.81 | 🟡 1.16 |5.26 |
6-
| **if-expression** | 🟡 0.06 | 🟢 0.04 | - | 🟠 0.13 | ⚫ 0.23 |
7-
| **projects-escaped** | 🟡 0.06 | 🟢 0.04 | ⚫ 0.24 | 🟠 0.11 | 🔴 0.21 |
8-
| **projects-unescaped** | 🟡 0.06 | 🟢 0.04 | ⚫ 0.22 | 🟠 0.11 | 0.21 |
9-
| **search-results** | 🟡 0.18 | 🟢 0.06 | 🟠 0.37 | 🟡 0.23 | ⚫ 0.67 |
10-
| **simple-0** | 🟢 0.02 | 🟡 0.03 | 🟠 0.06 | 🟡 0.04 | ⚫ 0.11 |
11-
| **simple-1** | 🟡 0.06 | 🟢 0.04 | ⚫ 0.23 | 🟠 0.13 | 🔴 0.21 |
12-
| **simple-2** | 🟡 0.05 | 🟢 0.04 | ⚫ 0.22 | 🟠 0.10 | 🔴 0.20 |
5+
| **friends** | 🟡 0.81 | 🟢 0.14 | 🟡 0.66 | 🟡 0.53 |4.32 |
6+
| **if-expression** | 🟡 0.05 | 🟢 0.03 | - | 🟡 0.05 | ⚫ 0.16 |
7+
| **projects-escaped** | 🟡 0.06 | 🟢 0.04 | ⚫ 0.19 | 🟡 0.05 | 🔴 0.15 |
8+
| **projects-unescaped** | 🟡 0.06 | 🟢 0.05 | ⚫ 0.17 | 🟢 0.05 | 🔴 0.15 |
9+
| **search-results** | 🟡 0.14 | 🟢 0.05 | 🟠 0.29 | 🟡 0.10 | ⚫ 0.49 |
10+
| **simple-0** | 🟢 0.02 | 🟢 0.02 | 🟠 0.05 | 🟡 0.03 | ⚫ 0.07 |
11+
| **simple-1** | 🟡 0.05 | 🟢 0.03 | ⚫ 0.18 | 🟡 0.05 | 🔴 0.15 |
12+
| **simple-2** | 🟡 0.04 | 🟢 0.03 | ⚫ 0.18 | 🟡 0.05 | 🔴 0.13 |

documentation-zh-CN.md

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@
88
{{ #if condition }}内容{{ elif other }}内容{{ else }}内容{{ /if }}
99
```
1010

11-
### **for / else**:循环遍历
11+
### **for**:循环遍历
1212

1313
```jianjia
14-
{{ #for item in items }}{{ item }}{{ else }}无数据{{ /for }}
14+
{{ #for item in items }}{{= item }}{{ /for }}
1515
```
1616

1717
### **assign**:变量赋值
@@ -48,27 +48,13 @@
4848
{{ continue }}
4949
```
5050

51-
### **with**:上下文变量赋值
52-
53-
```jianjia
54-
{{ #with obj }}
55-
{{= key }}
56-
{{ /with }}
57-
```
58-
5951
### **comment**:注释
6052

6153
```jianjia
6254
{{! 这是注释 }}
6355
{{ #comment }}多行注释{{ /comment }}
6456
```
6557

66-
### **raw**:原文输出(不解析内容)
67-
68-
```jianjia
69-
{{ #raw }}{{ #if x }}foo{{ /if }}{{ /raw }}
70-
```
71-
7258
### **expression(=)**:表达式输出
7359

7460
```jianjia
@@ -99,14 +85,15 @@ const myTag = {
9985
parse({ ast, base }) {
10086
// 解析逻辑
10187
ast.start({ ...base, name: 'my_tag' })
102-
ast.end({ ...base, startIndex: base.endIndex, name: 'end_my_tag' })
88+
ast.end({ ...base, start: base.end, name: 'end_my_tag' })
10389
},
10490
async compile({ template, tag, context, out }, compileContent) {
10591
// 编译逻辑
10692
out.pushStr('自定义标签内容')
107-
}
93+
},
10894
}
10995
const engine = new Engine()
96+
11097
engine.registerTags([myTag])
11198
```
11299

@@ -120,10 +107,11 @@ engine.registerTags([myTag])
120107

121108
```javascript
122109
const engine = new Engine()
110+
123111
engine.registerFilters({
124112
my_filter(value) {
125113
return `自定义:${value}`
126-
}
114+
},
127115
})
128116
```
129117

documentation.md

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@
88
{{ #if condition }}Content{{ elif other }}Content{{ else }}Content{{ /if }}
99
```
1010

11-
### **for / else**: Looping
11+
### **for**: Looping
1212

1313
```jianjia
14-
{{ #for item in items }}{{ item }}{{ else }}No data{{ /for }}
14+
{{ #for item in items }}{{= item }}{{ /for }}
1515
```
1616

1717
### **assign**: Variable Assignment
@@ -48,27 +48,13 @@
4848
{{ continue }}
4949
```
5050

51-
### **with**: Contextual Variable Assignment
52-
53-
```jianjia
54-
{{ #with obj }}
55-
{{= key }}
56-
{{ /with }}
57-
```
58-
5951
### **comment**: Comments
6052

6153
```jianjia
6254
{{! This is a comment }}
6355
{{ #comment }}Multi-line comment{{ /comment }}
6456
```
6557

66-
### **raw**: Raw Output (No Parsing)
67-
68-
```jianjia
69-
{{ #raw }}{{ #if x }}foo{{ /if }}{{ /raw }}
70-
```
71-
7258
### **expression (=)**: Expression Output
7359

7460
```jianjia
@@ -99,14 +85,15 @@ const myTag = {
9985
parse({ ast, base }) {
10086
// Parsing logic
10187
ast.start({ ...base, name: 'my_tag' })
102-
ast.end({ ...base, startIndex: base.endIndex, name: 'end_my_tag' })
88+
ast.end({ ...base, start: base.end, name: 'end_my_tag' })
10389
},
10490
async compile({ template, tag, context, out }, compileContent) {
10591
// Compilation logic
10692
out.pushStr('Custom tag content')
107-
}
93+
},
10894
}
10995
const engine = new Engine()
96+
11097
engine.registerTags([myTag])
11198
```
11299

@@ -120,10 +107,11 @@ Usage in template:
120107

121108
```javascript
122109
const engine = new Engine()
110+
123111
engine.registerFilters({
124112
my_filter(value) {
125113
return `Custom: ${value}`
126-
}
114+
},
127115
})
128116
```
129117

eslint.config.mjs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,11 @@ export default antfu(
44
{
55
ignores: ['**/benchmark/**', '**/coverage/**', '**/dist/**'],
66
},
7+
{
8+
rules: {
9+
'no-cond-assign': 'off',
10+
'unicorn/consistent-function-scoping': 'off',
11+
'antfu/consistent-chaining': 'error',
12+
},
13+
},
714
)

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@
2121
},
2222
"devDependencies": {
2323
"@antfu/eslint-config": "^5.4.1",
24-
"@types/node": "^24.5.0",
24+
"@types/node": "^24.6.0",
2525
"eslint": "^9.36.0",
2626
"husky": "^9.1.7",
27-
"oxlint": "^1.15.0",
27+
"oxlint": "^1.19.0",
2828
"typescript": "^5.9.2"
2929
}
3030
}

packages/template/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
"tinyrainbow": "^3.0.3"
2525
},
2626
"devDependencies": {
27-
"@types/node": "^24.5.0",
27+
"@types/node": "^24.6.0",
2828
"@vitest/coverage-v8": "3.2.4",
2929
"@vitest/ui": "3.2.4",
3030
"typescript": "^5.9.2",

0 commit comments

Comments
 (0)