Skip to content

Commit

Permalink
rewrite
Browse files Browse the repository at this point in the history
  • Loading branch information
ModProg committed Jul 2, 2024
1 parent 513f91a commit e69afcd
Show file tree
Hide file tree
Showing 25 changed files with 1,510 additions and 781 deletions.
19 changes: 16 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 2 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ repository = "https://github.com/ModProg/htmx"
documentation = "https://docs.rs/htmx"

[features]
default = ["axum", "actix-web"]
sorted_attributes = []
# default = ["axum", "actix-web"]
axum = ["dep:axum-core"]

[dependencies]
Expand All @@ -30,13 +29,10 @@ serde = "1.0.188"
serde_json = "1.0.107"
typed-builder = {git = "https://github.com/ModProg/rust-typed-builder", branch = "mutators"}
chrono = "0.4.31"
ghost = "0.1.17"

[dev-dependencies]
insta = "1.31.0"
# Enables `sorted_attributes` for tests, to make assertions stable.
htmx = { path = ".", default-features = false, features = [
"sorted_attributes",
] }
serde = { version = "1.0.188", features = ["derive"] }

[profile.dev.package.insta]
Expand Down
2 changes: 1 addition & 1 deletion example/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ repository = "https://github.com/ModProg/htmx"
documentation = "https://docs.rs/htmx"

[features]
default = ["axum"]
default = ["axum", "tauri", "actix"]
axum = ["htmx/axum", "dep:tokio", "dep:axum"]
tauri = ["dep:tauri-runtime", "dep:tauri-runtime-wry", "dep:url"]
actix = ["htmx/actix-web", "dep:actix-web"]
Expand Down
18 changes: 9 additions & 9 deletions example/axum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,17 @@ use std::error::Error;
use axum::response::IntoResponse;
use axum::routing::{get, post};
use axum::{Form, Router};
use htmx::{html, HtmxSrc};
use htmx::{html, HtmlPage, HtmxSrc};

async fn index() -> impl IntoResponse {
html! {
<head>
<HtmxSrc/>
</head>
<h1>"Axum Demo"</h1>
<form hx::post="/greet" hx::swap="outerHTML">
<input name="name" placeholder="Name"/>
<button> "Greet me" </button>
</form>
<HtmlPage mobile title="Axum Demo" scripts=["htmx"]>
<h1>"Axum Demo"</h1>
<form hx::post="/greet" hx::swap="outerHTML">
<input name="name" placeholder="Name"/>
<button> "Greet me" </button>
</form>
</_>
}
}

Expand All @@ -39,6 +38,7 @@ async fn main() -> Result<(), Box<dyn Error>> {
Router::new()
.route("/", get(index))
.route("/greet", post(greet))
.route("/htmx", get(HtmxSrc))
.into_make_service(),
)
.await
Expand Down
9 changes: 5 additions & 4 deletions example/tauri.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ use std::borrow::Cow;
use std::error::Error;
use std::fmt::Display;

use htmx::{html, Html, HtmxSrc};
use htmx::{html, HtmxSrc};
use tauri_runtime::http::ResponseBuilder;
use tauri_runtime::webview::{WebviewAttributes, WindowBuilder};
use tauri_runtime::window::PendingWindow;
use tauri_runtime::Runtime;
use tauri_runtime_wry::Wry;
use url::Url;

fn index() -> Html {
fn index() -> String {
html! {
<head><HtmxSrc/></head>
<h1>"Tauri Demo"</h1>
Expand All @@ -25,14 +25,16 @@ fn index() -> Html {
<button> "Greet me" </button>
</form>
}
.into_string()
}

fn greet(name: impl Display) -> Html {
fn greet(name: impl Display) -> String {
html! {
"Hello "
{format!("{name}! ")}
<a href="/"> ":D" </a>
}
.into_string()
}

fn get_param<'a>(key: &str, url: &'a Url) -> Result<Cow<'a, str>, String> {
Expand Down Expand Up @@ -61,7 +63,6 @@ fn main() -> Result<(), Box<dyn Error>> {
"/greet" => greet(get_param("name", &url)?),
path => return Err(format!("Unknown path `{path}`").into()),
}
.to_string()
.into_bytes(),
)
.unwrap())
Expand Down
2 changes: 2 additions & 0 deletions htmx-macros/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ proc-macro = true
attribute-derive.path = "../../../Rust/attribute-derive"
derive_more = { version = "1.0.0-beta.6", features = ["display"] }
forr = "0.2.2"
html-escape = "0.2.13"
htmx-script = { version = "0.1.0", path = "../htmx-script" }
ident_case = "1.0.1"
manyhow = "0.9"
proc-macro-utils = "0.10"
proc-macro2 = "1.0.66"
Expand Down
Loading

0 comments on commit e69afcd

Please sign in to comment.