Compare commits
1 Commits
Author | SHA1 | Date | |
---|---|---|---|
125853b2a7 |
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -6,4 +6,3 @@
|
|||
.idea
|
||||
*.user
|
||||
.vscode
|
||||
src/*.nupkg
|
||||
|
|
11
README.md
11
README.md
|
@ -25,10 +25,9 @@ A server may want to respond to a request that originated from htmx differently
|
|||
// "view" can be whatever your view engine needs for the body of the page
|
||||
let result view : HttpHandler =
|
||||
fun next ctx ->
|
||||
if ctx.Request.IsHtmx && not ctx.Request.IsHtmxRefresh then
|
||||
partial view
|
||||
else
|
||||
full view
|
||||
match ctx.Request.IsHtmx && not ctx.Request.IsHtmxRefresh with
|
||||
| true -> partial view
|
||||
| false -> 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.
|
||||
|
@ -50,9 +49,7 @@ As an example, creating a `div` that loads data once the HTML is rendered:
|
|||
|
||||
```fsharp
|
||||
let autoload =
|
||||
div [ _hxGet "/lazy-load-data"; _hxTrigger HxTrigger.Load ] [
|
||||
str "Loading..."
|
||||
]
|
||||
div [ _hxGet "/lazy-load-data"; _hxTrigger "load" ] [ str "Loading..." ]
|
||||
```
|
||||
|
||||
_(As `hx-boost="true"` is the usual desire for boosting, `_hxBoost` implies true. To disable it for an element, use `_hxNoBoost` instead.)_
|
||||
|
|
|
@ -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: 2.0.3**
|
||||
**htmx version: 1.9.12**
|
||||
|
|
|
@ -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;net8.0</TargetFrameworks>
|
||||
<VersionPrefix>2.0.3</VersionPrefix>
|
||||
<PackageReleaseNotes>Update script tags to pull htmx 2.0.3 (no header or attribute changes)</PackageReleaseNotes>
|
||||
<TargetFrameworks>net6.0;net7.0;net8.0</TargetFrameworks>
|
||||
<VersionPrefix>1.9.12</VersionPrefix>
|
||||
<PackageReleaseNotes>Update script tags to pull htmx 1.9.12</PackageReleaseNotes>
|
||||
<Authors>danieljsummers</Authors>
|
||||
<Company>Bit Badger Solutions</Company>
|
||||
<PackageProjectUrl>https://git.bitbadger.solutions/bit-badger/Giraffe.Htmx</PackageProjectUrl>
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Giraffe" Version="6.4.0" />
|
||||
<PackageReference Include="Giraffe" Version="6.2.0" />
|
||||
<PackageReference Update="FSharp.Core" Version="6.0.0" />
|
||||
</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`.
|
||||
|
||||
**htmx version: 2.0.3**
|
||||
|
||||
_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.*._
|
||||
**htmx version: 1.9.12**
|
||||
|
||||
### Setup
|
||||
|
||||
|
|
|
@ -3,4 +3,4 @@ open Expecto
|
|||
let allTests = testList "Giraffe" [ Common.allTests; Htmx.allTests; ViewEngine.allTests ]
|
||||
|
||||
[<EntryPoint>]
|
||||
let main args = runTestsWithCLIArgs [] args allTests
|
||||
let main args = runTestsWithArgs defaultConfig args allTests
|
||||
|
|
|
@ -18,9 +18,8 @@
|
|||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Expecto" Version="10.2.1" />
|
||||
<PackageReference Include="NSubstitute" Version="5.1.0" />
|
||||
<PackageReference Update="FSharp.Core" Version="8.0.300" />
|
||||
<PackageReference Include="Expecto" Version="9.0.4" />
|
||||
<PackageReference Include="NSubstitute" Version="5.0.0" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
|
|
@ -781,6 +781,10 @@ let attributes =
|
|||
test "_hxSelectOob succeeds" {
|
||||
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" {
|
||||
del [ _hxSwap "innerHTML" ] [] |> shouldRender """<del hx-swap="innerHTML"></del>"""
|
||||
}
|
||||
|
@ -804,11 +808,8 @@ let attributes =
|
|||
dt [ _hxVals """{ "extra": "values" }""" ] []
|
||||
|> shouldRender """<dt hx-vals="{ "extra": "values" }"></dt>"""
|
||||
}
|
||||
test "_sseSwap succeeds" {
|
||||
ul [ _sseSwap "sseMessageName" ] [] |> shouldRender """<ul sse-swap="sseMessageName"></ul>"""
|
||||
}
|
||||
test "_sseConnect succeeds" {
|
||||
div [ _sseConnect "/gps/sse" ] [] |> shouldRender """<div sse-connect="/gps/sse"></div>"""
|
||||
test "_hxWs succeeds" {
|
||||
ul [ _hxWs "connect:/web-socket" ] [] |> shouldRender """<ul hx-ws="connect:/web-socket"></ul>"""
|
||||
}
|
||||
]
|
||||
|
||||
|
@ -819,14 +820,14 @@ let script =
|
|||
let html = RenderView.AsString.htmlNode Script.minified
|
||||
Expect.equal
|
||||
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.12" integrity="sha384-ujb1lZYygJmzgSwoxRggbCHcjc0rB2XoQrxeTUQyRjrOnlCoYta87iKBWq3EsdM2" 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@2.0.3/dist/htmx.js" integrity="sha384-BBDmZzVt6vjz5YbQqZPtFZW82o8QotoM7RUp5xOxV3nSJ8u2pSdtzFAbGKzTlKtg" crossorigin="anonymous"></script>"""
|
||||
"""<script src="https://unpkg.com/htmx.org@1.9.12/dist/htmx.js" integrity="sha384-qbtR4rS9RrUMECUWDWM2+YGgN3U4V4ZncZ0BvUcg9FGct0jqXz3PUdVpU1p0yrXS" crossorigin="anonymous"></script>"""
|
||||
"Unminified script tag is incorrect"
|
||||
}
|
||||
]
|
||||
|
@ -978,6 +979,18 @@ let renderFragment =
|
|||
]
|
||||
]
|
||||
|
||||
#nowarn "44"
|
||||
|
||||
/// Tests for the HtmxAttrs module
|
||||
let deprecatedAttributes =
|
||||
testList "Deprecated Attributes" [
|
||||
test "_hxOn succeeds" {
|
||||
let newLine = "\n"
|
||||
strong [ _hxOn "submit: alert('oops')\nclick: alert('howdy!')" ] []
|
||||
|> shouldRender $"""<strong hx-on="submit: alert('oops'){newLine}click: alert('howdy!')"></strong>"""
|
||||
}
|
||||
]
|
||||
|
||||
/// All tests in this module
|
||||
let allTests =
|
||||
testList "ViewEngine.Htmx" [
|
||||
|
@ -991,4 +1004,5 @@ let allTests =
|
|||
attributes
|
||||
script
|
||||
renderFragment
|
||||
deprecatedAttributes
|
||||
]
|
||||
|
|
|
@ -317,6 +317,7 @@ module HxVals =
|
|||
/// Create values from a list of key/value pairs
|
||||
let From = toJson
|
||||
|
||||
open System
|
||||
|
||||
/// Attributes and flags for htmx
|
||||
[<AutoOpen>]
|
||||
|
@ -367,6 +368,10 @@ module HtmxAttrs =
|
|||
/// Overrides a previous `hx-boost`
|
||||
let _hxNoBoost = attr "hx-boost" "false"
|
||||
|
||||
/// Attach an event handler for DOM or htmx events
|
||||
[<Obsolete "This will be removed in htmx 2; use _hxOnEvent or _hxOnHxEvent instead">]
|
||||
let _hxOn = attr "hx-on"
|
||||
|
||||
/// Attach an event handler for DOM events
|
||||
let _hxOnEvent evtName =
|
||||
attr $"hx-on:%s{evtName}"
|
||||
|
@ -408,6 +413,9 @@ module HtmxAttrs =
|
|||
/// Selects a subset of an out-of-band server response
|
||||
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')
|
||||
let _hxSwap = attr "hx-swap"
|
||||
|
||||
|
@ -433,26 +441,23 @@ module HtmxAttrs =
|
|||
/// Adds to the parameters that will be submitted with the request
|
||||
let _hxVals = attr "hx-vals"
|
||||
|
||||
/// The name of the message to swap into the DOM.
|
||||
let _sseSwap = attr "sse-swap"
|
||||
|
||||
/// The URL of the SSE server.
|
||||
let _sseConnect = attr "sse-connect"
|
||||
/// Establishes a WebSocket or sends information to one
|
||||
let _hxWs = attr "hx-ws"
|
||||
|
||||
|
||||
/// Script tags to pull htmx into a web page
|
||||
/// Script tags to pull htmx into an web page
|
||||
module Script =
|
||||
|
||||
/// Script tag to load the minified version from unpkg.com
|
||||
let minified =
|
||||
script [ _src "https://unpkg.com/htmx.org@2.0.3"
|
||||
_integrity "sha384-0895/pl2MU10Hqc6jd4RvrthNlDiE9U1tWmX7WRESftEDRosgxNsQG/Ze9YMRzHq"
|
||||
script [ _src "https://unpkg.com/htmx.org@1.9.12"
|
||||
_integrity "sha384-ujb1lZYygJmzgSwoxRggbCHcjc0rB2XoQrxeTUQyRjrOnlCoYta87iKBWq3EsdM2"
|
||||
_crossorigin "anonymous" ] []
|
||||
|
||||
/// Script tag to load the unminified version from unpkg.com
|
||||
let unminified =
|
||||
script [ _src "https://unpkg.com/htmx.org@2.0.3/dist/htmx.js"
|
||||
_integrity "sha384-BBDmZzVt6vjz5YbQqZPtFZW82o8QotoM7RUp5xOxV3nSJ8u2pSdtzFAbGKzTlKtg"
|
||||
script [ _src "https://unpkg.com/htmx.org@1.9.12/dist/htmx.js"
|
||||
_integrity "sha384-qbtR4rS9RrUMECUWDWM2+YGgN3U4V4ZncZ0BvUcg9FGct0jqXz3PUdVpU1p0yrXS"
|
||||
_crossorigin "anonymous" ] []
|
||||
|
||||
|
||||
|
|
|
@ -2,9 +2,7 @@
|
|||
|
||||
This package enables [htmx](https://htmx.org) support within the [Giraffe](https://giraffe.wiki) view engine.
|
||||
|
||||
**htmx version: 2.0.3**
|
||||
|
||||
_Upgrading from v1.x: see [the migration guide](https://htmx.org/migration-guide-htmx-1/) for changes_
|
||||
**htmx version: 1.9.12**
|
||||
|
||||
### Setup
|
||||
|
||||
|
|
|
@ -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