8 Commits

Author SHA1 Message Date
dea2323499 Update NuGet READMEs 2023-11-22 16:13:57 -05:00
fcaaa693bc Bump htmx version; add .NET 8 support 2023-11-22 16:09:52 -05:00
8fd6af8c26 Add support for hx-disabled-elt
- Update script tag to 1.9.6
2023-09-27 20:31:56 -04:00
69a4034661 Update to htmx 1.9.5 2023-08-25 12:36:30 -04:00
5aa9408e60 Update to htmx 1.9.4 2023-07-26 12:54:48 -04:00
98f53a5e53 Add HX-Reselect; update for 1.9.3 2023-07-15 17:54:01 -04:00
7798314fb8 Update script tags for v1.9.2 2023-05-06 13:14:58 -04:00
50c66435e8 Add _hxOn and _hxSwapWithTransition
- Update scripts and version to 1.9.0
2023-04-14 16:56:08 -04:00
11 changed files with 57 additions and 16 deletions

View File

@@ -13,7 +13,7 @@ jobs:
strategy:
matrix:
dotnet-version: [ "6.0", "7.0" ]
dotnet-version: [ "6.0", "7.0", "8.0" ]
steps:
- uses: actions/checkout@v3

1
.gitignore vendored
View File

@@ -5,3 +5,4 @@
.ionide
.idea
*.user
.vscode

View File

@@ -1,4 +1,4 @@
/// Common definitions shared between attribute values and response headers
/// Common definitions shared between attribute values and response headers
[<AutoOpen>]
module Giraffe.Htmx.Common

View File

