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
|
27
src/main.rs
27
src/main.rs
|
@ -2,15 +2,17 @@
|
|||
#[macro_use]
|
||||
extern crate tracing;
|
||||
|
||||
use std::sync::{atomic::AtomicU64, Arc};
|
||||
|
||||
use axum::{response::Html, routing::get};
|
||||
use tracing::level_filters::LevelFilter;
|
||||
use tracing_subscriber::layer::SubscriberExt;
|
||||
use vespid::*;
|
||||
use vespid::{axum_compat::render, *};
|
||||
|
||||
#[component]
|
||||
fn Shell(children: String) -> String {
|
||||
info!("Index");
|
||||
html! {
|
||||
view! {
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
|
@ -26,13 +28,15 @@ fn Shell(children: String) -> String {
|
|||
}
|
||||
|
||||
async fn index() -> Html<String> {
|
||||
vespid::axum_compat::render(async move {
|
||||
html! {
|
||||
render(async move {
|
||||
view! {
|
||||
<Shell>
|
||||
<h1>"Hello to Crusto!"</h1>
|
||||
<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>
|
||||
</Shell>
|
||||
}
|
||||
|
@ -54,16 +58,13 @@ async fn main() -> eyre::Result<()> {
|
|||
.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 ts = std::time::SystemTime::now()
|
||||
.duration_since(std::time::UNIX_EPOCH)
|
||||
.unwrap()
|
||||
.as_secs();
|
||||
vespid::axum_compat::render(async move {
|
||||
html! {
|
||||
<div style="background-color: red; color: white; padding: 10px; border-radius: 5px;">
|
||||
render(async move {
|
||||
view! {
|
||||
<div style="background-color: red; color: white; padding: 10px; border-radius: 5px;" id="widget">
|
||||
<h2>"Widget"</h2>
|
||||
<p>{ts}</p>
|
||||
<p>{amount_of_refreshes.fetch_add(1, std::sync::atomic::Ordering::Relaxed)}</p>
|
||||
</div>
|
||||
}
|
||||
}).await
|
||||
|
|
|
@ -4,18 +4,30 @@ use proc_macro::TokenStream;
|
|||
use proc_macro2_diagnostics::Diagnostic;
|
||||
use quote::{quote, quote_spanned, ToTokens};
|
||||
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]
|
||||
pub fn html(tokens: TokenStream) -> TokenStream {
|
||||
pub fn view(tokens: TokenStream) -> TokenStream {
|
||||
html_inner(tokens, false)
|
||||
}
|
||||
|
||||
#[proc_macro]
|
||||
pub fn html_ide(tokens: TokenStream) -> TokenStream {
|
||||
pub fn view_docs(tokens: TokenStream) -> TokenStream {
|
||||
html_inner(tokens, true)
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
use axum::response::Html;
|
||||
use std::{future::Future, sync::OnceLock, thread::available_parallelism};
|
||||
|
||||
use axum::response::Html;
|
||||
use tokio_util::task::LocalPoolHandle;
|
||||
|
||||
use crate::context;
|
||||
|
|
|
@ -18,7 +18,7 @@ pub mod axum_compat;
|
|||
|
||||
pub use vespid_macros::*;
|
||||
|
||||
#[doc(hidden)]
|
||||
pub extern crate typed_builder;
|
||||
#[doc(hidden)]
|
||||
pub extern crate html_escape;
|
||||
#[doc(hidden)]
|
||||
pub extern crate typed_builder;
|
||||
|
|
|
@ -6,8 +6,18 @@ use std::{
|
|||
io::ErrorKind,
|
||||
net::{IpAddr, Ipv4Addr, Ipv6Addr, SocketAddr, SocketAddrV4, SocketAddrV6},
|
||||
num::{
|
||||
NonZeroI128, NonZeroI16, NonZeroI32, NonZeroI64, NonZeroI8, NonZeroIsize, NonZeroU128,
|
||||
NonZeroU16, NonZeroU32, NonZeroU64, NonZeroU8, NonZeroUsize,
|
||||
NonZeroI128,
|
||||
NonZeroI16,
|
||||
NonZeroI32,
|
||||
NonZeroI64,
|
||||
NonZeroI8,
|
||||
NonZeroIsize,
|
||||
NonZeroU128,
|
||||
NonZeroU16,
|
||||
NonZeroU32,
|
||||
NonZeroU64,
|
||||
NonZeroU8,
|
||||
NonZeroUsize,
|
||||
},
|
||||
rc::Rc,
|
||||
sync::{
|
||||
|
|
Loading…
Reference in a new issue