{-# LANGUAGE AllowAmbiguousTypes #-} {-# LANGUAGE UndecidableInstances #-} {-| Module: IHP.ViewSupport Description: Provides functions to be used in all views Copyright: (c) digitally induced GmbH, 2020 -} module IHP.ViewSupport ( HtmlWithContext , Layout , Html , View (..) , currentViewId , forEach , isActivePath , isActivePathOrSub , css , onClick , onLoad , theRequest , viewContext , addStyle , ViewFetchHelpMessage , param , fetch , query , isActiveController , isActiveAction , nl2br , stripTags , theCSSFramework , fromCSSFramework , liveReloadWebsocketUrl ) where import IHP.Prelude import qualified Text.Blaze.Html5 as Html5 import IHP.ControllerSupport import IHP.ModelSupport import qualified Data.Aeson as JSON import qualified Data.Text as Text import qualified Data.Typeable as Typeable import qualified Text.Inflections as Inflector import qualified Data.Either as Either import GHC.TypeLits as T import qualified Data.ByteString as ByteString import IHP.RouterSupport hiding (get) import qualified Network.Wai as Wai import Text.Blaze.Html5.Attributes as A import IHP.HSX.QQ (hsx) import IHP.HSX.ToHtml import qualified Data.Sequences as Sequences import qualified IHP.Controller.RequestContext import qualified IHP.View.CSSFramework as CSSFramework () import IHP.View.Types import qualified IHP.FrameworkConfig as FrameworkConfig import IHP.Controller.Context import qualified IHP.HSX.Attribute as HSX class View theView where -- | Hook which is called before the render is called beforeRender :: (?context :: ControllerContext) => theView -> IO () beforeRender view = pure () -- Renders the view as html html :: (?context :: ControllerContext, ?view :: theView) => theView -> Html5.Html -- | Renders the view to a JSON json :: theView -> JSON.Value json = error "Json View for this route is not implemented" -- | Returns a string to be used as a html id attribute for the current view. -- E.g. when calling @currentViewId@ while rendering the view @Web.View.Projects.Show@, this will return @"projects-show"@ -- -- Useful to automatically scope certain css rules to a specific view. -- Example: -- -- > module Web.View.Projects.Show where -- > render = [hsx|