Compare commits
18 Commits
v2.0.0-alp
...
main
Author | SHA1 | Date | |
---|---|---|---|
5626031593 | |||
f0de18845f | |||
961307fd99 | |||
a2960a79c6 | |||
541384a92f | |||
8cb5d6bfa7 | |||
1a11e3511a | |||
32e962416d | |||
29839fa795 | |||
7f9b3a6234 | |||
a8d2b819dc | |||
1ea05b79ed | |||
4f6bb8367a | |||
b3665a4b72 | |||
bdb7255a1c | |||
94b68f76c9 | |||
90de16529c | |||
59246ae7f5 |
10
.github/workflows/ci.yml
vendored
10
.github/workflows/ci.yml
vendored
|
@ -17,9 +17,9 @@ jobs:
|
||||||
dotnet-version: [ "6.0", "7.0", "8.0" ]
|
dotnet-version: [ "6.0", "7.0", "8.0" ]
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v4
|
||||||
- name: Setup .NET ${{ matrix.dotnet-version }}.x
|
- name: Setup .NET ${{ matrix.dotnet-version }}.x
|
||||||
uses: actions/setup-dotnet@v3
|
uses: actions/setup-dotnet@v4
|
||||||
with:
|
with:
|
||||||
dotnet-version: ${{ matrix.dotnet-version }}.x
|
dotnet-version: ${{ matrix.dotnet-version }}.x
|
||||||
- name: Restore dependencies
|
- name: Restore dependencies
|
||||||
|
@ -32,9 +32,9 @@ jobs:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
needs: build-and-test
|
needs: build-and-test
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v4
|
||||||
- name: Setup .NET
|
- name: Setup .NET
|
||||||
uses: actions/setup-dotnet@v3
|
uses: actions/setup-dotnet@v4
|
||||||
with:
|
with:
|
||||||
dotnet-version: "8.0"
|
dotnet-version: "8.0"
|
||||||
- name: Package Common library
|
- name: Package Common library
|
||||||
|
@ -50,7 +50,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@v3
|
uses: actions/upload-artifact@v4
|
||||||
with:
|
with:
|
||||||
name: packages
|
name: packages
|
||||||
path: |
|
path: |
|
||||||
|
|
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -6,3 +6,4 @@
|
||||||
.idea
|
.idea
|
||||||
*.user
|
*.user
|
||||||
.vscode
|
.vscode
|
||||||
|
src/*.nupkg
|
||||||
|
|
23
README.md
23
README.md
|
@ -21,19 +21,20 @@ 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 ->
|
||||||
match ctx.Request.IsHtmx && not ctx.Request.IsHtmxRefresh with
|
if ctx.Request.IsHtmx && not ctx.Request.IsHtmxRefresh then
|
||||||
| true -> partial view
|
partial view
|
||||||
| false -> full view
|
else
|
||||||
|
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
|
||||||
|
@ -48,8 +49,10 @@ 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 "load" ] [ str "Loading..." ]
|
div [ _hxGet "/lazy-load-data"; _hxTrigger 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.)_
|
_(As `hx-boost="true"` is the usual desire for boosting, `_hxBoost` implies true. To disable it for an element, use `_hxNoBoost` instead.)_
|
||||||
|
@ -57,7 +60,7 @@ _(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"
|
||||||
]
|
]
|
||||||
|
|
|
@ -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.0-alpha1**
|
**htmx version: 2.0.3**
|
||||||
|
|
|
@ -1,18 +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;net7.0;net8.0</TargetFrameworks>
|
<TargetFrameworks>net6.0;net8.0</TargetFrameworks>
|
||||||
<VersionPrefix>2.0.0</VersionPrefix>
|
<VersionPrefix>2.0.3</VersionPrefix>
|
||||||
<VersionSuffix>alpha1</VersionSuffix>
|
<PackageReleaseNotes>Update script tags to pull htmx 2.0.3 (no header or attribute changes)</PackageReleaseNotes>
|
||||||
<PackageReleaseNotes>Update script tags to pull htmx 2.0.0-alpha1</PackageReleaseNotes>
|
|
||||||
<Authors>danieljsummers</Authors>
|
<Authors>danieljsummers</Authors>
|
||||||
<Company>Bit Badger Solutions</Company>
|
<Company>Bit Badger Solutions</Company>
|
||||||
<PackageProjectUrl>https://github.com/bit-badger/Giraffe.Htmx</PackageProjectUrl>
|
<PackageProjectUrl>https://git.bitbadger.solutions/bit-badger/Giraffe.Htmx</PackageProjectUrl>
|
||||||
<PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance>
|
<PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance>
|
||||||
<RepositoryUrl>https://github.com/bit-badger/Giraffe.Htmx</RepositoryUrl>
|
<RepositoryUrl>https://git.bitbadger.solutions/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 alpha</PackageTags>
|
<PackageTags>Giraffe htmx</PackageTags>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
</Project>
|
</Project>
|
||||||
|
|
|
@ -13,7 +13,7 @@
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Giraffe" Version="6.2.0" />
|
<PackageReference Include="Giraffe" Version="6.4.0" />
|
||||||
<PackageReference Update="FSharp.Core" Version="6.0.0" />
|
<PackageReference Update="FSharp.Core" Version="6.0.0" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
|
|
@ -2,13 +2,13 @@
|
||||||
|
|
||||||
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.0-alpha1**
|
**htmx version: 2.0.3**
|
||||||
|
|
||||||
_Note that htmx 2.0 is an ALPHA release. The [migration guide](https://v2-0v2-0.htmx.org/migration-guide-htmx-1/) does not currently specify any request or response header changes. This means that, as of this release, there are no required code changes in moving to this major version._
|
_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
|
||||||
|
|
||||||
1. Install the package (must use `--Prerelease` flag).
|
1. Install the package.
|
||||||
2. Prior to using the request header extension properties or the header-setting `HttpHandler`s, `open Giraffe.Htmx`.
|
2. Prior to using the request header extension properties or the header-setting `HttpHandler`s, `open Giraffe.Htmx`.
|
||||||
|
|
||||||
### Use
|
### Use
|
||||||
|
@ -16,7 +16,7 @@ _Note that htmx 2.0 is an ALPHA release. The [migration guide](https://v2-0v2-0.
|
||||||
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
|
||||||
|
@ -26,7 +26,7 @@ To obtain a request header, using the `IHeaderDictionary` extension properties:
|
||||||
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]
|
||||||
|
|
|
@ -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 = runTestsWithArgs defaultConfig args allTests
|
let main args = runTestsWithCLIArgs [] args allTests
|
||||||
|
|
|
@ -18,8 +18,9 @@
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Expecto" Version="9.0.4" />
|
<PackageReference Include="Expecto" Version="10.2.1" />
|
||||||
<PackageReference Include="NSubstitute" Version="5.0.0" />
|
<PackageReference Include="NSubstitute" Version="5.1.0" />
|
||||||
|
<PackageReference Update="FSharp.Core" Version="8.0.300" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|
|
@ -781,10 +781,6 @@ 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>"""
|
||||||
}
|
}
|
||||||
|
@ -808,8 +804,11 @@ 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 "_hxWs succeeds" {
|
test "_sseSwap succeeds" {
|
||||||
ul [ _hxWs "connect:/web-socket" ] [] |> shouldRender """<ul hx-ws="connect:/web-socket"></ul>"""
|
ul [ _sseSwap "sseMessageName" ] [] |> shouldRender """<ul sse-swap="sseMessageName"></ul>"""
|
||||||
|
}
|
||||||
|
test "_sseConnect succeeds" {
|
||||||
|
div [ _sseConnect "/gps/sse" ] [] |> shouldRender """<div sse-connect="/gps/sse"></div>"""
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@ -820,14 +819,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.0-alpha1" integrity="sha384-KGfWLOUs4pJD2kawhHdm4vgr/cEAofjPPagKWIZ/YnYDQ2bcthCK5LRfBMr7zco+" crossorigin="anonymous"></script>"""
|
"""<script src="https://unpkg.com/htmx.org@2.0.3" integrity="sha384-0895/pl2MU10Hqc6jd4RvrthNlDiE9U1tWmX7WRESftEDRosgxNsQG/Ze9YMRzHq" 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.0-alpha1/dist/htmx.js" integrity="sha384-2kZGZBH6t8d5fRh0/kvj/fwwVwnnTpwcLOhp0t8F0/mXWF5M5iPbo/ygeFN2cFbG" crossorigin="anonymous"></script>"""
|
"""<script src="https://unpkg.com/htmx.org@2.0.3/dist/htmx.js" integrity="sha384-BBDmZzVt6vjz5YbQqZPtFZW82o8QotoM7RUp5xOxV3nSJ8u2pSdtzFAbGKzTlKtg" crossorigin="anonymous"></script>"""
|
||||||
"Unminified script tag is incorrect"
|
"Unminified script tag is incorrect"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
@ -979,18 +978,6 @@ 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
|
/// All tests in this module
|
||||||
let allTests =
|
let allTests =
|
||||||
testList "ViewEngine.Htmx" [
|
testList "ViewEngine.Htmx" [
|
||||||
|
@ -1004,5 +991,4 @@ let allTests =
|
||||||
attributes
|
attributes
|
||||||
script
|
script
|
||||||
renderFragment
|
renderFragment
|
||||||
deprecatedAttributes
|
|
||||||
]
|
]
|
||||||
|
|
|
@ -317,7 +317,6 @@ module HxVals =
|
||||||
/// Create values from a list of key/value pairs
|
/// Create values from a list of key/value pairs
|
||||||
let From = toJson
|
let From = toJson
|
||||||
|
|
||||||
open System
|
|
||||||
|
|
||||||
/// Attributes and flags for htmx
|
/// Attributes and flags for htmx
|
||||||
[<AutoOpen>]
|
[<AutoOpen>]
|
||||||
|
@ -368,10 +367,6 @@ 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 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
|
/// Attach an event handler for DOM events
|
||||||
let _hxOnEvent evtName =
|
let _hxOnEvent evtName =
|
||||||
attr $"hx-on:%s{evtName}"
|
attr $"hx-on:%s{evtName}"
|
||||||
|
@ -413,9 +408,6 @@ 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"
|
||||||
|
|
||||||
|
@ -441,23 +433,26 @@ 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"
|
||||||
|
|
||||||
/// Establishes a WebSocket or sends information to one
|
/// The name of the message to swap into the DOM.
|
||||||
let _hxWs = attr "hx-ws"
|
let _sseSwap = attr "sse-swap"
|
||||||
|
|
||||||
|
/// The URL of the SSE server.
|
||||||
|
let _sseConnect = attr "sse-connect"
|
||||||
|
|
||||||
|
|
||||||
/// Script tags to pull htmx into an web page
|
/// Script tags to pull htmx into a 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.0-alpha1"
|
script [ _src "https://unpkg.com/htmx.org@2.0.3"
|
||||||
_integrity "sha384-KGfWLOUs4pJD2kawhHdm4vgr/cEAofjPPagKWIZ/YnYDQ2bcthCK5LRfBMr7zco+"
|
_integrity "sha384-0895/pl2MU10Hqc6jd4RvrthNlDiE9U1tWmX7WRESftEDRosgxNsQG/Ze9YMRzHq"
|
||||||
_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.0-alpha1/dist/htmx.js"
|
script [ _src "https://unpkg.com/htmx.org@2.0.3/dist/htmx.js"
|
||||||
_integrity "sha384-2kZGZBH6t8d5fRh0/kvj/fwwVwnnTpwcLOhp0t8F0/mXWF5M5iPbo/ygeFN2cFbG"
|
_integrity "sha384-BBDmZzVt6vjz5YbQqZPtFZW82o8QotoM7RUp5xOxV3nSJ8u2pSdtzFAbGKzTlKtg"
|
||||||
_crossorigin "anonymous" ] []
|
_crossorigin "anonymous" ] []
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -2,13 +2,13 @@
|
||||||
|
|
||||||
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.0-alpha1**
|
**htmx version: 2.0.3**
|
||||||
|
|
||||||
_Note that this is an ALPHA release of htmx 2.0; see [the migration guide](https://v2-0v2-0.htmx.org/migration-guide-htmx-1/) for changes_
|
_Upgrading from v1.x: see [the migration guide](https://htmx.org/migration-guide-htmx-1/) for changes_
|
||||||
|
|
||||||
### Setup
|
### Setup
|
||||||
|
|
||||||
1. Install the package (must use `--Prelease` flag).
|
1. Install the package.
|
||||||
2. Prior to using the attribute or support modules, `open Giraffe.ViewEngine.Htmx`.
|
2. Prior to using the attribute or support modules, `open Giraffe.ViewEngine.Htmx`.
|
||||||
|
|
||||||
### Use
|
### Use
|
||||||
|
@ -16,7 +16,7 @@ _Note that this is an ALPHA release of htmx 2.0; see [the migration guide](https
|
||||||
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 +45,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
|
||||||
```
|
```
|
||||||
|
|
7
src/pack.sh
Executable file
7
src/pack.sh
Executable file
|
@ -0,0 +1,7 @@
|
||||||
|
#!/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