refinements
This commit is contained in:
parent
0476cccb5a
commit
91eaf8f6e3
6 changed files with 59 additions and 24 deletions
11
rustfmt.toml
Normal file
11
rustfmt.toml
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
# Minky rustfmt
|
||||||
|
unstable_features = true
|
||||||
|
format_macro_bodies = true
|
||||||
|
format_macro_matchers = true
|
||||||
|
imports_layout = "HorizontalVertical"
|
||||||
|
imports_granularity = "Crate"
|
||||||
|
overflow_delimited_expr = true
|
||||||
|
reorder_impl_items = true
|
||||||
|
reorder_imports = true
|
||||||
|
group_imports = "StdExternalCrate"
|
||||||
|
use_field_init_shorthand = true
|
29
src/main.rs
29
src/main.rs
|
@ -2,15 +2,17 @@
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate tracing;
|
extern crate tracing;
|
||||||
|
|
||||||
|
use std::sync::{atomic::AtomicU64, Arc};
|
||||||
|
|
||||||
use axum::{response::Html, routing::get};
|
use axum::{response::Html, routing::get};
|
||||||
use tracing::level_filters::LevelFilter;
|
use tracing::level_filters::LevelFilter;
|
||||||
use tracing_subscriber::layer::SubscriberExt;
|
use tracing_subscriber::layer::SubscriberExt;
|
||||||
use vespid::*;
|
use vespid::{axum_compat::render, *};
|
||||||
|
|
||||||
#[component]
|
#[component]
|
||||||
fn Shell(children: String) -> String {
|
fn Shell(children: String) -> String {
|
||||||
info!("Index");
|
info!("Index");
|
||||||
html! {
|
view! {
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
|
@ -26,13 +28,15 @@ fn Shell(children: String) -> String {
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn index() -> Html<String> {
|
async fn index() -> Html<String> {
|
||||||
vespid::axum_compat::render(async move {
|
render(async move {
|
||||||
html! {
|
view! {
|
||||||
<Shell>
|
<Shell>
|
||||||
<h1>"Hello to Crusto!"</h1>
|
<h1>"Hello to Crusto!"</h1>
|
||||||
<p>"Index"</p>
|
<p>"Index"</p>
|
||||||
|
|
||||||
<div hx-get="/widget" hx-swap="innerHTML" hx-trigger="load">
|
<button hx-get="/widget" hx-swap="outerHTML" hx-target="#widget">"Get widget"</button>
|
||||||
|
|
||||||
|
<div id="widget">
|
||||||
</div>
|
</div>
|
||||||
</Shell>
|
</Shell>
|
||||||
}
|
}
|
||||||
|
@ -54,16 +58,13 @@ async fn main() -> eyre::Result<()> {
|
||||||
.with(tracing_subscriber::fmt::layer()),
|
.with(tracing_subscriber::fmt::layer()),
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
|
let amount_of_refreshes = Arc::new(AtomicU64::new(0));
|
||||||
let app = axum::Router::new().route("/", get(index)).route("/widget", get(|| async move {
|
let app = axum::Router::new().route("/", get(index)).route("/widget", get(|| async move {
|
||||||
let ts = std::time::SystemTime::now()
|
render(async move {
|
||||||
.duration_since(std::time::UNIX_EPOCH)
|
view! {
|
||||||
.unwrap()
|
<div style="background-color: red; color: white; padding: 10px; border-radius: 5px;" id="widget">
|
||||||
.as_secs();
|
|
||||||
vespid::axum_compat::render(async move {
|
|
||||||
html! {
|
|
||||||
<div style="background-color: red; color: white; padding: 10px; border-radius: 5px;">
|
|
||||||
<h2>"Widget"</h2>
|
<h2>"Widget"</h2>
|
||||||
<p>{ts}</p>
|
<p>{amount_of_refreshes.fetch_add(1, std::sync::atomic::Ordering::Relaxed)}</p>
|
||||||
</div>
|
</div>
|
||||||
}
|
}
|
||||||
}).await
|
}).await
|
||||||
|
|
|
@ -4,18 +4,30 @@ use proc_macro::TokenStream;
|
||||||
use proc_macro2_diagnostics::Diagnostic;
|
use proc_macro2_diagnostics::Diagnostic;
|
||||||
use quote::{quote, quote_spanned, ToTokens};
|
use quote::{quote, quote_spanned, ToTokens};
|
||||||
use rstml::{
|
use rstml::{
|
||||||
node::{KeyedAttribute, Node, NodeAttribute, NodeElement, NodeName}, Infallible, Parser, ParserConfig
|
node::{KeyedAttribute, Node, NodeAttribute, NodeElement, NodeName},
|
||||||
|
Infallible,
|
||||||
|
Parser,
|
||||||
|
ParserConfig,
|
||||||
|
};
|
||||||
|
use syn::{
|
||||||
|
parse::Parse,
|
||||||
|
parse_quote,
|
||||||
|
punctuated::Punctuated,
|
||||||
|
spanned::Spanned,
|
||||||
|
Expr,
|
||||||
|
ExprLit,
|
||||||
|
FnArg,
|
||||||
|
ItemStruct,
|
||||||
|
Token,
|
||||||
};
|
};
|
||||||
use syn::punctuated::Punctuated;
|
|
||||||
use syn::{parse::Parse, parse_quote, spanned::Spanned, Expr, ExprLit, FnArg, ItemStruct, Token};
|
|
||||||
|
|
||||||
#[proc_macro]
|
#[proc_macro]
|
||||||
pub fn html(tokens: TokenStream) -> TokenStream {
|
pub fn view(tokens: TokenStream) -> TokenStream {
|
||||||
html_inner(tokens, false)
|
html_inner(tokens, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[proc_macro]
|
#[proc_macro]
|
||||||
pub fn html_ide(tokens: TokenStream) -> TokenStream {
|
pub fn view_docs(tokens: TokenStream) -> TokenStream {
|
||||||
html_inner(tokens, true)
|
html_inner(tokens, true)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
use axum::response::Html;
|
|
||||||
use std::{future::Future, sync::OnceLock, thread::available_parallelism};
|
use std::{future::Future, sync::OnceLock, thread::available_parallelism};
|
||||||
|
|
||||||
|
use axum::response::Html;
|
||||||
use tokio_util::task::LocalPoolHandle;
|
use tokio_util::task::LocalPoolHandle;
|
||||||
|
|
||||||
use crate::context;
|
use crate::context;
|
||||||
|
|
|
@ -18,7 +18,7 @@ pub mod axum_compat;
|
||||||
|
|
||||||
pub use vespid_macros::*;
|
pub use vespid_macros::*;
|
||||||
|
|
||||||
#[doc(hidden)]
|
|
||||||
pub extern crate typed_builder;
|
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
pub extern crate html_escape;
|
pub extern crate html_escape;
|
||||||
|
#[doc(hidden)]
|
||||||
|
pub extern crate typed_builder;
|
||||||
|
|
|
@ -6,8 +6,18 @@ use std::{
|
||||||
io::ErrorKind,
|
io::ErrorKind,
|
||||||
net::{IpAddr, Ipv4Addr, Ipv6Addr, SocketAddr, SocketAddrV4, SocketAddrV6},
|
net::{IpAddr, Ipv4Addr, Ipv6Addr, SocketAddr, SocketAddrV4, SocketAddrV6},
|
||||||
num::{
|
num::{
|
||||||
NonZeroI128, NonZeroI16, NonZeroI32, NonZeroI64, NonZeroI8, NonZeroIsize, NonZeroU128,
|
NonZeroI128,
|
||||||
NonZeroU16, NonZeroU32, NonZeroU64, NonZeroU8, NonZeroUsize,
|
NonZeroI16,
|
||||||
|
NonZeroI32,
|
||||||
|
NonZeroI64,
|
||||||
|
NonZeroI8,
|
||||||
|
NonZeroIsize,
|
||||||
|
NonZeroU128,
|
||||||
|
NonZeroU16,
|
||||||
|
NonZeroU32,
|
||||||
|
NonZeroU64,
|
||||||
|
NonZeroU8,
|
||||||
|
NonZeroUsize,
|
||||||
},
|
},
|
||||||
rc::Rc,
|
rc::Rc,
|
||||||
sync::{
|
sync::{
|
||||||
|
|
Loading…
Reference in a new issue