Last active
February 19, 2024 23:07
-
-
Save RyanBreaker/f0311bf654dd831b464bfcdf604faf02 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@file:Suppress("unused") | |
package rocks.breaker.htmx | |
import kotlinx.html.HTMLTag | |
private fun joinModifiers(modifiers: List<String>) = modifiers.joinToString(prefix = " ", separator = " ") | |
/** | |
* [hx-get HTMX reference](https://htmx.org/attributes/hx-get/) | |
*/ | |
fun HTMLTag.hxGet(value: String) { | |
attributes["hx-get"] = value | |
} | |
/** | |
* [hx-post HTMX reference](https://htmx.org/attributes/hx-post/) | |
*/ | |
fun HTMLTag.hxPost(value: String) { | |
attributes["hx-post"] = value | |
} | |
/** | |
* [hx-put HTMX reference](https://htmx.org/attributes/hx-put/) | |
*/ | |
fun HTMLTag.hxPut(value: String) { | |
attributes["hx-put"] = value | |
} | |
/** | |
* [hx-delete HTMX reference](https://htmx.org/attributes/hx-delete/) | |
*/ | |
fun HTMLTag.hxDelete(value: String) { | |
attributes["hx-delete"] = value | |
} | |
/** | |
* [hx-patch HTMX reference](https://htmx.org/attributes/hx-patch/) | |
*/ | |
fun HTMLTag.hxPatch(value: String) { | |
attributes["hx-patch"] = value | |
} | |
/** | |
* [hx-boost HTMX reference](https://htmx.org/attributes/hx-boost/) | |
*/ | |
fun HTMLTag.hxBoost(enabled: Boolean = true) { | |
attributes["hx-boost"] = "$enabled" | |
} | |
/** | |
* [hx-confirm HTMX reference](https://htmx.org/attributes/hx-confirm/) | |
*/ | |
fun HTMLTag.hxConfirm(value: String) { | |
attributes["hx-confirm"] = value | |
} | |
/** | |
* [hx-disable HTMX reference](https://htmx.org/attributes/hx-disable/) | |
*/ | |
fun HTMLTag.hxDisable() { | |
attributes["hx-disable"] = "" | |
} | |
/** | |
* [hx-disabled-elt HTMX reference](https://htmx.org/attributes/hx-disabled-elt/) | |
*/ | |
fun HTMLTag.hxDisabledElt(value: String) { | |
attributes["hx-disabled-elt"] = value | |
} | |
/** | |
* [hx-disinherit HTMX reference](https://htmx.org/attributes/hx-disinherit/) | |
*/ | |
fun HTMLTag.hxDisinherit(value: String) { | |
attributes["hx-disinherit"] = value | |
} | |
/** | |
* [hx-encoding HTMX reference](https://htmx.org/attributes/hx-encoding/) | |
*/ | |
fun HTMLTag.hxEncoding(value: String) { | |
attributes["hx-encoding"] = value | |
} | |
/** | |
* [hx-ext HTMX reference](https://htmx.org/attributes/hx-ext/) | |
*/ | |
fun HTMLTag.hxExt(value: String) { | |
attributes["hx-ext"] = value | |
} | |
/** | |
* [hx-headers HTMX reference](https://htmx.org/attributes/hx-headers/) | |
*/ | |
fun HTMLTag.hxHeaders(value: String) { | |
attributes["hx-headers"] = value | |
} | |
/** | |
* [hx-history HTMX reference](https://htmx.org/attributes/hx-history/) | |
*/ | |
fun HTMLTag.hxHistory(historyEnabled: Boolean = false) { | |
attributes["hx-history"] = "$historyEnabled" | |
} | |
/** | |
* [hx-history-elt HTMX reference](https://htmx.org/attributes/hx-history-elt/) | |
*/ | |
fun HTMLTag.hxHistoryElt() { | |
attributes["hx-history-eld"] = "" | |
} | |
/** | |
* [hx-include HTMX reference](https://htmx.org/attributes/hx-include/) | |
*/ | |
fun HTMLTag.hxInclude(value: String) { | |
attributes["hx-include"] = value | |
} | |
/** | |
* [hx-indicator HTMX reference](https://htmx.org/attributes/hx-indicator/) | |
*/ | |
fun HTMLTag.hxIndicator(value: String) { | |
attributes["hx-indicator"] = value | |
} | |
/** | |
* [hx-on HTMX reference](https://htmx.org/attributes/hx-on/) | |
*/ | |
fun HTMLTag.hxOn(event: String, value: String) { | |
attributes["hx-on::$event"] = value | |
} | |
/** | |
* [hx-params HTMX reference](https://htmx.org/attributes/hx-params/) | |
*/ | |
fun HTMLTag.hxParams(value: String) { | |
attributes["hx-params"] = value | |
} | |
/** | |
* [hx-preserve HTMX reference](https://htmx.org/attributes/hx-preserve/) | |
*/ | |
fun HTMLTag.hxPreserve() { | |
attributes["hx-preserve"] = "" | |
} | |
/** | |
* [hx-prompt HTMX reference](https://htmx.org/attributes/hx-prompt/) | |
*/ | |
fun HTMLTag.hxPrompt(value: String) { | |
attributes["hx-prompt"] = value | |
} | |
/** | |
* [hx-replace-url HTMX reference](https://htmx.org/attributes/hx-replace-url/) | |
*/ | |
fun HTMLTag.hxReplaceUrl(value: String) { | |
attributes["hx-replace-url"] = value | |
} | |
/** | |
* [hx-replace-url HTMX reference](https://htmx.org/attributes/hx-replace-url/) | |
*/ | |
fun HTMLTag.hxReplaceUrl(enabled: Boolean = true) { | |
attributes["hx-replace-url"] = "$enabled" | |
} | |
/** | |
* [hx-request HTMX reference](https://htmx.org/attributes/hx-request/) | |
*/ | |
fun HTMLTag.hxRequest(value: String) { | |
attributes["hx-request"] = value | |
} | |
/** | |
* [hx-select HTMX reference](https://htmx.org/attributes/hx-select/) | |
*/ | |
fun HTMLTag.hxSelect(value: String) { | |
attributes["hx-select"] = value | |
} | |
/** | |
* [hx-select-oob HTMX reference](https://htmx.org/attributes/hx-select-oob/) | |
*/ | |
fun HTMLTag.hxSelectOob(value: String) { | |
attributes["hx-select-oob"] = value | |
} | |
/** | |
* [hx-swap HTMX reference](https://htmx.org/attributes/hx-swap/) | |
*/ | |
fun HTMLTag.hxSwapInnerHtml(modifiers: List<String> = emptyList()) { | |
attributes["hx-swap"] = "innerHTML${joinModifiers(modifiers)}" | |
} | |
/** | |
* [hx-swap HTMX reference](https://htmx.org/attributes/hx-swap/) | |
*/ | |
fun HTMLTag.hxSwapOuterHtml(modifiers: List<String> = emptyList()) { | |
attributes["hx-swap"] = "outerHTML${joinModifiers(modifiers)}" | |
} | |
/** | |
* [hx-swap HTMX reference](https://htmx.org/attributes/hx-swap/) | |
*/ | |
fun HTMLTag.hxSwapBeforeBegin(modifiers: List<String> = emptyList()) { | |
attributes["hx-swap"] = "beforebegin${joinModifiers(modifiers)}" | |
} | |
/** | |
* [hx-swap HTMX reference](https://htmx.org/attributes/hx-swap/) | |
*/ | |
fun HTMLTag.hxSwapAfterBegin(modifiers: List<String> = emptyList()) { | |
attributes["hx-swap"] = "afterbegin${joinModifiers(modifiers)}" | |
} | |
/** | |
* [hx-swap HTMX reference](https://htmx.org/attributes/hx-swap/) | |
*/ | |
fun HTMLTag.hxSwapBeforeEnd(modifiers: List<String> = emptyList()) { | |
attributes["hx-swap"] = "beforeend${joinModifiers(modifiers)}" | |
} | |
/** | |
* [hx-swap HTMX reference](https://htmx.org/attributes/hx-swap/) | |
*/ | |
fun HTMLTag.hxSwapAfterEnd(modifiers: List<String> = emptyList()) { | |
attributes["hx-swap"] = "afterend${joinModifiers(modifiers)}" | |
} | |
/** | |
* [hx-swap HTMX reference](https://htmx.org/attributes/hx-swap/) | |
*/ | |
fun HTMLTag.hxSwapDelete(modifiers: List<String> = emptyList()) { | |
attributes["hx-swap"] = "delete${joinModifiers(modifiers)}" | |
} | |
/** | |
* [hx-swap HTMX reference](https://htmx.org/attributes/hx-swap/) | |
*/ | |
fun HTMLTag.hxSwapNone(modifiers: List<String> = emptyList()) { | |
attributes["hx-swap"] = "none${joinModifiers(modifiers)}" | |
} | |
/** | |
* [hx-swap-oob HTMX reference](https://htmx.org/attributes/hx-swap-oob/) | |
*/ | |
fun HTMLTag.hxSwapOob(value: String) { | |
attributes["hx-swap-oob"] = value | |
} | |
/** | |
* [hx-sync HTMX reference](https://htmx.org/attributes/hx-sync/) | |
*/ | |
fun HTMLTag.hxSync(value: String) { | |
attributes["hx-sync"] = value | |
} | |
/** | |
* [hx-target HTMX reference](https://htmx.org/attributes/hx-target/) | |
*/ | |
fun HTMLTag.hxTarget(value: String) { | |
attributes["hx-target"] = value | |
} | |
/** | |
* [hx-vals HTMX reference](https://htmx.org/attributes/hx-vals/) | |
*/ | |
fun HTMLTag.hxVals(value: String) { | |
attributes["hx-vals"] = value | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment