Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| c587a28770 | |||
| b5292bffc4 | |||
| 86defea3c1 | |||
| 9a9f159cab | |||
| 9fcba06e75 |
@@ -63,6 +63,8 @@ Some attributes have known values, such as `hx-trigger` and `hx-swap`; for these
|
||||
]
|
||||
```
|
||||
|
||||
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
|
||||
|
||||
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/).
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
<?xml version="1.0" encoding="utf-8" standalone="no"?>
|
||||
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<VersionPrefix>0.9.2</VersionPrefix>
|
||||
<PackageReleaseNotes>Complete view engine modules; add READMEs</PackageReleaseNotes>
|
||||
<VersionPrefix>1.7.0</VersionPrefix>
|
||||
<PackageReleaseNotes>Support new attributes/headers in htmx 1.7.0</PackageReleaseNotes>
|
||||
<Authors>danieljsummers</Authors>
|
||||
<Company>Bit Badger Solutions</Company>
|
||||
<PackageProjectUrl>https://github.com/bit-badger/Giraffe.Htmx</PackageProjectUrl>
|
||||
|
||||
@@ -217,6 +217,17 @@ module HandlerTests =
|
||||
Assert.Equal ("/a-new-url", dic.["HX-Push"].[0])
|
||||
}
|
||||
|
||||
[<Fact>]
|
||||
let ``withHxNoPush succeeds`` () =
|
||||
let ctx = Substitute.For<HttpContext> ()
|
||||
let dic = HeaderDictionary ()
|
||||
ctx.Response.Headers.ReturnsForAnyArgs dic |> ignore
|
||||
task {
|
||||
let! _ = withHxNoPush next ctx
|
||||
Assert.True (dic.ContainsKey "HX-Push")
|
||||
Assert.Equal ("false", dic.["HX-Push"].[0])
|
||||
}
|
||||
|
||||
[<Fact>]
|
||||
let ``withHxRedirect succeeds`` () =
|
||||
let ctx = Substitute.For<HttpContext> ()
|
||||
@@ -250,6 +261,17 @@ module HandlerTests =
|
||||
Assert.Equal ("false", dic.["HX-Refresh"].[0])
|
||||
}
|
||||
|
||||
[<Fact>]
|
||||
let ``withHxRetarget succeeds`` () =
|
||||
let ctx = Substitute.For<HttpContext> ()
|
||||
let dic = HeaderDictionary ()
|
||||
ctx.Response.Headers.ReturnsForAnyArgs dic |> ignore
|
||||
task {
|
||||
let! _ = withHxRetarget "#somewhereElse" next ctx
|
||||
Assert.True (dic.ContainsKey "HX-Retarget")
|
||||
Assert.Equal ("#somewhereElse", dic.["HX-Retarget"].[0])
|
||||
}
|
||||
|
||||
[<Fact>]
|
||||
let ``withHxTrigger succeeds`` () =
|
||||
let ctx = Substitute.For<HttpContext> ()
|
||||
|
||||
@@ -39,10 +39,10 @@ type IHeaderDictionary with
|
||||
/// Extensions for the request object
|
||||
type HttpRequest with
|
||||
|
||||
/// Whether this request was initiated from HTMX
|
||||
/// Whether this request was initiated from htmx
|
||||
member this.IsHtmx with get () = this.Headers.HxRequest |> Option.defaultValue false
|
||||
|
||||
/// Whether this request is an HTMX history-miss refresh request
|
||||
/// Whether this request is an htmx history-miss refresh request
|
||||
member this.IsHtmxRefresh with get () =
|
||||
this.IsHtmx && (this.Headers.HxHistoryRestoreRequest |> Option.defaultValue false)
|
||||
|
||||
@@ -66,6 +66,10 @@ module Handlers =
|
||||
let withHxPush : string -> HttpHandler =
|
||||
setHttpHeader "HX-Push"
|
||||
|
||||
// Explicitly do not push a new URL into the history stack
|
||||
let withHxNoPush : HttpHandler =
|
||||
toLowerBool false |> withHxPush
|
||||
|
||||
/// Can be used to do a client-side redirect to a new location
|
||||
let withHxRedirect : string -> HttpHandler =
|
||||
setHttpHeader "HX-Redirect"
|
||||
@@ -74,6 +78,10 @@ module Handlers =
|
||||
let withHxRefresh : bool -> HttpHandler =
|
||||
toLowerBool >> setHttpHeader "HX-Refresh"
|
||||
|
||||
/// Allows you to override the `hx-target` attribute
|
||||
let withHxRetarget : string -> HttpHandler =
|
||||
setHttpHeader "HX-Retarget"
|
||||
|
||||
/// Allows you to trigger a single client side event
|
||||
let withHxTrigger : string -> HttpHandler =
|
||||
setHttpHeader "HX-Trigger"
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
|
||||
This package enables server-side support for [htmx](https://htmx.org) within [Giraffe](https://giraffe.wiki) and ASP.NET's `HttpContext`.
|
||||
|
||||
**htmx version: 1.7.0**
|
||||
|
||||
### Setup
|
||||
|
||||
1. Install the package.
|
||||
|
||||
@@ -344,6 +344,10 @@ module Attributes =
|
||||
let ``_hxDisable succeeds`` () =
|
||||
p [ _hxDisable ] [] |> shouldRender """<p hx-disable></p>"""
|
||||
|
||||
[<Fact>]
|
||||
let ``_hxDisinherit succeeds`` () =
|
||||
strong [ _hxDisinherit "*" ] [] |> shouldRender """<strong hx-disinherit="*"></strong>"""
|
||||
|
||||
[<Fact>]
|
||||
let ``_hxEncoding succeeds`` () =
|
||||
form [ _hxEncoding "utf-7" ] [] |> shouldRender """<form hx-encoding="utf-7"></form>"""
|
||||
@@ -425,6 +429,10 @@ module Attributes =
|
||||
let ``_hxSwapOob succeeds`` () =
|
||||
li [ _hxSwapOob "true" ] [] |> shouldRender """<li hx-swap-oob="true"></li>"""
|
||||
|
||||
[<Fact>]
|
||||
let ``_hxSync succeeds`` () =
|
||||
nav [ _hxSync "closest form:abort" ] [] |> shouldRender """<nav hx-sync="closest form:abort"></nav>"""
|
||||
|
||||
[<Fact>]
|
||||
let ``_hxTarget succeeds`` () =
|
||||
header [ _hxTarget "#somewhereElse" ] [] |> shouldRender """<header hx-target="#somewhereElse"></header>"""
|
||||
@@ -442,3 +450,18 @@ module Attributes =
|
||||
let ``_hxWs succeeds`` () =
|
||||
ul [ _hxWs "connect:/web-socket" ] [] |> shouldRender """<ul hx-ws="connect:/web-socket"></ul>"""
|
||||
|
||||
|
||||
/// Tests for the Script module
|
||||
module Script =
|
||||
|
||||
[<Fact>]
|
||||
let ``Script.minified succeeds`` () =
|
||||
let html = RenderView.AsString.htmlNode Script.minified
|
||||
Assert.Equal ("""<script src="https://unpkg.com/htmx.org@1.7.0" integrity="sha384-EzBXYPt0/T6gxNp0nuPtLkmRpmDBbjg6WmCUZRLXBBwYYmwAUxzlSGej0ARHX0Bo" crossorigin="anonymous"></script>""",
|
||||
html)
|
||||
|
||||
[<Fact>]
|
||||
let ``Script.unminified succeeds`` () =
|
||||
let html = RenderView.AsString.htmlNode Script.unminified
|
||||
Assert.Equal ("""<script src="https://unpkg.com/htmx.org@1.7.0/dist/htmx.js" integrity="sha384-ESk4PjE7dwjGkEciohREmmf8rLMX0E95MKwxM3bvC90sZ3XbF2TELnVk2w7bX0d9" crossorigin="anonymous"></script>""",
|
||||
html)
|
||||
|
||||
@@ -153,7 +153,7 @@ module HxVals =
|
||||
let From = toJson
|
||||
|
||||
|
||||
/// Attributes and flags for HTMX
|
||||
/// Attributes and flags for htmx
|
||||
[<AutoOpen>]
|
||||
module HtmxAttrs =
|
||||
/// Progressively enhances anchors and forms to use AJAX requests (use `_hxNoBoost` to set to false)
|
||||
@@ -164,6 +164,8 @@ module HtmxAttrs =
|
||||
let _hxDelete = attr "hx-delete"
|
||||
/// Disables htmx processing for the given node and any children nodes
|
||||
let _hxDisable = flag "hx-disable"
|
||||
/// Disinherit all ("*") or specific htmx attributes
|
||||
let _hxDisinherit = attr "hx-disinherit"
|
||||
/// Changes the request encoding type
|
||||
let _hxEncoding = attr "hx-encoding"
|
||||
/// Extensions to use for this element
|
||||
@@ -204,6 +206,8 @@ module HtmxAttrs =
|
||||
let _hxSwap = attr "hx-swap"
|
||||
/// Marks content in a response as being "Out of Band", i.e. swapped somewhere other than the target
|
||||
let _hxSwapOob = attr "hx-swap-oob"
|
||||
/// Synchronize events based on another element
|
||||
let _hxSync = attr "hx-sync"
|
||||
/// Specifies the target element to be swapped
|
||||
let _hxTarget = attr "hx-target"
|
||||
/// Specifies the event that triggers the request
|
||||
@@ -212,3 +216,23 @@ module HtmxAttrs =
|
||||
let _hxVals = attr "hx-vals"
|
||||
/// Establishes a WebSocket or sends information to one
|
||||
let _hxWs = attr "hx-ws"
|
||||
|
||||
|
||||
/// 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@1.7.0"
|
||||
_integrity "sha384-EzBXYPt0/T6gxNp0nuPtLkmRpmDBbjg6WmCUZRLXBBwYYmwAUxzlSGej0ARHX0Bo"
|
||||
_crossorigin "anonymous"
|
||||
] []
|
||||
|
||||
/// Script tag to load the unminified version from unpkg.com
|
||||
let unminified =
|
||||
script [
|
||||
_src "https://unpkg.com/htmx.org@1.7.0/dist/htmx.js"
|
||||
_integrity "sha384-ESk4PjE7dwjGkEciohREmmf8rLMX0E95MKwxM3bvC90sZ3XbF2TELnVk2w7bX0d9"
|
||||
_crossorigin "anonymous"
|
||||
] []
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
|
||||
This package enables [htmx](https://htmx.org) support within the [Giraffe](https://giraffe.wiki) view engine.
|
||||
|
||||
**htmx version: 1.7.0**
|
||||
|
||||
### Setup
|
||||
|
||||
1. Install the package.
|
||||
@@ -25,6 +27,8 @@ Support modules include:
|
||||
- `HxTrigger`
|
||||
- `HxVals`
|
||||
|
||||
There are two `XmlNode`s that will load the htmx script from unpkg; `Htmx.Script.minified` loads the minified version, and `Htmx.Script.unminified` loads the unminified version (useful for debugging).
|
||||
|
||||
### Learn
|
||||
|
||||
htmx's attributes and these attribute functions map one-to-one. The lone exception is `_hxBoost`, which implies `true`; use `_hxNoBoost` to set it to `false`. The support modules contain named properties for known values (as illustrated with `HxTrigger.Load` above). A few of the modules are more than collections of names, though:
|
||||
|
||||
Reference in New Issue
Block a user