From c587a28770f65c20dab09c1744502127778b40c2 Mon Sep 17 00:00:00 2001 From: "Daniel J. Summers" Date: Wed, 23 Feb 2022 21:54:51 -0500 Subject: [PATCH] Update for htmx 1.7.0 (#4) Fixes #3 --- src/Directory.Build.props | 4 ++-- src/Htmx.Tests/Tests.fs | 11 +++++++++++ src/Htmx/Htmx.fs | 4 ++++ src/Htmx/README.md | 2 +- src/ViewEngine.Htmx.Tests/Tests.fs | 25 ++++++++++++++++++++++++- src/ViewEngine.Htmx/Htmx.fs | 12 ++++++++---- src/ViewEngine.Htmx/README.md | 2 +- 7 files changed, 51 insertions(+), 9 deletions(-) diff --git a/src/Directory.Build.props b/src/Directory.Build.props index 0fce98c..560d16f 100644 --- a/src/Directory.Build.props +++ b/src/Directory.Build.props @@ -1,8 +1,8 @@  - 1.6.1 - Initial production-ready release + 1.7.0 + Support new attributes/headers in htmx 1.7.0 danieljsummers Bit Badger Solutions https://github.com/bit-badger/Giraffe.Htmx diff --git a/src/Htmx.Tests/Tests.fs b/src/Htmx.Tests/Tests.fs index e026770..80fb933 100644 --- a/src/Htmx.Tests/Tests.fs +++ b/src/Htmx.Tests/Tests.fs @@ -217,6 +217,17 @@ module HandlerTests = Assert.Equal ("/a-new-url", dic.["HX-Push"].[0]) } + [] + let ``withHxNoPush succeeds`` () = + let ctx = Substitute.For () + 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]) + } + [] let ``withHxRedirect succeeds`` () = let ctx = Substitute.For () diff --git a/src/Htmx/Htmx.fs b/src/Htmx/Htmx.fs index 1880852..51489a5 100644 --- a/src/Htmx/Htmx.fs +++ b/src/Htmx/Htmx.fs @@ -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" diff --git a/src/Htmx/README.md b/src/Htmx/README.md index 78b5a2d..c1b95c7 100644 --- a/src/Htmx/README.md +++ b/src/Htmx/README.md @@ -2,7 +2,7 @@ This package enables server-side support for [htmx](https://htmx.org) within [Giraffe](https://giraffe.wiki) and ASP.NET's `HttpContext`. -**htmx version: 1.6.1** +**htmx version: 1.7.0** ### Setup diff --git a/src/ViewEngine.Htmx.Tests/Tests.fs b/src/ViewEngine.Htmx.Tests/Tests.fs index 4e94258..86ed2cf 100644 --- a/src/ViewEngine.Htmx.Tests/Tests.fs +++ b/src/ViewEngine.Htmx.Tests/Tests.fs @@ -344,6 +344,10 @@ module Attributes = let ``_hxDisable succeeds`` () = p [ _hxDisable ] [] |> shouldRender """

""" + [] + let ``_hxDisinherit succeeds`` () = + strong [ _hxDisinherit "*" ] [] |> shouldRender """""" + [] let ``_hxEncoding succeeds`` () = form [ _hxEncoding "utf-7" ] [] |> shouldRender """
""" @@ -425,6 +429,10 @@ module Attributes = let ``_hxSwapOob succeeds`` () = li [ _hxSwapOob "true" ] [] |> shouldRender """
  • """ + [] + let ``_hxSync succeeds`` () = + nav [ _hxSync "closest form:abort" ] [] |> shouldRender """""" + [] let ``_hxTarget succeeds`` () = header [ _hxTarget "#somewhereElse" ] [] |> shouldRender """
    """ @@ -441,4 +449,19 @@ module Attributes = [] let ``_hxWs succeeds`` () = ul [ _hxWs "connect:/web-socket" ] [] |> shouldRender """
      """ - \ No newline at end of file + + +/// Tests for the Script module +module Script = + + [] + let ``Script.minified succeeds`` () = + let html = RenderView.AsString.htmlNode Script.minified + Assert.Equal ("""""", + html) + + [] + let ``Script.unminified succeeds`` () = + let html = RenderView.AsString.htmlNode Script.unminified + Assert.Equal ("""""", + html) diff --git a/src/ViewEngine.Htmx/Htmx.fs b/src/ViewEngine.Htmx/Htmx.fs index 945dd01..ff3e606 100644 --- a/src/ViewEngine.Htmx/Htmx.fs +++ b/src/ViewEngine.Htmx/Htmx.fs @@ -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 @@ -220,15 +224,15 @@ module Script = /// Script tag to load the minified version from unpkg.com let minified = script [ - _src "https://unpkg.com/htmx.org@1.6.1" - _integrity "sha384-tvG/2mnCFmGQzYC1Oh3qxQ7CkQ9kMzYjWZSNtrRZygHPDDqottzEJsqS4oUVodhW" + _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.6.1/dist/htmx.js" - _integrity "sha384-7G9OE6gS4pBnBGH74HojjPQ8xOEGrdBeQc7JJOc58k6LG/YVfKXARd91w9715AYG" + _src "https://unpkg.com/htmx.org@1.7.0/dist/htmx.js" + _integrity "sha384-ESk4PjE7dwjGkEciohREmmf8rLMX0E95MKwxM3bvC90sZ3XbF2TELnVk2w7bX0d9" _crossorigin "anonymous" ] [] diff --git a/src/ViewEngine.Htmx/README.md b/src/ViewEngine.Htmx/README.md index 23918cd..6314948 100644 --- a/src/ViewEngine.Htmx/README.md +++ b/src/ViewEngine.Htmx/README.md @@ -2,7 +2,7 @@ This package enables [htmx](https://htmx.org) support within the [Giraffe](https://giraffe.wiki) view engine. -**htmx version: 1.6.1** +**htmx version: 1.7.0** ### Setup