模块开发指南之模板编写

This commit is contained in:
undefined committed 2020-05-19 11:23:20 +08:00
1 parent b6dce8a030
commit 747cb1b9b5
12 files changed
+236 -195

No files matched your search

+8
View File
@@ -2,3 +2,11 @@
Hydro 后端使用 NodeJS 编写,前端使用 JQuery + React。
代码风格遵循 airbnb 标准(详见 .eslintrc.js)。
由于模块中不能使用 require() 引入 Hydro 的文件,因此需要从 global.Hydro 中取出需要的模块。
例:
```js
const { db } = global.Hydro.service;
const { problem } = global.Hydro.model;
```
@@ -1,8 +1,11 @@
[
"basic",
"module",
"hydro",
"handler",
"service",
"lib",
"file",
"locale",
"template"
]
+11
View File
@@ -0,0 +1,11 @@
# Hydro.json
Hydro.json 是模块的声明文件,格式如下。
```json
{
"id": "模块ID",
"version": "模块版本",
"description": "模块描述"
}
```
+3
View File
@@ -0,0 +1,3 @@
# Lib
库文件。通常用于提供一些功能(废话)。
+3
View File
@@ -0,0 +1,3 @@
# Locale
用于提供多国翻译。格式与 Hydro 的 locale 文件夹格式相同。
+28 -2
View File
@@ -1,5 +1,31 @@
# Template
页面模板。
页面模板,使用 nunjucks 语法。
传入了 _ 翻译函数与 model 等。
TODO
```html
{% set page_name = "page_name" %}
{% extends "layout/basic.html" %}
{% block content %}
<div class="error__container clearfix">
<div class="error__icon-container">
<div class="error__twd2"></div>
</div>
<div class="error__text-container">
<h1>{{ _('Oops!') }}</h1>
<p>{{ _(error.message).format(error.params) }}</p>
<p>{{ _('Technical Information') }}:</p>
<p>{{ _('Type') }}: {{ error.code }}</p>
<p>{{ _('Arguments') }}:
<ol>
{% for param in error.params %}
<li>{{ param }}</li>
{% endfor %}
</ol>
</p>
</div>
</div>
{% endblock %}
```
<blockquote class="note">请不要覆盖已有模板。</blockquote>