IHP Api Reference
Copyright(c) digitally induced GmbH 2020
Safe HaskellNone

IHP.ViewSupport

Description

 
Synopsis

Documentation

type HtmlWithContext context = (?context :: context) => 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>
|]

class View theView where Source #

Minimal complete definition

html

Methods

beforeRender :: theView -> IO () Source #

Hook which is called before the render is called

html :: theView -> Html Source #

json :: theView -> Value Source #

Renders the view to a JSON

Instances

Instances details
View EmptyView Source # 
Instance details

Defined in IHP.Job.Dashboard.View

View HtmlView Source # 
Instance details

Defined in IHP.Job.Dashboard.View

View SomeView Source #

Since the only constructor for SomeView requires that it is passed a View, we can use that to implement a View instance for SomeView

Instance details

Defined in IHP.Job.Dashboard.View

View a => View [a] Source #

Define how to render a list of views as a view. Just concatenate them together!

Instance details

Defined in IHP.Job.Dashboard.View

Methods

beforeRender :: [a] -> IO () Source #

html :: [a] -> Html Source #

json :: [a] -> Value 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 :: (?context :: ControllerContext, 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 :: (?context :: ControllerContext, 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 :: (?context :: ControllerContext) => Request Source #

Returns the current request

viewContext :: (?context :: ControllerContext) => ControllerContext Source #

Alias for ?context

addStyle :: ConvertibleStrings string Text => string -> Markup Source #

Adds an inline style element to the html.

This helps to work around the issue, that our HSX parser cannot deal with CSS yet.

Example:

myStyle = addStyle "#my-div { color: blue; }"
[hsx|{myStyle}<div id="my-div">Hello World</div>|]

This will render like:

<style>
    #my-div { color: blue; }
</style>
<div id="my-div">Hello World</div>

class ViewFetchHelpMessage Source #

This class provides helpful compile-time error messages when you use common controller functions inside of your views.

Minimal complete definition

fetch, query

Instances

Instances details
(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 # 
Instance details

Defined in IHP.ViewSupport

Methods

fetch :: a Source #

query :: a Source #

param :: ViewParamHelpMessage => a Source #

isActiveController :: forall {k} (controller :: k). (?context :: ControllerContext, 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 @PostsController
True

Returns True because the current action is part of the PostsController

isActiveAction :: (?context :: ControllerContext, 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 PostsAction
True

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"

fromCSSFramework :: forall (field :: Symbol) appliedFunction. (?context :: ControllerContext, KnownSymbol field, HasField field CSSFramework (CSSFramework -> appliedFunction)) => Proxy field -> appliedFunction Source #

liveReloadWebsocketUrl :: (?context :: ControllerContext) => Text Source #

The URL for the dev-mode live reload server. Typically "ws://localhost:8001"

Orphan instances

InputValue (PrimaryKey table) => ApplyAttribute (Id' table) Source # 
Instance details

Methods

applyAttribute :: Text -> Text -> Id' table -> Html -> Html

(TypeError (('Text "Looks like you forgot to pass a " ':<>: 'ShowType (GetModelByTableName record)) ':<>: 'Text " id to this data constructor.") :: Constraint) => Eq (Id' record -> controller) Source # 
Instance details

Methods

(==) :: (Id' record -> controller) -> (Id' record -> controller) -> Bool #

(/=) :: (Id' record -> controller) -> (Id' record -> controller) -> Bool #