- Adds XML documentation (#13)
- Adds `HxSync` module and attribute helper
- Updates script version to 2.0.6
- Drops .NET 6 support (#14 )

Reviewed-on: #15
This commit was merged in pull request #15.
This commit is contained in:
2025-07-03 00:15:24 +00:00
parent 10c31d77b5
commit 6b7458070b
12 changed files with 920 additions and 435 deletions

View File

@@ -1,28 +1,53 @@
/// Common definitions shared between attribute values and response headers
/// <summary>Common definitions shared between attribute values and response headers</summary>
[<AutoOpen>]
module Giraffe.Htmx.Common
/// Valid values for the `hx-swap` attribute / `HX-Reswap` header (may be combined with swap/settle/scroll/show config)
/// <summary>Serialize a list of key/value pairs to JSON (very rudimentary)</summary>
/// <param name="pairs">The key/value pairs to be serialized to JSON</param>
/// <returns>A string with the key/value pairs serialized to JSON</returns>
let internal toJson (pairs: (string * string) list) =
pairs
|> List.map (fun pair -> sprintf "\"%s\": \"%s\"" (fst pair) ((snd pair).Replace ("\"", "\\\"")))
|> String.concat ", "
|> sprintf "{ %s }"
/// <summary>Convert a boolean to lowercase "true" or "false"</summary>
/// <param name="boolValue">The boolean value to convert</param>
/// <returns>"true" for <c>true</c>, "false" for <c>false</c></returns>
let internal toLowerBool (boolValue: bool) =
(string boolValue).ToLowerInvariant()
/// <summary>Valid values for the <c>hx-swap</c> attribute / <c>HX-Reswap</c> header</summary>
/// <remarks>May be combined with <c>swap</c> / <c>settle</c> / <c>scroll</c> / <c>show</c> config)</remarks>
/// <seealso href="https://htmx.org/attributes/hx-swap/">Documentation</seealso>
[<RequireQualifiedAccess>]
module HxSwap =
/// The default, replace the inner html of the target element
/// <summary>The default, replace the inner HTML of the target element</summary>
[<Literal>]
let InnerHtml = "innerHTML"
/// Replace the entire target element with the response
/// <summary>Replace the entire target element with the response</summary>
[<Literal>]
let OuterHtml = "outerHTML"
/// Insert the response before the target element
/// <summary>Insert the response before the target element</summary>
[<Literal>]
let BeforeBegin = "beforebegin"
/// Insert the response before the first child of the target element
/// <summary>Insert the response before the first child of the target element</summary>
[<Literal>]
let AfterBegin = "afterbegin"
/// Insert the response after the last child of the target element
/// <summary>Insert the response after the last child of the target element</summary>
[<Literal>]
let BeforeEnd = "beforeend"
/// Insert the response after the target element
/// <summary>Insert the response after the target element</summary>
[<Literal>]
let AfterEnd = "afterend"
/// Does not append content from response (out of band items will still be processed).
/// <summary>Does not append content from response (out of band items will still be processed).</summary>
[<Literal>]
let None = "none"