Make Web an executable handbook with recursive Markdown layouts

This commit is contained in:
cflmy committed 2026-11-08 21:50:01 +08:00
1 parent cc5277d2b5
commit 5080136d65
84 files changed
+3394 -957

No files matched your search

+111 -145
View File
@@ -6,48 +6,34 @@ description: >-
Document/Endpoint first-class. No compose_* / configure / author ensure_plugin.
Agents: read ext/web/index.mq.md first (layout file-partition law).
import:
cap: ext/web/_capability.mq.md
page_mod: ext/web/page.mq.md
route_mod: ext/web/route.mq.md
dom_mod: ext/web/dom.mq.md
client_mod: ext/web/client.mq.md
cap: ext/web/_capability/index.mq.md
page_mod: ext/web/page/index.mq.md
route_mod: ext/web/route/index.mq.md
dom_mod: ext/web/dom/index.mq.md
client_mod: ext/web/client/index.mq.md
table: lib/table.mq.md
---
Importing this module is the web capability (native plugin loads on first facade
call). Cold-start agents should open ext/web/index.mq.md before calling tools
here. Pages are file-partitioned View/Markdown assemblies — not HTML injection.
Layout skill: ext/web/layout/index.mq.md.
Web facade — [start at the root handbook](index.mq.md), then use this module
for server lifecycle and rendering. Layout assembly remains in pure component
functions; database, security and network clients stay in their own packages.
## For AI agents
```sh
marqdo call ext/web/web.mq.md render 'body="# A Document"' 'title="Preview"' --effects plugin --json
marqdo call ext/web/web.mq.md inspect 'root="examples/web-layout-handbook"' --effects plugin --json
```
Every ## below is a tool. Prefer --effects plugin. For how to split nav /
sidebar / footer into files, call layout rules first:
inspect with root scans declared metadata without starting a server. To inspect
an in-memory app, pass its actual handle; an empty fresh process cannot inspect
another process. serve is a blocking lifecycle operation: write a launcher and
use marqdo run, not call. Explicit view: main Documents assemble once at startup
through normal functions and imports. Restart after changing their content.
Call example (plain text):
marqdo call ext/web/layout/index.mq.md rules --json
marqdo call ext/web/web.mq.md inspect --effects plugin --json
Do not use dom_patch / raw HTML to build a whole Document homepage. Prefer
type: web Artifact files under a site root and web.serve.
*None*
Develop layout structure in layout/component and the Go artifact renderer;
keep this facade as orchestration. Preserve the existing app object and manual
route API. Contracts precede execution; ordinary prose titles are not functions.
## page
+ `title`=""
+ `route`="/"
+ `method`="GET"
+ `body`=""
+ `nodes`=None
+ `data_source`=""
+ `data_order`=""
+ `data_where`=""
Construct a Document handle with title, route, method, Markdown body, optional
View nodes, and flat data_source / data_order / data_where keys. Prefer
discovering type: web Artifact files via serve rather than hand-building every
page in memory. nodes must be the unified View schema, never a private dialect
or an HTML string shell.
| 参数 | 类型 | 说明 |
|------|------|------|
@@ -60,6 +46,12 @@ or an HTML string shell.
| data_order | text | order key |
| data_where | text | filters |
Construct a Document handle with `title`="", `route`="/", `method`="GET",
`body`="", optional View `nodes`=None, and flat `data_source`="", `data_order`="",
`data_where`="" keys. Prefer discovering type: web Artifact files via serve
rather than hand-building every page in memory. nodes must be the unified View
schema, never a private dialect or an HTML string shell.
| 返回 | 类型 | 说明 |
|------|------|------|
| result | any | page handle |
@@ -67,21 +59,6 @@ or an HTML string shell.
*> page_mod.page title=`title` route=`route` method=`method` body=`body` nodes=`nodes` data_source=`data_source` data_order=`data_order` data_where=`data_where`*
## route
+ `app`
+ `path`
+ `method`="GET"
+ `page`=None
+ `fn`=""
+ `request`="json"
+ `response`="json"
+ `auth`=""
+ `class`=""
Register a declared Document page or Endpoint on app. path and method identify
the HTTP surface. page holds a Document; fn names an Endpoint lib.member.
request / response / auth / class document the contract. Optional class values
include execute, short, read, control. User routes must be declared — never
implicit. After building the route object this tool registers it on the app.
| 参数 | 类型 | 说明 |
|------|------|------|
@@ -95,6 +72,13 @@ implicit. After building the route object this tool registers it on the app.
| auth | text | auth tag |
| class | text | route class |
Register a declared Document page or Endpoint on `app` at `path` with
`method`="GET" . `page`=None holds a Document; `fn`="" names an Endpoint
lib.member. `request`="json", `response`="json", `auth`="", and `class`=""
document the contract. Optional class values include execute, short, read,
control. User routes must be declared — never implicit. After building the
route object this tool registers it on the app.
| 返回 | 类型 | 说明 |
|------|------|------|
| result | any | registration result |
@@ -103,17 +87,6 @@ implicit. After building the route object this tool registers it on the app.
*> `r`.register app=`app`*
## render
+ `doc`=None
+ `nodes`=None
+ `body`=""
+ `title`=""
+ `db`=None
Render a Document or View nodes to HTML for offline preview. Prefer nodes from
file-partitioned components. When doc is set, delegates to page.render. When
only nodes are set, renders that View table. Otherwise renders Markdown body.
Requires the native plugin. Do not treat this as permission to paste a full HTML
homepage — keep using View tables and Markdown.
| 参数 | 类型 | 说明 |
|------|------|------|
@@ -123,6 +96,13 @@ homepage — keep using View tables and Markdown.
| title | text | title |
| db | any | optional db |
Render a Document or View nodes to HTML for offline preview. Prefer nodes from
file-partitioned components. Optional `doc`=None is a Document handle; when set,
delegates to page.render. Optional `nodes`=None is a View table; when set without
doc, renders that table. Otherwise renders Markdown `body`="" with optional
`title`="" and `db`=None . Requires the native plugin. Do not treat this as
permission to paste a full HTML homepage — keep using View tables and Markdown.
| 返回 | 类型 | 说明 |
|------|------|------|
| result | any | HTML or payload |
@@ -136,18 +116,16 @@ homepage — keep using View tables and Markdown.
*> web_render_document page=`doc` body=`body` db=`db` title=`title`*
## use
+ `app`
+ `middleware`
Attach first-class middleware to app. Pass a GFM table (security headers, cors
row, and similar). This replaces the old configure(...) junk drawer with an
explicit table authors can read.
| 参数 | 类型 | 说明 |
|------|------|------|
| app | any | app handle |
| middleware | any | middleware table |
Attach first-class `middleware` to `app`. Pass a GFM table (security headers,
cors row, and similar). This replaces the old configure(...) junk drawer with an
explicit table authors can read.
| 返回 | 类型 | 说明 |
|------|------|------|
| result | any | app handle |
@@ -156,35 +134,26 @@ explicit table authors can read.
*> web_app_use app=`app` middleware=`middleware`*
## inspect
+ `app`=None
Return declared versus system route tables for introspection. System routes such
as /_part and /_form must appear here. Use this to verify a site after serve or
manual registration. Optional app selects which application to inspect.
| 参数 | 类型 | 说明 |
|------|------|------|
| app | any | app or None |
| root | text | Site directory to inspect without listening |
Return declared versus system route tables for introspection. System routes such
as /_part and /_form must appear here. Use this to verify a site after serve or
manual registration. Optional `app`=None selects which application to inspect.
Optional `root`="" scans a site directory when supplied; it does not start a server.
| 返回 | 类型 | 说明 |
|------|------|------|
| result | any | {declared, system} |
> cap.load
*> web_inspect app=`app`*
*> web_inspect app=`app` root=`root`*
## serve
+ `root`="."
+ `host`="127.0.0.1"
+ `port`=18081
+ `db`=None
+ `static_dir`=""
+ `middleware`=None
Scan root for type web or endpoint Artifacts, register declared routes, attach
system routes, and listen on host:port. The site directory should already follow
the layout law (components split until simple). Optional db and middleware bind
resources without stuffing them into this facade as author APIs.
| 参数 | 类型 | 说明 |
|------|------|------|
@@ -195,6 +164,12 @@ resources without stuffing them into this facade as author APIs.
| static_dir | text | static files |
| middleware | any | optional middleware |
Scan `root`="." for type web or endpoint Artifacts, register declared routes,
attach system routes, and listen on `host`="127.0.0.1" and `port`=18081 . The
site directory should already follow the layout law (components split until
simple). Optional `db`=None, `static_dir`="", and `middleware`=None bind
resources without stuffing them into this facade as author APIs.
| 返回 | 类型 | 说明 |
|------|------|------|
| result | any | serve result |
@@ -203,14 +178,6 @@ resources without stuffing them into this facade as author APIs.
*> web_serve_root root=`root` host=`host` port=`port` db=`db` static_dir=`static_dir` middleware=`middleware`*
## client_embed
+ `bridge`="/static/marqdo-bridge.js"
+ `wasm`="/static/marqdo_wasm.wasm"
+ `source`=""
+ `boot`=True
Describe WASM bridge embed tags for a page that needs client Marqdo. This is not
a substitute for Document layout: still partition nav and main in files, then
embed the bridge where interaction needs it.
| 参数 | 类型 | 说明 |
|------|------|------|
@@ -219,6 +186,12 @@ embed the bridge where interaction needs it.
| source | text | optional source |
| boot | bool | auto boot |
Describe WASM bridge embed tags for a page that needs client Marqdo. Defaults:
`bridge`="/static/marqdo-bridge.js", `wasm`="/static/marqdo_wasm.wasm",
`source`="", `boot`=True . This is not a substitute for Document layout: still
partition nav and main in files, then embed the bridge where interaction needs
it.
| 返回 | 类型 | 说明 |
|------|------|------|
| result | any | embed descriptor |
@@ -226,18 +199,16 @@ embed the bridge where interaction needs it.
*> client_mod.embed bridge=`bridge` wasm=`wasm` source=`source` boot=`boot`*
## text_patch
+ `sel`
+ `text`
Client patch: set text content for CSS selector sel. Use for small interactive
updates after a Document is already laid out with View tables — not for building
the initial homepage shell.
| 参数 | 类型 | 说明 |
|------|------|------|
| sel | text | CSS selector |
| text | text | new text |
Client patch: set text content for CSS selector `sel` to string `text`. Use for
small interactive updates after a Document is already laid out with View tables —
not for building the initial homepage shell.
| 返回 | 类型 | 说明 |
|------|------|------|
| result | any | patch descriptor |
@@ -245,14 +216,6 @@ the initial homepage shell.
*> client_mod.text_patch sel=`sel` text=`text`*
## dom_patch
+ `sel`
+ `html`=""
+ `attrs`=None
+ `remove`=False
Client patch for selector sel with optional html, attrs, or remove. Treat html
here as a surgical update, never as the primary way to author nav, sidebar, or
footer. Layout law still applies to the Document that hosts the selector.
| 参数 | 类型 | 说明 |
|------|------|------|
@@ -261,6 +224,11 @@ footer. Layout law still applies to the Document that hosts the selector.
| attrs | any | optional attrs |
| remove | bool | remove node |
Client patch for selector `sel` with optional `html`="", `attrs`=None, or
`remove`=False . Treat html here as a surgical update, never as the primary way
to author nav, sidebar, or footer. Layout law still applies to the Document that
hosts the selector.
| 返回 | 类型 | 说明 |
|------|------|------|
| result | any | patch descriptor |
@@ -268,13 +236,6 @@ footer. Layout law still applies to the Document that hosts the selector.
*> client_mod.dom_patch sel=`sel` html=`html` attrs=`attrs` remove=`remove`*
## make_style
+ `name`=""
+ `table`
+ `strict`=False
Compile a named style table into CSS. Styles remain data next to content; this
is not a hidden page DSL. Prefer referencing style names from View style columns
after file-partitioned components define their look.
| 参数 | 类型 | 说明 |
|------|------|------|
@@ -282,6 +243,11 @@ after file-partitioned components define their look.
| table | any | property table |
| strict | bool | strict mode |
Compile a named style `table` into CSS. Optional `name`="" and `strict`=False .
Styles remain data next to content; this is not a hidden page DSL. Prefer
referencing style names from View style columns after file-partitioned
components define their look.
| 返回 | 类型 | 说明 |
|------|------|------|
| result | any | CSS / style handle |
@@ -290,15 +256,14 @@ after file-partitioned components define their look.
*> web_style name=`name` table=`table` strict=`strict`*
## make_images
+ `table`
Build image descriptors from a readable table of sources and alts. Keep media
declarations in Markdown tables beside the Document that uses them.
| 参数 | 类型 | 说明 |
|------|------|------|
| table | any | images table |
Build image descriptors from a readable `table` of sources and alts. Keep media
declarations in Markdown tables beside the Document that uses them.
| 返回 | 类型 | 说明 |
|------|------|------|
| result | any | images payload |
@@ -307,15 +272,14 @@ declarations in Markdown tables beside the Document that uses them.
*> web_images table=`table`*
## make_head
+ `table`
Build head resource rows (link, script, icon) from a table. Prefer declaring
head needs as data rather than injecting opaque HTML head strings.
| 参数 | 类型 | 说明 |
|------|------|------|
| table | any | head table |
Build head resource rows (link, script, icon) from a `table`. Prefer declaring
head needs as data rather than injecting opaque HTML head strings.
| 返回 | 类型 | 说明 |
|------|------|------|
| result | any | head payload |
@@ -324,15 +288,20 @@ head needs as data rather than injecting opaque HTML head strings.
*> web_head table=`table`*
# app
+ `page`=None
+ `db`=None
+ `host`=127.0.0.1
+ `port`=18081
+ `admin`=False
+ `admin_prefix`=/admin
+ `shell_css`=None
+ `layout`=None
+ `asset_version`=None
| 参数 | 类型 | 说明 |
|------|------|------|
| page | any | See prose default / 见叙述默认值 |
| db | any | See prose default / 见叙述默认值 |
| host | any | See prose default / 见叙述默认值 |
| port | any | See prose default / 见叙述默认值 |
| admin | any | See prose default / 见叙述默认值 |
| admin_prefix | any | See prose default / 见叙述默认值 |
| shell_css | any | See prose default / 见叙述默认值 |
| layout | any | See prose default / 见叙述默认值 |
| asset_version | any | See prose default / 见叙述默认值 |
Inputs: `page`=None, `db`=None, `host`=127.0.0.1, `port`=18081, `admin`=False, `admin_prefix`="/admin", `shell_css`=None, `layout`=None, `asset_version`=None
Low-level app handle for advanced mounts. Prefer web.serve for Artifact sites
that already follow file-partition layout. Optional page, db, host, port, admin
@@ -342,22 +311,24 @@ discovery should stay on serve; agents should not invent HTML shells on this
object. Methods static, listen, and gate hang off the returned handle for
mounts that remain table- and Metadata-driven.
| 返回 | 类型 | 说明 |
|------|------|------|
| result | any | Constructed value / 构造结果 |
> cap.load
*> web_app_new page=`page` db=`db` admin=`admin` host=`host` port=`port` admin_prefix=`admin_prefix` login_redirect=None logout_redirect=None shell_css=`shell_css` layout=`layout` asset_version=`asset_version`*
## static
+ `dir`
+ `mount`=/static
Mount static files from dir at mount path on this app. Use for bridge scripts and
assets referenced by Documents — not for dumping an HTML-only site tree that
bypasses Artifact Documents.
| 参数 | 类型 | 说明 |
|------|------|------|
| dir | text | filesystem directory |
| mount | text | URL mount |
Mount static files from `dir` at `mount`=/static on this app. Use for bridge
scripts and assets referenced by Documents — not for dumping an HTML-only site
tree that bypasses Artifact Documents.
| 返回 | 类型 | 说明 |
|------|------|------|
| result | any | app handle |
@@ -376,16 +347,6 @@ root scanning; listen is for advanced app handles after manual route setup.
*> web_listen app=`self`*
## gate
+ `path`
+ `roles`=admin
+ `permissions`=""
+ `match`=prefix
+ `on_deny`=forbid
+ `exclude`=None
Attach an authorization gate on path for this app. roles, permissions, match,
on_deny, and exclude document who may enter. Auth resources live in ext/security;
this method only wires the gate onto the web app surface.
| 参数 | 类型 | 说明 |
|------|------|------|
@@ -396,6 +357,11 @@ this method only wires the gate onto the web app surface.
| on_deny | text | deny behavior |
| exclude | any | exclusions |
Attach an authorization gate on `path` for this app. Defaults: `roles`="admin",
`permissions`="", `match`="prefix", `on_deny`="forbid", `exclude`=None . Auth
resources live in ext/security; this method only wires the gate onto the web
app surface.
| 返回 | 类型 | 说明 |
|------|------|------|
| result | any | app handle |