htmx 0.0.0.1 → 0.1.0.0
raw patch · 11 files changed
+6/−574 lines, 11 filesdep +http-api-datadep −htmxdep −luciddep −servant
Dependencies added: http-api-data
Dependencies removed: htmx, lucid, servant
Files
- README.md +1/−1
- htmx.cabal +4/−27
- src/Htmx/Lucid/Core.hs +0/−80
- src/Htmx/Lucid/Extension/IncludeVals.hs +0/−18
- src/Htmx/Lucid/Extra.hs +0/−202
- src/Htmx/Lucid/Head.hs +0/−91
- src/Htmx/Lucid/Servant.hs +0/−55
- src/Htmx/Servant/RequestHeaders.hs +0/−36
- src/Htmx/Servant/ResponseHeaders.hs +0/−49
- src/Htmx/Swap.hs +1/−1
- test/Spec.hs +0/−14
README.md view
@@ -1,1 +1,1 @@-# htmx for Haskell+# htmx
htmx.cabal view
@@ -1,6 +1,6 @@ cabal-version: 3.6 name: htmx-version: 0.0.0.1+version: 0.1.0.0 synopsis: Use htmx with various haskell libraries description: Please see the README on GitHub at <https://github.com/JonathanLorimer/htmx#readme>@@ -28,36 +28,13 @@ exposed-modules: Htmx.Event Htmx.Extension- Htmx.Lucid.Core- Htmx.Lucid.Extension.IncludeVals- Htmx.Lucid.Extra- Htmx.Lucid.Head- Htmx.Lucid.Servant Htmx.Render- Htmx.Servant.RequestHeaders- Htmx.Servant.ResponseHeaders Htmx.Swap hs-source-dirs: src build-depends:- , base >=4.7 && <5- , lucid >=2.9.12.1 && <2.11.20230408.0- , servant >=0.19 && <0.30- , text >=2 && <3-- default-language: Haskell2010--test-suite htmx-test- import: def-exts- type: exitcode-stdio-1.0- main-is: Spec.hs- hs-source-dirs: test- ghc-options: -threaded -rtsopts -with-rtsopts=-N- build-depends:- , base >=4.7 && <5- , htmx- , lucid >=2.9.12.1 && <2.11.20230408.0- , servant >=0.19 && <0.30- , text >=2 && <3+ , base >=4.7 && <5+ , http-api-data >=0.5 && <0.7+ , text >=2 && <3 default-language: Haskell2010
− src/Htmx/Lucid/Core.hs
@@ -1,80 +0,0 @@-{- |-Module : Htmx.Lucid.Core-Description : Provides core htmx tags--This module defines the "core" 11 HTMX attributes-<https://htmx.org/reference/#attributes>--}-module Htmx.Lucid.Core where--import Data.Text (Text, pack)-import Htmx.Event-import Htmx.Render-import Htmx.Swap (Swap)-import Lucid (Html, HtmlT, script_, src_)-import Lucid.Base (Attribute, makeAttribute)---- | <https://htmx.org/attributes/hx-get/>--- issues a GET to the specified URL-hxGet_ :: Text -> Attribute-hxGet_ = makeAttribute "hx-get"---- | <https://htmx.org/attributes/hx-get/>--- issues a POST to the specified URL-hxPost_ :: Text -> Attribute-hxPost_ = makeAttribute "hx-post"---- | <https://htmx.org/attributes/hx-push-url/>--- push a URL into the browser location bar to create history-hxPushUrl_ :: Text -> Attribute-hxPushUrl_ = makeAttribute "hx-push-url"---- | <https://htmx.org/attributes/hx-select/>--- select content to swap in from a response-hxSelect_ :: Text -> Attribute-hxSelect_ = makeAttribute "hx-select"---- | <https://htmx.org/attributes/hx-select-oob/>--- select content to swap in from a response, somewhere other than the target--- (out of band)-hxSelectOob_ :: Text -> Attribute-hxSelectOob_ = makeAttribute "hx-select-oob"---- | <https://htmx.org/attributes/hx-swap/>--- controls how content will swap in (outerHTML, beforeend, afterend, …)-hxSwap_ :: Text -> Attribute-hxSwap_ = makeAttribute "hx-swap"---- | Like 'hxSwap' but takes a strongly typed swap style.--- This doesn't allow [modifiers](https://htmx.org/attributes/hx-swap/#modifiers) to be applied.-hxSwapS_ :: Swap -> Attribute-hxSwapS_ = makeAttribute "hx-swap" . render---- | <https://htmx.org/attributes/hx-swap-oob/>--- mark element to swap in from a response (out of band)-hxSwapOob_ :: Text -> Attribute-hxSwapOob_ = makeAttribute "hx-swap-oob"---- | <https://htmx.org/attributes/hx-target/>--- specifies the target element to be swapped-hxTarget_ :: Text -> Attribute-hxTarget_ = makeAttribute "hx-target"---- | <https://htmx.org/attributes/hx-trigger/>--- specifies the event that triggers the request-hxTrigger_ :: Text -> Attribute-hxTrigger_ = makeAttribute "hx-trigger"---- | <https://htmx.org/attributes/hx-vals/>--- add values to submit with the request (JSON format)-hxVals_ :: Text -> Attribute-hxVals_ = makeAttribute "hx-vals"--data OnEvent = DomOnEvent Text | HtmxOnEvent HtmxEvent---- | <https://htmx.org/attributes/hx-on/>--- handle events with inline scripts on elements-hxOn_ :: OnEvent -> Text -> Attribute-hxOn_ = \case- DomOnEvent event -> makeAttribute $ "hx-on:" <> event- HtmxOnEvent htmxEvent -> makeAttribute $ "hx-on::" <> render htmxEvent
− src/Htmx/Lucid/Extension/IncludeVals.hs
@@ -1,18 +0,0 @@-{- |-Module : Htmx.Lucid.Extension.IncludeVals-Description : Attribute for adding values to a request--This module defines an attribute that allows you to include additional values in a request-<https://github.com/bigskysoftware/htmx-extensions/blob/main/src/include-vals/README.md>--}-module Htmx.Lucid.Extension.IncludeVals where--import Data.Text (Text)-import Lucid-import Lucid.Base (makeAttribute)---- | <https://github.com/bigskysoftware/htmx-extensions/blob/main/src/include-vals/README.md>--- The value of this attribute is one or more name/value pairs, which will be evaluated as the fields in a javascript object literal.--- i.e. "included:true, computed: computeValue()"-includeVals_ :: Text -> Attribute-includeVals_ = makeAttribute "include-vals"
− src/Htmx/Lucid/Extra.hs
@@ -1,202 +0,0 @@-{- |-Module : Htmx.Lucid.Extra-Description : Provides extra htmx tags--This module defines additional attributes that can be used to get additional-behaviour-<https://htmx.org/reference/#attributes-additional>--}-module Htmx.Lucid.Extra where--import Data.Foldable-import Data.List (intersperse)-import Data.Text (Text, pack)-import Htmx.Extension-import Htmx.Render-import Lucid (Html, HtmlT, script_, src_)-import Lucid.Base (Attribute, makeAttribute)---- | <https://htmx.org/attributes/hx-boost/>--- add progressive enhancement for links and forms-hxBoost_ :: Text -> Attribute-hxBoost_ = makeAttribute "hx-boost"---- | <https://htmx.org/attributes/hx-confirm/>--- shows a confirm() dialog before issuing a request-hxConfirm_ :: Text -> Attribute-hxConfirm_ = makeAttribute "hx-confirm"---- | <https://htmx.org/attributes/hx-delete/>--- issues a DELETE to the specified URL-hxDelete_ :: Text -> Attribute-hxDelete_ = makeAttribute "hx-delete"---- | <https://htmx.org/attributes/hx-disable/>--- disables htmx processing for the given node and any children nodes-hxDisable_ :: Attribute-hxDisable_ = makeAttribute "hx-disable" mempty---- | <https://htmx.org/attributes/hx-disabled-elt/>--- adds the disabled attribute to the specified elements while a request is in flight-hxDisabledElt_ :: Text -> Attribute-hxDisabledElt_ = makeAttribute "hx-disabled-elt"---- | <https://htmx.org/attributes/hx-disinherit/>--- control and disable automatic attribute inheritance for child nodes-hxDisinherit_ :: Text -> Attribute-hxDisinherit_ = makeAttribute "hx-disinherit"---- | <https://htmx.org/attributes/hx-encoding/>--- changes the request encoding type-hxEncoding_ :: Text -> Attribute-hxEncoding_ = makeAttribute "hx-encoding"---- | <https://htmx.org/attributes/hx-ext/>--- extensions to use for this element-hxExt_ :: Text -> Attribute-hxExt_ = makeAttribute "hx-ext"---- | A typesafe version of 'hxExt_' that works with the "included" extensions--- that the htmx codebase is tested against-hxExtension_ :: HtmxExtension -> Attribute-hxExtension_ = makeAttribute "hx-ext" . render---- | Include multiple extensions in one declaration-hxExtensions_ :: [HtmxExtension] -> Attribute-hxExtensions_ = makeAttribute "hx-ext" . fold . intersperse "," . fmap render---- | <https://htmx.org/attributes/hx-headers/>--- adds to the headers that will be submitted with the request-hxHeaders_ :: Text -> Attribute-hxHeaders_ = makeAttribute "hx-headers"---- | <https://htmx.org/attributes/hx-history/>--- prevent sensitive data being saved to the history cache-hxHistory_ :: Text -> Attribute-hxHistory_ = makeAttribute "hx-history"---- | <https://htmx.org/attributes/hx-history-elt/>--- the element to snapshot and restore during history navigation-hxHistoryElt_ :: Attribute-hxHistoryElt_ = makeAttribute "hx-history-elt" mempty---- | <https://htmx.org/attributes/hx-include/>--- include additional data in requests-hxInclude_ :: Text -> Attribute-hxInclude_ = makeAttribute "hx-include"---- | <https://htmx.org/attributes/hx-indicator/>--- the element to put the htmx-request class on during the request-hxIndicator_ :: Text -> Attribute-hxIndicator_ = makeAttribute "hx-indicator"--data ParamsFilter- = -- | Include all parameters (default)- All- | -- | Include no parameters- None- | -- | Include all except the list of parameter names- Exclude [Text]- | -- | Include all the list of parameter names- Include [Text]---- | <https://htmx.org/attributes/hx-params/>--- filters the parameters that will be submitted with a request-hxParams_ :: ParamsFilter -> Attribute-hxParams_ = \case- All -> makeAttribute "hx-params" "*"- None -> makeAttribute "hx-params" "none"- Exclude ps -> makeAttribute "hx-params" $ "not " <> (fold . intersperse "," $ ps)- Include ps -> makeAttribute "hx-params" $ fold . intersperse "," $ ps---- | <https://htmx.org/attributes/hx-patch/>--- issues a PATCH to the specified URL-hxPatch_ :: Text -> Attribute-hxPatch_ = makeAttribute "hx-patch"---- | <https://htmx.org/attributes/hx-preserve/>--- specifies elements to keep unchanged between requests-hxPreserve_ :: Attribute-hxPreserve_ = makeAttribute "hx-preserve" mempty---- | <https://htmx.org/attributes/hx-prompt/>--- shows a prompt() before submitting a request-hxPrompt_ :: Text -> Attribute-hxPrompt_ = makeAttribute "hx-prompt"---- | <https://htmx.org/attributes/hx-put/>--- issues a PUT to the specified URL-hxPut_ :: Text -> Attribute-hxPut_ = makeAttribute "hx-put"---- | <https://htmx.org/attributes/hx-replace-url/>--- replace the URL in the browser location bar-hxReplaceUrl_ :: Text -> Attribute-hxReplaceUrl_ = makeAttribute "hx-replace-url"---- | <https://htmx.org/attributes/hx-request/>--- configures various aspects of the request-hxRequest_ :: Text -> Attribute-hxRequest_ = makeAttribute "hx-request"--{-# DEPRECATED- hxSse_- "Don't use hx-sse directly, please use the server sent events extension instead https://htmx.org/extensions/server-sent-events/"- #-}---- | <https://htmx.org/attributes/hx-sse/>--- has been moved to an extension. Documentation for older versions-hxSse_ :: Text -> Attribute-hxSse_ = makeAttribute "hx-sse"--data SyncStrategy- = -- | drop (ignore) this request if an existing request is in flight (the default)- SyncDrop- | -- | drop (ignore) this request if an existing request is in flight, and, if- -- that is not the case, abort this request if another request occurs while it is- -- still in flight- SyncAbort- | -- | abort the current request, if any, and replace it with this request- SyncReplace- | -- | queue the first request to show up while a request is in flight- SyncQueueFirst- | -- | queue the last request to show up while a request is in flight- SyncQueueLast- | -- | queue all requests that show up while a request is in flight- SyncQueueAll---- | <https://htmx.org/attributes/hx-sync/>--- control how requests made by different elements are synchronized-hxSync_ :: Text -> Attribute-hxSync_ = makeAttribute "hx-sync"---- | <https://htmx.org/attributes/hx-sync/>--- the same as 'hxSync_' but accepts a strongly typed htmx 'SyncStrategy'-hxSyncStrategy_ :: Text -> SyncStrategy -> Attribute-hxSyncStrategy_ selector = \case- SyncDrop -> makeAttribute "hx-sync" $ selector <> ":" <> "drop"- SyncAbort -> makeAttribute "hx-sync" $ selector <> ":" <> "abort"- SyncReplace -> makeAttribute "hx-sync" $ selector <> ":" <> "replace"- SyncQueueFirst -> makeAttribute "hx-sync" $ selector <> ":" <> "queue first"- SyncQueueLast -> makeAttribute "hx-sync" $ selector <> ":" <> "queue last"- SyncQueueAll -> makeAttribute "hx-sync" $ selector <> ":" <> "queue all"---- | <https://htmx.org/attributes/hx-validate/>--- force elements to validate themselves before a request-hxValidate_ :: Text -> Attribute-hxValidate_ = makeAttribute "hx-validate"---- | <https://htmx.org/attributes/hx-vars/>--- adds values dynamically to the parameters to submit with the request (deprecated, please use hx-vals)-hxVars_ :: Text -> Attribute-hxVars_ = makeAttribute "hx-vars"--{-# DEPRECATED- hxWs_- "Don't use hx-ws directly, please use the web sockets extension instead https://htmx.org/extensions/server-sent-events/https://htmx.org/extensions/web-sockets/"- #-}---- | <https://htmx.org/attributes/hx-ws/>--- has been moved to an extension. Documentation for older versions-hxWs_ :: Text -> Attribute-hxWs_ = makeAttribute "hx-ws"
− src/Htmx/Lucid/Head.hs
@@ -1,91 +0,0 @@-{- |-Module : Htmx.Lucid.Head-Description : Utilities for including HTMX in the html head tag--This module defines utilities for installing HTMX and HTMX extensions-via the head tag in your html document-<https://htmx.org/docs/#installing>--}-module Htmx.Lucid.Head (- useHtmx,- useHtmxVersion,- useHtmxExtension,- useHtmxExtensionV,- useHtmxExtensions,- useHtmxExtensionsV,- recommendedVersion,- htmxSrc,- htmxSrcWithSemVer,- htmxExtSrc,-) where--import Data.Foldable (forM_)-import Data.Text (Text, pack)-import GHC.Natural (Natural)-import Htmx.Extension-import Htmx.Render-import Lucid (Html, HtmlT, script_, src_)-import Lucid.Base (Attribute, makeAttribute)---- | Place in your template after @useHtmx@, but before where the extension is used via @hxExt_@--- NOTE: This uses 'recommendedVersion' as the version section of the URL-useHtmxExtension :: (Monad m) => HtmxExtension -> HtmlT m ()-useHtmxExtension = useHtmxExtensionV recommendedVersion---- | Same as 'useHtmxExt' but lets you choose the version url-useHtmxExtensionV ::- (Monad m) => (Natural, Natural, Natural) -> HtmxExtension -> HtmlT m ()-useHtmxExtensionV v ext = script_ [src_ $ htmxExtSrc v (render ext)] ("" :: Html ())---- | A typesafe version of 'useHtmxExtension' based on the "included" extensions--- that the htmx codebase is tested against--- NOTE: This uses 'recommendedVersion' as the version section of the URL-useHtmxExtensions :: (Monad m) => [HtmxExtension] -> HtmlT m ()-useHtmxExtensions exts = forM_ exts useHtmxExtension---- | Same as 'useHtmxExts' but with a versioned url-useHtmxExtensionsV ::- (Monad m) => (Natural, Natural, Natural) -> [HtmxExtension] -> HtmlT m ()-useHtmxExtensionsV v exts = forM_ exts (useHtmxExtensionV v)---- | Place in your @head_@ tag to use htmx attributes in your lucid template-useHtmx :: (Monad m) => HtmlT m ()-useHtmx = useHtmxVersion recommendedVersion---- | Choose the version of htmx to use using a 3-tuple representing semantic versioning-useHtmxVersion :: (Monad m) => (Natural, Natural, Natural) -> HtmlT m ()-useHtmxVersion semVer = script_ [src_ $ htmxSrcWithSemVer semVer] ("" :: Html ())---- | This is the recommended version of htmx for using this library--- (lucid-htmx). It is the version of the documentation that the implementation--- is based off of.-recommendedVersion :: (Natural, Natural, Natural)-recommendedVersion = (2, 0, 0)--htmxSrc :: Text-htmxSrc = "https://unpkg.com/htmx.org"--showT :: (Show a) => a -> Text-showT = pack . show--showSemVer :: (Natural, Natural, Natural) -> Text-showSemVer (major, minor, patch) =- "@"- <> showT major- <> "."- <> showT minor- <> "."- <> showT patch--htmxSrcWithSemVer :: (Natural, Natural, Natural) -> Text-htmxSrcWithSemVer ver =- htmxSrc <> showSemVer ver--htmxExtSrc :: (Natural, Natural, Natural) -> Text -> Text-htmxExtSrc ver ext =- "https://unpkg.com/htmx-ext-"- <> ext- <> showSemVer ver- <> "/"- <> ext- <> ".js"
− src/Htmx/Lucid/Servant.hs
@@ -1,55 +0,0 @@-{- |-Module : Htmx.Lucid.Servant-Description : Typesafe versions of HTMX request tags--This module exports Lucid combinators that leverage the Servant 'Link'-type to guarantee that they are live URLs, therefore making the requests-"safe".--}-module Htmx.Lucid.Servant (- hxDeleteSafe_,- hxGetSafe_,- hxPatchSafe_,- hxPostSafe_,- hxPushUrlSafe_,- hxPutSafe_,-)-where--import Data.Text (Text)-import Htmx.Lucid.Core (- hxGet_,- hxPost_,- hxPushUrl_,- )-import Htmx.Lucid.Extra (- hxDelete_,- hxPatch_,- hxPut_,- )-import Lucid.Base (Attribute)-import Servant.API (ToHttpApiData (..), toUrlPiece)-import Servant.Links (Link)--hxDeleteSafe_ :: Link -> Attribute-hxDeleteSafe_ = hxDelete_ . toUrl--hxGetSafe_ :: Link -> Attribute-hxGetSafe_ = hxGet_ . toUrl--hxPatchSafe_ :: Link -> Attribute-hxPatchSafe_ = hxPatch_ . toUrl--hxPostSafe_ :: Link -> Attribute-hxPostSafe_ = hxPost_ . toUrl--hxPushUrlSafe_ :: Either Bool Link -> Attribute-hxPushUrlSafe_ boolOrUrl = hxPushUrl_ $ case boolOrUrl of- Left bool -> if bool then "true" else "false"- Right url -> toUrl url--hxPutSafe_ :: Link -> Attribute-hxPutSafe_ = hxPut_ . toUrl--toUrl :: (ToHttpApiData a) => a -> Text-toUrl = ("/" <>) . toUrlPiece
− src/Htmx/Servant/RequestHeaders.hs
@@ -1,36 +0,0 @@-{-# LANGUAGE DataKinds #-}--{- |-Module : Htmx.Servant.RequestHeaders-Description : Helper types for HTMX request headers--<https://htmx.org/reference/#request_headers>--}-module Htmx.Servant.RequestHeaders where--import Data.Text (Text)-import Servant.API.Header (Header)---- | indicates that the request is via an element using hx-boost-type HXBoosted = Header "HX-Boosted" Bool---- | the current URL of the browser-type HXCurrentURL = Header "HX-Current-URL" Text---- | “true” if the request is for history restoration after a miss in the local history cache-type HXHistoryRestoreRequest = Header "HX-History-Restore-Request" Bool---- | the user response to an hx-prompt-type HXPrompt a = Header "HX-Prompt" a---- | always “true”-type HXRequest = Header "HX-Prompt" Bool---- | the id of the target element if it exists-type HXTarget = Header "HX-Target" Text---- | the name of the triggered element if it exists-type HXTriggerName = Header "HX-Trigger-Name" Text---- | the id of the triggered element if it exists-type HXTrigger = Header "HX-Trigger" Text
− src/Htmx/Servant/ResponseHeaders.hs
@@ -1,49 +0,0 @@-{-# LANGUAGE DataKinds #-}--{- |-Module : Htmx.Servant.ResponseHeaders-Description : Helper types for HTMX response headers--<https://htmx.org/reference/#response_headers>--}-module Htmx.Servant.ResponseHeaders where--import Data.Text (Text)-import Htmx.Swap (Swap)-import Servant.API.Header (Header)---- | allows you to do a client-side redirect that does not do a full page reload-type HXLocation = Header "HX-Location" Text---- | pushes a new url into the history stack-type HXPushURL = Header "HX-Push-Url" Text---- | can be used to do a client-side redirect to a new location-type HXRedirect = Header "HX-Redirect" Text---- | if set to “true” the client-side will do a full refresh of the page-type HXRefresh = Header "HX-Refresh" Bool---- | replaces the current URL in the location bar-type HXReplaceUrl = Header "HX-Replace-Url" Bool---- | replaces the current URL in the location bar-type HXReswap = Header "HX-Reswap" Swap---- | a CSS selector that updates the target of the--- content update to a different element on the page-type HXRetarget = Header "HX-Retarget" Text---- | a CSS selector that allows you to choose which part of the response is used--- to be swapped in. Overrides an existing hx-select on the triggering element-type HXReselect = Header "HX-Reselect" Text---- | allows you to trigger client-side events-type HXTrigger = Header "HX-Trigger" Text---- | allows you to trigger client-side events after the settle step-type HXTriggerAfterSettle = Header "HX-Trigger-After-Settle" Text---- | allows you to trigger client-side events after the swap stepallows you to--- trigger client-side events after the settle step-type HXTriggerAfterSwap = Header "HX-Trigger-After-Swap" Text
src/Htmx/Swap.hs view
@@ -9,7 +9,7 @@ import Data.Text (Text, pack) import Htmx.Render-import Servant.API (FromHttpApiData (..), ToHttpApiData (..))+import Web.HttpApiData (FromHttpApiData (..), ToHttpApiData (..)) -- | <https://htmx.org/attributes/hx-swap/> -- The different styles that can be used for swapping in content.
− test/Spec.hs
@@ -1,14 +0,0 @@-{-# LANGUAGE OverloadedStrings, ExtendedDefaultRules #-}-import Lucid-import Lucid.Htmx-import System.IO (stdout, hSetEncoding, utf8)-import Data.Text.Lazy.IO as L--main :: IO ()-main = do- hSetEncoding stdout utf8- L.hPutStr stdout (renderText template1)--template1 :: Html ()-template1 =- div_ [id_ "someId" , hxPost_ "/some/url" ] "Content of div"