Compare commits
No commits in common. "main" and "v1.9.4" have entirely different histories.
17
.github/workflows/ci.yml
vendored
17
.github/workflows/ci.yml
vendored
|
@ -2,10 +2,9 @@ name: CI
|
||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
branches: [ "main", "htmx-version-2" ]
|
branches: [ "main" ]
|
||||||
pull_request:
|
pull_request:
|
||||||
branches: [ "main" ]
|
branches: [ "main" ]
|
||||||
workflow_dispatch:
|
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build-and-test:
|
build-and-test:
|
||||||
|
@ -14,12 +13,12 @@ jobs:
|
||||||
|
|
||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
dotnet-version: [ "6.0", "7.0", "8.0" ]
|
dotnet-version: [ "6.0", "7.0" ]
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v3
|
||||||
- name: Setup .NET ${{ matrix.dotnet-version }}.x
|
- name: Setup .NET ${{ matrix.dotnet-version }}.x
|
||||||
uses: actions/setup-dotnet@v4
|
uses: actions/setup-dotnet@v3
|
||||||
with:
|
with:
|
||||||
dotnet-version: ${{ matrix.dotnet-version }}.x
|
dotnet-version: ${{ matrix.dotnet-version }}.x
|
||||||
- name: Restore dependencies
|
- name: Restore dependencies
|
||||||
|
@ -32,11 +31,11 @@ jobs:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
needs: build-and-test
|
needs: build-and-test
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v3
|
||||||
- name: Setup .NET
|
- name: Setup .NET
|
||||||
uses: actions/setup-dotnet@v4
|
uses: actions/setup-dotnet@v3
|
||||||
with:
|
with:
|
||||||
dotnet-version: "8.0"
|
dotnet-version: "7.0"
|
||||||
- name: Package Common library
|
- name: Package Common library
|
||||||
run: dotnet pack src/Common/Giraffe.Htmx.Common.fsproj -c Release
|
run: dotnet pack src/Common/Giraffe.Htmx.Common.fsproj -c Release
|
||||||
- name: Move Common package
|
- name: Move Common package
|
||||||
|
@ -50,7 +49,7 @@ jobs:
|
||||||
- name: Move View Engine package
|
- name: Move View Engine package
|
||||||
run: cp src/ViewEngine.Htmx/bin/Release/Giraffe.ViewEngine.Htmx.*.nupkg .
|
run: cp src/ViewEngine.Htmx/bin/Release/Giraffe.ViewEngine.Htmx.*.nupkg .
|
||||||
- name: Save Packages
|
- name: Save Packages
|
||||||
uses: actions/upload-artifact@v4
|
uses: actions/upload-artifact@v3
|
||||||
with:
|
with:
|
||||||
name: packages
|
name: packages
|
||||||
path: |
|
path: |
|
||||||
|
|
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -6,4 +6,3 @@
|
||||||
.idea
|
.idea
|
||||||
*.user
|
*.user
|
||||||
.vscode
|
.vscode
|
||||||
src/*.nupkg
|
|
||||||
|
|
39
README.md
39
README.md
|
@ -21,23 +21,22 @@ In addition to the regular HTTP request payloads, htmx sets [one or more headers
|
||||||
A server may want to respond to a request that originated from htmx differently than a regular request. One way htmx can provide the same feel as a Single Page Application (SPA) is by swapping out the `body` content (or an element within it) instead of reloading the entire page. In this case, the developer can provide a partial layout to be used for these responses, while returning the full page for regular requests. The `IsHtmx` property makes this easy...
|
A server may want to respond to a request that originated from htmx differently than a regular request. One way htmx can provide the same feel as a Single Page Application (SPA) is by swapping out the `body` content (or an element within it) instead of reloading the entire page. In this case, the developer can provide a partial layout to be used for these responses, while returning the full page for regular requests. The `IsHtmx` property makes this easy...
|
||||||
|
|
||||||
```fsharp
|
```fsharp
|
||||||
// "partial" and "full" are handlers that return the contents;
|
// "partial" and "full" are handlers that return the contents;
|
||||||
// "view" can be whatever your view engine needs for the body of the page
|
// "view" can be whatever your view engine needs for the body of the page
|
||||||
let result view : HttpHandler =
|
let result view : HttpHandler =
|
||||||
fun next ctx ->
|
fun next ctx ->
|
||||||
if ctx.Request.IsHtmx && not ctx.Request.IsHtmxRefresh then
|
match ctx.Request.IsHtmx && not ctx.Request.IsHtmxRefresh with
|
||||||
partial view
|
| true -> partial view
|
||||||
else
|
| false -> full view
|
||||||
full view
|
|
||||||
```
|
```
|
||||||
|
|
||||||
htmx also utilizes [response headers](https://htmx.org/docs/#response_headers) to affect client-side behavior. For each of these, this library provides `HttpHandler`s that can be chained along with the response. As an example, if the server returns a redirect response (301, 302, 303, 307), the `XMLHttpRequest` handler on the client will follow the redirection before htmx can do anything with it. To redirect to a new page, you would return an OK (200) response with an `HX-Redirect` header set in the response.
|
htmx also utilizes [response headers](https://htmx.org/docs/#response_headers) to affect client-side behavior. For each of these, this library provides `HttpHandler`s that can be chained along with the response. As an example, if the server returns a redirect response (301, 302, 303, 307), the `XMLHttpRequest` handler on the client will follow the redirection before htmx can do anything with it. To redirect to a new page, you would return an OK (200) response with an `HX-Redirect` header set in the response.
|
||||||
|
|
||||||
```fsharp
|
```fsharp
|
||||||
let theHandler : HttpHandler =
|
let theHandler : HttpHandler =
|
||||||
fun next ctx ->
|
fun next ctx ->
|
||||||
// some interesting stuff
|
// some interesting stuff
|
||||||
withHxRedirect "/the-new-url" >=> Successful.OK
|
withHxRedirect "/the-new-url" >=> Successful.OK
|
||||||
```
|
```
|
||||||
|
|
||||||
Of note is that the `HX-Trigger` headers can take either one or more events. For a single event with no parameters, use `withHxTrigger`; for a single event with parameters, or multiple events, use `withHxTriggerMany`. Both these have `AfterSettle` and `AfterSwap` versions as well.
|
Of note is that the `HX-Trigger` headers can take either one or more events. For a single event with no parameters, use `withHxTrigger`; for a single event with parameters, or multiple events, use `withHxTriggerMany`. Both these have `AfterSettle` and `AfterSwap` versions as well.
|
||||||
|
@ -49,10 +48,8 @@ As htmx uses [attributes](https://htmx.org/docs/#attributes) to extend HTML, the
|
||||||
As an example, creating a `div` that loads data once the HTML is rendered:
|
As an example, creating a `div` that loads data once the HTML is rendered:
|
||||||
|
|
||||||
```fsharp
|
```fsharp
|
||||||
let autoload =
|
let autoload =
|
||||||
div [ _hxGet "/lazy-load-data"; _hxTrigger HxTrigger.Load ] [
|
div [ _hxGet "/lazy-load-data"; _hxTrigger "load" ] [ str "Loading..." ]
|
||||||
str "Loading..."
|
|
||||||
]
|
|
||||||
```
|
```
|
||||||
|
|
||||||
_(As `hx-boost="true"` is the usual desire for boosting, `_hxBoost` implies true. To disable it for an element, use `_hxNoBoost` instead.)_
|
_(As `hx-boost="true"` is the usual desire for boosting, `_hxBoost` implies true. To disable it for an element, use `_hxNoBoost` instead.)_
|
||||||
|
@ -60,20 +57,20 @@ _(As `hx-boost="true"` is the usual desire for boosting, `_hxBoost` implies true
|
||||||
Some attributes have known values, such as `hx-trigger` and `hx-swap`; for these, there are modules with those values. For example, `HxTrigger.Load` could be used in the example above, to ensure that the known values are spelled correctly. `hx-trigger` can also take modifiers, such as an action that only responds to `Ctrl`+click. The `HxTrigger` module has a `Filter` submodule to assist with defining these actions.
|
Some attributes have known values, such as `hx-trigger` and `hx-swap`; for these, there are modules with those values. For example, `HxTrigger.Load` could be used in the example above, to ensure that the known values are spelled correctly. `hx-trigger` can also take modifiers, such as an action that only responds to `Ctrl`+click. The `HxTrigger` module has a `Filter` submodule to assist with defining these actions.
|
||||||
|
|
||||||
```fsharp
|
```fsharp
|
||||||
let shiftClick =
|
let shiftClick =
|
||||||
p [ _hxGet = "/something"; _hxTrigger (HxTrigger.Filter.Shift HxTrigger.Click) ] [
|
p [ _hxGet = "/something"; _hxTrigger (HxTrigger.Filter.Shift HxTrigger.Click) ] [
|
||||||
str "hold down Shift and click me"
|
str "hold down Shift and click me"
|
||||||
]
|
]
|
||||||
```
|
```
|
||||||
|
|
||||||
If you want to load htmx from unpkg, `Htmx.Script.minified` or `Htmx.Script.unminified` can be used to load the script in your HTML trees.
|
If you want to load htmx from unpkg, `Htmx.Script.minified` or `Htmx.Script.unminified` can be used to load the script in your HTML trees.
|
||||||
|
|
||||||
## Feedback / Help
|
## Feedback / Help
|
||||||
|
|
||||||
The author hangs out in the #dotnet-htmx channel (and most others) of the [htmx Discord server](https://htmx.org/discord) and the #web channel of the [F# Software Foundation's Slack server](https://fsharp.org/guides/slack/).
|
The author hangs out in the #htmx-general channel of the [htmx Discord server](https://htmx.org/discord) and the #web channel of the [F# Software Foundation's Slack server](https://fsharp.org/guides/slack/).
|
||||||
|
|
||||||
## Thanks
|
## Thanks
|
||||||
|[<img src="https://giraffe.wiki/giraffe.png" alt="Giraffe logo" width="200">](https://giraffe.wiki)| [<img src="https://bitbadger.solutions/upload/bit-badger/2024/01/htmx-black-transparent.svg" alt="htmx logo" width="200">](https://htmx.org) |[<img src="https://resources.jetbrains.com/storage/products/company/brand/logos/jb_beam.png" alt="JetBrains Logo (Main)" width="200">](https://jb.gg/OpenSource)|
|
|[<img src="https://giraffe.wiki/giraffe.png" alt="Giraffe logo" width="200">](https://giraffe.wiki)|[<img src="https://bitbadger.solutions/htmx-black-transparent.svg" alt="htmx logo" width="200">](https://htmx.org)|[<img src="https://resources.jetbrains.com/storage/products/company/brand/logos/jb_beam.png" alt="JetBrains Logo (Main)" width="200">](https://jb.gg/OpenSource)|
|
||||||
| :---: |:------------------------------------------------------------------------------------------------------------------------------------:| :---: |
|
| :---: | :---: | :---: |
|
||||||
|for making ASP.NET Core functional| for making HTML cool again |for licensing their tools to this project|
|
|for making ASP.NET Core functional|for making HTML cool again|for licensing their tools to this project|
|
||||||
|
|
||||||
|
|
|
@ -9,11 +9,6 @@
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Include="Common.fs" />
|
<Compile Include="Common.fs" />
|
||||||
<None Include="README.md" Pack="true" PackagePath="\" />
|
<None Include="README.md" Pack="true" PackagePath="\" />
|
||||||
<None Include="..\icon.png" Pack="true" PackagePath="\" />
|
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<PackageReference Update="FSharp.Core" Version="6.0.0" />
|
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|
|
@ -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.
|
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: 2.0.3**
|
**htmx version: 1.9.4**
|
||||||
|
|
|
@ -1,17 +1,17 @@
|
||||||
<?xml version="1.0" encoding="utf-8" standalone="no"?>
|
<?xml version="1.0" encoding="utf-8" standalone="no"?>
|
||||||
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFrameworks>net6.0;net8.0</TargetFrameworks>
|
<TargetFrameworks>net6.0;net7.0</TargetFrameworks>
|
||||||
<VersionPrefix>2.0.3</VersionPrefix>
|
<VersionPrefix>1.9.4</VersionPrefix>
|
||||||
<PackageReleaseNotes>Update script tags to pull htmx 2.0.3 (no header or attribute changes)</PackageReleaseNotes>
|
<PackageReleaseNotes>Update script tags to pull htmx 1.9.4</PackageReleaseNotes>
|
||||||
<Authors>danieljsummers</Authors>
|
<Authors>danieljsummers</Authors>
|
||||||
<Company>Bit Badger Solutions</Company>
|
<Company>Bit Badger Solutions</Company>
|
||||||
<PackageProjectUrl>https://git.bitbadger.solutions/bit-badger/Giraffe.Htmx</PackageProjectUrl>
|
<PackageProjectUrl>https://github.com/bit-badger/Giraffe.Htmx</PackageProjectUrl>
|
||||||
<PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance>
|
<PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance>
|
||||||
<RepositoryUrl>https://git.bitbadger.solutions/bit-badger/Giraffe.Htmx</RepositoryUrl>
|
<RepositoryUrl>https://github.com/bit-badger/Giraffe.Htmx</RepositoryUrl>
|
||||||
<RepositoryType>Git</RepositoryType>
|
<RepositoryType>Git</RepositoryType>
|
||||||
<Copyright>MIT License</Copyright>
|
<Copyright>MIT License</Copyright>
|
||||||
<PackageLicenseExpression>MIT</PackageLicenseExpression>
|
<PackageLicenseExpression>MIT</PackageLicenseExpression>
|
||||||
<PackageTags>Giraffe htmx</PackageTags>
|
<PackageTags>Giraffe htmx</PackageTags>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
</Project>
|
</Project>
|
|
@ -9,12 +9,10 @@
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Include="Htmx.fs" />
|
<Compile Include="Htmx.fs" />
|
||||||
<None Include="README.md" Pack="true" PackagePath="\" />
|
<None Include="README.md" Pack="true" PackagePath="\" />
|
||||||
<None Include="..\icon.png" Pack="true" PackagePath="\" />
|
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Giraffe" Version="6.4.0" />
|
<PackageReference Include="Giraffe" Version="5.0.0" />
|
||||||
<PackageReference Update="FSharp.Core" Version="6.0.0" />
|
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|
|
@ -2,9 +2,7 @@
|
||||||
|
|
||||||
This package enables server-side support for [htmx](https://htmx.org) within [Giraffe](https://giraffe.wiki) and ASP.NET's `HttpContext`.
|
This package enables server-side support for [htmx](https://htmx.org) within [Giraffe](https://giraffe.wiki) and ASP.NET's `HttpContext`.
|
||||||
|
|
||||||
**htmx version: 2.0.3**
|
**htmx version: 1.9.4**
|
||||||
|
|
||||||
_Upgrading from v1.x: the [migration guide](https://htmx.org/migration-guide-htmx-1/) does not currently specify any request or response header changes. This means that there are no required code changes in moving from v1.* to v2.*._
|
|
||||||
|
|
||||||
### Setup
|
### Setup
|
||||||
|
|
||||||
|
@ -16,20 +14,20 @@ _Upgrading from v1.x: the [migration guide](https://htmx.org/migration-guide-htm
|
||||||
To obtain a request header, using the `IHeaderDictionary` extension properties:
|
To obtain a request header, using the `IHeaderDictionary` extension properties:
|
||||||
|
|
||||||
```fsharp
|
```fsharp
|
||||||
let myHandler : HttpHander =
|
let myHandler : HttpHander =
|
||||||
fun next ctx ->
|
fun next ctx ->
|
||||||
match ctx.HxPrompt with
|
match ctx.HxPrompt with
|
||||||
| Some prompt -> ... // do something with the text the user provided
|
| Some prompt -> ... // do something with the text the user provided
|
||||||
| None -> ... // no text provided
|
| None -> ... // no text provided
|
||||||
```
|
```
|
||||||
|
|
||||||
To set a response header:
|
To set a response header:
|
||||||
|
|
||||||
```fsharp
|
```fsharp
|
||||||
let myHandler : HttpHander =
|
let myHandler : HttpHander =
|
||||||
fun next ctx ->
|
fun next ctx ->
|
||||||
// some meaningful work
|
// some meaningful work
|
||||||
withHxPushUrl "/some/new/url" >=> [other handlers]
|
withHxPushUrl "/some/new/url" >=> [other handlers]
|
||||||
```
|
```
|
||||||
|
|
||||||
The `HxSwap` module has constants to use for the `HX-Reswap` header. These may be extended with settle, show, and other qualifiers; see the htmx documentation for the `hx-swap` attribute for more information.
|
The `HxSwap` module has constants to use for the `HX-Reswap` header. These may be extended with settle, show, and other qualifiers; see the htmx documentation for the `hx-swap` attribute for more information.
|
||||||
|
|
|
@ -3,4 +3,4 @@ open Expecto
|
||||||
let allTests = testList "Giraffe" [ Common.allTests; Htmx.allTests; ViewEngine.allTests ]
|
let allTests = testList "Giraffe" [ Common.allTests; Htmx.allTests; ViewEngine.allTests ]
|
||||||
|
|
||||||
[<EntryPoint>]
|
[<EntryPoint>]
|
||||||
let main args = runTestsWithCLIArgs [] args allTests
|
let main args = runTestsWithArgs defaultConfig args allTests
|
||||||
|
|
|
@ -18,9 +18,8 @@
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Expecto" Version="10.2.1" />
|
<PackageReference Include="Expecto" Version="9.0.4" />
|
||||||
<PackageReference Include="NSubstitute" Version="5.1.0" />
|
<PackageReference Include="NSubstitute" Version="5.0.0" />
|
||||||
<PackageReference Update="FSharp.Core" Version="8.0.300" />
|
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|
|
@ -15,399 +15,6 @@ let hxEncoding =
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
||||||
let hxEvent =
|
|
||||||
testList "HxEvent" [
|
|
||||||
testList "Abort" [
|
|
||||||
test "ToString succeeds" {
|
|
||||||
Expect.equal (string Abort) "abort" "Abort event name not correct"
|
|
||||||
}
|
|
||||||
test "ToHxOnString succeeds" {
|
|
||||||
Expect.equal (Abort.ToHxOnString()) "abort" "Abort hx-on event name not correct"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
testList "AfterOnLoad" [
|
|
||||||
test "ToString succeeds" {
|
|
||||||
Expect.equal (string AfterOnLoad) "afterOnLoad" "AfterOnLoad event name not correct"
|
|
||||||
}
|
|
||||||
test "ToHxOnString succeeds" {
|
|
||||||
Expect.equal (AfterOnLoad.ToHxOnString()) "after-on-load" "AfterOnLoad hx-on event name not correct"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
testList "AfterProcessNode" [
|
|
||||||
test "ToString succeeds" {
|
|
||||||
Expect.equal (string AfterProcessNode) "afterProcessNode" "AfterProcessNode event name not correct"
|
|
||||||
}
|
|
||||||
test "ToHxOnString succeeds" {
|
|
||||||
Expect.equal
|
|
||||||
(AfterProcessNode.ToHxOnString())
|
|
||||||
"after-process-node"
|
|
||||||
"AfterProcessNode hx-on event name not correct"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
testList "AfterRequest" [
|
|
||||||
test "ToString succeeds" {
|
|
||||||
Expect.equal (string AfterRequest) "afterRequest" "AfterRequest event name not correct"
|
|
||||||
}
|
|
||||||
test "ToHxOnString succeeds" {
|
|
||||||
Expect.equal (AfterRequest.ToHxOnString()) "after-request" "AfterRequest hx-on event name not correct"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
testList "AfterSettle" [
|
|
||||||
test "ToString succeeds" {
|
|
||||||
Expect.equal (string AfterSettle) "afterSettle" "AfterSettle event name not correct"
|
|
||||||
}
|
|
||||||
test "ToHxOnString succeeds" {
|
|
||||||
Expect.equal (AfterSettle.ToHxOnString()) "after-settle" "AfterSettle hx-on event name not correct"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
testList "AfterSwap" [
|
|
||||||
test "ToString succeeds" {
|
|
||||||
Expect.equal (string AfterSwap) "afterSwap" "AfterSwap event name not correct"
|
|
||||||
}
|
|
||||||
test "ToHxOnString succeeds" {
|
|
||||||
Expect.equal (AfterSwap.ToHxOnString()) "after-swap" "AfterSwap hx-on event name not correct"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
testList "BeforeCleanupElement" [
|
|
||||||
test "ToString succeeds" {
|
|
||||||
Expect.equal
|
|
||||||
(string BeforeCleanupElement) "beforeCleanupElement" "BeforeCleanupElement event name not correct"
|
|
||||||
}
|
|
||||||
test "ToHxOnString succeeds" {
|
|
||||||
Expect.equal
|
|
||||||
(BeforeCleanupElement.ToHxOnString())
|
|
||||||
"before-cleanup-element"
|
|
||||||
"BeforeCleanupElement hx-on event name not correct"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
testList "BeforeOnLoad" [
|
|
||||||
test "ToString succeeds" {
|
|
||||||
Expect.equal (string BeforeOnLoad) "beforeOnLoad" "BeforeOnLoad event name not correct"
|
|
||||||
}
|
|
||||||
test "ToHxOnString succeeds" {
|
|
||||||
Expect.equal (BeforeOnLoad.ToHxOnString()) "before-on-load" "BeforeOnLoad hx-on event name not correct"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
testList "BeforeProcessNode" [
|
|
||||||
test "ToString succeeds" {
|
|
||||||
Expect.equal (string BeforeProcessNode) "beforeProcessNode" "BeforeProcessNode event name not correct"
|
|
||||||
}
|
|
||||||
test "ToHxOnString succeeds" {
|
|
||||||
Expect.equal
|
|
||||||
(BeforeProcessNode.ToHxOnString())
|
|
||||||
"before-process-node"
|
|
||||||
"BeforeProcessNode hx-on event name not correct"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
testList "BeforeRequest" [
|
|
||||||
test "ToString succeeds" {
|
|
||||||
Expect.equal (string BeforeRequest) "beforeRequest" "BeforeRequest event name not correct"
|
|
||||||
}
|
|
||||||
test "ToHxOnString succeeds" {
|
|
||||||
Expect.equal
|
|
||||||
(BeforeRequest.ToHxOnString()) "before-request" "BeforeRequest hx-on event name not correct"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
testList "BeforeSwap" [
|
|
||||||
test "ToString succeeds" {
|
|
||||||
Expect.equal (string BeforeSwap) "beforeSwap" "BeforeSwap event name not correct"
|
|
||||||
}
|
|
||||||
test "ToHxOnString succeeds" {
|
|
||||||
Expect.equal (BeforeSwap.ToHxOnString()) "before-swap" "BeforeSwap hx-on event name not correct"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
testList "BeforeSend" [
|
|
||||||
test "ToString succeeds" {
|
|
||||||
Expect.equal (string BeforeSend) "beforeSend" "BeforeSend event name not correct"
|
|
||||||
}
|
|
||||||
test "ToHxOnString succeeds" {
|
|
||||||
Expect.equal (BeforeSend.ToHxOnString()) "before-send" "BeforeSend hx-on event name not correct"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
testList "ConfigRequest" [
|
|
||||||
test "ToString succeeds" {
|
|
||||||
Expect.equal (string ConfigRequest) "configRequest" "ConfigRequest event name not correct"
|
|
||||||
}
|
|
||||||
test "ToHxOnString succeeds" {
|
|
||||||
Expect.equal
|
|
||||||
(ConfigRequest.ToHxOnString()) "config-request" "ConfigRequest hx-on event name not correct"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
testList "Confirm" [
|
|
||||||
test "ToString succeeds" {
|
|
||||||
Expect.equal (string Confirm) "confirm" "Confirm event name not correct"
|
|
||||||
}
|
|
||||||
test "ToHxOnString succeeds" {
|
|
||||||
Expect.equal (Confirm.ToHxOnString()) "confirm" "Confirm hx-on event name not correct"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
testList "HistoryCacheError" [
|
|
||||||
test "ToString succeeds" {
|
|
||||||
Expect.equal (string HistoryCacheError) "historyCacheError" "HistoryCacheError event name not correct"
|
|
||||||
}
|
|
||||||
test "ToHxOnString succeeds" {
|
|
||||||
Expect.equal
|
|
||||||
(HistoryCacheError.ToHxOnString())
|
|
||||||
"history-cache-error"
|
|
||||||
"HistoryCacheError hx-on event name not correct"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
testList "HistoryCacheMiss" [
|
|
||||||
test "ToString succeeds" {
|
|
||||||
Expect.equal (string HistoryCacheMiss) "historyCacheMiss" "HistoryCacheMiss event name not correct"
|
|
||||||
}
|
|
||||||
test "ToHxOnString succeeds" {
|
|
||||||
Expect.equal
|
|
||||||
(HistoryCacheMiss.ToHxOnString())
|
|
||||||
"history-cache-miss"
|
|
||||||
"HistoryCacheMiss hx-on event name not correct"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
testList "HistoryCacheMissError" [
|
|
||||||
test "ToString succeeds" {
|
|
||||||
Expect.equal
|
|
||||||
(string HistoryCacheMissError)
|
|
||||||
"historyCacheMissError"
|
|
||||||
"HistoryCacheMissError event name not correct"
|
|
||||||
}
|
|
||||||
test "ToHxOnString succeeds" {
|
|
||||||
Expect.equal
|
|
||||||
(HistoryCacheMissError.ToHxOnString())
|
|
||||||
"history-cache-miss-error"
|
|
||||||
"HistoryCacheMissError hx-on event name not correct"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
testList "HistoryCacheMissLoad" [
|
|
||||||
test "ToString succeeds" {
|
|
||||||
Expect.equal
|
|
||||||
(string HistoryCacheMissLoad) "historyCacheMissLoad" "HistoryCacheMissLoad event name not correct"
|
|
||||||
}
|
|
||||||
test "ToHxOnString succeeds" {
|
|
||||||
Expect.equal
|
|
||||||
(HistoryCacheMissLoad.ToHxOnString())
|
|
||||||
"history-cache-miss-load"
|
|
||||||
"HistoryCacheMissLoad hx-on event name not correct"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
testList "HistoryRestore" [
|
|
||||||
test "ToString succeeds" {
|
|
||||||
Expect.equal (string HistoryRestore) "historyRestore" "HistoryRestore event name not correct"
|
|
||||||
}
|
|
||||||
test "ToHxOnString succeeds" {
|
|
||||||
Expect.equal
|
|
||||||
(HistoryRestore.ToHxOnString()) "history-restore" "HistoryRestore hx-on event name not correct"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
testList "BeforeHistorySave" [
|
|
||||||
test "ToString succeeds" {
|
|
||||||
Expect.equal (string BeforeHistorySave) "beforeHistorySave" "BeforeHistorySave event name not correct"
|
|
||||||
}
|
|
||||||
test "ToHxOnString succeeds" {
|
|
||||||
Expect.equal
|
|
||||||
(BeforeHistorySave.ToHxOnString())
|
|
||||||
"before-history-save"
|
|
||||||
"BeforeHistorySave hx-on event name not correct"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
testList "Load" [
|
|
||||||
test "ToString succeeds" {
|
|
||||||
Expect.equal (string Load) "load" "Load event name not correct"
|
|
||||||
}
|
|
||||||
test "ToHxOnString succeeds" {
|
|
||||||
Expect.equal (Load.ToHxOnString()) "load" "Load hx-on event name not correct"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
testList "NoSseSourceError" [
|
|
||||||
test "ToString succeeds" {
|
|
||||||
Expect.equal (string NoSseSourceError) "noSSESourceError" "NoSseSourceError event name not correct"
|
|
||||||
}
|
|
||||||
test "ToHxOnString succeeds" {
|
|
||||||
Expect.equal
|
|
||||||
(NoSseSourceError.ToHxOnString())
|
|
||||||
"no-sse-source-error"
|
|
||||||
"NoSseSourceError hx-on event name not correct"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
testList "OnLoadError" [
|
|
||||||
test "ToString succeeds" {
|
|
||||||
Expect.equal (string OnLoadError) "onLoadError" "OnLoadError event name not correct"
|
|
||||||
}
|
|
||||||
test "ToHxOnString succeeds" {
|
|
||||||
Expect.equal (OnLoadError.ToHxOnString()) "on-load-error" "OnLoadError hx-on event name not correct"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
testList "OobAfterSwap" [
|
|
||||||
test "ToString succeeds" {
|
|
||||||
Expect.equal (string OobAfterSwap) "oobAfterSwap" "OobAfterSwap event name not correct"
|
|
||||||
}
|
|
||||||
test "ToHxOnString succeeds" {
|
|
||||||
Expect.equal (OobAfterSwap.ToHxOnString()) "oob-after-swap" "OobAfterSwap hx-on event name not correct"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
testList "OobBeforeSwap" [
|
|
||||||
test "ToString succeeds" {
|
|
||||||
Expect.equal (string OobBeforeSwap) "oobBeforeSwap" "OobBeforeSwap event name not correct"
|
|
||||||
}
|
|
||||||
test "ToHxOnString succeeds" {
|
|
||||||
Expect.equal
|
|
||||||
(OobBeforeSwap.ToHxOnString()) "oob-before-swap" "OobBeforeSwap hx-on event name not correct"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
testList "OobErrorNoTarget" [
|
|
||||||
test "ToString succeeds" {
|
|
||||||
Expect.equal (string OobErrorNoTarget) "oobErrorNoTarget" "OobErrorNoTarget event name not correct"
|
|
||||||
}
|
|
||||||
test "ToHxOnString succeeds" {
|
|
||||||
Expect.equal
|
|
||||||
(OobErrorNoTarget.ToHxOnString())
|
|
||||||
"oob-error-no-target"
|
|
||||||
"OobErrorNoTarget hx-on event name not correct"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
testList "Prompt" [
|
|
||||||
test "ToString succeeds" {
|
|
||||||
Expect.equal (string Prompt) "prompt" "Prompt event name not correct"
|
|
||||||
}
|
|
||||||
test "ToHxOnString succeeds" {
|
|
||||||
Expect.equal (Prompt.ToHxOnString()) "prompt" "Prompt hx-on event name not correct"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
testList "PushedIntoHistory" [
|
|
||||||
test "ToString succeeds" {
|
|
||||||
Expect.equal (string PushedIntoHistory) "pushedIntoHistory" "PushedIntoHistory event name not correct"
|
|
||||||
}
|
|
||||||
test "ToHxOnString succeeds" {
|
|
||||||
Expect.equal
|
|
||||||
(PushedIntoHistory.ToHxOnString())
|
|
||||||
"pushed-into-history"
|
|
||||||
"PushedIntoHistory hx-on event name not correct"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
testList "ResponseError" [
|
|
||||||
test "ToString succeeds" {
|
|
||||||
Expect.equal (string ResponseError) "responseError" "ResponseError event name not correct"
|
|
||||||
}
|
|
||||||
test "ToHxOnString succeeds" {
|
|
||||||
Expect.equal
|
|
||||||
(ResponseError.ToHxOnString()) "response-error" "ResponseError hx-on event name not correct"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
testList "SendError" [
|
|
||||||
test "ToString succeeds" {
|
|
||||||
Expect.equal (string SendError) "sendError" "SendError event name not correct"
|
|
||||||
}
|
|
||||||
test "ToHxOnString succeeds" {
|
|
||||||
Expect.equal (SendError.ToHxOnString()) "send-error" "SendError hx-on event name not correct"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
testList "SseError" [
|
|
||||||
test "ToString succeeds" {
|
|
||||||
Expect.equal (string SseError) "sseError" "SseError event name not correct"
|
|
||||||
}
|
|
||||||
test "ToHxOnString succeeds" {
|
|
||||||
Expect.equal (SseError.ToHxOnString()) "sse-error" "SseError hx-on event name not correct"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
testList "SseOpen" [
|
|
||||||
test "ToString succeeds" {
|
|
||||||
Expect.equal (string SseOpen) "sseOpen" "SseOpen event name not correct"
|
|
||||||
}
|
|
||||||
test "ToHxOnString succeeds" {
|
|
||||||
Expect.equal (SseOpen.ToHxOnString()) "sse-open" "SseOpen hx-on event name not correct"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
testList "SwapError" [
|
|
||||||
test "ToString succeeds" {
|
|
||||||
Expect.equal (string SwapError) "swapError" "SwapError event name not correct"
|
|
||||||
}
|
|
||||||
test "ToHxOnString succeeds" {
|
|
||||||
Expect.equal (SwapError.ToHxOnString()) "swap-error" "SwapError hx-on event name not correct"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
testList "TargetError" [
|
|
||||||
test "ToString succeeds" {
|
|
||||||
Expect.equal (string TargetError) "targetError" "TargetError event name not correct"
|
|
||||||
}
|
|
||||||
test "ToHxOnString succeeds" {
|
|
||||||
Expect.equal (TargetError.ToHxOnString()) "target-error" "TargetError hx-on event name not correct"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
testList "Timeout" [
|
|
||||||
test "ToString succeeds" {
|
|
||||||
Expect.equal (string Timeout) "timeout" "Timeout event name not correct"
|
|
||||||
}
|
|
||||||
test "ToHxOnString succeeds" {
|
|
||||||
Expect.equal (Timeout.ToHxOnString()) "timeout" "Timeout hx-on event name not correct"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
testList "ValidationValidate" [
|
|
||||||
test "ToString succeeds" {
|
|
||||||
Expect.equal
|
|
||||||
(string ValidationValidate) "validation:validate" "ValidationValidate event name not correct"
|
|
||||||
}
|
|
||||||
test "ToHxOnString succeeds" {
|
|
||||||
Expect.equal
|
|
||||||
(ValidationValidate.ToHxOnString())
|
|
||||||
"validation:validate"
|
|
||||||
"ValidationValidate hx-on event name not correct"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
testList "ValidationFailed" [
|
|
||||||
test "ToString succeeds" {
|
|
||||||
Expect.equal (string ValidationFailed) "validation:failed" "ValidationFailed event name not correct"
|
|
||||||
}
|
|
||||||
test "ToHxOnString succeeds" {
|
|
||||||
Expect.equal
|
|
||||||
(ValidationFailed.ToHxOnString())
|
|
||||||
"validation:failed"
|
|
||||||
"ValidationFailed hx-on event name not correct"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
testList "ValidationHalted" [
|
|
||||||
test "ToString succeeds" {
|
|
||||||
Expect.equal (string ValidationHalted) "validation:halted" "ValidationHalted event name not correct"
|
|
||||||
}
|
|
||||||
test "ToHxOnString succeeds" {
|
|
||||||
Expect.equal
|
|
||||||
(ValidationHalted.ToHxOnString())
|
|
||||||
"validation:halted"
|
|
||||||
"ValidationHalted hx-on event name not correct"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
testList "XhrAbort" [
|
|
||||||
test "ToString succeeds" {
|
|
||||||
Expect.equal (string XhrAbort) "xhr:abort" "XhrAbort event name not correct"
|
|
||||||
}
|
|
||||||
test "ToHxOnString succeeds" {
|
|
||||||
Expect.equal (XhrAbort.ToHxOnString()) "xhr:abort" "XhrAbort hx-on event name not correct"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
testList "XhrLoadEnd" [
|
|
||||||
test "ToString succeeds" {
|
|
||||||
Expect.equal (string XhrLoadEnd) "xhr:loadend" "XhrLoadEnd event name not correct"
|
|
||||||
}
|
|
||||||
test "ToHxOnString succeeds" {
|
|
||||||
Expect.equal (XhrLoadEnd.ToHxOnString()) "xhr:loadend" "XhrLoadEnd hx-on event name not correct"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
testList "XhrLoadStart" [
|
|
||||||
test "ToString succeeds" {
|
|
||||||
Expect.equal (string XhrLoadStart) "xhr:loadstart" "XhrLoadStart event name not correct"
|
|
||||||
}
|
|
||||||
test "ToHxOnString succeeds" {
|
|
||||||
Expect.equal (XhrLoadStart.ToHxOnString()) "xhr:loadstart" "XhrLoadStart hx-on event name not correct"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
testList "XhrProgress" [
|
|
||||||
test "ToString succeeds" {
|
|
||||||
Expect.equal (string XhrProgress) "xhr:progress" "XhrProgress event name not correct"
|
|
||||||
}
|
|
||||||
test "ToHxOnString succeeds" {
|
|
||||||
Expect.equal (XhrProgress.ToHxOnString()) "xhr:progress" "XhrProgress hx-on event name not correct"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
|
|
||||||
]
|
|
||||||
/// Tests for the HxHeaders module
|
/// Tests for the HxHeaders module
|
||||||
let hxHeaders =
|
let hxHeaders =
|
||||||
testList "HxHeaders" [
|
testList "HxHeaders" [
|
||||||
|
@ -686,14 +293,14 @@ let hxVals =
|
||||||
]
|
]
|
||||||
]
|
]
|
||||||
|
|
||||||
/// Pipe-able assertion for a rendered node
|
|
||||||
let shouldRender expected node =
|
|
||||||
Expect.equal (RenderView.AsString.htmlNode node) expected "Rendered HTML incorrect"
|
|
||||||
|
|
||||||
/// Tests for the HtmxAttrs module
|
/// Tests for the HtmxAttrs module
|
||||||
let attributes =
|
let attributes =
|
||||||
testList "Attributes" [
|
testList "Attributes" [
|
||||||
|
|
||||||
|
/// Pipe-able assertion for a rendered node
|
||||||
|
let shouldRender expected node =
|
||||||
|
Expect.equal (RenderView.AsString.htmlNode node) expected "Rendered HTML incorrect"
|
||||||
|
|
||||||
test "_hxBoost succeeds" {
|
test "_hxBoost succeeds" {
|
||||||
div [ _hxBoost ] [] |> shouldRender """<div hx-boost="true"></div>"""
|
div [ _hxBoost ] [] |> shouldRender """<div hx-boost="true"></div>"""
|
||||||
}
|
}
|
||||||
|
@ -706,9 +313,6 @@ let attributes =
|
||||||
test "_hxDisable succeeds" {
|
test "_hxDisable succeeds" {
|
||||||
p [ _hxDisable ] [] |> shouldRender """<p hx-disable></p>"""
|
p [ _hxDisable ] [] |> shouldRender """<p hx-disable></p>"""
|
||||||
}
|
}
|
||||||
test "_hxDisabledElt succeeds" {
|
|
||||||
button [ _hxDisabledElt "this" ] [] |> shouldRender """<button hx-disabled-elt="this"></button>"""
|
|
||||||
}
|
|
||||||
test "_hxDisinherit succeeds" {
|
test "_hxDisinherit succeeds" {
|
||||||
strong [ _hxDisinherit "*" ] [] |> shouldRender """<strong hx-disinherit="*"></strong>"""
|
strong [ _hxDisinherit "*" ] [] |> shouldRender """<strong hx-disinherit="*"></strong>"""
|
||||||
}
|
}
|
||||||
|
@ -740,12 +344,10 @@ let attributes =
|
||||||
test "_hxNoBoost succeeds" {
|
test "_hxNoBoost succeeds" {
|
||||||
td [ _hxNoBoost ] [] |> shouldRender """<td hx-boost="false"></td>"""
|
td [ _hxNoBoost ] [] |> shouldRender """<td hx-boost="false"></td>"""
|
||||||
}
|
}
|
||||||
test "_hxOnEvent succeeds" {
|
test "_hxOn succeeds" {
|
||||||
a [ _hxOnEvent "click" "doThis()" ] [] |> shouldRender """<a hx-on:click="doThis()"></a>"""
|
let newLine = "\n"
|
||||||
}
|
strong [ _hxOn "submit: alert('oops')\nclick: alert('howdy!')" ] []
|
||||||
test "_hxOnHxEvent succeeds" {
|
|> shouldRender $"""<strong hx-on="submit: alert('oops'){newLine}click: alert('howdy!')"></strong>"""
|
||||||
strong [ _hxOnHxEvent BeforeSwap "changeStuff()" ] []
|
|
||||||
|> shouldRender """<strong hx-on::before-swap="changeStuff()"></strong>"""
|
|
||||||
}
|
}
|
||||||
test "_hxParams succeeds" {
|
test "_hxParams succeeds" {
|
||||||
br [ _hxParams "[p1,p2]" ] |> shouldRender """<br hx-params="[p1,p2]">"""
|
br [ _hxParams "[p1,p2]" ] |> shouldRender """<br hx-params="[p1,p2]">"""
|
||||||
|
@ -781,6 +383,10 @@ let attributes =
|
||||||
test "_hxSelectOob succeeds" {
|
test "_hxSelectOob succeeds" {
|
||||||
section [ _hxSelectOob "#oob" ] [] |> shouldRender """<section hx-select-oob="#oob"></section>"""
|
section [ _hxSelectOob "#oob" ] [] |> shouldRender """<section hx-select-oob="#oob"></section>"""
|
||||||
}
|
}
|
||||||
|
test "_hxSse succeeds" {
|
||||||
|
footer [ _hxSse "connect:/my-events" ] []
|
||||||
|
|> shouldRender """<footer hx-sse="connect:/my-events"></footer>"""
|
||||||
|
}
|
||||||
test "_hxSwap succeeds" {
|
test "_hxSwap succeeds" {
|
||||||
del [ _hxSwap "innerHTML" ] [] |> shouldRender """<del hx-swap="innerHTML"></del>"""
|
del [ _hxSwap "innerHTML" ] [] |> shouldRender """<del hx-swap="innerHTML"></del>"""
|
||||||
}
|
}
|
||||||
|
@ -804,11 +410,8 @@ let attributes =
|
||||||
dt [ _hxVals """{ "extra": "values" }""" ] []
|
dt [ _hxVals """{ "extra": "values" }""" ] []
|
||||||
|> shouldRender """<dt hx-vals="{ "extra": "values" }"></dt>"""
|
|> shouldRender """<dt hx-vals="{ "extra": "values" }"></dt>"""
|
||||||
}
|
}
|
||||||
test "_sseSwap succeeds" {
|
test "_hxWs succeeds" {
|
||||||
ul [ _sseSwap "sseMessageName" ] [] |> shouldRender """<ul sse-swap="sseMessageName"></ul>"""
|
ul [ _hxWs "connect:/web-socket" ] [] |> shouldRender """<ul hx-ws="connect:/web-socket"></ul>"""
|
||||||
}
|
|
||||||
test "_sseConnect succeeds" {
|
|
||||||
div [ _sseConnect "/gps/sse" ] [] |> shouldRender """<div sse-connect="/gps/sse"></div>"""
|
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@ -819,14 +422,14 @@ let script =
|
||||||
let html = RenderView.AsString.htmlNode Script.minified
|
let html = RenderView.AsString.htmlNode Script.minified
|
||||||
Expect.equal
|
Expect.equal
|
||||||
html
|
html
|
||||||
"""<script src="https://unpkg.com/htmx.org@2.0.3" integrity="sha384-0895/pl2MU10Hqc6jd4RvrthNlDiE9U1tWmX7WRESftEDRosgxNsQG/Ze9YMRzHq" crossorigin="anonymous"></script>"""
|
"""<script src="https://unpkg.com/htmx.org@1.9.4" integrity="sha384-zUfuhFKKZCbHTY6aRR46gxiqszMk5tcHjsVFxnUo8VMus4kHGVdIYVbOYYNlKmHV" crossorigin="anonymous"></script>"""
|
||||||
"Minified script tag is incorrect"
|
"Minified script tag is incorrect"
|
||||||
}
|
}
|
||||||
test "unminified succeeds" {
|
test "unminified succeeds" {
|
||||||
let html = RenderView.AsString.htmlNode Script.unminified
|
let html = RenderView.AsString.htmlNode Script.unminified
|
||||||
Expect.equal
|
Expect.equal
|
||||||
html
|
html
|
||||||
"""<script src="https://unpkg.com/htmx.org@2.0.3/dist/htmx.js" integrity="sha384-BBDmZzVt6vjz5YbQqZPtFZW82o8QotoM7RUp5xOxV3nSJ8u2pSdtzFAbGKzTlKtg" crossorigin="anonymous"></script>"""
|
"""<script src="https://unpkg.com/htmx.org@1.9.4/dist/htmx.js" integrity="sha384-2caa3Jf+wayjuHAc9J3mR3xz191GzmIDNYVBsE8LetbkJn4wjLrO6Ht9rRMuEjIo" crossorigin="anonymous"></script>"""
|
||||||
"Unminified script tag is incorrect"
|
"Unminified script tag is incorrect"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
@ -980,15 +583,5 @@ let renderFragment =
|
||||||
|
|
||||||
/// All tests in this module
|
/// All tests in this module
|
||||||
let allTests =
|
let allTests =
|
||||||
testList "ViewEngine.Htmx" [
|
testList "ViewEngine.Htmx"
|
||||||
hxEncoding
|
[ hxEncoding; hxHeaders; hxParams; hxRequest; hxTrigger; hxVals; attributes; script; renderFragment ]
|
||||||
hxEvent
|
|
||||||
hxHeaders
|
|
||||||
hxParams
|
|
||||||
hxRequest
|
|
||||||
hxTrigger
|
|
||||||
hxVals
|
|
||||||
attributes
|
|
||||||
script
|
|
||||||
renderFragment
|
|
||||||
]
|
|
||||||
|
|
|
@ -9,12 +9,10 @@
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Include="Htmx.fs" />
|
<Compile Include="Htmx.fs" />
|
||||||
<None Include="README.md" Pack="true" PackagePath="\" />
|
<None Include="README.md" Pack="true" PackagePath="\" />
|
||||||
<None Include="..\icon.png" Pack="true" PackagePath="\" />
|
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Giraffe.ViewEngine" Version="1.4.0" />
|
<PackageReference Include="Giraffe.ViewEngine" Version="1.4.0" />
|
||||||
<PackageReference Update="FSharp.Core" Version="6.0.0" />
|
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|
|
@ -19,147 +19,6 @@ module HxEncoding =
|
||||||
let MultipartForm = "multipart/form-data"
|
let MultipartForm = "multipart/form-data"
|
||||||
|
|
||||||
|
|
||||||
/// The events recognized by htmx
|
|
||||||
[<Struct>]
|
|
||||||
type HxEvent =
|
|
||||||
/// Send this event to an element to abort a request
|
|
||||||
| Abort
|
|
||||||
/// Triggered after an AJAX request has completed processing a successful response
|
|
||||||
| AfterOnLoad
|
|
||||||
/// Triggered after htmx has initialized a node
|
|
||||||
| AfterProcessNode
|
|
||||||
/// Triggered after an AJAX request has completed
|
|
||||||
| AfterRequest
|
|
||||||
/// Triggered after the DOM has settled
|
|
||||||
| AfterSettle
|
|
||||||
/// Triggered after new content has been swapped in
|
|
||||||
| AfterSwap
|
|
||||||
/// Triggered before htmx disables an element or removes it from the DOM
|
|
||||||
| BeforeCleanupElement
|
|
||||||
/// Triggered before any response processing occurs
|
|
||||||
| BeforeOnLoad
|
|
||||||
/// Triggered before htmx initializes a node
|
|
||||||
| BeforeProcessNode
|
|
||||||
/// Triggered before an AJAX request is made
|
|
||||||
| BeforeRequest
|
|
||||||
/// Triggered before a swap is done, allows you to configure the swap
|
|
||||||
| BeforeSwap
|
|
||||||
/// Triggered just before an ajax request is sent
|
|
||||||
| BeforeSend
|
|
||||||
/// Triggered before the request, allows you to customize parameters, headers
|
|
||||||
| ConfigRequest
|
|
||||||
/// Triggered after a trigger occurs on an element, allows you to cancel (or delay) issuing the AJAX request
|
|
||||||
| Confirm
|
|
||||||
/// Triggered on an error during cache writing
|
|
||||||
| HistoryCacheError
|
|
||||||
/// Triggered on a cache miss in the history subsystem
|
|
||||||
| HistoryCacheMiss
|
|
||||||
/// Triggered on a unsuccessful remote retrieval
|
|
||||||
| HistoryCacheMissError
|
|
||||||
/// Triggered on a successful remote retrieval
|
|
||||||
| HistoryCacheMissLoad
|
|
||||||
/// Triggered when htmx handles a history restoration action
|
|
||||||
| HistoryRestore
|
|
||||||
/// Triggered before content is saved to the history cache
|
|
||||||
| BeforeHistorySave
|
|
||||||
/// Triggered when new content is added to the DOM
|
|
||||||
| Load
|
|
||||||
/// Triggered when an element refers to a SSE event in its trigger, but no parent SSE source has been defined
|
|
||||||
| NoSseSourceError
|
|
||||||
/// Triggered when an exception occurs during the onLoad handling in htmx
|
|
||||||
| OnLoadError
|
|
||||||
/// Triggered after an out of band element as been swapped in
|
|
||||||
| OobAfterSwap
|
|
||||||
/// Triggered before an out of band element swap is done, allows you to configure the swap
|
|
||||||
| OobBeforeSwap
|
|
||||||
/// Triggered when an out of band element does not have a matching ID in the current DOM
|
|
||||||
| OobErrorNoTarget
|
|
||||||
/// Triggered after a prompt is shown
|
|
||||||
| Prompt
|
|
||||||
/// Triggered after an url is pushed into history
|
|
||||||
| PushedIntoHistory
|
|
||||||
/// Triggered when an HTTP response error (non-200 or 300 response code) occurs
|
|
||||||
| ResponseError
|
|
||||||
/// Triggered when a network error prevents an HTTP request from happening
|
|
||||||
| SendError
|
|
||||||
/// Triggered when an error occurs with a SSE source
|
|
||||||
| SseError
|
|
||||||
/// Triggered when a SSE source is opened
|
|
||||||
| SseOpen
|
|
||||||
/// Triggered when an error occurs during the swap phase
|
|
||||||
| SwapError
|
|
||||||
/// Triggered when an invalid target is specified
|
|
||||||
| TargetError
|
|
||||||
/// Triggered when a request timeout occurs
|
|
||||||
| Timeout
|
|
||||||
/// Triggered before an element is validated
|
|
||||||
| ValidationValidate
|
|
||||||
/// Triggered when an element fails validation
|
|
||||||
| ValidationFailed
|
|
||||||
/// Triggered when a request is halted due to validation errors
|
|
||||||
| ValidationHalted
|
|
||||||
/// Triggered when an ajax request aborts
|
|
||||||
| XhrAbort
|
|
||||||
/// Triggered when an ajax request ends
|
|
||||||
| XhrLoadEnd
|
|
||||||
/// Triggered when an ajax request starts
|
|
||||||
| XhrLoadStart
|
|
||||||
/// Triggered periodically during an ajax request that supports progress events
|
|
||||||
| XhrProgress
|
|
||||||
|
|
||||||
/// The htmx event name (fst) and kebab-case name (snd, for use with hx-on)
|
|
||||||
static member private Values = Map [
|
|
||||||
Abort, ("abort", "abort")
|
|
||||||
AfterOnLoad, ("afterOnLoad", "after-on-load")
|
|
||||||
AfterProcessNode, ("afterProcessNode", "after-process-node")
|
|
||||||
AfterRequest, ("afterRequest", "after-request")
|
|
||||||
AfterSettle, ("afterSettle", "after-settle")
|
|
||||||
AfterSwap, ("afterSwap", "after-swap")
|
|
||||||
BeforeCleanupElement, ("beforeCleanupElement", "before-cleanup-element")
|
|
||||||
BeforeOnLoad, ("beforeOnLoad", "before-on-load")
|
|
||||||
BeforeProcessNode, ("beforeProcessNode", "before-process-node")
|
|
||||||
BeforeRequest, ("beforeRequest", "before-request")
|
|
||||||
BeforeSwap, ("beforeSwap", "before-swap")
|
|
||||||
BeforeSend, ("beforeSend", "before-send")
|
|
||||||
ConfigRequest, ("configRequest", "config-request")
|
|
||||||
Confirm, ("confirm", "confirm")
|
|
||||||
HistoryCacheError, ("historyCacheError", "history-cache-error")
|
|
||||||
HistoryCacheMiss, ("historyCacheMiss", "history-cache-miss")
|
|
||||||
HistoryCacheMissError, ("historyCacheMissError", "history-cache-miss-error")
|
|
||||||
HistoryCacheMissLoad, ("historyCacheMissLoad", "history-cache-miss-load")
|
|
||||||
HistoryRestore, ("historyRestore", "history-restore")
|
|
||||||
BeforeHistorySave, ("beforeHistorySave", "before-history-save")
|
|
||||||
Load, ("load", "load")
|
|
||||||
NoSseSourceError, ("noSSESourceError", "no-sse-source-error")
|
|
||||||
OnLoadError, ("onLoadError", "on-load-error")
|
|
||||||
OobAfterSwap, ("oobAfterSwap", "oob-after-swap")
|
|
||||||
OobBeforeSwap, ("oobBeforeSwap", "oob-before-swap")
|
|
||||||
OobErrorNoTarget, ("oobErrorNoTarget", "oob-error-no-target")
|
|
||||||
Prompt, ("prompt", "prompt")
|
|
||||||
PushedIntoHistory, ("pushedIntoHistory", "pushed-into-history")
|
|
||||||
ResponseError, ("responseError", "response-error")
|
|
||||||
SendError, ("sendError", "send-error")
|
|
||||||
SseError, ("sseError", "sse-error")
|
|
||||||
SseOpen, ("sseOpen", "sse-open")
|
|
||||||
SwapError, ("swapError", "swap-error")
|
|
||||||
TargetError, ("targetError", "target-error")
|
|
||||||
Timeout, ("timeout", "timeout")
|
|
||||||
ValidationValidate, ("validation:validate", "validation:validate")
|
|
||||||
ValidationFailed, ("validation:failed", "validation:failed")
|
|
||||||
ValidationHalted, ("validation:halted", "validation:halted")
|
|
||||||
XhrAbort, ("xhr:abort", "xhr:abort")
|
|
||||||
XhrLoadEnd, ("xhr:loadend", "xhr:loadend")
|
|
||||||
XhrLoadStart, ("xhr:loadstart", "xhr:loadstart")
|
|
||||||
XhrProgress, ("xhr:progress", "xhr:progress")
|
|
||||||
]
|
|
||||||
|
|
||||||
/// The htmx event name
|
|
||||||
override this.ToString() = fst HxEvent.Values[this]
|
|
||||||
|
|
||||||
/// The hx-on variant of the htmx event name
|
|
||||||
member this.ToHxOnString() = snd HxEvent.Values[this]
|
|
||||||
|
|
||||||
|
|
||||||
/// Helper to create the `hx-headers` attribute
|
/// Helper to create the `hx-headers` attribute
|
||||||
[<RequireQualifiedAccess>]
|
[<RequireQualifiedAccess>]
|
||||||
module HxHeaders =
|
module HxHeaders =
|
||||||
|
@ -334,9 +193,6 @@ module HtmxAttrs =
|
||||||
/// Disables htmx processing for the given node and any children nodes
|
/// Disables htmx processing for the given node and any children nodes
|
||||||
let _hxDisable = flag "hx-disable"
|
let _hxDisable = flag "hx-disable"
|
||||||
|
|
||||||
/// Specifies elements that should be disabled when an htmx request is in flight
|
|
||||||
let _hxDisabledElt = attr "hx-disabled-elt"
|
|
||||||
|
|
||||||
/// Disinherit all ("*") or specific htmx attributes
|
/// Disinherit all ("*") or specific htmx attributes
|
||||||
let _hxDisinherit = attr "hx-disinherit"
|
let _hxDisinherit = attr "hx-disinherit"
|
||||||
|
|
||||||
|
@ -367,13 +223,8 @@ module HtmxAttrs =
|
||||||
/// Overrides a previous `hx-boost`
|
/// Overrides a previous `hx-boost`
|
||||||
let _hxNoBoost = attr "hx-boost" "false"
|
let _hxNoBoost = attr "hx-boost" "false"
|
||||||
|
|
||||||
/// Attach an event handler for DOM events
|
/// Attach an event handler for DOM or htmx events
|
||||||
let _hxOnEvent evtName =
|
let _hxOn = attr "hx-on"
|
||||||
attr $"hx-on:%s{evtName}"
|
|
||||||
|
|
||||||
/// Attach an event handler for htmx events
|
|
||||||
let _hxOnHxEvent (hxEvent: HxEvent) =
|
|
||||||
_hxOnEvent $":{hxEvent.ToHxOnString()}"
|
|
||||||
|
|
||||||
/// Filters the parameters that will be submitted with a request
|
/// Filters the parameters that will be submitted with a request
|
||||||
let _hxParams = attr "hx-params"
|
let _hxParams = attr "hx-params"
|
||||||
|
@ -408,6 +259,9 @@ module HtmxAttrs =
|
||||||
/// Selects a subset of an out-of-band server response
|
/// Selects a subset of an out-of-band server response
|
||||||
let _hxSelectOob = attr "hx-select-oob"
|
let _hxSelectOob = attr "hx-select-oob"
|
||||||
|
|
||||||
|
/// Establishes and listens to Server Sent Event (SSE) sources for events
|
||||||
|
let _hxSse = attr "hx-sse"
|
||||||
|
|
||||||
/// Controls how the response content is swapped into the DOM (e.g. 'outerHTML' or 'beforeEnd')
|
/// Controls how the response content is swapped into the DOM (e.g. 'outerHTML' or 'beforeEnd')
|
||||||
let _hxSwap = attr "hx-swap"
|
let _hxSwap = attr "hx-swap"
|
||||||
|
|
||||||
|
@ -433,26 +287,23 @@ module HtmxAttrs =
|
||||||
/// Adds to the parameters that will be submitted with the request
|
/// Adds to the parameters that will be submitted with the request
|
||||||
let _hxVals = attr "hx-vals"
|
let _hxVals = attr "hx-vals"
|
||||||
|
|
||||||
/// The name of the message to swap into the DOM.
|
/// Establishes a WebSocket or sends information to one
|
||||||
let _sseSwap = attr "sse-swap"
|
let _hxWs = attr "hx-ws"
|
||||||
|
|
||||||
/// The URL of the SSE server.
|
|
||||||
let _sseConnect = attr "sse-connect"
|
|
||||||
|
|
||||||
|
|
||||||
/// Script tags to pull htmx into a web page
|
/// Script tags to pull htmx into an web page
|
||||||
module Script =
|
module Script =
|
||||||
|
|
||||||
/// Script tag to load the minified version from unpkg.com
|
/// Script tag to load the minified version from unpkg.com
|
||||||
let minified =
|
let minified =
|
||||||
script [ _src "https://unpkg.com/htmx.org@2.0.3"
|
script [ _src "https://unpkg.com/htmx.org@1.9.4"
|
||||||
_integrity "sha384-0895/pl2MU10Hqc6jd4RvrthNlDiE9U1tWmX7WRESftEDRosgxNsQG/Ze9YMRzHq"
|
_integrity "sha384-zUfuhFKKZCbHTY6aRR46gxiqszMk5tcHjsVFxnUo8VMus4kHGVdIYVbOYYNlKmHV"
|
||||||
_crossorigin "anonymous" ] []
|
_crossorigin "anonymous" ] []
|
||||||
|
|
||||||
/// Script tag to load the unminified version from unpkg.com
|
/// Script tag to load the unminified version from unpkg.com
|
||||||
let unminified =
|
let unminified =
|
||||||
script [ _src "https://unpkg.com/htmx.org@2.0.3/dist/htmx.js"
|
script [ _src "https://unpkg.com/htmx.org@1.9.4/dist/htmx.js"
|
||||||
_integrity "sha384-BBDmZzVt6vjz5YbQqZPtFZW82o8QotoM7RUp5xOxV3nSJ8u2pSdtzFAbGKzTlKtg"
|
_integrity "sha384-2caa3Jf+wayjuHAc9J3mR3xz191GzmIDNYVBsE8LetbkJn4wjLrO6Ht9rRMuEjIo"
|
||||||
_crossorigin "anonymous" ] []
|
_crossorigin "anonymous" ] []
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -2,9 +2,7 @@
|
||||||
|
|
||||||
This package enables [htmx](https://htmx.org) support within the [Giraffe](https://giraffe.wiki) view engine.
|
This package enables [htmx](https://htmx.org) support within the [Giraffe](https://giraffe.wiki) view engine.
|
||||||
|
|
||||||
**htmx version: 2.0.3**
|
**htmx version: 1.9.4**
|
||||||
|
|
||||||
_Upgrading from v1.x: see [the migration guide](https://htmx.org/migration-guide-htmx-1/) for changes_
|
|
||||||
|
|
||||||
### Setup
|
### Setup
|
||||||
|
|
||||||
|
@ -16,7 +14,7 @@ _Upgrading from v1.x: see [the migration guide](https://htmx.org/migration-guide
|
||||||
Following Giraffe View Engine's lead, there are a set of attribute functions for htmx; for many of the attributes, there are also helper modules to assist with typing the values. The example below utilizes both:
|
Following Giraffe View Engine's lead, there are a set of attribute functions for htmx; for many of the attributes, there are also helper modules to assist with typing the values. The example below utilizes both:
|
||||||
|
|
||||||
```fsharp
|
```fsharp
|
||||||
let autoload =
|
let autoload =
|
||||||
div [ _hxGet "/this/data"; _hxTrigger HxTrigger.Load ] [ str "Loading..." ]
|
div [ _hxGet "/this/data"; _hxTrigger HxTrigger.Load ] [ str "Loading..." ]
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -45,19 +43,19 @@ The support modules contain named properties for known values (as illustrated wi
|
||||||
- `HxRequest` has a `Configure` function, which takes a list of strings; the other functions in the module allow for configuring the request.
|
- `HxRequest` has a `Configure` function, which takes a list of strings; the other functions in the module allow for configuring the request.
|
||||||
|
|
||||||
```fsharp
|
```fsharp
|
||||||
HxRequest.Configure [ HxRequest.Timeout 500 ] |> _hxRequest
|
HxRequest.Configure [ HxRequest.Timeout 500 ] |> _hxRequest
|
||||||
```
|
```
|
||||||
- `HxTrigger` is _(by far)_ the most complex of these modules. Most uses won't need that complexity; however, complex triggers can be defined by piping into or composing with other functions. For example, to define an event that responds to a shift-click anywhere on the document, with a delay of 3 seconds before firing:
|
- `HxTrigger` is _(by far)_ the most complex of these modules. Most uses won't need that complexity; however, complex triggers can be defined by piping into or composing with other functions. For example, to define an event that responds to a shift-click anywhere on the document, with a delay of 3 seconds before firing:
|
||||||
|
|
||||||
```fsharp
|
```fsharp
|
||||||
HxTrigger.Click
|
HxTrigger.Click
|
||||||
|> HxTrigger.Filter.Shift
|
|> HxTrigger.Filter.Shift
|
||||||
|> HxTrigger.FromDocument
|
|> HxTrigger.FromDocument
|
||||||
|> HxTrigger.Delay "3s"
|
|> HxTrigger.Delay "3s"
|
||||||
|> _hxTrigger
|
|> _hxTrigger
|
||||||
|
|
||||||
// or
|
// or
|
||||||
|
|
||||||
(HxTrigger.Filter.Shift >> HxTrigger.FromDocument >> HxTrigger.Delay "3s") HxTrigger.Click
|
(HxTrigger.Filter.Shift >> HxTrigger.FromDocument >> HxTrigger.Delay "3s") HxTrigger.Click
|
||||||
|> _hxTrigger
|
|> _hxTrigger
|
||||||
```
|
```
|
||||||
|
|
BIN
src/icon.png
BIN
src/icon.png
Binary file not shown.
Before Width: | Height: | Size: 11 KiB |
|
@ -1,7 +0,0 @@
|
||||||
#!/bin/bash
|
|
||||||
dotnet pack Common/Giraffe.Htmx.Common.fsproj -c Release
|
|
||||||
dotnet pack Htmx/Giraffe.Htmx.fsproj -c Release
|
|
||||||
dotnet pack ViewEngine.Htmx/Giraffe.ViewEngine.Htmx.fsproj -c Release
|
|
||||||
cp Common/bin/Release/Giraffe.Htmx.Common.*.nupkg .
|
|
||||||
cp Htmx/bin/Release/Giraffe.Htmx.*.nupkg .
|
|
||||||
cp ViewEngine.Htmx/bin/Release/Giraffe.ViewEngine.Htmx.*.nupkg .
|
|
Loading…
Reference in New Issue
Block a user