{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE TupleSections #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE TypeSynonymInstances #-}
{-# LANGUAGE UndecidableInstances #-}
{-# LANGUAGE QuasiQuotes #-}
module Yesod.Core.Widget
(
WidgetT
, WidgetFor
, PageContent (..)
, whamlet
, whamletFile
, ihamletToRepHtml
, ihamletToHtml
, ToWidget (..)
, ToWidgetHead (..)
, ToWidgetBody (..)
, ToWidgetMedia (..)
, setTitle
, setTitleI
, setDescription
, setDescriptionI
, setDescriptionIdemp
, setDescriptionIdempI
, setOGType
, setOGImage
, addStylesheet
, addStylesheetAttrs
, addStylesheetRemote
, addStylesheetRemoteAttrs
, addStylesheetEither
, CssBuilder (..)
, addScript
, addScriptAttrs
, addScriptRemote
, addScriptRemoteAttrs
, addScriptEither
, handlerToWidget
, whamletFileWithSettings
, asWidgetT
) where
import Data.Monoid
import qualified Text.Blaze.Html5 as H
import Text.Hamlet
import Text.Cassius
import Text.Julius
import Yesod.Routes.Class
import Yesod.Core.Handler (getMessageRender, getUrlRenderParams)
import Text.Shakespeare.I18N (RenderMessage)
import Data.Text (Text)
import Data.Kind (Type)
import qualified Data.Map as Map
import Language.Haskell.TH.Quote (QuasiQuoter)
import Language.Haskell.TH.Syntax (Q, Exp (InfixE, VarE, LamE, AppE), Pat (VarP), newName)
import qualified Text.Hamlet as NP
import Data.Text.Lazy.Builder (fromLazyText)
import Text.Blaze.Html (toHtml, preEscapedToMarkup)
import qualified Data.Text.Lazy as TL
import qualified Data.Text.Lazy.Builder as TB
import Yesod.Core.Types
import Yesod.Core.Class.Handler
type WidgetT site (m :: Type -> Type) = WidgetFor site
{-# DEPRECATED WidgetT "Use WidgetFor directly" #-}
preEscapedLazyText :: TL.Text -> Html
preEscapedLazyText :: Text -> Html
preEscapedLazyText = forall a. ToMarkup a => a -> Html
preEscapedToMarkup
class ToWidget site a where
toWidget :: (MonadWidget m, HandlerSite m ~ site) => a -> m ()
instance render ~ RY site => ToWidget site (render -> Html) where
toWidget :: forall (m :: * -> *).
(MonadWidget m, HandlerSite m ~ site) =>
(render -> Html) -> m ()
toWidget render -> Html
x = forall (m :: * -> *).
MonadWidget m =>
GWData (Route (HandlerSite m)) -> m ()
tell forall a b. (a -> b) -> a -> b
$ forall a.
Body a
-> Last Title
-> Last Description
-> UniqueList (Script a)
-> UniqueList (Stylesheet a)
-> Map (Maybe Text) (CssBuilderUrl a)
-> Maybe (JavascriptUrl a)
-> Head a
-> GWData a
GWData (forall url. HtmlUrl url -> Body url
Body render -> Html
x) forall a. Monoid a => a
mempty forall a. Monoid a => a
mempty forall a. Monoid a => a
mempty forall a. Monoid a => a
mempty forall a. Monoid a => a
mempty forall a. Monoid a => a
mempty forall a. Monoid a => a
mempty
instance render ~ RY site => ToWidget site (render -> Css) where
toWidget :: forall (m :: * -> *).
(MonadWidget m, HandlerSite m ~ site) =>
(render -> Css) -> m ()
toWidget render -> Css
x = forall site a (m :: * -> *).
(ToWidget site a, MonadWidget m, HandlerSite m ~ site) =>
a -> m ()
toWidget forall a b. (a -> b) -> a -> b
$ Builder -> CssBuilder
CssBuilder forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Builder
fromLazyText forall b c a. (b -> c) -> (a -> b) -> a -> c
. Css -> Text
renderCss forall b c a. (b -> c) -> (a -> b) -> a -> c
. render -> Css
x
instance ToWidget site Css where
toWidget :: forall (m :: * -> *).
(MonadWidget m, HandlerSite m ~ site) =>
Css -> m ()
toWidget Css
x = forall site a (m :: * -> *).
(ToWidget site a, MonadWidget m, HandlerSite m ~ site) =>
a -> m ()
toWidget forall a b. (a -> b) -> a -> b
$ Builder -> CssBuilder
CssBuilder forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Builder
fromLazyText forall b c a. (b -> c) -> (a -> b) -> a -> c
. Css -> Text
renderCss forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. a -> b -> a
const Css
x
instance render ~ RY site => ToWidget site (render -> CssBuilder) where
toWidget :: forall (m :: * -> *).
(MonadWidget m, HandlerSite m ~ site) =>
(render -> CssBuilder) -> m ()
toWidget render -> CssBuilder
x = forall (m :: * -> *).
MonadWidget m =>
GWData (Route (HandlerSite m)) -> m ()
tell forall a b. (a -> b) -> a -> b
$ forall a.
Body a
-> Last Title
-> Last Description
-> UniqueList (Script a)
-> UniqueList (Stylesheet a)
-> Map (Maybe Text) (CssBuilderUrl a)
-> Maybe (JavascriptUrl a)
-> Head a
-> GWData a
GWData forall a. Monoid a => a
mempty forall a. Monoid a => a
mempty forall a. Monoid a => a
mempty forall a. Monoid a => a
mempty forall a. Monoid a => a
mempty (forall k a. k -> a -> Map k a
Map.singleton forall a. Maybe a
Nothing forall a b. (a -> b) -> a -> b
$ CssBuilder -> Builder
unCssBuilder forall b c a. (b -> c) -> (a -> b) -> a -> c
. render -> CssBuilder
x) forall a. Monoid a => a
mempty forall a. Monoid a => a
mempty
instance ToWidget site CssBuilder where
toWidget :: forall (m :: * -> *).
(MonadWidget m, HandlerSite m ~ site) =>
CssBuilder -> m ()
toWidget CssBuilder
x = forall (m :: * -> *).
MonadWidget m =>
GWData (Route (HandlerSite m)) -> m ()
tell forall a b. (a -> b) -> a -> b
$ forall a.
Body a
-> Last Title
-> Last Description
-> UniqueList (Script a)
-> UniqueList (Stylesheet a)
-> Map (Maybe Text) (CssBuilderUrl a)
-> Maybe (JavascriptUrl a)
-> Head a
-> GWData a
GWData forall a. Monoid a => a
mempty forall a. Monoid a => a
mempty forall a. Monoid a => a
mempty forall a. Monoid a => a
mempty forall a. Monoid a => a
mempty (forall k a. k -> a -> Map k a
Map.singleton forall a. Maybe a
Nothing forall a b. (a -> b) -> a -> b
$ CssBuilder -> Builder
unCssBuilder forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. a -> b -> a
const CssBuilder
x) forall a. Monoid a => a
mempty forall a. Monoid a => a
mempty
instance render ~ RY site => ToWidget site (render -> Javascript) where
toWidget :: forall (m :: * -> *).
(MonadWidget m, HandlerSite m ~ site) =>
(render -> Javascript) -> m ()
toWidget render -> Javascript
x = forall (m :: * -> *).
MonadWidget m =>
GWData (Route (HandlerSite m)) -> m ()
tell forall a b. (a -> b) -> a -> b
$ forall a.
Body a
-> Last Title
-> Last Description
-> UniqueList (Script a)
-> UniqueList (Stylesheet a)
-> Map (Maybe Text) (CssBuilderUrl a)
-> Maybe (JavascriptUrl a)
-> Head a
-> GWData a
GWData forall a. Monoid a => a
mempty forall a. Monoid a => a
mempty forall a. Monoid a => a
mempty forall a. Monoid a => a
mempty forall a. Monoid a => a
mempty forall a. Monoid a => a
mempty (forall a. a -> Maybe a
Just render -> Javascript
x) forall a. Monoid a => a
mempty
instance ToWidget site Javascript where
toWidget :: forall (m :: * -> *).
(MonadWidget m, HandlerSite m ~ site) =>
Javascript -> m ()
toWidget Javascript
x = forall (m :: * -> *).
MonadWidget m =>
GWData (Route (HandlerSite m)) -> m ()
tell forall a b. (a -> b) -> a -> b
$ forall a.
Body a
-> Last Title
-> Last Description
-> UniqueList (Script a)
-> UniqueList (Stylesheet a)
-> Map (Maybe Text) (CssBuilderUrl a)
-> Maybe (JavascriptUrl a)
-> Head a
-> GWData a
GWData forall a. Monoid a => a
mempty forall a. Monoid a => a
mempty forall a. Monoid a => a
mempty forall a. Monoid a => a
mempty forall a. Monoid a => a
mempty forall a. Monoid a => a
mempty (forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$ forall a b. a -> b -> a
const Javascript
x) forall a. Monoid a => a
mempty
instance (site' ~ site, a ~ ()) => ToWidget site' (WidgetFor site a) where
toWidget :: forall (m :: * -> *).
(MonadWidget m, HandlerSite m ~ site') =>
WidgetFor site a -> m ()
toWidget = forall (m :: * -> *) a.
MonadWidget m =>
WidgetFor (HandlerSite m) a -> m a
liftWidget
instance ToWidget site Html where
toWidget :: forall (m :: * -> *).
(MonadWidget m, HandlerSite m ~ site) =>
Html -> m ()
toWidget = forall site a (m :: * -> *).
(ToWidget site a, MonadWidget m, HandlerSite m ~ site) =>
a -> m ()
toWidget forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. a -> b -> a
const
instance ToWidget site Text where
toWidget :: forall (m :: * -> *).
(MonadWidget m, HandlerSite m ~ site) =>
Text -> m ()
toWidget = forall site a (m :: * -> *).
(ToWidget site a, MonadWidget m, HandlerSite m ~ site) =>
a -> m ()
toWidget forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. ToMarkup a => a -> Html
toHtml
instance ToWidget site TL.Text where
toWidget :: forall (m :: * -> *).
(MonadWidget m, HandlerSite m ~ site) =>
Text -> m ()
toWidget = forall site a (m :: * -> *).
(ToWidget site a, MonadWidget m, HandlerSite m ~ site) =>
a -> m ()
toWidget forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. ToMarkup a => a -> Html
toHtml
instance ToWidget site TB.Builder where
toWidget :: forall (m :: * -> *).
(MonadWidget m, HandlerSite m ~ site) =>
Builder -> m ()
toWidget = forall site a (m :: * -> *).
(ToWidget site a, MonadWidget m, HandlerSite m ~ site) =>
a -> m ()
toWidget forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. ToMarkup a => a -> Html
toHtml
class ToWidgetMedia site a where
toWidgetMedia :: (MonadWidget m, HandlerSite m ~ site)
=> Text
-> a
-> m ()
instance render ~ RY site => ToWidgetMedia site (render -> Css) where
toWidgetMedia :: forall (m :: * -> *).
(MonadWidget m, HandlerSite m ~ site) =>
Text -> (render -> Css) -> m ()
toWidgetMedia Text
media render -> Css
x = forall site a (m :: * -> *).
(ToWidgetMedia site a, MonadWidget m, HandlerSite m ~ site) =>
Text -> a -> m ()
toWidgetMedia Text
media forall a b. (a -> b) -> a -> b
$ Builder -> CssBuilder
CssBuilder forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Builder
fromLazyText forall b c a. (b -> c) -> (a -> b) -> a -> c
. Css -> Text
renderCss forall b c a. (b -> c) -> (a -> b) -> a -> c
. render -> Css
x
instance ToWidgetMedia site Css where
toWidgetMedia :: forall (m :: * -> *).
(MonadWidget m, HandlerSite m ~ site) =>
Text -> Css -> m ()
toWidgetMedia Text
media Css
x = forall site a (m :: * -> *).
(ToWidgetMedia site a, MonadWidget m, HandlerSite m ~ site) =>
Text -> a -> m ()
toWidgetMedia Text
media forall a b. (a -> b) -> a -> b
$ Builder -> CssBuilder
CssBuilder forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Builder
fromLazyText forall b c a. (b -> c) -> (a -> b) -> a -> c
. Css -> Text
renderCss forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. a -> b -> a
const Css
x
instance render ~ RY site => ToWidgetMedia site (render -> CssBuilder) where
toWidgetMedia :: forall (m :: * -> *).
(MonadWidget m, HandlerSite m ~ site) =>
Text -> (render -> CssBuilder) -> m ()
toWidgetMedia Text
media render -> CssBuilder
x = forall (m :: * -> *).
MonadWidget m =>
GWData (Route (HandlerSite m)) -> m ()
tell forall a b. (a -> b) -> a -> b
$ forall a.
Body a
-> Last Title
-> Last Description
-> UniqueList (Script a)
-> UniqueList (Stylesheet a)
-> Map (Maybe Text) (CssBuilderUrl a)
-> Maybe (JavascriptUrl a)
-> Head a
-> GWData a
GWData forall a. Monoid a => a
mempty forall a. Monoid a => a
mempty forall a. Monoid a => a
mempty forall a. Monoid a => a
mempty forall a. Monoid a => a
mempty (forall k a. k -> a -> Map k a
Map.singleton (forall a. a -> Maybe a
Just Text
media) forall a b. (a -> b) -> a -> b
$ CssBuilder -> Builder
unCssBuilder forall b c a. (b -> c) -> (a -> b) -> a -> c
. render -> CssBuilder
x) forall a. Monoid a => a
mempty forall a. Monoid a => a
mempty
instance ToWidgetMedia site CssBuilder where
toWidgetMedia :: forall (m :: * -> *).
(MonadWidget m, HandlerSite m ~ site) =>
Text -> CssBuilder -> m ()
toWidgetMedia Text
media CssBuilder
x = forall (m :: * -> *).
MonadWidget m =>
GWData (Route (HandlerSite m)) -> m ()
tell forall a b. (a -> b) -> a -> b
$ forall a.
Body a
-> Last Title
-> Last Description
-> UniqueList (Script a)
-> UniqueList (Stylesheet a)
-> Map (Maybe Text) (CssBuilderUrl a)
-> Maybe (JavascriptUrl a)
-> Head a
-> GWData a
GWData forall a. Monoid a => a
mempty forall a. Monoid a => a
mempty forall a. Monoid a => a
mempty forall a. Monoid a => a
mempty forall a. Monoid a => a
mempty (forall k a. k -> a -> Map k a
Map.singleton (forall a. a -> Maybe a
Just Text
media) forall a b. (a -> b) -> a -> b
$ CssBuilder -> Builder
unCssBuilder forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. a -> b -> a
const CssBuilder
x) forall a. Monoid a => a
mempty forall a. Monoid a => a
mempty
class ToWidgetBody site a where
toWidgetBody :: (MonadWidget m, HandlerSite m ~ site) => a -> m ()
instance render ~ RY site => ToWidgetBody site (render -> Html) where
toWidgetBody :: forall (m :: * -> *).
(MonadWidget m, HandlerSite m ~ site) =>
(render -> Html) -> m ()
toWidgetBody = forall site a (m :: * -> *).
(ToWidget site a, MonadWidget m, HandlerSite m ~ site) =>
a -> m ()
toWidget
instance render ~ RY site => ToWidgetBody site (render -> Javascript) where
toWidgetBody :: forall (m :: * -> *).
(MonadWidget m, HandlerSite m ~ site) =>
(render -> Javascript) -> m ()
toWidgetBody render -> Javascript
j = forall site a (m :: * -> *).
(ToWidget site a, MonadWidget m, HandlerSite m ~ site) =>
a -> m ()
toWidget forall a b. (a -> b) -> a -> b
$ \RY site
r -> Html -> Html
H.script forall a b. (a -> b) -> a -> b
$ Text -> Html
preEscapedLazyText forall a b. (a -> b) -> a -> b
$ forall url.
(url -> [(Text, Text)] -> Text) -> JavascriptUrl url -> Text
renderJavascriptUrl RY site
r render -> Javascript
j
instance ToWidgetBody site Javascript where
toWidgetBody :: forall (m :: * -> *).
(MonadWidget m, HandlerSite m ~ site) =>
Javascript -> m ()
toWidgetBody Javascript
j = forall site a (m :: * -> *).
(ToWidget site a, MonadWidget m, HandlerSite m ~ site) =>
a -> m ()
toWidget forall a b. (a -> b) -> a -> b
$ \RY site
_ -> Html -> Html
H.script forall a b. (a -> b) -> a -> b
$ Text -> Html
preEscapedLazyText forall a b. (a -> b) -> a -> b
$ Javascript -> Text
renderJavascript Javascript
j
instance ToWidgetBody site Html where
toWidgetBody :: forall (m :: * -> *).
(MonadWidget m, HandlerSite m ~ site) =>
Html -> m ()
toWidgetBody = forall site a (m :: * -> *).
(ToWidget site a, MonadWidget m, HandlerSite m ~ site) =>
a -> m ()
toWidget
class ToWidgetHead site a where
toWidgetHead :: (MonadWidget m, HandlerSite m ~ site) => a -> m ()
instance render ~ RY site => ToWidgetHead site (render -> Html) where
toWidgetHead :: forall (m :: * -> *).
(MonadWidget m, HandlerSite m ~ site) =>
(render -> Html) -> m ()
toWidgetHead = forall (m :: * -> *).
MonadWidget m =>
GWData (Route (HandlerSite m)) -> m ()
tell forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a.
Body a
-> Last Title
-> Last Description
-> UniqueList (Script a)
-> UniqueList (Stylesheet a)
-> Map (Maybe Text) (CssBuilderUrl a)
-> Maybe (JavascriptUrl a)
-> Head a
-> GWData a
GWData forall a. Monoid a => a
mempty forall a. Monoid a => a
mempty forall a. Monoid a => a
mempty forall a. Monoid a => a
mempty forall a. Monoid a => a
mempty forall a. Monoid a => a
mempty forall a. Monoid a => a
mempty forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall url. HtmlUrl url -> Head url
Head
instance render ~ RY site => ToWidgetHead site (render -> Css) where
toWidgetHead :: forall (m :: * -> *).
(MonadWidget m, HandlerSite m ~ site) =>
(render -> Css) -> m ()
toWidgetHead = forall site a (m :: * -> *).
(ToWidget site a, MonadWidget m, HandlerSite m ~ site) =>
a -> m ()
toWidget
instance ToWidgetHead site Css where
toWidgetHead :: forall (m :: * -> *).
(MonadWidget m, HandlerSite m ~ site) =>
Css -> m ()
toWidgetHead = forall site a (m :: * -> *).
(ToWidget site a, MonadWidget m, HandlerSite m ~ site) =>
a -> m ()
toWidget
instance render ~ RY site => ToWidgetHead site (render -> CssBuilder) where
toWidgetHead :: forall (m :: * -> *).
(MonadWidget m, HandlerSite m ~ site) =>
(render -> CssBuilder) -> m ()
toWidgetHead = forall site a (m :: * -> *).
(ToWidget site a, MonadWidget m, HandlerSite m ~ site) =>
a -> m ()
toWidget
instance ToWidgetHead site CssBuilder where
toWidgetHead :: forall (m :: * -> *).
(MonadWidget m, HandlerSite m ~ site) =>
CssBuilder -> m ()
toWidgetHead = forall site a (m :: * -> *).
(ToWidget site a, MonadWidget m, HandlerSite m ~ site) =>
a -> m ()
toWidget
instance render ~ RY site => ToWidgetHead site (render -> Javascript) where
toWidgetHead :: forall (m :: * -> *).
(MonadWidget m, HandlerSite m ~ site) =>
(render -> Javascript) -> m ()
toWidgetHead render -> Javascript
j = forall site a (m :: * -> *).
(ToWidgetHead site a, MonadWidget m, HandlerSite m ~ site) =>
a -> m ()
toWidgetHead forall a b. (a -> b) -> a -> b
$ \RY site
r -> Html -> Html
H.script forall a b. (a -> b) -> a -> b
$ Text -> Html
preEscapedLazyText forall a b. (a -> b) -> a -> b
$ forall url.
(url -> [(Text, Text)] -> Text) -> JavascriptUrl url -> Text
renderJavascriptUrl RY site
r render -> Javascript
j
instance ToWidgetHead site Javascript where
toWidgetHead :: forall (m :: * -> *).
(MonadWidget m, HandlerSite m ~ site) =>
Javascript -> m ()
toWidgetHead Javascript
j = forall site a (m :: * -> *).
(ToWidgetHead site a, MonadWidget m, HandlerSite m ~ site) =>
a -> m ()
toWidgetHead forall a b. (a -> b) -> a -> b
$ \RY site
_ -> Html -> Html
H.script forall a b. (a -> b) -> a -> b
$ Text -> Html
preEscapedLazyText forall a b. (a -> b) -> a -> b
$ Javascript -> Text
renderJavascript Javascript
j
instance ToWidgetHead site Html where
toWidgetHead :: forall (m :: * -> *).
(MonadWidget m, HandlerSite m ~ site) =>
Html -> m ()
toWidgetHead = forall site a (m :: * -> *).
(ToWidgetHead site a, MonadWidget m, HandlerSite m ~ site) =>
a -> m ()
toWidgetHead forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. a -> b -> a
const
setTitle :: MonadWidget m => Html -> m ()
setTitle :: forall (m :: * -> *). MonadWidget m => Html -> m ()
setTitle Html
x = forall (m :: * -> *).
MonadWidget m =>
GWData (Route (HandlerSite m)) -> m ()
tell forall a b. (a -> b) -> a -> b
$ forall a.
Body a
-> Last Title
-> Last Description
-> UniqueList (Script a)
-> UniqueList (Stylesheet a)
-> Map (Maybe Text) (CssBuilderUrl a)
-> Maybe (JavascriptUrl a)
-> Head a
-> GWData a
GWData forall a. Monoid a => a
mempty (forall a. Maybe a -> Last a
Last forall a b. (a -> b) -> a -> b
$ forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$ Html -> Title
Title Html
x) forall a. Monoid a => a
mempty forall a. Monoid a => a
mempty forall a. Monoid a => a
mempty forall a. Monoid a => a
mempty forall a. Monoid a => a
mempty forall a. Monoid a => a
mempty
setTitleI :: (MonadWidget m, RenderMessage (HandlerSite m) msg) => msg -> m ()
setTitleI :: forall (m :: * -> *) msg.
(MonadWidget m, RenderMessage (HandlerSite m) msg) =>
msg -> m ()
setTitleI msg
msg = do
msg -> Text
mr <- forall (m :: * -> *) message.
(MonadHandler m, RenderMessage (HandlerSite m) message) =>
m (message -> Text)
getMessageRender
forall (m :: * -> *). MonadWidget m => Html -> m ()
setTitle forall a b. (a -> b) -> a -> b
$ forall a. ToMarkup a => a -> Html
toHtml forall a b. (a -> b) -> a -> b
$ msg -> Text
mr msg
msg
setDescription :: MonadWidget m => Text -> m ()
setDescription :: forall (m :: * -> *). MonadWidget m => Text -> m ()
setDescription Text
description =
forall site a (m :: * -> *).
(ToWidgetHead site a, MonadWidget m, HandlerSite m ~ site) =>
a -> m ()
toWidgetHead forall a b. (a -> b) -> a -> b
$ [hamlet|<meta name=description content=#{description}>|]
{-# WARNING setDescription
[ "setDescription is not idempotent; we recommend setDescriptionIdemp instead"
, "Multiple calls to setDescription will insert multiple meta tags in the page head."
, "If you want an idempotent function, use setDescriptionIdemp - but if you do, you \
\may need to change your layout to include pageDescription."
]
#-}
setDescriptionI
:: (MonadWidget m, RenderMessage (HandlerSite m) msg)
=> msg -> m ()
setDescriptionI :: forall (m :: * -> *) msg.
(MonadWidget m, RenderMessage (HandlerSite m) msg) =>
msg -> m ()
setDescriptionI msg
msg = do
msg -> Text
mr <- forall (m :: * -> *) message.
(MonadHandler m, RenderMessage (HandlerSite m) message) =>
m (message -> Text)
getMessageRender
forall site a (m :: * -> *).
(ToWidgetHead site a, MonadWidget m, HandlerSite m ~ site) =>
a -> m ()
toWidgetHead forall a b. (a -> b) -> a -> b
$ [hamlet|<meta name=description content=#{mr msg}>|]
{-# WARNING setDescriptionI
[ "setDescriptionI is not idempotent; we recommend setDescriptionIdempI instead"
, "Multiple calls to setDescriptionI will insert multiple meta tags in the page head."
, "If you want an idempotent function, use setDescriptionIdempI - but if you do, you \
\may need to change your layout to include pageDescription."
]
#-}
setDescriptionIdemp :: MonadWidget m => Text -> m ()
setDescriptionIdemp :: forall (m :: * -> *). MonadWidget m => Text -> m ()
setDescriptionIdemp Text
description = forall (m :: * -> *).
MonadWidget m =>
GWData (Route (HandlerSite m)) -> m ()
tell forall a b. (a -> b) -> a -> b
$ forall a.
Body a
-> Last Title
-> Last Description
-> UniqueList (Script a)
-> UniqueList (Stylesheet a)
-> Map (Maybe Text) (CssBuilderUrl a)
-> Maybe (JavascriptUrl a)
-> Head a
-> GWData a
GWData forall a. Monoid a => a
mempty forall a. Monoid a => a
mempty (forall a. Maybe a -> Last a
Last forall a b. (a -> b) -> a -> b
$ forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$ Text -> Description
Description Text
description) forall a. Monoid a => a
mempty forall a. Monoid a => a
mempty forall a. Monoid a => a
mempty forall a. Monoid a => a
mempty forall a. Monoid a => a
mempty
setDescriptionIdempI
:: (MonadWidget m, RenderMessage (HandlerSite m) msg)
=> msg -> m ()
setDescriptionIdempI :: forall (m :: * -> *) msg.
(MonadWidget m, RenderMessage (HandlerSite m) msg) =>
msg -> m ()
setDescriptionIdempI msg
msg = do
msg -> Text
mr <- forall (m :: * -> *) message.
(MonadHandler m, RenderMessage (HandlerSite m) message) =>
m (message -> Text)
getMessageRender
forall (m :: * -> *). MonadWidget m => Text -> m ()
setDescriptionIdemp forall a b. (a -> b) -> a -> b
$ msg -> Text
mr msg
msg
setOGType :: MonadWidget m => Text -> m ()
setOGType :: forall (m :: * -> *). MonadWidget m => Text -> m ()
setOGType Text
a = forall site a (m :: * -> *).
(ToWidgetHead site a, MonadWidget m, HandlerSite m ~ site) =>
a -> m ()
toWidgetHead forall a b. (a -> b) -> a -> b
$ [hamlet|<meta property="og:type" content=#{a}>|]
setOGImage :: MonadWidget m => Text -> m ()
setOGImage :: forall (m :: * -> *). MonadWidget m => Text -> m ()
setOGImage Text
a = forall site a (m :: * -> *).
(ToWidgetHead site a, MonadWidget m, HandlerSite m ~ site) =>
a -> m ()
toWidgetHead forall a b. (a -> b) -> a -> b
$ [hamlet|<meta property="og:image" content=#{a}>|]
addStylesheet :: MonadWidget m => Route (HandlerSite m) -> m ()
addStylesheet :: forall (m :: * -> *).
MonadWidget m =>
Route (HandlerSite m) -> m ()
addStylesheet = forall a b c. (a -> b -> c) -> b -> a -> c
flip forall (m :: * -> *).
MonadWidget m =>
Route (HandlerSite m) -> [(Text, Text)] -> m ()
addStylesheetAttrs []
addStylesheetAttrs :: MonadWidget m
=> Route (HandlerSite m)
-> [(Text, Text)]
-> m ()
addStylesheetAttrs :: forall (m :: * -> *).
MonadWidget m =>
Route (HandlerSite m) -> [(Text, Text)] -> m ()
addStylesheetAttrs Route (HandlerSite m)
x [(Text, Text)]
y = forall (m :: * -> *).
MonadWidget m =>
GWData (Route (HandlerSite m)) -> m ()
tell forall a b. (a -> b) -> a -> b
$ forall a.
Body a
-> Last Title
-> Last Description
-> UniqueList (Script a)
-> UniqueList (Stylesheet a)
-> Map (Maybe Text) (CssBuilderUrl a)
-> Maybe (JavascriptUrl a)
-> Head a
-> GWData a
GWData forall a. Monoid a => a
mempty forall a. Monoid a => a
mempty forall a. Monoid a => a
mempty forall a. Monoid a => a
mempty (forall x. x -> UniqueList x
toUnique forall a b. (a -> b) -> a -> b
$ forall url. Location url -> [(Text, Text)] -> Stylesheet url
Stylesheet (forall url. url -> Location url
Local Route (HandlerSite m)
x) [(Text, Text)]
y) forall a. Monoid a => a
mempty forall a. Monoid a => a
mempty forall a. Monoid a => a
mempty
addStylesheetRemote :: MonadWidget m => Text -> m ()
addStylesheetRemote :: forall (m :: * -> *). MonadWidget m => Text -> m ()
addStylesheetRemote = forall a b c. (a -> b -> c) -> b -> a -> c
flip forall (m :: * -> *).
MonadWidget m =>
Text -> [(Text, Text)] -> m ()
addStylesheetRemoteAttrs []
addStylesheetRemoteAttrs :: MonadWidget m => Text -> [(Text, Text)] -> m ()
addStylesheetRemoteAttrs :: forall (m :: * -> *).
MonadWidget m =>
Text -> [(Text, Text)] -> m ()
addStylesheetRemoteAttrs Text
x [(Text, Text)]
y = forall (m :: * -> *).
MonadWidget m =>
GWData (Route (HandlerSite m)) -> m ()
tell forall a b. (a -> b) -> a -> b
$ forall a.
Body a
-> Last Title
-> Last Description
-> UniqueList (Script a)
-> UniqueList (Stylesheet a)
-> Map (Maybe Text) (CssBuilderUrl a)
-> Maybe (JavascriptUrl a)
-> Head a
-> GWData a
GWData forall a. Monoid a => a
mempty forall a. Monoid a => a
mempty forall a. Monoid a => a
mempty forall a. Monoid a => a
mempty (forall x. x -> UniqueList x
toUnique forall a b. (a -> b) -> a -> b
$ forall url. Location url -> [(Text, Text)] -> Stylesheet url
Stylesheet (forall url. Text -> Location url
Remote Text
x) [(Text, Text)]
y) forall a. Monoid a => a
mempty forall a. Monoid a => a
mempty forall a. Monoid a => a
mempty
addStylesheetEither :: MonadWidget m
=> Either (Route (HandlerSite m)) Text
-> m ()
addStylesheetEither :: forall (m :: * -> *).
MonadWidget m =>
Either (Route (HandlerSite m)) Text -> m ()
addStylesheetEither = forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either forall (m :: * -> *).
MonadWidget m =>
Route (HandlerSite m) -> m ()
addStylesheet forall (m :: * -> *). MonadWidget m => Text -> m ()
addStylesheetRemote
addScriptEither :: MonadWidget m
=> Either (Route (HandlerSite m)) Text
-> m ()
addScriptEither :: forall (m :: * -> *).
MonadWidget m =>
Either (Route (HandlerSite m)) Text -> m ()
addScriptEither = forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either forall (m :: * -> *).
MonadWidget m =>
Route (HandlerSite m) -> m ()
addScript forall (m :: * -> *). MonadWidget m => Text -> m ()
addScriptRemote
addScript :: MonadWidget m => Route (HandlerSite m) -> m ()
addScript :: forall (m :: * -> *).
MonadWidget m =>
Route (HandlerSite m) -> m ()
addScript = forall a b c. (a -> b -> c) -> b -> a -> c
flip forall (m :: * -> *).
MonadWidget m =>
Route (HandlerSite m) -> [(Text, Text)] -> m ()
addScriptAttrs []
addScriptAttrs :: MonadWidget m => Route (HandlerSite m) -> [(Text, Text)] -> m ()
addScriptAttrs :: forall (m :: * -> *).
MonadWidget m =>
Route (HandlerSite m) -> [(Text, Text)] -> m ()
addScriptAttrs Route (HandlerSite m)
x [(Text, Text)]
y = forall (m :: * -> *).
MonadWidget m =>
GWData (Route (HandlerSite m)) -> m ()
tell forall a b. (a -> b) -> a -> b
$ forall a.
Body a
-> Last Title
-> Last Description
-> UniqueList (Script a)
-> UniqueList (Stylesheet a)
-> Map (Maybe Text) (CssBuilderUrl a)
-> Maybe (JavascriptUrl a)
-> Head a
-> GWData a
GWData forall a. Monoid a => a
mempty forall a. Monoid a => a
mempty forall a. Monoid a => a
mempty (forall x. x -> UniqueList x
toUnique forall a b. (a -> b) -> a -> b
$ forall url. Location url -> [(Text, Text)] -> Script url
Script (forall url. url -> Location url
Local Route (HandlerSite m)
x) [(Text, Text)]
y) forall a. Monoid a => a
mempty forall a. Monoid a => a
mempty forall a. Monoid a => a
mempty forall a. Monoid a => a
mempty
addScriptRemote :: MonadWidget m => Text -> m ()
addScriptRemote :: forall (m :: * -> *). MonadWidget m => Text -> m ()
addScriptRemote = forall a b c. (a -> b -> c) -> b -> a -> c
flip forall (m :: * -> *).
MonadWidget m =>
Text -> [(Text, Text)] -> m ()
addScriptRemoteAttrs []
addScriptRemoteAttrs :: MonadWidget m => Text -> [(Text, Text)] -> m ()
addScriptRemoteAttrs :: forall (m :: * -> *).
MonadWidget m =>
Text -> [(Text, Text)] -> m ()
addScriptRemoteAttrs Text
x [(Text, Text)]
y = forall (m :: * -> *).
MonadWidget m =>
GWData (Route (HandlerSite m)) -> m ()
tell forall a b. (a -> b) -> a -> b
$ forall a.
Body a
-> Last Title
-> Last Description
-> UniqueList (Script a)
-> UniqueList (Stylesheet a)
-> Map (Maybe Text) (CssBuilderUrl a)
-> Maybe (JavascriptUrl a)
-> Head a
-> GWData a
GWData forall a. Monoid a => a
mempty forall a. Monoid a => a
mempty forall a. Monoid a => a
mempty (forall x. x -> UniqueList x
toUnique forall a b. (a -> b) -> a -> b
$ forall url. Location url -> [(Text, Text)] -> Script url
Script (forall url. Text -> Location url
Remote Text
x) [(Text, Text)]
y) forall a. Monoid a => a
mempty forall a. Monoid a => a
mempty forall a. Monoid a => a
mempty forall a. Monoid a => a
mempty
whamlet :: QuasiQuoter
whamlet :: QuasiQuoter
whamlet = Q HamletRules -> HamletSettings -> QuasiQuoter
NP.hamletWithSettings Q HamletRules
rules HamletSettings
NP.defaultHamletSettings
whamletFile :: FilePath -> Q Exp
whamletFile :: String -> Q Exp
whamletFile = Q HamletRules -> HamletSettings -> String -> Q Exp
NP.hamletFileWithSettings Q HamletRules
rules HamletSettings
NP.defaultHamletSettings
whamletFileWithSettings :: NP.HamletSettings -> FilePath -> Q Exp
whamletFileWithSettings :: HamletSettings -> String -> Q Exp
whamletFileWithSettings = Q HamletRules -> HamletSettings -> String -> Q Exp
NP.hamletFileWithSettings Q HamletRules
rules
asWidgetT :: WidgetT site m () -> WidgetT site m ()
asWidgetT :: forall site (m :: * -> *). WidgetT site m () -> WidgetT site m ()
asWidgetT = forall a. a -> a
id
rules :: Q NP.HamletRules
rules :: Q HamletRules
rules = do
Exp
ah <- [|asWidgetT . toWidget|]
let helper :: m Exp -> (Exp -> m Exp) -> m Exp
helper m Exp
qg Exp -> m Exp
f = do
Name
x <- forall (m :: * -> *). Quote m => String -> m Name
newName String
"urender"
Exp
e <- Exp -> m Exp
f forall a b. (a -> b) -> a -> b
$ Name -> Exp
VarE Name
x
let e' :: Exp
e' = [Pat] -> Exp -> Exp
LamE [Name -> Pat
VarP Name
x] Exp
e
Exp
g <- m Exp
qg
Exp
bind <- [|(>>=)|]
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ Maybe Exp -> Exp -> Maybe Exp -> Exp
InfixE (forall a. a -> Maybe a
Just Exp
g) Exp
bind (forall a. a -> Maybe a
Just Exp
e')
let ur :: (Env -> t) -> t
ur Env -> t
f = do
let env :: Env
env = Maybe ((Exp -> Q Exp) -> Q Exp)
-> Maybe ((Exp -> Q Exp) -> Q Exp) -> Env
NP.Env
(forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$ forall {m :: * -> *}. Quote m => m Exp -> (Exp -> m Exp) -> m Exp
helper [|getUrlRenderParams|])
(forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$ forall {m :: * -> *}. Quote m => m Exp -> (Exp -> m Exp) -> m Exp
helper [|fmap (toHtml .) getMessageRender|])
Env -> t
f Env
env
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ Exp
-> ((Env -> Q Exp) -> Q Exp)
-> (Env -> Exp -> Q Exp)
-> HamletRules
NP.HamletRules Exp
ah forall {t}. (Env -> t) -> t
ur forall a b. (a -> b) -> a -> b
$ \Env
_ Exp
b -> forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ Exp
ah Exp -> Exp -> Exp
`AppE` Exp
b
ihamletToRepHtml :: (MonadHandler m, RenderMessage (HandlerSite m) message)
=> HtmlUrlI18n message (Route (HandlerSite m))
-> m Html
ihamletToRepHtml :: forall (m :: * -> *) message.
(MonadHandler m, RenderMessage (HandlerSite m) message) =>
HtmlUrlI18n message (Route (HandlerSite m)) -> m Html
ihamletToRepHtml = forall (m :: * -> *) message.
(MonadHandler m, RenderMessage (HandlerSite m) message) =>
HtmlUrlI18n message (Route (HandlerSite m)) -> m Html
ihamletToHtml
{-# DEPRECATED ihamletToRepHtml "Please use ihamletToHtml instead" #-}
ihamletToHtml :: (MonadHandler m, RenderMessage (HandlerSite m) message)
=> HtmlUrlI18n message (Route (HandlerSite m))
-> m Html
ihamletToHtml :: forall (m :: * -> *) message.
(MonadHandler m, RenderMessage (HandlerSite m) message) =>
HtmlUrlI18n message (Route (HandlerSite m)) -> m Html
ihamletToHtml HtmlUrlI18n message (Route (HandlerSite m))
ih = do
Route (HandlerSite m) -> [(Text, Text)] -> Text
urender <- forall (m :: * -> *).
MonadHandler m =>
m (Route (HandlerSite m) -> [(Text, Text)] -> Text)
getUrlRenderParams
message -> Text
mrender <- forall (m :: * -> *) message.
(MonadHandler m, RenderMessage (HandlerSite m) message) =>
m (message -> Text)
getMessageRender
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ HtmlUrlI18n message (Route (HandlerSite m))
ih (forall a. ToMarkup a => a -> Html
toHtml forall b c a. (b -> c) -> (a -> b) -> a -> c
. message -> Text
mrender) Route (HandlerSite m) -> [(Text, Text)] -> Text
urender
tell :: MonadWidget m => GWData (Route (HandlerSite m)) -> m ()
tell :: forall (m :: * -> *).
MonadWidget m =>
GWData (Route (HandlerSite m)) -> m ()
tell = forall (m :: * -> *) a.
MonadWidget m =>
WidgetFor (HandlerSite m) a -> m a
liftWidget forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall site. GWData (Route site) -> WidgetFor site ()
tellWidget
toUnique :: x -> UniqueList x
toUnique :: forall x. x -> UniqueList x
toUnique = forall x. ([x] -> [x]) -> UniqueList x
UniqueList forall b c a. (b -> c) -> (a -> b) -> a -> c
. (:)
handlerToWidget :: HandlerFor site a -> WidgetFor site a
handlerToWidget :: forall site a. HandlerFor site a -> WidgetFor site a
handlerToWidget (HandlerFor HandlerData site site -> IO a
f) = forall site a. (WidgetData site -> IO a) -> WidgetFor site a
WidgetFor forall a b. (a -> b) -> a -> b
$ HandlerData site site -> IO a
f forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall site. WidgetData site -> HandlerData site site
wdHandler