Skip to content

Commit b89e9e6

Browse files
committed
chore: update documentation for block and custom directive usage
Clarifies the behavior of block overriding and inheritance in both English and Chinese documentation. Updates the CustomNode example to extend Traversal instead of implementing ASTNode, and improves explanations for include and block directives.
1 parent 1a8df7e commit b89e9e6

2 files changed

Lines changed: 23 additions & 13 deletions

File tree

documentation-zh-CN.md

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

33
## 内置指令
44

5-
### **include**模板继承/包含
5+
### **include**模板继承与包含
66

77
```janja
88
{{ include "template" }}
@@ -32,7 +32,9 @@
3232
{{ set foo }}内容{{ endset }}
3333
```
3434

35-
### **block / super**:模板继承与区块
35+
### **block / super**:区块覆盖与继承
36+
37+
同名区块自动覆盖或继承,区块总是渲染在第一次出现的地方
3638

3739
```janja
3840
{{ block title }}{{ super }}默认标题{{ endblock }}
@@ -88,13 +90,15 @@ abs, capitalize, add, ceil, compact, div, entries, even, fallback, first, get, g
8890
### 自定义指令
8991

9092
```typescript
91-
class CustomNode implements ASTNode {
93+
class CustomNode extends Traversal {
9294
readonly type = 'CUSTOM'
9395
constructor(
94-
public val: string,
95-
public loc: Loc,
96-
public strip: Strip,
97-
) { }
96+
public readonly val: string,
97+
public readonly loc: Loc,
98+
public readonly strip: Strip,
99+
) {
100+
super()
101+
}
98102
}
99103
render('{{ custom }}', {}, {
100104
parsers: {

documentation.md

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

33
## Built-in Directives
44

5+
### **include**: Template Inheritance & Inclusion
6+
57
```janja
68
{{ include "template" }}
79
```
@@ -30,7 +32,9 @@
3032
{{ set foo }}Content{{ endset }}
3133
```
3234

33-
### **block / super**: Template Inheritance & Blocks
35+
### **block / super**: Block Overriding & Inheritance
36+
37+
Blocks with the same name will automatically overwrite or inherit, and blocks are always rendered where they first appear.
3438

3539
```janja
3640
{{ block title }}{{ super }}Default Title{{ endblock }}
@@ -86,13 +90,15 @@ abs, capitalize, add, ceil, compact, div, entries, even, fallback, first, get, g
8690
### Custom Directive
8791

8892
```typescript
89-
class CustomNode implements ASTNode {
93+
class CustomNode extends Traversal {
9094
readonly type = 'CUSTOM'
9195
constructor(
92-
public val: string,
93-
public loc: Loc,
94-
public strip: Strip,
95-
) { }
96+
public readonly val: string,
97+
public readonly loc: Loc,
98+
public readonly strip: Strip,
99+
) {
100+
super()
101+
}
96102
}
97103
render('{{ custom }}', {}, {
98104
parsers: {

0 commit comments

Comments
 (0)