From a0c56fa352fe7eb4547c3f1c7a8bb274dfda8c97 Mon Sep 17 00:00:00 2001 From: cflmy Date: Wed, 12 Aug 2026 09:20:34 +0800 Subject: [PATCH] =?UTF-8?q?Add=20Chinese=20web-site=20example=20and=20?= =?UTF-8?q?=E7=BD=91=E9=A1=B5.mq.md=20smoke.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Mirrors the English sample on port 18082 using only Chinese class APIs for page, db, form, and app. Co-authored-by: Cursor --- examples/web-site-zh/README.md | 10 +++ examples/web-site-zh/components/foot.mq.md | 9 +++ examples/web-site-zh/components/nav.mq.md | 12 ++++ examples/web-site-zh/components/side.mq.md | 10 +++ examples/web-site-zh/db/articles.mq.md | 22 ++++++ examples/web-site-zh/db/index.mq.md | 19 +++++ examples/web-site-zh/index.mq.md | 64 +++++++++++++++++ examples/web-site-zh/styles/shell.mq.md | 42 +++++++++++ tests/ext/web-zh-smoke.mq.md | 82 ++++++++++++++++++++++ tests/gold.rs | 17 +++++ 10 files changed, 287 insertions(+) create mode 100644 examples/web-site-zh/README.md create mode 100644 examples/web-site-zh/components/foot.mq.md create mode 100644 examples/web-site-zh/components/nav.mq.md create mode 100644 examples/web-site-zh/components/side.mq.md create mode 100644 examples/web-site-zh/db/articles.mq.md create mode 100644 examples/web-site-zh/db/index.mq.md create mode 100644 examples/web-site-zh/index.mq.md create mode 100644 examples/web-site-zh/styles/shell.mq.md create mode 100644 tests/ext/web-zh-smoke.mq.md diff --git a/examples/web-site-zh/README.md b/examples/web-site-zh/README.md new file mode 100644 index 0000000..90a5024 --- /dev/null +++ b/examples/web-site-zh/README.md @@ -0,0 +1,10 @@ +# examples/web-site-zh + +中文作者面示例:只导入 `ext/web/网页.mq.md`(不用英文 `web.mq.md`)。 + +```bash +cargo build -p marqdo_plugin_web +cargo run -- examples/web-site-zh/index.mq.md +``` + +打开 http://127.0.0.1:18082/ — `/about`、`/new`、`/admin`。 diff --git a/examples/web-site-zh/components/foot.mq.md b/examples/web-site-zh/components/foot.mq.md new file mode 100644 index 0000000..46d74ce --- /dev/null +++ b/examples/web-site-zh/components/foot.mq.md @@ -0,0 +1,9 @@ +## foot + +`foot` = + +| 属性 | 值 | 样式 | +|------|-----|------| +| Marqdo | https://github.com | | + +**`foot`** diff --git a/examples/web-site-zh/components/nav.mq.md b/examples/web-site-zh/components/nav.mq.md new file mode 100644 index 0000000..19095c5 --- /dev/null +++ b/examples/web-site-zh/components/nav.mq.md @@ -0,0 +1,12 @@ +## nav + +`nav` = + +| 属性 | 值 | 样式 | +|------|-----|------| +| 首页 | / | | +| 关于 | /about | | +| 写文章 | /new | | +| 后台 | /admin | | + +**`nav`** diff --git a/examples/web-site-zh/components/side.mq.md b/examples/web-site-zh/components/side.mq.md new file mode 100644 index 0000000..7db7c02 --- /dev/null +++ b/examples/web-site-zh/components/side.mq.md @@ -0,0 +1,10 @@ +## side + +`side` = + +| 属性 | 值 | 样式 | +|------|-----|------| +| 笔记 | / | | +| 文档 | https://github.com | | + +**`side`** diff --git a/examples/web-site-zh/db/articles.mq.md b/examples/web-site-zh/db/articles.mq.md new file mode 100644 index 0000000..8d56413 --- /dev/null +++ b/examples/web-site-zh/db/articles.mq.md @@ -0,0 +1,22 @@ +## schema + +`fields` = + +| 字段 | 类型 | 可空 | +|------|------|------| +| id | integer | false | +| title | text | false | +| body | text | true | + +**`fields`** + +## seed + +`rows` = + +| id | title | body | +|----|-------|------| +| 1 | 你好 Marqdo | 第一篇来自 GFM 表格。 | +| 2 | 代码即文档 | 页面表就是程序。 | + +**`rows`** diff --git a/examples/web-site-zh/db/index.mq.md b/examples/web-site-zh/db/index.mq.md new file mode 100644 index 0000000..72d7bf8 --- /dev/null +++ b/examples/web-site-zh/db/index.mq.md @@ -0,0 +1,19 @@ +--- +title: db/index +description: 打开 sqlite、建表、幂等种子。 +> ext/web/网页.mq.md +> articles.mq.md as articles +--- + +## open + +*`store` = > 网页.数据库 地址="sqlite:data/site-zh.db" * +*`fields` = > articles.schema * +> `store`.初始化 名=articles 字段=`fields` +*`rows` = > `store`.查询 表=articles 上限=1 * +1. `rows` + **`store`** +2. * + *`seed` = > articles.seed * + > `store`.插入 表=articles 行=`seed` + **`store`** diff --git a/examples/web-site-zh/index.mq.md b/examples/web-site-zh/index.mq.md new file mode 100644 index 0000000..3b630cd --- /dev/null +++ b/examples/web-site-zh/index.mq.md @@ -0,0 +1,64 @@ +--- +title: 中文站点示例 +description: Home + /about + /new(表单嵌入)+ 后台;只用 ext/web/网页.mq.md。 +> ext/web/网页.mq.md +> styles/shell.mq.md +> components/nav.mq.md +> components/side.mq.md +> components/foot.mq.md +> db/articles.mq.md +> db/index.mq.md as db +--- + +# main + +`home` = + +| 组件 | 样式 | +|------|------| +| nav.`nav` | shell.`topnav` | +| side.`side` | shell.`side_panel` | +| foot.`foot` | | + +`index` = + +| 属性 | 值 | 样式 | +|------|-----|------| +| `title` | articles.`articles`.title | shell.`card_title` | +| `body` | articles.`articles`.body | shell.`card_body` | + +`article_fields` = + +| 字段 | 标签 | 类型 | 必填 | 默认 | +|------|------|------|------|------| +| title | 标题 | text | true | | +| body | 正文 | textarea | false | | + +`article_rules` = + +| 字段 | 规则 | 消息 | +|------|------|------| +| title | required | 标题不能为空 | +| title | max:120 | 标题太长 | +| body | max:8000 | 正文太长 | + +*`store` = > db.open * +*`page` = > 网页.页面 标题="Marqdo 中文站" 引言="

