Skip to content

Commit

Permalink
Merge pull request #330 from Peefy/builtin-template-function
Browse files Browse the repository at this point in the history
docs: add builtin template function
  • Loading branch information
Peefy authored Apr 7, 2024
2 parents e7f4b09 + 521ba1a commit f38c47b
Show file tree
Hide file tree
Showing 5 changed files with 104 additions and 2 deletions.
3 changes: 3 additions & 0 deletions docs/reference/model/overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,7 @@ For relatively complex general logic, it is provided through the system modules.
<DocsCard header="file" href="file">
<p>Provides filesystem functions.</p>
</DocsCard>
<DocsCard header="template" href="template">
<p>Provides template functions.</p>
</DocsCard>
</DocsCards>
48 changes: 48 additions & 0 deletions docs/reference/model/template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
---
title: "template"
linkTitle: "template"
type: "docs"
description: template functions
weight: 100
---

## execute

`execute(template: str, data: {str:any} = {}) -> str`

Applies a parsed template to the specified data object and returns the string output. See https://handlebarsjs.com/ for more documents and examples.

```python3
import template

content = template.execute("""\
<div class="entry">
{{#if author}}
<h1>{{firstName}} {{lastName}}</h1>
{{/if}}
</div>
""", {
author: True,
firstName: "Yehuda",
lastName: "Katz",
})
```

## html_escape

`html_escape(data: str) -> str`

Replaces the characters `&"<>` with the equivalent html / xml entities.

```python3

import template

content = template.html_escape("""\
<div class="entry">
{{#if author}}
<h1>{{firstName}} {{lastName}}</h1>
{{/if}}
</div>
""")
```
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,10 @@ KCL 通过内置模块、系统库模块和插件模块提供工程化的扩展
<DocsCard header="yaml" href="yaml">
<p>提供了与 YAML 相关的编码/解码函数。</p>
</DocsCard>
<DocsCard header="file" href="yaml">
<DocsCard header="file" href="file">
<p>提供了与文件系统相关的函数。</p>
</DocsCard>
<DocsCard header="template" href="template">
<p>提供了与模版相关的函数。</p>
</DocsCard>
</DocsCards>
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
---
title: "template"
linkTitle: "template"
type: "docs"
description: 模版操作
weight: 100
---

## execute

`execute(template: str, data: {str:any} = {}) -> str`

将解析过的模板应用于指定的数据对象,并返回字符串输出。查看 https://handlebarsjs.com/ 获取更多文档和示例。

```python3
import template

content = template.execute("""\
<div class="entry">
{{#if author}}
<h1>{{firstName}} {{lastName}}</h1>
{{/if}}
</div>
""", {
author: True,
firstName: "Yehuda",
lastName: "Katz",
})
```

## html_escape

`html_escape(data: str) -> str`

将字符 `&"<>` 替换为等效的 html / xml实体。

```python3

import template

content = template.html_escape("""\
<div class="entry">
{{#if author}}
<h1>{{firstName}} {{lastName}}</h1>
{{/if}}
</div>
""")
```
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ KCL 通过内置模块、系统库模块和插件模块提供工程化的扩展
<DocsCard header="yaml" href="yaml">
<p>提供了与 YAML 相关的编码/解码函数。</p>
</DocsCard>
<DocsCard header="file" href="yaml">
<DocsCard header="file" href="file">
<p>提供了与文件系统相关的函数。</p>
</DocsCard>
</DocsCards>

0 comments on commit f38c47b

Please sign in to comment.