Desarrollo tempranoPre-1.0: la sintaxis puede cambiar.Historial de versionesGitHub

Guía de Rune-Web

Acciones y listas

Crea una lista de equipaje con acciones para añadir, marcar y eliminar. Un array de estado controla la vista repetida y el mensaje de lista vacía.

i18n.Guide.syntax

@Logic define acciones con parámetros. items.push(...) añade un registro; un bucle for actualiza el elemento y items.filter it.id != id lo elimina.

for item in items: repite una vista; if items.length == 0: muestra el caso vacío. Las expresiones condicionales eligen el texto Packed y la clase done. Usa identificadores estables para los registros.

Añade Snacks, márcalo y desmárcalo; elimina todos los elementos para ver el estado vacío. El código contiene la aplicación completa.

Ejecuta esta lección localmente

cargo run -- examples/rune-web/guide/packing.rune
cargo run -- examples/rune-web/guide/packing.rune -o html > index.html

Cada ejemplo es una aplicación Rune-Web completa e importa parts/style.rune. Abre el código para ver ambos archivos. Los datos de demostración permanecen en este navegador y se reinician al recargar la vista previa.

Aplicación Rune-Web en vivo

Acciones y listas

Esta vista se compila a partir del ejemplo Rune real, incluidos sus estilos y acciones. Prueba la aplicación y abre el código fuente.

Ver código fuente
packing.rune
#!RUNE
# Named actions update an array; the view repeats and handles empty state.
import "parts/style.rune"
@App
name = Weekend packing list
type = REST
@Frontend
type = rune-web
path = %ROOT%
page = packing
@Logic/packing
state:
    draft = ""
    nextId = 3
    items = [{ "id": 1, "name": "Water bottle", "packed": false }, { "id": 2, "name": "Rain jacket", "packed": false }]
action setDraft(value):
    draft = value
action addItem():
    if draft != "":
        items.push({ "id": nextId, "name": draft, "packed": false })
        nextId = nextId + 1
        draft = ""
action toggleItem(id):
    for item in items:
        if item.id == id:
            item.packed = !item.packed
action removeItem(id):
    items = items.filter it.id != id
@Page/packing
title = Weekend packing list
style = guide
logic = packing
view:
    main:
        h1 "Pack for the weekend"
        label for=new-item "Item to bring"
        input #new-item type=text value="{draft}" change="setDraft(this.value)"
        button click=addItem() "Add item"
        p "Items: {items.length}"
        if items.length == 0:
            p .panel "Your list is empty. Add something for your trip."
        for item in items:
            article .panel:
                h2 .{item.packed ? 'done' : ''} "{item.name}"
                p "{item.packed ? 'Packed' : 'Still to pack'}"
                div .choices:
                    button click="toggleItem({item.id})" "{item.packed ? 'Unpack' : 'Pack'}"
                    button click="removeItem({item.id})" "Remove {item.name}"
parts/style.rune
@Style/guide
tokens:
    brand = #166b73
    ink = #143841
    surface = #ffffff
    space = 1rem
presets:
    panel:
        background = {surface}
        border = 1px solid #c7e2e4
        border-radius = 16px
        padding = {space}
rules:
    body:
        margin = 0
        font-family = system-ui, sans-serif
        color = {ink}
        background = #edf7f7
    main:
        max-width = 900px
        margin = 0 auto
        padding = 1rem
    .grid:
        display = grid
        grid-template-columns = repeat(auto-fit, minmax(min(100%, 220px), 1fr))
        gap = {space}
    .panel:
        use = (panel)
        margin-bottom = 1rem
    .choices:
        display = flex
        flex-wrap = wrap
        gap = 0.5rem
        margin-bottom = 1rem
    button:
        padding = 0.75rem 1rem
        background = {brand}
        color = white
        border = 0
        border-radius = 8px
        cursor = pointer
        font = inherit
    button:focus-visible:
        outline = 3px solid #d56c45
        outline-offset = 3px
    button.active:
        background = #a94022
    input, select:
        display = block
        box-sizing = border-box
        width = 100%
        padding = 0.75rem
        margin = 0.5rem 0 1rem
        font = inherit
        border = 1px solid #8baeb3
        border-radius = 8px
    .muted:
        color = #44646b
    .done:
        text-decoration = line-through
    h1:
        font-size = clamp(1.5rem, 5vw, 2.2rem)
    p, li:
        line-height = 1.6
Sitio creado íntegramente con Rune-Web