Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ jobs:
coverage_report_title: JaCoCo
github_token: ${{ secrets.GITHUB_TOKEN }}
skip_check_run: false
minimum_coverage: 55
minimum_coverage: 60
fail_below_threshold: true
publish_only_summary: false

Expand Down
50 changes: 28 additions & 22 deletions docs/dsl.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ val listTemplate = htmxTemplate<List<String>> {
|---------------------------------------------------------------|-----------|-----------------------------------------------------------------------------------------------------------------------------------------------|
| [`hx-get`](https://htmx.org/attributes/hx-get/) | ✅ | [Example](https://github.com/wakingrufus/khtmx/blob/main/khtmx-dsl/src/commonTest/kotlin/com/github/wakingrufus/htmx/exemplar/HxGet.kt) |
| [`hx-post`](https://htmx.org/attributes/hx-post/) | ✅ | [Example](https://github.com/wakingrufus/khtmx/blob/main/khtmx-dsl/src/commonTest/kotlin/com/github/wakingrufus/htmx/exemplar/HxPost.kt) |
| [`hx-on*`](https://htmx.org/attributes/hx-on/) | ❌ | |
| [`hx-on*`](https://htmx.org/attributes/hx-on/) | ✅ | [Example](https://github.com/wakingrufus/khtmx/blob/main/khtmx-dsl/src/commonTest/kotlin/com/github/wakingrufus/htmx/exemplar/HxOn.kt) |
| [`hx-push-url`](https://htmx.org/attributes/hx-push-url/) | ✅ | [Example](https://github.com/wakingrufus/khtmx/blob/main/khtmx-dsl/src/commonTest/kotlin/com/github/wakingrufus/htmx/exemplar/HxPushUrl.kt) |
| [`hx-select`](https://htmx.org/attributes/hx-select/) | ✅ | [Example](https://github.com/wakingrufus/khtmx/blob/main/khtmx-dsl/src/commonTest/kotlin/com/github/wakingrufus/htmx/exemplar/HxSelect.kt) |
| [`hx-select-oob`](https://htmx.org/attributes/hx-select-oob/) | ✅ | [Example](https://github.com/wakingrufus/khtmx/blob/main/khtmx-dsl/src/commonTest/kotlin/com/github/wakingrufus/htmx/exemplar/HxSelectOob.kt) |
Expand All @@ -87,27 +87,33 @@ val listTemplate = htmxTemplate<List<String>> {
| [`hx-boost`](https://htmx.org/attributes/hx-boost/) | ❌ | |
| [`hx-confirm`](https://htmx.org/attributes/hx-confirm/) | ❌ | |
| [`hx-delete`](https://htmx.org/attributes/hx-delete/) | ✅ | [Example](https://github.com/wakingrufus/khtmx/blob/main/khtmx-dsl/src/commonTest/kotlin/com/github/wakingrufus/htmx/exemplar/HxDelete.kt) |
| [`hx-disable`](https://htmx.org/attributes/hx-disable/) | ❌ |
| [`hx-disabled-elt`](https://htmx.org/attributes/hx-disabled-elt/) | ❌ |
| [`hx-disinherit`](https://htmx.org/attributes/hx-disinherit/) | ❌ |
| [`hx-encoding`](https://htmx.org/attributes/hx-encoding/) | ❌ |
| [`hx-ext`](https://htmx.org/attributes/hx-ext/) | ❌ |
| [`hx-headers`](https://htmx.org/attributes/hx-headers/) | ❌ |
| [`hx-history`](https://htmx.org/attributes/hx-history/) | ❌ |
| [`hx-history-elt`](https://htmx.org/attributes/hx-history-elt/) | ❌ |
| [`hx-include`](https://htmx.org/attributes/hx-include/) | ❌ |
| [`hx-indicator`](https://htmx.org/attributes/hx-indicator/) | ❌ |
| [`hx-inherit`](https://htmx.org/attributes/hx-inherit/) | ❌ |
| [`hx-params`](https://htmx.org/attributes/hx-params/) | ✅ |
| [`hx-patch`](https://htmx.org/attributes/hx-patch/) | ✅ |
| [`hx-preserve`](https://htmx.org/attributes/hx-preserve/) | ❌ |
| [`hx-prompt`](https://htmx.org/attributes/hx-prompt/) | ❌ |
| [`hx-put`](https://htmx.org/attributes/hx-put/) | ✅ |
| [`hx-replace-url`](https://htmx.org/attributes/hx-replace-url/) | ❌ |
| [`hx-request`](https://htmx.org/attributes/hx-request/) | ❌ |
| [`hx-sync`](https://htmx.org/attributes/hx-sync/) | ❌ |
| [`hx-validate`](https://htmx.org/attributes/hx-validate/) | ❌ |
| [`hx-vars`](https://htmx.org/attributes/hx-vars/) | ❌ |
| [`hx-disable`](https://htmx.org/attributes/hx-disable/) | ❌ | |
| [`hx-disabled-elt`](https://htmx.org/attributes/hx-disabled-elt/) | ❌ | |
| [`hx-disinherit`](https://htmx.org/attributes/hx-disinherit/) | ❌ | |
| [`hx-encoding`](https://htmx.org/attributes/hx-encoding/) | ❌ | |
| [`hx-ext`](https://htmx.org/attributes/hx-ext/) | ❌ | |
| [`hx-headers`](https://htmx.org/attributes/hx-headers/) | ❌ | |
| [`hx-history`](https://htmx.org/attributes/hx-history/) | ❌ | |
| [`hx-history-elt`](https://htmx.org/attributes/hx-history-elt/) | ❌ | |
| [`hx-include`](https://htmx.org/attributes/hx-include/) | ❌ | |
| [`hx-indicator`](https://htmx.org/attributes/hx-indicator/) | ❌ | |
| [`hx-inherit`](https://htmx.org/attributes/hx-inherit/) | ❌ | |
| [`hx-params`](https://htmx.org/attributes/hx-params/) | ✅ | |
| [`hx-patch`](https://htmx.org/attributes/hx-patch/) | ✅ | |
| [`hx-preserve`](https://htmx.org/attributes/hx-preserve/) | ❌ | |
| [`hx-prompt`](https://htmx.org/attributes/hx-prompt/) | ❌ | |
| [`hx-put`](https://htmx.org/attributes/hx-put/) | ✅ | |
| [`hx-replace-url`](https://htmx.org/attributes/hx-replace-url/) | ❌ | |
| [`hx-request`](https://htmx.org/attributes/hx-request/) | ❌ | |
| [`hx-sync`](https://htmx.org/attributes/hx-sync/) | ❌ | |
| [`hx-validate`](https://htmx.org/attributes/hx-validate/) | ❌ | |
| [`hx-vars`](https://htmx.org/attributes/hx-vars/) | ❌ | |

| Constants | Supported |
|-----------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------|
| [CSS Classes](https://htmx.org/reference/#classes) | [✅](https://github.com/wakingrufus/khtmx/blob/main/khtmx-dsl/src/commonMain/kotlin/com/github/wakingrufus/htmx/HtmxConstants.kt) |
| [HTTP Headers](https://htmx.org/reference/#headers) | [✅](https://github.com/wakingrufus/khtmx/blob/main/khtmx-dsl/src/commonMain/kotlin/com/github/wakingrufus/htmx/HtmxConstants.kt) |
| [Events](https://htmx.org/reference/#events) | [✅](https://github.com/wakingrufus/khtmx/blob/main/khtmx-dsl/src/commonMain/kotlin/com/github/wakingrufus/htmx/HtmxEvent.kt) |

| HTMX Features | Supported |
|-----------------------------------------------------|------------|
Expand Down
9 changes: 6 additions & 3 deletions docs/spring.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ khtmx-spring provides a DSL for Spring Boot which allows a seamless integration

## Getting Started

This entry point for khtmx-spring is the `SpringHtmxDsl` class.
This entry point for khtmx-spring is the `SpringHtmxDsl` class.

### AutoConfiguration
To use `SpringHtmxDsl` in an Spring application with AutoConfiguration, extend this class, similar to `BeanRegistrarDsl`:
Expand Down Expand Up @@ -168,7 +168,10 @@ get("things", TestController::getAll) {
```kotlin
route(HttpVerb.GET, "thing/1", TestController::get) {
span {
+it.id.toString()
+it.id.toString()
}
}
```
```

### Response Headers
There is no support yet for [HTMX Response Headers](https://htmx.org/reference/#response_headers).
Original file line number Diff line number Diff line change
Expand Up @@ -4,102 +4,190 @@ import com.github.wakingrufus.htmx.swap.HxSwapDsl
import com.github.wakingrufus.htmx.swap.HxSwapType
import kotlinx.html.HTMLTag

/**
* Entry point for the DSL which works with any [HttpVerb].
* @param dsl high-level DSL that helps to author triggers in a way that coordinates the related attributes and enforce type safety
*/
@HtmxDsl
fun HTMLTag.hx(verb: HttpVerb, path: String, dsl: HxDsl.() -> Unit = {}) {
HxDsl(verb, path).apply(dsl).invoke(this)
}

/**
* Convenience method for using [hx] for a POST
* https://htmx.org/attributes/hx-post/
* @param dsl high-level DSL that helps to author triggers in a way that coordinates the related attributes and enforce type safety
*/
@HtmxDsl
fun HTMLTag.hxPost(path: String, dsl: HxDsl.() -> Unit = {}) {
hx(HttpVerb.POST, path, dsl)
}

/**
* Convenience method for using [hx] for a GET
* https://htmx.org/attributes/hx-get/
* @param dsl high-level DSL that helps to author triggers in a way that coordinates the related attributes and enforce type safety
*/
@HtmxDsl
fun HTMLTag.hxGet(path: String, dsl: HxDsl.() -> Unit = {}) {
hx(HttpVerb.GET, path, dsl)
}

/**
* Convenience method for using [hx] for a PUT
* https://htmx.org/attributes/hx-put/
* @param dsl high-level DSL that helps to author triggers in a way that coordinates the related attributes and enforce type safety
*/
@HtmxDsl
fun HTMLTag.hxPut(path: String, dsl: HxDsl.() -> Unit = {}) {
hx(HttpVerb.PUT, path, dsl)
}

/**
* Convenience method for using [hx] for a PATCH
* https://htmx.org/attributes/hx-patch/
* @param dsl high-level DSL that helps to author triggers in a way that coordinates the related attributes and enforce type safety
*/
@HtmxDsl
fun HTMLTag.hxPatch(path: String, dsl: HxDsl.() -> Unit = {}) {
hx(HttpVerb.PATCH, path, dsl)
}

/**
* Convenience method for using [hx] for a DELETE
* https://htmx.org/attributes/hx-delete/
* @param dsl high-level DSL that helps to author triggers in a way that coordinates the related attributes and enforce type safety
*/
@HtmxDsl
fun HTMLTag.hxDelete(path: String, dsl: HxDsl.() -> Unit = {}) {
hx(HttpVerb.DELETE, path, dsl)
}

/**
* https://htmx.org/attributes/hx-select/
*/
@HtmxDsl
fun HTMLTag.hxSelect(selector: String) {
attributes["hx-select"] = selector
}

/**
* https://htmx.org/attributes/hx-select-oob/
*/
@HtmxDsl
fun HTMLTag.hxSelectOob(selector: String) {
attributes["hx-select-oob"] = selector
}

/**
* https://htmx.org/attributes/hx-params/
*/
@HtmxDsl
fun HTMLTag.hxParams(params: String) {
attributes["hx-params"] = params
}

/**
* https://htmx.org/attributes/hx-push-url/
*/
@HtmxDsl
fun HTMLTag.hxPushUrl(value: Boolean) {
attributes["hx-push-url"] = value.toString()
}

/**
* https://htmx.org/attributes/hx-push-url/
*/
@HtmxDsl
fun HTMLTag.hxPushUrl(value: String) {
attributes["hx-push-url"] = value
}

/**
* https://htmx.org/attributes/hx-swap/
*/
@HtmxDsl
fun HTMLTag.hxSwap(value: String) {
attributes["hx-swap"] = value
}

/**
* https://htmx.org/attributes/hx-swap/
*/
@HtmxDsl
fun HTMLTag.hxSwap(dsl: HxSwapDsl.() -> Unit = {}) {
attributes["hx-swap"] = HxSwapDsl().apply(dsl).invoke().invoke()
}

/**
* https://htmx.org/attributes/hx-select-oob/
*/
@HtmxDsl
fun HTMLTag.hxSwapOob(value: Boolean) {
attributes["hx-swap-oob"] = value.toString()
}

/**
* https://htmx.org/attributes/hx-select-oob/
*/
@HtmxDsl
fun HTMLTag.hxSwapOob(type: HxSwapType) {
attributes["hx-swap-oob"] = type.stringValue
}

/**
* https://htmx.org/attributes/hx-select-oob/
*/
@HtmxDsl
fun HTMLTag.hxSwapOob(type: HxSwapType, selector: String) {
attributes["hx-swap-oob"] = type.stringValue + ":" + selector
}

/**
* https://htmx.org/attributes/hx-target/
*/
@HtmxDsl
fun HTMLTag.hxTarget(selector: String) {
attributes["hx-target"] = selector
}

/**
* https://htmx.org/attributes/hx-trigger/
*/
@HtmxDsl
fun HTMLTag.hxTrigger(value: String) {
attributes["hx-trigger"] = value
}

/**
* https://htmx.org/attributes/hx-vals/
*/
@HtmxDsl
fun HTMLTag.hxVals(json: String) {
attributes["hx-vals"] = json
}

/**
* https://htmx.org/attributes/hx-on/
*/
@HtmxDsl
fun HTMLTag.hxPost(path: String, dsl: HxDsl.() -> Unit = {}) {
hx(HttpVerb.POST, path, dsl)
}

@HtmxDsl
fun HTMLTag.hxGet(path: String, dsl: HxDsl.() -> Unit = {}) {
hx(HttpVerb.GET, path, dsl)
}

@HtmxDsl
fun HTMLTag.hxPut(path: String, dsl: HxDsl.() -> Unit = {}) {
hx(HttpVerb.PUT, path, dsl)
fun HTMLTag.hxOn(event: String, script: String) {
attributes["hx-on:$event"] = script
}

/**
* https://htmx.org/attributes/hx-on/
*/
@HtmxDsl
fun HTMLTag.hxPatch(path: String, dsl: HxDsl.() -> Unit = {}) {
hx(HttpVerb.PATCH, path, dsl)
}

@HtmxDsl
fun HTMLTag.hxDelete(path: String, dsl: HxDsl.() -> Unit = {}) {
hx(HttpVerb.DELETE, path, dsl)
fun HTMLTag.hxOn(event: HtmxEvent, script: String) {
attributes["hx-on:" + event.htmlForm] = script
}

/**
* https://htmx.org/attributes/hx-on/
* @param event reference to an event via [HtmxEvents] method reference
*/
@HtmxDsl
fun HTMLTag.htmxIndicator() {
attributes["class"] = "htmx-indicator"
fun HTMLTag.hxOn(event: () -> HtmxEvent, script: String) {
attributes["hx-on:" + event().htmlForm] = script
}
Loading