中文站

表格 + 类方法。

" * +*`page` = > `page`.组件装配 组件=`home` * +*`page` = > `page`.主体装配 主体=`index` * + +*`about` = > 网页.页面 标题="关于" 引言="

关于

导入网页.mq.md 即用中文 API。

" * +*`about` = > `about`.组件装配 组件=`home` * + +*`article_form` = > 网页.表单 表=articles 动作=插入 * +*`article_form` = > `article_form`.字段 字段=`article_fields` * +*`article_form` = > `article_form`.规则 规则=`article_rules` * + +*`new` = > 网页.页面 标题="写文章" 引言="

写文章

表单嵌在主区。

" * +*`new` = > `new`.组件装配 组件=`home` * +*`new` = > `new`.表单装配 id=article 表单=`article_form` * + +*`app` = > 网页.应用 页面=`page` 数据库=`store` 后台=True 主机=127.0.0.1 端口=18082 * +*`app` = > `app`.路由 路径=/about 页面=`about` * +*`app` = > `app`.路由 路径=/new 页面=`new` * +> `app`.监听 diff --git a/examples/web-site-zh/styles/shell.mq.md b/examples/web-site-zh/styles/shell.mq.md new file mode 100644 index 0000000..15cd41b --- /dev/null +++ b/examples/web-site-zh/styles/shell.mq.md @@ -0,0 +1,42 @@ +## topnav + +`topnav` = + +| 属性 | 值 | +|------|-----| +| background | #ffffff | +| border-bottom | 1px solid #e7e5e4 | + +**`topnav`** + +## side_panel + +`side_panel` = + +| 属性 | 值 | +|------|-----| +| background | #f5f5f4 | + +**`side_panel`** + +## card_title + +`card_title` = + +| 属性 | 值 | +|------|-----| +| font-size | 1.15rem | +| margin | 0 0 0.35rem | + +**`card_title`** + +## card_body + +`card_body` = + +| 属性 | 值 | +|------|-----| +| color | #57534e | +| margin | 0 | + +**`card_body`** diff --git a/tests/ext/web-zh-smoke.mq.md b/tests/ext/web-zh-smoke.mq.md new file mode 100644 index 0000000..574623c --- /dev/null +++ b/tests/ext/web-zh-smoke.mq.md @@ -0,0 +1,82 @@ +--- +title: web zh API smoke +description: Offline Chinese 网页.mq.md assemble (no listen). +> ext/web/网页.mq.md +> web-fixtures/components/nav.mq.md +> web-fixtures/components/side.mq.md +> web-fixtures/components/foot.mq.md +> web-fixtures/db/articles.mq.md as articles +> lib/json.mq.md +--- + +# main + +*`store` = > 网页.数据库 地址="sqlite:web-fixtures/data/zh-smoke.db" * +*`schema` = > articles.schema * +> `store`.初始化 名=articles 字段=`schema` +> `store`.执行 sql="DELETE FROM articles" +> `store`.执行 sql="DELETE FROM sqlite_sequence WHERE name='articles'" + +`layout` = + +| 组件 | 样式 | +|------|------| +| nav.`nav` | | +| side.`side` | | +| foot.`foot` | | + +`index` = + +| 属性 | 值 | 样式 | +|------|-----|------| +| `title` | articles.`articles`.title | | +| `body` | articles.`articles`.body | | + +`seed` = + +| title | body | +|-------|------| +| 中文种子 | 正文 | + +> `store`.插入 表=articles 行=`seed` + +*`page` = > 网页.页面 标题="中文烟测" 引言="

