{-# LANGUAGE OverloadedStrings #-}
module Lucid.XStatic (xstaticScripts) where
import Data.Foldable (traverse_)
import Data.Text.Encoding
import Lucid
import XStatic
xstaticScripts :: [XStaticFile] -> Html ()
xstaticScripts :: [XStaticFile] -> Html ()
xstaticScripts = forall (t :: * -> *) (f :: * -> *) a b.
(Foldable t, Applicative f) =>
(a -> f b) -> t a -> f ()
traverse_ XStaticFile -> Html ()
xrender
where
xrender :: XStaticFile -> Html ()
xrender :: XStaticFile -> Html ()
xrender XStaticFile
xf =
let src :: Text
src = Text
"/xstatic" forall a. Semigroup a => a -> a -> a
<> ByteString -> Text
decodeUtf8 (XStaticFile -> ByteString
xfPath XStaticFile
xf) forall a. Semigroup a => a -> a -> a
<> Text
"?v=" forall a. Semigroup a => a -> a -> a
<> ByteString -> Text
decodeUtf8 (XStaticFile -> ByteString
xfETag XStaticFile
xf)
in case XStaticFile -> ByteString
xfType XStaticFile
xf of
ByteString
"application/javascript" -> forall a. With a => a -> [Attribute] -> a
with (forall arg result. TermRaw arg result => arg -> result
script_ forall a. Monoid a => a
mempty) [Text -> Attribute
src_ Text
src]
ByteString
"text/css" -> forall (m :: * -> *). Applicative m => [Attribute] -> HtmlT m ()
link_ [Text -> Attribute
href_ Text
src, Text -> Attribute
rel_ Text
"stylesheet"]
ByteString
_ -> forall (f :: * -> *) a. Applicative f => a -> f a
pure ()