-
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
75 additions
and
45 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,60 +1,90 @@ | ||
namespace Oxpecker.Htmx | ||
|
||
open System.Runtime.CompilerServices | ||
open Oxpecker.ViewEngine | ||
|
||
module Extension = | ||
|
||
[<Extension>] | ||
type CoreHtmxExtensions = | ||
[<Extension>] | ||
static member hxBoost(el: HtmlElement, value: bool) = | ||
el.attr("hx-boost", if value then "true" else "false") | ||
[<Extension>] | ||
static member hxGet(el: HtmlElement, value) = | ||
el.attr("hx-get", value) | ||
[<Extension>] | ||
static member hxPost(el: HtmlElement, value) = | ||
el.attr("hx-post", value) | ||
[<Extension>] | ||
static member hxOn(el: HtmlElement, event, value) = | ||
el.attr("hx-on:"+event, value) | ||
[<Extension>] | ||
static member hxPushUrl(el: HtmlElement, value) = | ||
el.attr("hx-push-url", value) | ||
[<Extension>] | ||
static member hxSelect(el: HtmlElement, value) = | ||
el.attr("hx-select", value) | ||
[<Extension>] | ||
static member hxSelectOob(el: HtmlElement, value) = | ||
el.attr("hx-select-oob", value) | ||
[<Extension>] | ||
static member hxSwap(el: HtmlElement, value) = | ||
el.attr("hx-swap", value) | ||
[<Extension>] | ||
static member hxSwapOob(el: HtmlElement, value) = | ||
el.attr("hx-swap-oob", value) | ||
[<Extension>] | ||
static member hxTarget(el: HtmlElement, value) = | ||
el.attr("hx-target", value) | ||
[<Extension>] | ||
static member hxTrigger(el: HtmlElement, value) = | ||
el.attr("hx-trigger", value) | ||
[<Extension>] | ||
static member hxVals(el: HtmlElement, value) = | ||
el.attr("hx-vals", value) | ||
[<AutoOpen>] | ||
module CoreAttributes = | ||
type HtmlElement with | ||
member this.hxGet with set value = | ||
this.attr("hx-get", value) |> ignore | ||
member this.hxPost with set value = | ||
this.attr("hx-post", value) |> ignore | ||
member this.hxOn(event, value) = | ||
this.attr("hx-on:"+event, value) | ||
member this.hxPushUrl with set value = | ||
this.attr("hx-push-url", value) |> ignore | ||
member this.hxSelect with set value = | ||
this.attr("hx-select", value) |> ignore | ||
member this.hxSelectOob with set value = | ||
this.attr("hx-select-oob", value) |> ignore | ||
member this.hxSwap with set value = | ||
this.attr("hx-swap", value) |> ignore | ||
member this.hxSwapOob with set value = | ||
this.attr("hx-swap-oob", value) |> ignore | ||
member this.hxTarget with set value = | ||
this.attr("hx-target", value) |> ignore | ||
member this.hxTrigger with set value = | ||
this.attr("hx-trigger", value) |> ignore | ||
member this.hxVals with set value = | ||
this.attr("hx-vals", value) |> ignore | ||
|
||
|
||
[<AutoOpen>] | ||
module AdditionalAttributes = | ||
type HtmlElement with | ||
member this.hxBoost with set value = | ||
this.attr("hx-boost", if value then "true" else "false") |> ignore | ||
member this.hxConfirm with set value = | ||
this.attr("hx-confirm", value) |> ignore | ||
member this.hxDelete with set value = | ||
this.attr("hx-delete", value) |> ignore | ||
member this.hxDisable with set value = | ||
if value then | ||
this.attr("hx-disable", "true") |> ignore | ||
member this.hxDisabledElt with set value = | ||
this.attr("hx-disabled-elt", value) |> ignore | ||
member this.hxDisinherit with set value = | ||
this.attr("hx-disinherit", value) |> ignore | ||
member this.hxExt with set value = | ||
this.attr("hx-ext", value) |> ignore | ||
member this.hxHeaders with set value = | ||
this.attr("hx-headers", value) |> ignore | ||
member this.hxHistory with set value = | ||
this.attr("hx-history", if value then "true" else "false") |> ignore | ||
member this.hxHistoryElt with set value = | ||
if value then | ||
this.attr("hx-history-elt", "") |> ignore | ||
member this.hxInclude with set value = | ||
this.attr("hx-include", value) |> ignore | ||
member this.hxIndicator with set value = | ||
this.attr("hx-indicator", value) |> ignore | ||
member this.hxParams with set value = | ||
this.attr("hx-params", value) |> ignore | ||
member this.hxPatch with set value = | ||
this.attr("hx-patch", value) |> ignore | ||
member this.hxPreserve with set value = | ||
if value then | ||
this.attr("hx-preserve", "") |> ignore | ||
member this.hxPrompt with set value = | ||
this.attr("hx-prompt", value) |> ignore | ||
member this.hxPut with set value = | ||
this.attr("hx-put", value) |> ignore | ||
member this.hxReplaceUrl with set value = | ||
this.attr("hx-replace-url", value) |> ignore | ||
member this.hxRequest with set value = | ||
this.attr("hx-request", value) |> ignore | ||
member this.hxSync with set value = | ||
this.attr("hx-sync", value) |> ignore | ||
member this.hxValidate with set value = | ||
this.attr("hx-validate", if value then "true" else "false") |> ignore | ||
|
||
module Test = | ||
|
||
open Extension | ||
|
||
let test () = | ||
|
||
let z = | ||
div().hxGet("").hxOn("clicked", "alert!") | ||
.hxTrigger("click[ctrlKey&&shiftKey]"){ | ||
div(hxGet = "/", hxDisable = true, hxHistoryElt = true).hxOn("clicked", "alert!") | ||
{ | ||
"sdf" | ||
} | ||
z |