@@ -2,4 +2,4 @@
This package contains common code shared between [`Giraffe.Htmx`](https://www.nuget.org/packages/Giraffe.Htmx) and [`Giraffe.ViewEngine.Htmx`](https://www.nuget.org/packages/Giraffe.ViewEngine.Htmx), and will be automatically installed when you install either one.
**htmx version: 1.8.6**
**htmx version: 1.9.8**

View File

@@ -1,9 +1,9 @@
<?xml version="1.0" encoding="utf-8" standalone="no"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<TargetFrameworks>net6.0;net7.0</TargetFrameworks>
<VersionPrefix>1.8.6</VersionPrefix>
<PackageReleaseNotes>Update script tags for htmx 1.8.6</PackageReleaseNotes>
<TargetFrameworks>net6.0;net7.0;net8.0</TargetFrameworks>
<VersionPrefix>1.9.8</VersionPrefix>
<PackageReleaseNotes>Update script tags to pull htmx 1.9.8; add support for .NET 8</PackageReleaseNotes>
<Authors>danieljsummers</Authors>
<Company>Bit Badger Solutions</Company>
<PackageProjectUrl>https://github.com/bit-badger/Giraffe.Htmx</PackageProjectUrl>

View File

@@ -1,4 +1,4 @@
module Giraffe.Htmx
module Giraffe.Htmx
open Microsoft.AspNetCore.Http
open Microsoft.Extensions.Primitives
@@ -94,6 +94,10 @@ module Handlers =
let withHxNoReplaceUrl : HttpHandler =
toLowerBool false |> withHxReplaceUrl
/// Override which portion of the response will be swapped into the target document
let withHxReselect : string -> HttpHandler =
setHttpHeader "HX-Reselect"
/// Override the `hx-swap` attribute from the initiating element
let withHxReswap : string -> HttpHandler =
setHttpHeader "HX-Reswap"

View File

@@ -2,7 +2,7 @@
This package enables server-side support for [htmx](https://htmx.org) within [Giraffe](https://giraffe.wiki) and ASP.NET's `HttpContext`.
**htmx version: 1.8.6**
**htmx version: 1.9.8**
### Setup

View File

@@ -265,6 +265,14 @@ let handlers =
Expect.isTrue (dic.ContainsKey "HX-Replace-Url") "The HX-Replace-Url header should be present"
Expect.equal dic["HX-Replace-Url"].[0] "false" "The HX-Replace-Url value was incorrect"
}
testTask "withHxReselect succeeds" {
let ctx = Substitute.For<HttpContext> ()
let dic = HeaderDictionary ()
ctx.Response.Headers.ReturnsForAnyArgs dic |> ignore
let! _ = withHxReselect "#test" next ctx
Expect.isTrue (dic.ContainsKey "HX-Reselect") "The HX-Reselect header should be present"
Expect.equal dic["HX-Reselect"].[0] "#test" "The HX-Reselect value was incorrect"
}
testTask "withHxReswap succeeds" {
let ctx = Substitute.For<HttpContext> ()
let dic = HeaderDictionary ()

View File

@@ -313,6 +313,9 @@ let attributes =
test "_hxDisable succeeds" {
p [ _hxDisable ] [] |> shouldRender """<p hx-disable></p>"""
}
test "_hxDisabledElt succeeds" {
button [ _hxDiabledElt "this" ] [] |> shouldRender """<button hx-disabled-elt="this"></button>"""
}
test "_hxDisinherit succeeds" {
strong [ _hxDisinherit "*" ] [] |> shouldRender """<strong hx-disinherit="*"></strong>"""
}
@@ -344,6 +347,11 @@ let attributes =
test "_hxNoBoost succeeds" {
td [ _hxNoBoost ] [] |> shouldRender """<td hx-boost="false"></td>"""
}
test "_hxOn succeeds" {
let newLine = "\n"
strong [ _hxOn "submit: alert('oops')\nclick: alert('howdy!')" ] []
|> shouldRender $"""<strong hx-on="submit: alert(&#39;oops&#39;){newLine}click: alert(&#39;howdy!&#39;)"></strong>"""
}
test "_hxParams succeeds" {
br [ _hxParams "[p1,p2]" ] |> shouldRender """<br hx-params="[p1,p2]">"""
}
@@ -385,6 +393,10 @@ let attributes =
test "_hxSwap succeeds" {
del [ _hxSwap "innerHTML" ] [] |> shouldRender """<del hx-swap="innerHTML"></del>"""
}
test "_hxSwapWithTransition succeeds" {
del [ _hxSwapWithTransition "innerHTML" ] []
|> shouldRender """<del hx-swap="innerHTML transition:true"></del>"""
}
test "_hxSwapOob succeeds" {
li [ _hxSwapOob "true" ] [] |> shouldRender """<li hx-swap-oob="true"></li>"""
}
@@ -413,14 +425,14 @@ let script =
let html = RenderView.AsString.htmlNode Script.minified
Expect.equal
html
"""<script src="https://unpkg.com/htmx.org@1.8.6" integrity="sha384-Bj8qm/6B+71E6FQSySofJOUjA/gq330vEqjFx9LakWybUySyI1IQHwPtbTU7bNwx" crossorigin="anonymous"></script>"""
"""<script src="https://unpkg.com/htmx.org@1.9.8" integrity="sha384-rgjA7mptc2ETQqXoYC3/zJvkU7K/aP44Y+z7xQuJiVnB/422P/Ak+F/AqFR7E4Wr" crossorigin="anonymous"></script>"""
"Minified script tag is incorrect"
}
test "unminified succeeds" {
let html = RenderView.AsString.htmlNode Script.unminified
Expect.equal
html
"""<script src="https://unpkg.com/htmx.org@1.8.6/dist/htmx.js" integrity="sha384-denUmZOxhLrCvV+ej1uWe4EXwjmJtWzbg0sjv6YfuHhUAP0CEVIArcYjlUbJHh87" crossorigin="anonymous"></script>"""
"""<script src="https://unpkg.com/htmx.org@1.9.8/dist/htmx.js" integrity="sha384-zOAIsdGekNHQVAjCjVrQ1xHoxyvnxgr63EH6IyXsCfvKZdRFRyG1u8GbWxO5oZ38" crossorigin="anonymous"></script>"""
"Unminified script tag is incorrect"
}
]

View File

