| Copyright | (c) digitally induced GmbH 2020 |
|---|---|
| Safe Haskell | None |
| Language | GHC2021 |
IHP.ViewSupport
Contents
Description
Synopsis
- type HtmlWithContext context = (?context :: context, ?request :: Request) => Html
- type Layout = Html -> Html
- type Html = HtmlWithContext ControllerContext
- class View theView where
- currentViewId :: (?view :: view, Typeable view) => Text
- forEach :: (MonoFoldable mono, Applicative m) => mono -> (Element mono -> m ()) -> m ()
- isActivePath :: (?request :: Request, PathString controller) => controller -> Bool
- isActivePathOrSub :: (?request :: Request, PathString controller) => controller -> Bool
- css :: QuasiQuoter
- onClick :: AttributeValue -> Attribute
- onLoad :: AttributeValue -> Attribute
- theRequest :: (?request :: Request) => Request
- class ViewFetchHelpMessage
- param :: ViewParamHelpMessage => a
- fetch :: ViewFetchHelpMessage => a
- query :: ViewFetchHelpMessage => a
- isActiveController :: forall {k} (controller :: k). (?request :: Request, Typeable controller) => Bool
- isActiveAction :: (?request :: Request, HasPath controllerAction) => controllerAction -> Bool
- nl2br :: (Textual text, ToHtml text) => text -> Html
- stripTags :: Text -> Text
- theCSSFramework :: (?request :: Request) => CSSFramework
- fromCSSFramework :: forall (field :: Symbol) appliedFunction. (?request :: Request, KnownSymbol field, HasField field CSSFramework (CSSFramework -> appliedFunction)) => Proxy field -> appliedFunction
- liveReloadWebsocketUrl :: (?request :: Request) => Text
- assetPath :: (?request :: Request) => Text -> Text
- assetVersion :: (?request :: Request) => Text
Documentation
type HtmlWithContext context = (?context :: context, ?request :: Request) => Html Source #
type Layout = Html -> Html Source #
A layout is just a function taking a view and returning a new view.
Example: A very basic html layout.
myLayout :: Layout
myLayout view = [hsx|
<html>
<body>
{view}
</body>
</html>
|]type Html = HtmlWithContext ControllerContext Source #
currentViewId :: (?view :: view, Typeable view) => Text Source #
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|<div id={currentViewId}>Hello World!</div>|]This will render id="projects-show"Hello World!/div
forEach :: (MonoFoldable mono, Applicative m) => mono -> (Element mono -> m ()) -> m () Source #
Example:
forEach users \user -> putStrLn (tshow user)
Example: Within HSX
renderUser :: User -> Html
renderUser user = [hsx|<div>User: {user.name}</div>|]
render = [hsx|{forEach users renderUser}|]isActivePath :: (?request :: Request, PathString controller) => controller -> Bool Source #
Returns True when the current request path matches the path given as argument. Takes into account the search query: ?name=value
Example: The browser has requested the url /Projects.
>>>isActivePath "/Projects"True
Returns True because "/Projects" is the current requested path.
>>>isActivePath "/Users"False
Returns false because "/Users" is not "/Projects"
Example: The browser has requested the url /Projects.
>>>isActivePath "/Projects/1"False
This function returns False when a sub-path is request. Use isActivePathOrSub if you want this example to return True.
isActivePathOrSub :: (?request :: Request, PathString controller) => controller -> Bool Source #
Returns True when the current request path starts with the path given as argument.
Example: The browser has requested the url /Projects/1.
>>>isActivePathOrSub "/Projects"True
Example: The browser has requested the url /Projects.
>>>isActivePathOrSub "/Projects"True
Also see isActivePath.
css :: QuasiQuoter Source #
onClick :: AttributeValue -> Attribute Source #
onLoad :: AttributeValue -> Attribute Source #
theRequest :: (?request :: Request) => Request Source #
Returns the current request
class ViewFetchHelpMessage Source #
This class provides helpful compile-time error messages when you use common controller functions inside of your views.
Instances
| (TypeError ('Text "\8216fetch\8216 or \8216query\8216 can only be used inside your controller actions. You have to call it from your controller action and then pass the result to the view.") :: Constraint) => ViewFetchHelpMessage Source # | |
fetch :: ViewFetchHelpMessage => a Source #
query :: ViewFetchHelpMessage => a Source #
isActiveController :: forall {k} (controller :: k). (?request :: Request, Typeable controller) => Bool Source #
Returns True when the given type matches the type of the currently executed controller action
Example: The browser has requested /Posts and the Posts action of the PostsController is called.
>>>isActiveController @PostsControllerTrue
Returns True because the current action is part of the PostsController
isActiveAction :: (?request :: Request, HasPath controllerAction) => controllerAction -> Bool Source #
Returns True when the given action matches the path of the currently executed action
Example: The browser has requested /PostsAction.
>>>isActiveAction PostsActionTrue
nl2br :: (Textual text, ToHtml text) => text -> Html Source #
Replaces all newline characters with a br tag. Useful for displaying preformatted text.
>>>nl2br "Hello\nWorld!"[hsx|Hello<br/>World!|]
stripTags :: Text -> Text Source #
Removes all html tags from a given html text
>>>stripTags "This is <b>Bold</b>""This is Bold"
theCSSFramework :: (?request :: Request) => CSSFramework Source #
fromCSSFramework :: forall (field :: Symbol) appliedFunction. (?request :: Request, KnownSymbol field, HasField field CSSFramework (CSSFramework -> appliedFunction)) => Proxy field -> appliedFunction Source #
liveReloadWebsocketUrl :: (?request :: Request) => Text Source #
The URL for the dev-mode live reload server. Typically "ws://localhost:8001"
assetPath :: (?request :: Request) => Text -> Text Source #
Adds a cache buster to a asset path
>>>assetPath "/keyhandlers.js""/keyhandlers.js?v=9be8995c-7055-43d9-a1b2-43e05c210271"
The asset version can be configured using the
IHP_ASSET_VERSION environment variable.
assetVersion :: (?request :: Request) => Text Source #
Returns the assetVersion
>>>assetVersion"9be8995c-7055-43d9-a1b2-43e05c210271"
The asset version can be configured using the
IHP_ASSET_VERSION environment variable.
Orphan instances
| InputValue (PrimaryKey table) => ApplyAttribute (Id' table) Source # | |
| (TypeError (('Text "Looks like you forgot to pass a " ':<>: 'ShowType (GetModelByTableName record)) ':<>: 'Text " id to this data constructor.") :: Constraint) => Eq (Id' record -> controller) Source # | |