完整示例

项目结构

myapp/
├── main.dj
├── components/
│   ├── button.dj
│   └── card.dj
└── utils/
    └── strings.dj

工具函数

utils/strings.dj

export func title_case(name: string) -> string {
    name
}

组件

components/button.dj

export func button({ label: string }) -> widget {
    element(
        name: "button",
        children: [text(label)],
    )
}

components/card.dj

import { button } from "./button.dj"
import { title_case } from "../utils/strings.dj"

export func card({ title: string, body: string }) -> widget {
    let header = title_case(title);

    element(
        name: "div",
        children: [
            text(header),
            text(body),
            button(label: "OK"),
        ],
    )
}

入口

main.dj

import { card } from "./components/card.dj"

func main() -> widget {
    card(title: "hello", body: "world")
}