Add ext/web forms (design §5.5): fields, validate, submit, GET|POST /_form.
Also fix static links (URLs with dots) being misread as db fields. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
9599303c4c
commit
ee019fb1c2
13 files changed
+890
-46
No files matched your search
+14
-12
@@ -1,24 +1,26 @@
|
||||
# ext/web
|
||||
|
||||
Official dynamic website extension. Design: [`doc/design/ext-web.md`](../../doc/design/ext-web.md).
|
||||
Official dynamic website extension: **GFM tables + class methods**.
|
||||
Design: [`doc/design/ext-web.md`](../../doc/design/ext-web.md).
|
||||
|
||||
| Surface | Import | Classes |
|
||||
|---------|--------|---------|
|
||||
| English | `> ext/web/web.mq.md` | `page` · `db` · `app` · `form` · `style` |
|
||||
| Chinese | `> ext/web/网页.mq.md` | `页面` · `数据库` · `应用` · `表单` · `样式` |
|
||||
|
||||
```bash
|
||||
cargo build -p marqdo_plugin_web
|
||||
# optional install into ~/.marqdo/ext
|
||||
marqdo ext add web
|
||||
```
|
||||
|
||||
```markdown
|
||||
---
|
||||
> ext/web/web.mq.md
|
||||
---
|
||||
Canonical sample (design §4): [`examples/web-site/`](../../examples/web-site/).
|
||||
|
||||
# main
|
||||
> web.ensure_plugin
|
||||
*`page` = > web.page title=Hi *
|
||||
*`app` = > web.app page=`page` *
|
||||
> `app`.listen
|
||||
```bash
|
||||
cargo run -- run examples/web-site/index.mq.md
|
||||
# http://127.0.0.1:18081/ · /admin
|
||||
```
|
||||
|
||||
Scaffold: `> web.scaffold dest=./myapp`
|
||||
Offline assemble smoke: `tests/ext/web-smoke.mq.md`.
|
||||
|
||||
Multipage site pack (compose + table CSS + `/_part`): see [`examples/web-site/`](../../examples/web-site/).
|
||||
**Form / validate / submit** (§5.5): field table + rules + `mount_form` → `GET|POST /_form/{id}`.
|
||||
+25
-7
@@ -127,30 +127,40 @@ Style tables live as `##` exports in site style modules; compose resolves them b
|
||||
+ `action`=insert
|
||||
+ `id`=None
|
||||
|
||||
Form API is planned (design §5.5); first trial ships the class shell only.
|
||||
Field table + rules table; submit writes through `# db`.
|
||||
|
||||
**`self`**
|
||||
> ensure_plugin
|
||||
**> web_form_new table=`table` action=`action` id=`id`**
|
||||
|
||||
## fields
|
||||
+ `fields`
|
||||
|
||||
**`self`**
|
||||
**> web_form_fields form=`self` fields=`fields`**
|
||||
|
||||
## rules
|
||||
+ `rules`
|
||||
|
||||
**> web_form_rules form=`self` rules=`rules`**
|
||||
|
||||
## validate
|
||||
+ `rules`=None
|
||||
+ `data`
|
||||
|
||||
**`data`**
|
||||
**> web_form_validate form=`self` rules=`rules` data=`data`**
|
||||
|
||||
## render
|
||||
+ `id`=form
|
||||
+ `data`=None
|
||||
+ `errors`=None
|
||||
|
||||
**""**
|
||||
**> web_form_render form=`self` id=`id` data=`data` errors=`errors`**
|
||||
|
||||
## submit
|
||||
+ `data`
|
||||
+ `db`
|
||||
|
||||
**`data`**
|
||||
*`url` = > json.get value=`db` key=url *
|
||||
**> web_form_submit form=`self` data=`data` url=`url`**
|
||||
|
||||
# app
|
||||
+ `page`
|
||||
@@ -168,8 +178,16 @@ Form API is planned (design §5.5); first trial ships the class shell only.
|
||||
|
||||
**`self`**
|
||||
|
||||
## mount_form
|
||||
+ `id`
|
||||
+ `form`
|
||||
|
||||
Register `GET|POST /_form/{id}` for listen.
|
||||
|
||||
**> web_app_mount_form app=`self` id=`id` form=`form`**
|
||||
|
||||
## listen
|
||||
|
||||
Serve `/`, `/_part/{id}`, and optional `/admin` from the assembled page.
|
||||
Serve `/`, `/_part/{id}`, `/_form/{id}`, and optional `/admin`.
|
||||
|
||||
**> web_listen app=`self`**
|
||||
+22
-6
@@ -119,30 +119,40 @@ description: 官方网站类(中文)。表格 + 方法;不写袋式胶水
|
||||
+ `动作`=插入
|
||||
+ `id`=None
|
||||
|
||||
表单 API 已锁定(设计 §5.5);本试运行仅留类壳。
|
||||
字段表 + 校验表;提交经 `# 数据库` 写入。
|
||||
|
||||
**`self`**
|
||||
> 确保插件
|
||||
**> web_form_new table=`表` action=`动作` id=`id`**
|
||||
|
||||
## 字段
|
||||
+ `字段`
|
||||
|
||||
**`self`**
|
||||
**> web_form_fields form=`self` fields=`字段`**
|
||||
|
||||
## 规则
|
||||
+ `规则`
|
||||
|
||||
**> web_form_rules form=`self` rules=`规则`**
|
||||
|
||||
## 校验
|
||||
+ `规则`=None
|
||||
+ `数据`
|
||||
|
||||
**`数据`**
|
||||
**> web_form_validate form=`self` rules=`规则` data=`数据`**
|
||||
|
||||
## 渲染
|
||||
+ `id`=form
|
||||
+ `数据`=None
|
||||
+ `错误`=None
|
||||
|
||||
**""**
|
||||
**> web_form_render form=`self` id=`id` data=`数据` errors=`错误`**
|
||||
|
||||
## 提交
|
||||
+ `数据`
|
||||
+ `数据库`
|
||||
|
||||
**`数据`**
|
||||
*`url` = > json.get value=`数据库` key=url *
|
||||
**> web_form_submit form=`self` data=`数据` url=`url`**
|
||||
|
||||
# 应用
|
||||
+ `页面`
|
||||
@@ -160,6 +170,12 @@ description: 官方网站类(中文)。表格 + 方法;不写袋式胶水
|
||||
|
||||
**`self`**
|
||||
|
||||
## 挂载表单
|
||||
+ `id`
|
||||
+ `表单`
|
||||
|
||||
**> web_app_mount_form app=`self` id=`id` form=`表单`**
|
||||
|
||||
## 监听
|
||||
|
||||
**> web_listen app=`self`**
|
||||
Reference in new issue
Block a user