中文

" * +*`page` = > `page`.组件装配 组件=`layout` * +*`page` = > `page`.主体装配 主体=`index` * + +*`html` = > `page`.渲染 数据库=`store` * +1. `html` + > print text=render-ok +2. * + > print text=render-fail + +*`nav` = > json.get value=`page` key=nav * +1. `nav` + > print text=compose-ok +2. * + > print text=compose-fail + +`fields` = + +| 字段 | 标签 | 类型 | 必填 | 默认 | +|------|------|------|------|------| +| title | 标题 | text | true | | + +*`f` = > 网页.表单 表=articles 动作=插入 * +*`f` = > `f`.字段 字段=`fields` * +*`page` = > `page`.表单装配 id=article 表单=`f` * +*`fid` = > json.get value=`page` key=form_id * +1. `fid` == "article" + > print text=form-ok +2. * + > print text=form-fail + +*`app` = > 网页.应用 页面=`page` 数据库=`store` 主机=127.0.0.1 端口=18082 * +*`about` = > 网页.页面 标题="关于" 引言="

关于

" * +*`app` = > `app`.路由 路径=/about 页面=`about` * +*`routes` = > json.get value=`app` key=routes * +*`routed` = > json.get value=`routes` key="/about" * +1. `routed` + > print text=route-ok +2. * + > print text=route-fail diff --git a/tests/gold.rs b/tests/gold.rs index eb0e475..f8900c8 100644 --- a/tests/gold.rs +++ b/tests/gold.rs @@ -1341,6 +1341,23 @@ all-ok", ); } +#[test] +fn ext_web_zh_smoke() { + let status = Command::new("cargo") + .args(["build", "-p", "marqdo_plugin_web"]) + .current_dir(env!("CARGO_MANIFEST_DIR")) + .status() + .expect("build web plugin"); + assert!(status.success(), "failed to build marqdo_plugin_web"); + assert_out( + "tests/ext/web-zh-smoke.mq.md", + "render-ok +compose-ok +form-ok +route-ok", + ); +} + #[test] fn ext_agent_framework_smoke() { let status = Command::new("cargo")