Skip to content

Commit

Permalink
Add most HTML attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
kmicklas committed Jul 6, 2024
1 parent a119d0a commit fb6d3b0
Show file tree
Hide file tree
Showing 2 changed files with 134 additions and 29 deletions.
53 changes: 28 additions & 25 deletions examples/todomvc/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::collections::BTreeMap;

use ravel_web::{
attr::*, collections::btree_map, el::*, event::*, format_text,
attr as a, collections::btree_map, el::*, event::*, format_text,
run::spawn_body, text::text, View,
};
use web_sys::wasm_bindgen::{JsCast as _, UnwrapThrowExt};
Expand Down Expand Up @@ -53,7 +53,7 @@ impl Filter {
fn button(self, selected: Self) -> View!(Model) {
li(a((
format_text!("{:?}", self),
class((selected == self).then_some("selected")),
a::class((selected == self).then_some("selected")),
on_(Click, move |model: &mut Model| model.filter = self),
)))
}
Expand All @@ -68,17 +68,17 @@ fn item(filter: Filter, id: usize, item: &Item) -> View!(Model, '_) {

show.then(|| {
li((
class((
a::class((
item.checked.then_some("completed"),
item.editing.then_some("editing"),
)),
div((
class("view"),
a::class("view"),
input((
type_("checkbox"),
class("toggle"),
a::type_("checkbox"),
a::class("toggle"),
// TODO: avoid circular dependency
checked(item.checked),
a::checked(item.checked),
on(InputEvent, move |model: &mut Model, e| {
let input: web_sys::HtmlInputElement =
e.target().unwrap_throw().dyn_into().unwrap_throw();
Expand All @@ -93,14 +93,17 @@ fn item(filter: Filter, id: usize, item: &Item) -> View!(Model, '_) {
}),
)),
button((
class("destroy"),
a::class("destroy"),
on_(Click, move |model: &mut Model| {
model.items.remove(&id);
}),
)),
)),
form((
input((class("edit"), value_(CloneString(&item.text)))),
input((
a::class("edit"),
a::value_(a::CloneString(&item.text)),
)),
on(Active(Submit), move |model: &mut Model, e| {
e.prevent_default();

Expand All @@ -124,15 +127,15 @@ fn item(filter: Filter, id: usize, item: &Item) -> View!(Model, '_) {
fn todomvc(model: &Model) -> View!(Model, '_) {
(
section((
class("todoapp"),
a::class("todoapp"),
header((
class("header"),
a::class("header"),
h1("todos"),
form((
input((
class("new-todo"),
placeholder("What needs to be done?"),
autofocus(true),
a::class("new-todo"),
a::placeholder("What needs to be done?"),
a::autofocus(true),
)),
on(Active(Submit), move |model: &mut Model, e| {
e.prevent_default();
Expand All @@ -152,24 +155,24 @@ fn todomvc(model: &Model) -> View!(Model, '_) {
)),
)),
section((
class("main"),
a::class("main"),
input((
id("toggle-all"),
class("toggle-all"),
type_("checkbox"),
a::id("toggle-all"),
a::class("toggle-all"),
a::type_("checkbox"),
)),
label((for_("toggle-all"), "Mark all as complete")),
label((a::for_("toggle-all"), "Mark all as complete")),
ul((
class("todo-list"),
a::class("todo-list"),
btree_map(&model.items, |cx, id, i| {
cx.build(item(model.filter, *id, i))
}),
)),
)),
footer((
class("footer"),
a::class("footer"),
span((
class("todo-count"),
a::class("todo-count"),
strong(format_text!(
"{} {} left",
model.count(),
Expand All @@ -180,22 +183,22 @@ fn todomvc(model: &Model) -> View!(Model, '_) {
)),
)),
ul((
class("filters"),
a::class("filters"),
// TODO: array impls
Filter::All.button(model.filter),
Filter::Active.button(model.filter),
Filter::Completed.button(model.filter),
)),
button((
class("clear-completed"),
a::class("clear-completed"),
"Clear completed",
on_(Click, move |model: &mut Model| {
model.items.retain(|_, i| !i.checked)
}),
)),
)),
)),
footer((class("info"), p("Double-click to edit a todo"))),
footer((a::class("info"), p("Double-click to edit a todo"))),
)
}

Expand Down
110 changes: 106 additions & 4 deletions ravel-web/generate.toml
Original file line number Diff line number Diff line change
Expand Up @@ -137,16 +137,118 @@ slot = {}
template = {}

[attribute]
aria-hidden = {}
accept = {}
accept-charset = {}
accesskey = {}
action = {}
allow = {}
alt = {}
aria-hidden = {} # TODO: enum
as = { build = "as_" } # TODO: enum
async = { build = "async_", value_type = "bool", value_wrapper = "BooleanAttrValue" }
autocapitalize = {} # TODO: enum
autocomplete = {} # TODO: space-separated, enum?
autofocus = { value_type = "bool", value_wrapper = "BooleanAttrValue" }
autoplay = { value_type = "bool", value_wrapper = "BooleanAttrValue" }
capture = {} # TODO: enum
# charset = {}
checked = { value_type = "bool", value_wrapper = "BooleanAttrValue" }
cite = { build = "cite" }
class = { value_trait = "ClassValue", value_wrapper = "Classes" }
cols = {} # TODO: usize
colspan = {} # TODO: usize
# content = {}
contenteditable = {} # TODO: enum
controls = { value_type = "bool", value_wrapper = "BooleanAttrValue" }
coords = {} # TODO: custom type
crossorigin = {} # TODO: enum
csp = {}
data = { build = "data" }
datetime = {} # TODO: custom type
decoding = {} # TODO: enum
default = { value_type = "bool", value_wrapper = "BooleanAttrValue" }
defer = { value_type = "bool", value_wrapper = "BooleanAttrValue" }
dir = {} # TODO: enum
dirname = {} # TODO: enum
disabled = { value_type = "bool", value_wrapper = "BooleanAttrValue" }
download = {}
draggable = {} # TODO: bool enum!
enctype = {} # TODO: enum
enterkeyhint = {}
for = { build = "for_" }
form = { build = "form" }
formaction = {}
formenctype = {} # TODO: enum
formmethod = {} # TODO: enum
formnovalidate = { value_type = "bool", value_wrapper = "BooleanAttrValue" }
formtarget = {}
headers = {}
height = {} # TODO: usize
hidden = {} # TODO: enum
high = {} # TODO: number
href = {}
hreflang = {}
# http-equiv = {}
id = {}
max = {}
min = {}
inputmode = {} # TODO: enum
integrity = {}
ismap = { value_type = "bool", value_wrapper = "BooleanAttrValue" }
itemprop = {}
kind = {} # TODO: enum
label = { build = "label" }
lang = {}
list = {}
loading = {} # TODO: enum
loop = { build = "loop_", value_type = "bool", value_wrapper = "BooleanAttrValue" }
low = {} # TODO: number
max = {} # TODO: number
maxlength = {} # TODO: usize
minlength = {} # TODO: usize
media = {}
method = {} # TODO: enum
min = {} # TODO: number
multiple = { value_type = "bool", value_wrapper = "BooleanAttrValue" }
muted = { value_type = "bool", value_wrapper = "BooleanAttrValue" }
name = {}
novalidate = { value_type = "bool", value_wrapper = "BooleanAttrValue" }
open = { value_type = "bool", value_wrapper = "BooleanAttrValue" }
optimum = {} # TODO: number
pattern = {}
ping = {}
placeholder = {}
playsinline = { value_type = "bool", value_wrapper = "BooleanAttrValue" }
poster = {}
preload = {} # TODO: enum
readonly = { value_type = "bool", value_wrapper = "BooleanAttrValue" }
referrerpolicy = {} # TODO: enum
rel = {} # TODO: enum?
required = { value_type = "bool", value_wrapper = "BooleanAttrValue" }
reversed = { value_type = "bool", value_wrapper = "BooleanAttrValue" }
role = {} # TODO: enum?
rows = {} # TODO: usize
rowspan = {} # TODO: usize
sandbox = {} # TODO: enum?
scope = {} # TODO: enum
selected = { value_type = "bool", value_wrapper = "BooleanAttrValue" }
shape = {} # TODO: enum
size = {} # TODO: usize
sizes = {}
slot = { build = "slot" }
span = { build = "span" }
spellcheck = {} # TODO: bool enum!
src = {}
srcdoc = {}
srclang = {}
srcset = {}
start = {} # TODO: isize
step = {} # TODO: number
style = {}
type = { build = "type_" }
tabindex = {} # TODO: isize
target = {} # TODO: enum
title = {}
translate = {} # TODO: enum
type = { build = "type_" } # TODO: enum
usemap = {}
value = { build = "value_" } # TODO: do we really need this rename?
width = {} # TODO: usize
wrap = {} # TODO: enum

0 comments on commit fb6d3b0

Please sign in to comment.