@@ -193,6 +193,9 @@ module HtmxAttrs =
/// Disables htmx processing for the given node and any children nodes
let _hxDisable = flag "hx-disable"
/// Specifies elements that should be disabled when an htmx request is in flight
let _hxDiabledElt = attr "hx-disabled-elt"
/// Disinherit all ("*") or specific htmx attributes
let _hxDisinherit = attr "hx-disinherit"
@@ -223,6 +226,9 @@ module HtmxAttrs =
/// Overrides a previous `hx-boost`
let _hxNoBoost = attr "hx-boost" "false"
/// Attach an event handler for DOM or htmx events
let _hxOn = attr "hx-on"
/// Filters the parameters that will be submitted with a request
let _hxParams = attr "hx-params"
@@ -262,6 +268,10 @@ module HtmxAttrs =
/// Controls how the response content is swapped into the DOM (e.g. 'outerHTML' or 'beforeEnd')
let _hxSwap = attr "hx-swap"
/// Controls how the response content is swapped into the DOM (e.g. 'outerHTML' or 'beforeEnd'), enabling CSS
/// transitions
let _hxSwapWithTransition = sprintf "%s transition:true" >> _hxSwap
/// Marks content in a response as being "Out of Band", i.e. swapped somewhere other than the target
let _hxSwapOob = attr "hx-swap-oob"
@@ -289,14 +299,14 @@ module Script =
/// Script tag to load the minified version from unpkg.com
let minified =
script [ _src "https://unpkg.com/htmx.org@1.8.6"
_integrity "sha384-Bj8qm/6B+71E6FQSySofJOUjA/gq330vEqjFx9LakWybUySyI1IQHwPtbTU7bNwx"
script [ _src "https://unpkg.com/htmx.org@1.9.8"
_integrity "sha384-rgjA7mptc2ETQqXoYC3/zJvkU7K/aP44Y+z7xQuJiVnB/422P/Ak+F/AqFR7E4Wr"
_crossorigin "anonymous" ] []
/// Script tag to load the unminified version from unpkg.com
let unminified =
script [ _src "https://unpkg.com/htmx.org@1.8.6/dist/htmx.js"
_integrity "sha384-denUmZOxhLrCvV+ej1uWe4EXwjmJtWzbg0sjv6YfuHhUAP0CEVIArcYjlUbJHh87"
script [ _src "https://unpkg.com/htmx.org@1.9.8/dist/htmx.js"
_integrity "sha384-zOAIsdGekNHQVAjCjVrQ1xHoxyvnxgr63EH6IyXsCfvKZdRFRyG1u8GbWxO5oZ38"
_crossorigin "anonymous" ] []

View File

@@ -2,7 +2,7 @@
This package enables [htmx](https://htmx.org) support within the [Giraffe](https://giraffe.wiki) view engine.
**htmx version: 1.8.6**
**htmx version: 1.9.8**
### Setup
@@ -33,7 +33,13 @@ This also supports [fragment rendering](https://bitbadger.solutions/blog/2022/fr
### Learn
htmx's attributes and these attribute functions map one-to-one. The lone exception is `_hxBoost`, which implies `true`; use `_hxNoBoost` to set it to `false`. The support modules contain named properties for known values (as illustrated with `HxTrigger.Load` above). A few of the modules are more than collections of names, though:
htmx's attributes and these attribute functions map one-to-one. There are two exceptions:
- `_hxBoost` implies `true`; use `_hxNoBoost` to set it to `false`.
- `_hxSwapWithTransition` renders the standard `hx-swap` attribute and appends `transition:true` to the specified swap value.
The htmx `hx-on` attribute supports multiple events if they are separated with a newline (`\n`) character. The value provided to this attribute will be attribute-escaped, but in testing, it was interpreted correctly.
The support modules contain named properties for known values (as illustrated with `HxTrigger.Load` above). A few of the modules are more than collections of names, though:
- `HxRequest` has a `Configure` function, which takes a list of strings; the other functions in the module allow for configuring the request.
```fsharp