#![cfg_attr(not(feature = "std"), no_std)]
#![cfg_attr(docsrs, feature(doc_auto_cfg))]
#![warn(missing_docs)]
extern crate alloc;
use alloc::borrow::Cow;
use fun_html::Attribute;
pub fn hx_boost(value: bool) -> Attribute {
Attribute::new("hx-boost", boolean(value))
}
pub fn hx_get(path: impl Into<Cow<'static, str>>) -> Attribute {
Attribute::new("hx-get", path)
}
pub fn hx_post(path: impl Into<Cow<'static, str>>) -> Attribute {
Attribute::new("hx-post", path)
}
pub fn hx_put(path: impl Into<Cow<'static, str>>) -> Attribute {
Attribute::new("hx-put", path)
}
pub fn hx_patch(path: impl Into<Cow<'static, str>>) -> Attribute {
Attribute::new("hx-patch", path)
}
pub fn hx_delete(path: impl Into<Cow<'static, str>>) -> Attribute {
Attribute::new("hx-delete", path)
}
pub fn hx_trigger(path: impl Into<Cow<'static, str>>) -> Attribute {
Attribute::new("hx-trigger", path)
}
pub fn hx_select(path: impl Into<Cow<'static, str>>) -> Attribute {
Attribute::new("hx-select", path)
}
pub fn hx_target(path: impl Into<Cow<'static, str>>) -> Attribute {
Attribute::new("hx-target", path)
}
pub fn hx_swap(path: impl Into<Cow<'static, str>>) -> Attribute {
Attribute::new("hx-swap", path)
}
pub fn hx_swap_inner_html() -> Attribute {
hx_swap("innerHTML")
}
pub fn hx_swap_outer_html() -> Attribute {
hx_swap("outerHTML")
}
pub fn hx_swap_text_content() -> Attribute {
hx_swap("textContent")
}
pub fn hx_swap_before_begin() -> Attribute {
hx_swap("beforebegin")
}
pub fn hx_swap_after_begin() -> Attribute {
hx_swap("afterbegin")
}
pub fn hx_swap_before_end() -> Attribute {
hx_swap("beforeend")
}
pub fn hx_swap_after_end() -> Attribute {
hx_swap("afterend")
}
pub fn hx_swap_delete() -> Attribute {
hx_swap("delete")
}
pub fn hx_swap_none() -> Attribute {
hx_swap("none")
}
pub fn hx_push_url(value: bool) -> Attribute {
hx_push_url_str(boolean(value))
}
pub fn hx_push_url_str(url: impl Into<Cow<'static, str>>) -> Attribute {
Attribute::new("hx-push-url", url)
}
pub fn hx_confirm(value: impl Into<Cow<'static, str>>) -> Attribute {
Attribute::new("hx-confirm", value)
}
pub fn hx_swap_oob() -> Attribute {
hx_swap_oob_swap("true")
}
pub fn hx_swap_oob_swap(value: impl Into<Cow<'static, str>>) -> Attribute {
Attribute::new("hx-swap-oob", value)
}
pub fn hx_on(event: &'static str, action: impl Into<Cow<'static, str>>) -> Attribute {
Attribute::new_unsafe_name(alloc::format!("hx-on:{event}"), action)
}
pub fn hx_on_htmx_before_request(action: impl Into<Cow<'static, str>>) -> Attribute {
Attribute::new("hx-on::before-request", action)
}
pub fn hx_on_htmx_after_request(action: impl Into<Cow<'static, str>>) -> Attribute {
Attribute::new("hx-on::after-request", action)
}
pub fn hx_vals(values: impl Into<Cow<'static, str>>) -> Attribute {
Attribute::new("hx-vals", values)
}
pub fn hx_disinherit(attributes: impl IntoIterator<Item = &'static str>) -> Attribute {
let mut iter = attributes.into_iter();
let mut string = iter
.next()
.map(alloc::string::String::from)
.unwrap_or_default();
for value in iter {
string.push(' ');
string.push_str(value);
}
Attribute::new("hx-disinherit", string)
}
pub fn hx_disinherit_all() -> Attribute {
Attribute::new("hx-disinherit", "*")
}
#[cfg(feature = "serde_json")]
pub fn hx_vals_serde(values: &impl serde::Serialize) -> Attribute {
hx_vals(serde_json::to_string(values).expect("hx-vals values should not fail to serialize"))
}
fn boolean(value: bool) -> &'static str {
if value {
"true"
} else {
"false"
}
}