Rewrite ext/web around tables and class methods.

Drop bag/scaffold glue and rebuild the web plugin for compose, SQLite CRUD, and listen, with call_lib_path support and a §4 English site sample.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
cflmyandCursor committed 2026-08-11 15:06:39 +08:00
1 parent 8041a2274c
commit 9599303c4c
38 files changed
+2772 -4658

No files matched your search

+2
View File
@@ -20,3 +20,5 @@ marqdo ext add web
```
Scaffold: `> web.scaffold dest=./myapp`
Multipage site pack (compose + table CSS + `/_part`): see [`examples/web-site/`](../../examples/web-site/).
-10
View File
@@ -1,10 +0,0 @@
MARQDO_WEB_HOST=127.0.0.1
MARQDO_WEB_PORT=8080
DATABASE_URL=sqlite:./data/app.db
# MARQDO_WEB_ADMIN_USER=admin
# MARQDO_WEB_ADMIN_PASSWORD=change-me
# REDIS_URL=redis://127.0.0.1:6379/0
# MARQDO_S3_ENDPOINT=
# MARQDO_S3_BUCKET=
# MARQDO_S3_ACCESS_KEY=
# MARQDO_S3_SECRET_KEY=
-51
View File
@@ -1,51 +0,0 @@
---
title: ext/web starter app
description: Variable name = table name; page methods bind regions.
> ext/web/web.mq.md
---
# main
> web.load_env path=.env
> web.ensure_plugin
`nav` =
| 前端变量 | 后端数据库 | 绑定css样式 |
|----------|------------|-------------|
| 首页 | / | |
| 管理 | /admin | |
`side` =
| 前端变量 | 后端数据库 | 绑定css样式 |
|----------|------------|-------------|
| 全部文章 | / | |
| 管理后台 | /admin | |
`articles` =
| 字段 | 类型 | 可空 |
|------|------|------|
| id | integer | false |
| title | text | false |
| body | text | true |
`主体` =
| 前端变量 | 后端数据库 | 绑定css样式 |
|----------|------------|-------------|
| title | title | card-title |
| body | body | card-body |
*`db` = > web.db *
*`articles` = > `db`.init name=articles fields=`articles` *
*`page` = > web.page title=Starter *
*`page` = > `page`.nav table=`nav` *
*`page` = > `page`.sidebar table=`side` *
*`page` = > `page`.main table=`articles` bind=`主体` layout=cards intro="<h1>Starter</h1>" *
*`app` = > web.app page=`page` db=`db` admin=True *
> `app`.static dir=./static
> `app`.listen
@@ -1,6 +0,0 @@
CREATE TABLE IF NOT EXISTS posts (
id INTEGER PRIMARY KEY AUTOINCREMENT,
title TEXT NOT NULL,
body TEXT,
created_at TEXT DEFAULT (datetime('now'))
);
-509
View File
@@ -1,509 +0,0 @@
/* Marqdo Web default theme — semantic / classless shell.
Content kinds: prose, cards, table. No purple/cream-terracotta AI defaults. */
:root {
--ink: #1c1917;
--ink-muted: #57534e;
--paper: #fafaf9;
--panel: #ffffff;
--line: #e7e5e4;
--accent: #0f766e;
--accent-hover: #0d9488;
--side-w: 14rem;
--radius: 6px;
--font-display: "Source Serif 4", "Noto Serif SC", Georgia, serif;
--font-ui: "IBM Plex Sans", "Noto Sans SC", "Segoe UI", sans-serif;
--font-mono: "IBM Plex Mono", ui-monospace, monospace;
--space: 1.25rem;
--max-prose: 42rem;
}
* {
box-sizing: border-box;
}
html {
font-size: 16px;
-webkit-text-size-adjust: 100%;
}
body {
margin: 0;
min-height: 100vh;
display: grid;
grid-template-rows: auto 1fr auto;
grid-template-columns: 1fr;
background: var(--paper);
color: var(--ink);
font-family: var(--font-ui);
line-height: 1.55;
}
body.has-sidebar {
grid-template-columns: var(--side-w) 1fr;
grid-template-areas:
"top top"
"side main"
"foot foot";
}
body.no-sidebar {
grid-template-areas:
"top"
"main"
"foot";
}
/* —— Shell —— */
header.topnav {
grid-area: top;
background: var(--panel);
border-bottom: 1px solid var(--line);
padding: 0.85rem var(--space);
position: sticky;
top: 0;
z-index: 10;
}
aside.side {
grid-area: side;
background: #f5f5f4;
border-right: 1px solid var(--line);
padding: var(--space) 1rem;
min-height: 0;
}
main.main {
grid-area: main;
padding: calc(var(--space) * 1.25) var(--space) calc(var(--space) * 2);
min-width: 0;
}
footer.foot {
grid-area: foot;
border-top: 1px solid var(--line);
padding: 0.85rem var(--space);
color: var(--ink-muted);
font-size: 0.9rem;
background: var(--panel);
}
/* —— Nav links —— */
ul.nav,
ul.side-nav,
ul.foot-nav {
list-style: none;
margin: 0;
padding: 0;
display: flex;
gap: 0.35rem 1.15rem;
flex-wrap: wrap;
align-items: center;
}
ul.side-nav {
flex-direction: column;
align-items: stretch;
gap: 0.2rem;
}
aside.side .side-label {
display: block;
font-size: 0.72rem;
letter-spacing: 0.08em;
text-transform: uppercase;
color: var(--ink-muted);
margin: 0 0 0.65rem;
font-family: var(--font-ui);
}
ul.nav a,
ul.side-nav a,
ul.foot-nav a {
color: var(--ink);
text-decoration: none;
font-weight: 500;
border-radius: var(--radius);
padding: 0.35rem 0.45rem;
}
ul.side-nav a {
display: block;
padding: 0.45rem 0.6rem;
}
ul.nav a:hover,
ul.side-nav a:hover,
ul.foot-nav a:hover {
color: var(--accent);
background: rgba(15, 118, 110, 0.08);
}
ul.side-nav a[aria-current="page"],
ul.nav a[aria-current="page"] {
color: var(--accent);
background: rgba(15, 118, 110, 0.12);
}
/* —— Prose (intro / raw main HTML) —— */
.main-intro,
.content.prose {
max-width: var(--max-prose);
font-family: var(--font-display);
font-size: 1.125rem;
}
.main-intro h1,
.content.prose h1 {
font-size: 2rem;
line-height: 1.2;
margin: 0 0 0.75rem;
letter-spacing: -0.02em;
}
.main-intro p,
.content.prose p {
margin: 0 0 1rem;
color: var(--ink-muted);
}
/* Bound field hooks from `|绑定css样式|` */
.card-title {
font-family: var(--font-display);
}
.card-body {
color: var(--ink-muted);
}
.content.cards {
display: grid;
gap: 1rem;
margin-top: 1.25rem;
grid-template-columns: repeat(auto-fill, minmax(16rem, 1fr));
}
.content.cards article {
background: var(--panel);
border: 1px solid var(--line);
border-radius: var(--radius);
padding: 1rem 1.1rem;
box-shadow: 0 1px 0 rgba(28, 25, 23, 0.04);
}
.content.cards article h2 {
font-family: var(--font-display);
font-size: 1.2rem;
margin: 0 0 0.45rem;
line-height: 1.3;
}
.content.cards article p {
margin: 0;
color: var(--ink-muted);
font-size: 0.95rem;
}
.content.cards article .meta {
margin-top: 0.65rem;
font-size: 0.8rem;
color: var(--ink-muted);
font-family: var(--font-mono);
}
/* —— Table layout —— */
.content.table-wrap {
margin-top: 1.25rem;
overflow-x: auto;
border: 1px solid var(--line);
border-radius: var(--radius);
background: var(--panel);
}
.content.table-wrap table {
width: 100%;
border-collapse: collapse;
font-size: 0.95rem;
}
.content.table-wrap th,
.content.table-wrap td {
padding: 0.55rem 0.75rem;
text-align: left;
border-bottom: 1px solid var(--line);
}
.content.table-wrap th {
background: #f5f5f4;
font-weight: 600;
font-size: 0.8rem;
text-transform: uppercase;
letter-spacing: 0.04em;
color: var(--ink-muted);
}
.content.table-wrap tr:last-child td {
border-bottom: 0;
}
/* —— Simple list —— */
.content.list {
margin: 1.25rem 0 0;
padding: 0;
list-style: none;
max-width: var(--max-prose);
}
.content.list li {
padding: 0.65rem 0;
border-bottom: 1px solid var(--line);
font-family: var(--font-display);
}
/* —— Admin panel —— */
.admin-page {
max-width: 56rem;
}
.admin-bar {
display: flex;
flex-wrap: wrap;
align-items: flex-end;
justify-content: space-between;
gap: 1rem;
margin-bottom: 1.25rem;
padding-bottom: 1rem;
border-bottom: 1px solid var(--line);
}
.admin-crumbs {
margin: 0 0 0.25rem;
font-size: 0.8rem;
color: var(--ink-muted);
}
.admin-crumbs a {
color: var(--ink-muted);
text-decoration: none;
}
.admin-crumbs a:hover {
color: var(--accent);
}
.admin-bar h1 {
margin: 0;
font-family: var(--font-display);
font-size: 1.65rem;
letter-spacing: -0.02em;
}
.admin-actions {
display: flex;
flex-wrap: wrap;
gap: 0.5rem;
}
.admin-lead {
margin: 0 0 1rem;
color: var(--ink-muted);
}
.admin-empty {
color: var(--ink-muted);
padding: 1.5rem 0;
}
.admin-cards {
display: grid;
gap: 1rem;
grid-template-columns: repeat(auto-fill, minmax(14rem, 1fr));
}
.admin-card {
background: var(--panel);
border: 1px solid var(--line);
border-radius: var(--radius);
padding: 1rem 1.1rem;
}
.admin-card h2 {
margin: 0 0 0.35rem;
font-size: 1.15rem;
font-family: var(--font-display);
}
.admin-meta {
margin: 0 0 0.85rem;
font-size: 0.85rem;
color: var(--ink-muted);
font-family: var(--font-mono);
}
.admin-card-actions {
display: flex;
gap: 0.45rem;
}
.btn,
button.btn {
display: inline-flex;
align-items: center;
justify-content: center;
padding: 0.4rem 0.85rem;
border-radius: var(--radius);
border: 1px solid var(--accent);
background: var(--accent);
color: #fff;
font: inherit;
font-size: 0.9rem;
text-decoration: none;
cursor: pointer;
}
.btn:hover,
button.btn:hover {
background: var(--accent-hover);
border-color: var(--accent-hover);
color: #fff;
}
.btn-ghost {
background: transparent;
color: var(--ink);
border-color: var(--line);
}
.btn-ghost:hover {
background: #f5f5f4;
color: var(--ink);
border-color: var(--line);
}
.btn-danger {
background: #fff;
color: #b91c1c;
border-color: #fecaca;
}
.btn-danger:hover {
background: #fef2f2;
color: #991b1b;
border-color: #fecaca;
}
.btn-small {
padding: 0.25rem 0.55rem;
font-size: 0.8rem;
}
.col-actions {
white-space: nowrap;
width: 1%;
}
.inline-form {
display: inline;
margin: 0;
}
.admin-table th.col-actions {
text-align: right;
}
.admin-table td.col-actions {
text-align: right;
}
.admin-form {
max-width: 28rem;
}
.admin-form-fields {
display: grid;
gap: 0.9rem;
}
.admin-field {
display: grid;
gap: 0.35rem;
}
.admin-field span {
font-size: 0.85rem;
font-weight: 600;
color: var(--ink-muted);
}
.admin-field input,
.admin-field textarea {
width: 100%;
padding: 0.5rem 0.65rem;
border: 1px solid var(--line);
border-radius: var(--radius);
font: inherit;
background: var(--panel);
color: var(--ink);
}
.admin-field input:focus,
.admin-field textarea:focus {
outline: 2px solid color-mix(in srgb, var(--accent) 35%, transparent);
border-color: var(--accent);
}
.admin-form-footer {
display: flex;
gap: 0.5rem;
margin-top: 1.25rem;
}
.log-action {
font-family: var(--font-mono);
font-size: 0.85rem;
}
.log-create {
color: #0f766e;
}
.log-update {
color: #a16207;
}
.log-delete {
color: #b91c1c;
}
aside.side .side-label {
margin-bottom: 0.5rem;
}
a {
color: var(--accent);
}
a:hover {
color: var(--accent-hover);
}
@media (max-width: 720px) {
body.has-sidebar {
grid-template-columns: 1fr;
grid-template-areas:
"top"
"side"
"main"
"foot";
}
aside.side {
border-right: 0;
border-bottom: 1px solid var(--line);
}
ul.side-nav {
flex-direction: row;
flex-wrap: wrap;
}
}
+112 -312
View File
@@ -1,375 +1,175 @@
---
title: ext/web
description: >-
Dynamic website toolkit. Variable name = table name; page regions bound by methods.
title: ext/web/web
description: Official web site classes (English). Tables + methods; no bag glue.
> lib/plugin.mq.md
> lib/sys.mq.md
> lib/json.mq.md
> lib/plugin.mq.md
> lib/fs.mq.md
---
## load_env
+ `path`=None
**> sys.load_dotenv path=`path`**
## ensure_plugin
Load the ABI v2 `web` plugin once.
*`p` = > plugin.native_path name=web *
1. `p`
> plugin.load path=`p`
2. *
> print text=web-plugin-missing: cargo build -p marqdo_plugin_web or marqdo ext add web
> print text=ext/web: native web plugin not found (build marqdo_plugin_web or marqdo ext add web)
> sys.exit code=1
---
## as_links
+ `table`
**> web_as_links table=`table`**
## as_fields
+ `table`
**> web_as_fields table=`table`**
## as_bind
+ `table`
**> web_as_bind table=`table`**
## as_rows
+ `table`
**> web_as_rows table=`table`**
## table_name
+ `table`
*`t` = > type `table` *
1. `t` == map
*`n` = > json.get value=`table` key=name *
1. `n`
**`n`**
2. *
**`table`**
2. *
**`table`**
---
****
# page
+ `theme`=starter
+ `title`=Marqdo Web
+ `intro`="<p>Welcome</p>"
+ `layout`=cards
+ `db_url`=None
*`self` = > json.parse text={"_type":"page","theme":"starter","title":"Marqdo Web","intro":"<p>Welcome</p>","layout":"cards","slots":{},"nav":[],"sidebar":[],"footer":[]} *
*`self` = > json.set map=`self` key=theme value=`theme` *
*`self` = > json.set map=`self` key=title value=`title` *
*`self` = > json.set map=`self` key=intro value=`intro` *
*`self` = > json.set map=`self` key=layout value=`layout` *
1. `db_url`
*`self` = > json.set map=`self` key=db_url value=`db_url` *
2. *
*`_` = 1*
**`self`**
## nav
+ `table`
*`b` = > as_bind table=`table` *
*`self` = > json.set map=`self` key=nav value=`b` *
**`self`**
## sidebar
+ `table`
*`b` = > as_bind table=`table` *
*`self` = > json.set map=`self` key=sidebar value=`b` *
**`self`**
## footer
+ `table`
*`b` = > as_bind table=`table` *
*`self` = > json.set map=`self` key=footer value=`b` *
**`self`**
## main
+ `table`
+ `bind`
+ `layout`=cards
+ `title`="Marqdo Web"
+ `intro`=""
*`tn` = > table_name table=`table` *
*`b` = > as_bind table=`bind` *
*`self` = > json.set map=`self` key=table value=`tn` *
*`self` = > json.set map=`self` key=main value=`b` *
*`self` = > json.set map=`self` key=layout value=`layout` *
1. `intro`
*`self` = > json.set map=`self` key=intro value=`intro` *
2. *
*`_` = 1*
**`self`**
> ensure_plugin
**> web_page_new title=`title` intro=`intro`**
## follow
+ `name`
+ `live`
## compose_components
+ `components`
*`slots` = > json.get value=`self` key=slots *
1. `slots`
*`_` = 1*
2. *
*`slots` = > json.parse text={} *
*`slots` = > json.set map=`slots` key=`name` value=`live` *
*`self` = > json.set map=`self` key=slots value=`slots` *
1. `name` == main
*`self` = > json.set map=`self` key=main value=`live` *
2. `name` == 主体
*`self` = > json.set map=`self` key=main value=`live` *
3. *
*`_` = 1*
**`self`**
Assemble nav / sidebar / footer from a page table (`|组件|样式|` or `|src|style|`).
## resolve_live
+ `value`
**> web_compose_components page=`self` components=`components`**
*`t` = > type `value` *
1. `t` == map
*`kind` = > json.get value=`value` key=_type *
1. `kind` == live
*`url` = > json.get value=`value` key=url *
*`table` = > json.get value=`value` key=table *
*`limit` = > json.get value=`value` key=limit *
1. `limit`
*`_` = 1*
2. *
*`limit` = 200*
*`r` = > web_db_all url=`url` table=`table` limit=`limit` *
**> json.get value=`r` key=rows**
2. *
**`value`**
2. *
**`value`**
## compose_main
+ `main`
Assemble main from a bind table (`|属性|值|样式|` or `|front|back|css|`).
**> web_compose_main page=`self` main=`main`**
## render
+ `db`=None
*`title` = > json.get value=`self` key=title *
*`nav` = > json.get value=`self` key=nav *
*`sidebar` = > json.get value=`self` key=sidebar *
*`footer` = > json.get value=`self` key=footer *
*`intro` = > json.get value=`self` key=intro *
*`layout` = > json.get value=`self` key=layout *
*`db_url` = > json.get value=`self` key=db_url *
*`table` = > json.get value=`self` key=table *
*`main` = > json.get value=`self` key=main *
*`main` = > `self`.resolve_live value=`main` *
**> web_render title=`title` nav=`nav` sidebar=`sidebar` footer=`footer` main=`main` intro=`intro` layout=`layout` db_url=`db_url` table=`table`**
Offline HTML for tests / previews.
---
1. `db`
*`url` = > json.get value=`db` key=url *
**> web_render page=`self` url=`url`**
2. *
**> web_render page=`self`**
# style
+ `name`=""
Style tables live as `##` exports in site style modules; compose resolves them by path.
**`self`**
## process
+ `style`=None
+ `name`=None
+ `path`=None
**`self`**
# db
+ `url`=None
+ `url`="sqlite:site.db"
*`u` = `url` *
1. `u`
*`_` = 1*
2. *
*`u` = > sys.env_get name=DATABASE_URL *
1. `u`
*`_` = 1*
2. *
*`u` = sqlite:./data/app.db *
*`self` = > json.parse text={"_type":"db","tables":[]} *
*`self` = > json.set map=`self` key=url value=`u` *
**`self`**
> ensure_plugin
**> web_db_new url=`url`**
## init
+ `name`
+ `fields`
+ `primary`=id
*`url` = > json.get value=`self` key=url *
*`fs` = > as_fields table=`fields` *
*`_` = > web_db_define url=`url` table=`name` fields=`fs` primary=`primary` *
*`tables` = > json.get value=`self` key=tables *
*`tables` = > json.append list=`tables` item=`name` *
*`self` = > json.set map=`self` key=tables value=`tables` *
*`h` = > json.parse text={"_type":"db_table"} *
*`h` = > json.set map=`h` key=name value=`name` *
*`h` = > json.set map=`h` key=url value=`url` *
**`h`**
## define
+ `table`
+ `fields`
+ `primary`=id
*`tn` = > table_name table=`table` *
**> `self`.init name=`tn` fields=`fields` primary=`primary`**
## migrate
+ `dir`=migrations
*`url` = > json.get value=`self` key=url *
**> web_db_migrate url=`url` dir=`dir`**
## all
+ `table`
+ `limit`=200
*`url` = > json.get value=`self` key=url *
*`tn` = > table_name table=`table` *
*`r` = > web_db_all url=`url` table=`tn` limit=`limit` *
**> json.get value=`r` key=rows**
## follow
+ `table`
+ `limit`=200
*`url` = > json.get value=`self` key=url *
*`tn` = > table_name table=`table` *
*`live` = > json.parse text={"_type":"live","kind":"table"} *
*`live` = > json.set map=`live` key=url value=`url` *
*`live` = > json.set map=`live` key=table value=`tn` *
*`live` = > json.set map=`live` key=limit value=`limit` *
**`live`**
**> web_db_init url=`url` name=`name` fields=`fields`**
## insert
+ `table`
+ `rows`
*`url` = > json.get value=`self` key=url *
*`tn` = > table_name table=`table` *
*`rs` = > as_rows table=`rows` *
**> web_db_insert url=`url` table=`tn` rows=`rs`**
**> web_db_insert url=`url` table=`table` rows=`rows`**
## query
## select
+ `table`
+ `where`=None
+ `limit`=200
*`url` = > json.get value=`self` key=url *
*`r` = > web_db_select url=`url` table=`table` limit=`limit` *
**> json.get value=`r` key=rows**
## get
+ `table`
+ `id`
*`url` = > json.get value=`self` key=url *
**> web_db_get url=`url` table=`table` id=`id`**
## update
+ `table`
+ `id`
+ `row`
*`url` = > json.get value=`self` key=url *
**> web_db_update url=`url` table=`table` id=`id` row=`row`**
## delete
+ `table`
+ `id`
*`url` = > json.get value=`self` key=url *
**> web_db_delete url=`url` table=`table` id=`id`**
## exec
+ `sql`
+ `args`=None
*`url` = > json.get value=`self` key=url *
**> web_db_query url=`url` sql=`sql` args=`args`**
**> web_db_exec url=`url` sql=`sql` args=`args`**
---
# form
+ `table`=None
+ `action`=insert
+ `id`=None
# store
Form API is planned (design §5.5); first trial ships the class shell only.
*`ep` = > sys.env_get name=MARQDO_S3_ENDPOINT *
*`self` = > json.parse text={"_type":"store","ok":false} *
1. `ep`
*`self` = > json.set map=`self` key=ok value=True *
*`self` = > json.set map=`self` key=endpoint value=`ep` *
2. *
*`_` = 1*
**`self`**
---
## fields
+ `fields`
# cache
*`u` = > sys.env_get name=REDIS_URL *
1. `u`
*`_` = 1*
2. *
*`u` = > sys.env_get name=MARQDO_REDIS_URL *
*`self` = > json.parse text={"_type":"cache","ok":false} *
1. `u`
*`self` = > json.set map=`self` key=ok value=True *
*`self` = > json.set map=`self` key=url value=`u` *
2. *
*`_` = 1*
**`self`**
---
## validate
+ `rules`=None
+ `data`
**`data`**
## render
**""**
## submit
+ `data`
+ `db`
**`data`**
# app
+ `page`=None
+ `page`
+ `db`=None
+ `admin`=True
+ `host`=None
+ `port`=None
+ `admin`=False
+ `host`=127.0.0.1
+ `port`=18081
*`self` = > json.parse text={"_type":"app","static_dir":null,"admin":true} *
*`self` = > json.set map=`self` key=page value=`page` *
*`self` = > json.set map=`self` key=db value=`db` *
*`self` = > json.set map=`self` key=admin value=`admin` *
*`h` = `host` *
1. `h`
*`_` = 1*
2. *
*`h` = > sys.env_get name=MARQDO_WEB_HOST *
1. `h`
*`_` = 1*
2. *
*`h` = 127.0.0.1 *
*`p` = `port` *
1. `p`
*`_` = 1*
2. *
*`p` = > sys.env_get name=MARQDO_WEB_PORT *
1. `p`
*`_` = 1*
2. *
*`p` = 8080 *
*`self` = > json.set map=`self` key=host value=`h` *
*`self` = > json.set map=`self` key=port value=`p` *
**`self`**
> ensure_plugin
**> web_app_new page=`page` db=`db` admin=`admin` host=`host` port=`port`**
## static
+ `dir`
## route
+ `path`
+ `page`=None
*`self` = > json.set map=`self` key=static_dir value=`dir` *
**`self`**
## listen
+ `duration_ms`=None
*`page` = > json.get value=`self` key=page *
*`db` = > json.get value=`self` key=db *
*`db_url` = None*
*`tables` = > json.parse text=[] *
1. `db`
*`db_url` = > json.get value=`db` key=url *
*`tables` = > json.get value=`db` key=tables *
*`page` = > json.set map=`page` key=db_url value=`db_url` *
2. *
*`_` = 1*
*`host` = > json.get value=`self` key=host *
*`port` = > json.get value=`self` key=port *
*`sd` = > json.get value=`self` key=static_dir *
*`admin` = > json.get value=`self` key=admin *
**> web_listen host=`host` port=`port` page=`page` static_dir=`sd` db_url=`db_url` admin=`admin` admin_tables=`tables` duration_ms=`duration_ms`**
Serve `/`, `/_part/{id}`, and optional `/admin` from the assembled page.
---
## scaffold
+ `dest`
+ `theme`=starter
*`sep` = > json.parse text={"css":"/static/theme.css","env":"/.env.example","mig":"/migrations/001_init.sql","idx":"/index.mq.md"} *
*`css_s` = > json.get value=`sep` key=css *
*`env_s` = > json.get value=`sep` key=env *
*`mig_s` = > json.get value=`sep` key=mig *
*`idx_s` = > json.get value=`sep` key=idx *
*`css_out` = `dest` + `css_s` *
*`env_out` = `dest` + `env_s` *
*`mig_out` = `dest` + `mig_s` *
*`idx_out` = `dest` + `idx_s` *
*`theme_src` = "ext/web/templates/starter/static/theme.css" *
*`css` = > fs.read_text path=`theme_src` *
> fs.write_text path=`css_out` text=`css`
*`env` = "MARQDO_WEB_HOST=127.0.0.1\nMARQDO_WEB_PORT=8080\nDATABASE_URL=sqlite:./data/app.db\n" *
> fs.write_text path=`env_out` text=`env`
*`mig` = "CREATE TABLE IF NOT EXISTS articles (\n id INTEGER PRIMARY KEY AUTOINCREMENT,\n title TEXT NOT NULL,\n body TEXT,\n created_at TEXT DEFAULT (datetime('now'))\n);\n" *
> fs.write_text path=`mig_out` text=`mig`
*`app` = > json.parse text="---\n> ext/web/web.mq.md\n---\n\n# main\n\n> web.load_env path=.env\n> web.ensure_plugin\n\n`nav` =\n\n| 前端变量 | 后端数据库 | 绑定css样式 |\n|----------|------------|-------------|\n| 首页 | / | |\n| 管理 | /admin | |\n\n`side` =\n\n| 前端变量 | 后端数据库 | 绑定css样式 |\n|----------|------------|-------------|\n| 全部文章 | / | |\n| 管理后台 | /admin | |\n\n`articles` =\n\n| 字段 | 类型 | 可空 |\n|------|------|------|\n| id | integer | false |\n| title | text | false |\n| body | text | true |\n\n`主体` =\n\n| 前端变量 | 后端数据库 | 绑定css样式 |\n|----------|------------|-------------|\n| title | title | card-title |\n| body | body | card-body |\n\n*`db` = > web.db *\n*`articles` = > `db`.init name=articles fields=`articles` *\n\n*`page` = > web.page title=Starter *\n*`page` = > `page`.nav table=`nav` *\n*`page` = > `page`.sidebar table=`side` *\n*`page` = > `page`.main table=`articles` bind=`主体` layout=cards intro=\"<h1>Starter</h1>\" *\n\n*`app` = > web.app page=`page` db=`db` admin=True *\n> `app`.static dir=./static\n> `app`.listen\n" *
> fs.write_text path=`idx_out` text=`app`
**`dest`**
**> web_listen app=`self`**
+143 -51
View File
@@ -1,73 +1,165 @@
---
title: ext/web 网页
description: 动态网站 — 变量名即表名;页面方法挂载导航与主体(中文面)。
> ext/web/web.mq.md as en
title: ext/web/网页
description: 官方网站类(中文)。表格 + 方法;不写袋式胶水。
> lib/plugin.mq.md
> lib/sys.mq.md
> lib/json.mq.md
---
## 加载环境
+ `路径`=None
**> en.load_env path=`路径`**
## 确保插件
**> en.ensure_plugin**
加载 ABI v2 `web` 插件。
## 脚手架
+ `目标`
+ `主题`=starter
**> en.scaffold dest=`目标` theme=`主题`**
## 链从表
+ `表`
**> en.as_links table=`表`**
## 字段从表
+ `表`
**> en.as_fields table=`表`**
## 绑定从表
+ `表`
**> en.as_bind table=`表`**
## 行从表
+ `表`
**> en.as_rows table=`表`**
*`p` = > plugin.native_path name=web *
1. `p`
> plugin.load path=`p`
2. *
> print text=ext/web: 未找到原生 web 插件(请 build marqdo_plugin_web 或 marqdo ext add web)
> sys.exit code=1
****
# 页面
+ `主题`=starter
+ `标题`=Marqdo Web
+ `引言`="<p>欢迎</p>"
+ `主体样式`=cards
+ `标题`="站点"
+ `引言`=""
先创建页面,再用方法挂导航 / 侧栏 / 底栏 / 主体。
> 确保插件
**> web_page_new title=`标题` intro=`引言`**
**> en.page theme=`主题` title=`标题` intro=`引言` layout=`主体样式`**
## 组件装配
+ `组件`
**> web_compose_components page=`self` components=`组件`**
## 主体装配
+ `主体`
**> web_compose_main page=`self` main=`主体`**
## 渲染
+ `数据库`=None
1. `数据库`
*`url` = > json.get value=`数据库` key=url *
**> web_render page=`self` url=`url`**
2. *
**> web_render page=`self`**
# 样式
+ `名`=""
**`self`**
## 样式处理
+ `样式`=None
+ `名`=None
+ `路径`=None
**`self`**
# 数据库
+ `地址`=None
+ `地址`="sqlite:site.db"
**> en.db url=`地址`**
> 确保插件
**> web_db_new url=`地址`**
# 对象存储
## 初始化
+ `名`
+ `字段`
**> en.store**
*`url` = > json.get value=`self` key=url *
**> web_db_init url=`url` name=`名` fields=`字段`**
# 缓存
## 插入
+ `表`
+ `行`
**> en.cache**
*`url` = > json.get value=`self` key=url *
**> web_db_insert url=`url` table=`表` rows=`行`**
## 查询
+ `表`
+ `条件`=None
+ `上限`=200
*`url` = > json.get value=`self` key=url *
*`r` = > web_db_select url=`url` table=`表` limit=`上限` *
**> json.get value=`r` key=rows**
## 获取
+ `表`
+ `id`
*`url` = > json.get value=`self` key=url *
**> web_db_get url=`url` table=`表` id=`id`**
## 更新
+ `表`
+ `id`
+ `行`
*`url` = > json.get value=`self` key=url *
**> web_db_update url=`url` table=`表` id=`id` row=`行`**
## 删除
+ `表`
+ `id`
*`url` = > json.get value=`self` key=url *
**> web_db_delete url=`url` table=`表` id=`id`**
## 执行
+ `sql`
+ `参数`=None
*`url` = > json.get value=`self` key=url *
**> web_db_exec url=`url` sql=`sql` args=`参数`**
# 表单
+ `表`=None
+ `动作`=插入
+ `id`=None
表单 API 已锁定(设计 §5.5);本试运行仅留类壳。
**`self`**
## 字段
+ `字段`
**`self`**
## 校验
+ `规则`=None
+ `数据`
**`数据`**
## 渲染
**""**
## 提交
+ `数据`
+ `数据库`
**`数据`**
# 应用
+ `页面`=None
+ `页面`
+ `数据库`=None
+ `后台`=True
+ `主机`=None
+ `端口`=None
+ `后台`=False
+ `主机`=127.0.0.1
+ `端口`=18081
**> en.app page=`页面` db=`数据库` admin=`后台` host=`主机` port=`端口`**
> 确保插件
**> web_app_new page=`页面` db=`数据库` admin=`后台` host=`主机` port=`端口`**
## 路由
+ `路径`
+ `页面`=None
**`self`**
## 监听
**> web_listen app=`self`**