packages feed

servant-htmx (empty) → 0.1.0.0

raw patch · 9 files changed

+165/−0 lines, 9 filesdep +basedep +servantdep +servant-htmxsetup-changed

Dependencies added: base, servant, servant-htmx, servant-server, text

Files

+ ChangeLog.md view
@@ -0,0 +1,3 @@+# Changelog for servant-htmx++## Unreleased changes
+ LICENSE view
@@ -0,0 +1,30 @@+Copyright Author name here (c) 2022++All rights reserved.++Redistribution and use in source and binary forms, with or without+modification, are permitted provided that the following conditions are met:++    * Redistributions of source code must retain the above copyright+      notice, this list of conditions and the following disclaimer.++    * Redistributions in binary form must reproduce the above+      copyright notice, this list of conditions and the following+      disclaimer in the documentation and/or other materials provided+      with the distribution.++    * Neither the name of Author name here nor the names of other+      contributors may be used to endorse or promote products derived+      from this software without specific prior written permission.++THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ README.md view
@@ -0,0 +1,1 @@+# servant-htmx
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ app/Main.hs view
@@ -0,0 +1,6 @@+module Main where++import Lib++main :: IO ()+main = someFunc
+ servant-htmx.cabal view
@@ -0,0 +1,64 @@+cabal-version:      1.12+name:               servant-htmx+version:            0.1.0.0+license:            BSD3+license-file:       LICENSE+copyright:          2022 Author name here+maintainer:         example@example.com+author:             Author name here+homepage:           https://github.com/githubuser/servant-htmx#readme+bug-reports:        https://github.com/githubuser/servant-htmx/issues+synopsis:           A library for using htmx with servant+description:+    Please see the README on GitHub at <https://github.com/githubuser/servant-htmx#readme>++category:           Web+build-type:         Simple+extra-source-files:+    README.md+    ChangeLog.md++source-repository head+    type:     git+    location: https://github.com/githubuser/servant-htmx++library+    exposed-modules:+        Lib+        Servant.HTMX++    hs-source-dirs:   src+    other-modules:    Paths_servant_htmx+    default-language: Haskell2010+    build-depends:+        base >=4.7 && <5,+        servant >=0.18.3 && <0.19,+        servant-server >=0.18.3 && <0.19,+        text >=1.2.4.1 && <1.3++executable servant-htmx-exe+    main-is:          Main.hs+    hs-source-dirs:   app+    other-modules:    Paths_servant_htmx+    default-language: Haskell2010+    ghc-options:      -threaded -rtsopts -with-rtsopts=-N+    build-depends:+        base >=4.7 && <5,+        servant >=0.18.3 && <0.19,+        servant-htmx -any,+        servant-server >=0.18.3 && <0.19,+        text >=1.2.4.1 && <1.3++test-suite servant-htmx-test+    type:             exitcode-stdio-1.0+    main-is:          Spec.hs+    hs-source-dirs:   test+    other-modules:    Paths_servant_htmx+    default-language: Haskell2010+    ghc-options:      -threaded -rtsopts -with-rtsopts=-N+    build-depends:+        base >=4.7 && <5,+        servant >=0.18.3 && <0.19,+        servant-htmx -any,+        servant-server >=0.18.3 && <0.19,+        text >=1.2.4.1 && <1.3
+ src/Lib.hs view
@@ -0,0 +1,6 @@+module Lib+    ( someFunc+    ) where++someFunc :: IO ()+someFunc = putStrLn "someFunc"
+ src/Servant/HTMX.hs view
@@ -0,0 +1,51 @@+{-# LANGUAGE DataKinds #-}+{-# LANGUAGE TypeOperators #-}+{-# LANGUAGE OverloadedStrings #-}++module Servant.HTMX where++import Data.Text+import Servant+import Servant.API+import Servant.Server++-- | Request headers (sent by the client to the server)+type HXRequest = Header "HX-Request" Text+type HXTriggerId = Header "HX-Trigger" Text+type HXTriggerName = Header "HX-Trigger-Name" Text+type HXTarget = Header "HX-Target" Text+type HXPrompt = Header "HX-Prompt" Text++-- | Response headers (sent by the server to the client)+type HXPush = Header "HX-Push" Text -- use safelinks+type HXRedirect = Header "HX-Redirect" Text -- use safelinks+type HXRefresh = Header "HX-Refresh" Text +type HXTrigger = Header "HX-Trigger" Text+type HXTriggerAfterSwap = Header "HX-Trigger-After-Swap" Text+type HXTriggerAfterSettle = Header "HX-Trigger-After-Settle" Text++-- | Example usage of htmx header types+type ExampleAPI = HXRequest :> Get '[JSON] Text+                :<|> HXTriggerId :> Post '[JSON] Text+                :<|> "somePath" :> Get '[JSON] (Headers '[HXPush, HXRedirect] Text)++exampleServer :: Server ExampleAPI+exampleServer = exampleGetHandler+              :<|> examplePostHandler+              :<|> exampleSomePathHandler+  where+    exampleGetHandler :: Maybe Text -> Handler Text+    exampleGetHandler mb = case mb of+      Just "true" -> pure "The request was sent to the server by htmx" +      _ -> pure "The request wasn't sent to the server by htmx" ++    examplePostHandler :: Maybe Text -> Handler Text+    examplePostHandler mb = case mb of+      Just "adminPanel" -> pure "The request was triggered by the admin panel" +      _ -> pure "The request wasn't triggered by the admin panel" ++    exampleSomePathHandler :: Handler (Headers '[HXPush, HXRedirect] Text)+    exampleSomePathHandler = pure $ noHeader $ addHeader "someURLForRedirect" "This response has htmx headers" ++exampleApp :: Application+exampleApp = serve (Proxy :: Proxy ExampleAPI) exampleServer
+ test/Spec.hs view
@@ -0,0 +1,2 @@+main :: IO ()+main = putStrLn "Test suite not yet implemented"