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)
useHtmxExtension :: (Monad m) => HtmxExtension -> HtmlT m ()
useHtmxExtension :: forall (m :: * -> *). Monad m => HtmxExtension -> HtmlT m ()
useHtmxExtension = (Natural, Natural, Natural) -> HtmxExtension -> HtmlT m ()
forall (m :: * -> *).
Monad m =>
(Natural, Natural, Natural) -> HtmxExtension -> HtmlT m ()
useHtmxExtensionV (Natural, Natural, Natural)
recommendedVersion
useHtmxExtensionV ::
(Monad m) => (Natural, Natural, Natural) -> HtmxExtension -> HtmlT m ()
useHtmxExtensionV :: forall (m :: * -> *).
Monad m =>
(Natural, Natural, Natural) -> HtmxExtension -> HtmlT m ()
useHtmxExtensionV (Natural, Natural, Natural)
v HtmxExtension
ext = [Attribute] -> Html () -> HtmlT m ()
forall arg result. TermRaw arg result => arg -> result
script_ [Text -> Attribute
src_ (Text -> Attribute) -> Text -> Attribute
forall a b. (a -> b) -> a -> b
$ (Natural, Natural, Natural) -> Text -> Text
htmxExtSrc (Natural, Natural, Natural)
v (HtmxExtension -> Text
forall a. Render a => a -> Text
render HtmxExtension
ext)] (Html ()
"" :: Html ())
useHtmxExtensions :: (Monad m) => [HtmxExtension] -> HtmlT m ()
useHtmxExtensions :: forall (m :: * -> *). Monad m => [HtmxExtension] -> HtmlT m ()
useHtmxExtensions [HtmxExtension]
exts = [HtmxExtension] -> (HtmxExtension -> HtmlT m ()) -> HtmlT m ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
t a -> (a -> m b) -> m ()
forM_ [HtmxExtension]
exts HtmxExtension -> HtmlT m ()
forall (m :: * -> *). Monad m => HtmxExtension -> HtmlT m ()
useHtmxExtension
useHtmxExtensionsV ::
(Monad m) => (Natural, Natural, Natural) -> [HtmxExtension] -> HtmlT m ()
useHtmxExtensionsV :: forall (m :: * -> *).
Monad m =>
(Natural, Natural, Natural) -> [HtmxExtension] -> HtmlT m ()
useHtmxExtensionsV (Natural, Natural, Natural)
v [HtmxExtension]
exts = [HtmxExtension] -> (HtmxExtension -> HtmlT m ()) -> HtmlT m ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
t a -> (a -> m b) -> m ()
forM_ [HtmxExtension]
exts ((Natural, Natural, Natural) -> HtmxExtension -> HtmlT m ()
forall (m :: * -> *).
Monad m =>
(Natural, Natural, Natural) -> HtmxExtension -> HtmlT m ()
useHtmxExtensionV (Natural, Natural, Natural)
v)
useHtmx :: (Monad m) => HtmlT m ()
useHtmx :: forall (m :: * -> *). Monad m => HtmlT m ()
useHtmx = (Natural, Natural, Natural) -> HtmlT m ()
forall (m :: * -> *).
Monad m =>
(Natural, Natural, Natural) -> HtmlT m ()
useHtmxVersion (Natural, Natural, Natural)
recommendedVersion
useHtmxVersion :: (Monad m) => (Natural, Natural, Natural) -> HtmlT m ()
useHtmxVersion :: forall (m :: * -> *).
Monad m =>
(Natural, Natural, Natural) -> HtmlT m ()
useHtmxVersion (Natural, Natural, Natural)
semVer = [Attribute] -> Html () -> HtmlT m ()
forall arg result. TermRaw arg result => arg -> result
script_ [Text -> Attribute
src_ (Text -> Attribute) -> Text -> Attribute
forall a b. (a -> b) -> a -> b
$ (Natural, Natural, Natural) -> Text
htmxSrcWithSemVer (Natural, Natural, Natural)
semVer] (Html ()
"" :: Html ())
recommendedVersion :: (Natural, Natural, Natural)
recommendedVersion :: (Natural, Natural, Natural)
recommendedVersion = (Natural
2, Natural
0, Natural
0)
htmxSrc :: Text
htmxSrc :: Text
htmxSrc = Text
"https://unpkg.com/htmx.org"
showT :: (Show a) => a -> Text
showT :: forall a. Show a => a -> Text
showT = String -> Text
pack (String -> Text) -> (a -> String) -> a -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> String
forall a. Show a => a -> String
show
showSemVer :: (Natural, Natural, Natural) -> Text
showSemVer :: (Natural, Natural, Natural) -> Text
showSemVer (Natural
major, Natural
minor, Natural
patch) =
Text
"@"
Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Natural -> Text
forall a. Show a => a -> Text
showT Natural
major
Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"."
Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Natural -> Text
forall a. Show a => a -> Text
showT Natural
minor
Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"."
Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Natural -> Text
forall a. Show a => a -> Text
showT Natural
patch
htmxSrcWithSemVer :: (Natural, Natural, Natural) -> Text
htmxSrcWithSemVer :: (Natural, Natural, Natural) -> Text
htmxSrcWithSemVer (Natural, Natural, Natural)
ver =
Text
htmxSrc Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> (Natural, Natural, Natural) -> Text
showSemVer (Natural, Natural, Natural)
ver
htmxExtSrc :: (Natural, Natural, Natural) -> Text -> Text
htmxExtSrc :: (Natural, Natural, Natural) -> Text -> Text
htmxExtSrc (Natural, Natural, Natural)
ver Text
ext =
Text
"https://unpkg.com/htmx-ext-"
Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
ext
Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> (Natural, Natural, Natural) -> Text
showSemVer (Natural, Natural, Natural)
ver
Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"/"
Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
ext
Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
".js"