Feat: custom format_args for inlining variables into html templates

This commit is contained in:
Jonathan Kelley committed 2021-02-26 20:42:55 -05:00
1 parent a8b1225c48
commit e4b1f6ea0d
13 files changed
+886 -333

No files matched your search

+67
View File
@@ -0,0 +1,67 @@
// #[macro_use]
extern crate fstrings;
use bumpalo::collections::String;
// use dioxus_core::ifmt;
// use fstrings::format_args_f;
use bumpalo::core_alloc::fmt::Write;
fn main() {
let bump = bumpalo::Bump::new();
let b = ≎
let world = "123";
// dioxus_core::ifmt!(in b; "Hello {world}";);
}
// let mut s = bumpalo::collections::String::new_in(b);
// fstrings::write_f!(s, "Hello {world}");
// dbg!(s);
// let p = {
// println!("hello, {}", &world);
// ()
// };
// let g = format_args!("hello {world}", world = world);
// let g = dioxus_core::ifmt!(in b, "Hello {world}");
// let g = ifmt!(in b, "hhello {world}");
// let g = ::core::fmt::Arguments::new_v1(
// &["hello "],
// &match (&world,) {
// (arg0,) => [::core::fmt::ArgumentV1::new(
// arg0,
// ::core::fmt::Display::fmt,
// )],
// },
// );
// fn main() {
// let bump = bumpalo::Bump::new();
// let b = ≎
// let world = "123";
// let world = 123;
// let g = {
// use bumpalo::core_alloc::fmt::Write;
// use ::dioxus_core::prelude::bumpalo;
// use ::dioxus_core::prelude::format_args_f;
// let bump = b;
// let mut s = bumpalo::collections::String::new_in(bump);
// let _ = (&mut s).write_fmt(::core::fmt::Arguments::new_v1(
// &[""],
// &match (&::core::fmt::Arguments::new_v1(
// &["hhello "],
// &match (&world,) {
// (arg0,) => [::core::fmt::ArgumentV1::new(
// arg0,
// ::core::fmt::Display::fmt,
// )],
// },
// ),)
// {
// (arg0,) => [::core::fmt::ArgumentV1::new(
// arg0,
// ::core::fmt::Display::fmt,
// )],
// },
// ));
// s
// };
// }
+11 -12
View File
@@ -2,23 +2,22 @@
use dioxus_core::prelude::*;
fn main() {}
fn main() {
Some(10)
.map(|f| f * 5)
.map(|f| f / 3)
.map(|f| f * 5)
.map(|f| f / 3);
}
/*
Our flagship demo :)
*/
static Example: FC<()> = |ctx, props| {
let (val1, set_val1) = use_state(&ctx, || "b1");
let (name, set_name) = use_state(&ctx, || "...?");
ctx.view(html! {
<div>
<button onclick={move |_| set_val1("b1")}> "Set value to b1" </button>
<button onclick={move |_| set_val1("b2")}> "Set value to b2" </button>
<button onclick={move |_| set_val1("b3")}> "Set value to b3" </button>
<div>
<p> "Value is: {val1}" </p>
</div>
<h1> "Hello, {name}" </h1>
<button onclick={move |_| set_name("jack")}> "jack!" </button>
<button onclick={move |_| set_name("jill")}> "jill!" </button>
</div>
})
};