Skip to content

Commit f38c47b

Browse files
authored
Merge pull request #330 from Peefy/builtin-template-function
docs: add builtin template function
2 parents e7f4b09 + 521ba1a commit f38c47b

File tree

5 files changed

+104
-2
lines changed

5 files changed

+104
-2
lines changed

docs/reference/model/overview.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,4 +54,7 @@ For relatively complex general logic, it is provided through the system modules.
5454
<DocsCard header="file" href="file">
5555
<p>Provides filesystem functions.</p>
5656
</DocsCard>
57+
<DocsCard header="template" href="template">
58+
<p>Provides template functions.</p>
59+
</DocsCard>
5760
</DocsCards>

docs/reference/model/template.md

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
---
2+
title: "template"
3+
linkTitle: "template"
4+
type: "docs"
5+
description: template functions
6+
weight: 100
7+
---
8+
9+
## execute
10+
11+
`execute(template: str, data: {str:any} = {}) -> str`
12+
13+
Applies a parsed template to the specified data object and returns the string output. See https://handlebarsjs.com/ for more documents and examples.
14+
15+
```python3
16+
import template
17+
18+
content = template.execute("""\
19+
<div class="entry">
20+
{{#if author}}
21+
<h1>{{firstName}} {{lastName}}</h1>
22+
{{/if}}
23+
</div>
24+
""", {
25+
author: True,
26+
firstName: "Yehuda",
27+
lastName: "Katz",
28+
})
29+
```
30+
31+
## html_escape
32+
33+
`html_escape(data: str) -> str`
34+
35+
Replaces the characters `&"<>` with the equivalent html / xml entities.
36+
37+
```python3
38+
39+
import template
40+
41+
content = template.html_escape("""\
42+
<div class="entry">
43+
{{#if author}}
44+
<h1>{{firstName}} {{lastName}}</h1>
45+
{{/if}}
46+
</div>
47+
""")
48+
```

i18n/zh-CN/docusaurus-plugin-content-docs/current/reference/model/overview.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,10 @@ KCL 通过内置模块、系统库模块和插件模块提供工程化的扩展
5151
<DocsCard header="yaml" href="yaml">
5252
<p>提供了与 YAML 相关的编码/解码函数。</p>
5353
</DocsCard>
54-
<DocsCard header="file" href="yaml">
54+
<DocsCard header="file" href="file">
5555
<p>提供了与文件系统相关的函数。</p>
5656
</DocsCard>
57+
<DocsCard header="template" href="template">
58+
<p>提供了与模版相关的函数。</p>
59+
</DocsCard>
5760
</DocsCards>
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
---
2+
title: "template"
3+
linkTitle: "template"
4+
type: "docs"
5+
description: 模版操作
6+
weight: 100
7+
---
8+
9+
## execute
10+
11+
`execute(template: str, data: {str:any} = {}) -> str`
12+
13+
将解析过的模板应用于指定的数据对象,并返回字符串输出。查看 https://handlebarsjs.com/ 获取更多文档和示例。
14+
15+
```python3
16+
import template
17+
18+
content = template.execute("""\
19+
<div class="entry">
20+
{{#if author}}
21+
<h1>{{firstName}} {{lastName}}</h1>
22+
{{/if}}
23+
</div>
24+
""", {
25+
author: True,
26+
firstName: "Yehuda",
27+
lastName: "Katz",
28+
})
29+
```
30+
31+
## html_escape
32+
33+
`html_escape(data: str) -> str`
34+
35+
将字符 `&"<>` 替换为等效的 html / xml实体。
36+
37+
```python3
38+
39+
import template
40+
41+
content = template.html_escape("""\
42+
<div class="entry">
43+
{{#if author}}
44+
<h1>{{firstName}} {{lastName}}</h1>
45+
{{/if}}
46+
</div>
47+
""")
48+
```

i18n/zh-CN/docusaurus-plugin-content-docs/version-0.8/reference/model/overview.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ KCL 通过内置模块、系统库模块和插件模块提供工程化的扩展
5151
<DocsCard header="yaml" href="yaml">
5252
<p>提供了与 YAML 相关的编码/解码函数。</p>
5353
</DocsCard>
54-
<DocsCard header="file" href="yaml">
54+
<DocsCard header="file" href="file">
5555
<p>提供了与文件系统相关的函数。</p>
5656
</DocsCard>
5757
</DocsCards>

0 commit comments

Comments
 (0)