IHP Api Reference
Copyright(c) digitally induced GmbH 2020
Safe HaskellSafe-Inferred

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 :: (?context :: ControllerContext) => theView -> IO () Source #

Hook which is called before the render is called

html :: (?context :: ControllerContext, ?view :: theView) => theView -> Html Source #

json :: theView -> Value Source #

Renders the view to a JSON

Instances

Instances details
View GeneratorsView Source # 
Instance details

Defined in IHP.IDE.CodeGen.View.Generators

View NewActionView Source # 
Instance details

Defined in IHP.IDE.CodeGen.View.NewAction

View NewApplicationView Source # 
Instance details

Defined in IHP.IDE.CodeGen.View.NewApplication

View NewControllerView Source # 
Instance details

Defined in IHP.IDE.CodeGen.View.NewController

View NewJobView Source # 
Instance details

Defined in IHP.IDE.CodeGen.View.NewJob

View NewMailView Source # 
Instance details

Defined in IHP.IDE.CodeGen.View.NewMail

View NewMigrationView Source # 
Instance details

Defined in IHP.IDE.CodeGen.View.NewMigration

View NewScriptView Source # 
Instance details

Defined in IHP.IDE.CodeGen.View.NewScript

View NewViewView Source # 
Instance details

Defined in IHP.IDE.CodeGen.View.NewView

View EditRowView Source # 
Instance details

Defined in IHP.IDE.Data.View.EditRow

View EditValueView Source # 
Instance details

Defined in IHP.IDE.Data.View.EditValue

View NewRowView Source # 
Instance details

Defined in IHP.IDE.Data.View.NewRow

View ShowDatabaseView Source # 
Instance details

Defined in IHP.IDE.Data.View.ShowDatabase

View ShowForeignKeyHoverCardView Source # 
Instance details

Defined in IHP.IDE.Data.View.ShowForeignKeyHoverCard

View ShowQueryView Source # 
Instance details

Defined in IHP.IDE.Data.View.ShowQuery

View ShowTableRowsView Source # 
Instance details

Defined in IHP.IDE.Data.View.ShowTableRows

View LogsView Source # 
Instance details

Defined in IHP.IDE.Logs.View.Logs

View EditColumnView Source # 
Instance details

Defined in IHP.IDE.SchemaDesigner.View.Columns.Edit

View EditForeignKeyView Source # 
Instance details

Defined in IHP.IDE.SchemaDesigner.View.Columns.EditForeignKey

View NewColumnView Source # 
Instance details

Defined in IHP.IDE.SchemaDesigner.View.Columns.New

View NewForeignKeyView Source # 
Instance details

Defined in IHP.IDE.SchemaDesigner.View.Columns.NewForeignKey

View EditEnumValueView Source # 
Instance details

Defined in IHP.IDE.SchemaDesigner.View.EnumValues.Edit

View NewEnumValueView Source # 
Instance details

Defined in IHP.IDE.SchemaDesigner.View.EnumValues.New

View EditEnumView Source # 
Instance details

Defined in IHP.IDE.SchemaDesigner.View.Enums.Edit

View NewEnumView Source # 
Instance details

Defined in IHP.IDE.SchemaDesigner.View.Enums.New

View ShowEnumView Source # 
Instance details

Defined in IHP.IDE.SchemaDesigner.View.Enums.Show

View EditIndexView Source # 
Instance details

Defined in IHP.IDE.SchemaDesigner.View.Indexes.Edit

View EditView Source # 
Instance details

Defined in IHP.IDE.SchemaDesigner.View.Migrations.Edit

View IndexView Source # 
Instance details

Defined in IHP.IDE.SchemaDesigner.View.Migrations.Index

View NewView Source # 
Instance details

Defined in IHP.IDE.SchemaDesigner.View.Migrations.New

View EditPolicyView Source # 
Instance details

Defined in IHP.IDE.SchemaDesigner.View.Policies.Edit

View NewPolicyView Source # 
Instance details

Defined in IHP.IDE.SchemaDesigner.View.Policies.New

View CodeView Source # 
Instance details

Defined in IHP.IDE.SchemaDesigner.View.Schema.Code

View ErrorView Source # 
Instance details

Defined in IHP.IDE.SchemaDesigner.View.Schema.Error

View GeneratedCodeView Source # 
Instance details

Defined in IHP.IDE.SchemaDesigner.View.Schema.GeneratedCode

View SchemaUpdateFailedView Source # 
Instance details

Defined in IHP.IDE.SchemaDesigner.View.Schema.SchemaUpdateFailed

View EditTableView Source # 
Instance details

Defined in IHP.IDE.SchemaDesigner.View.Tables.Edit

View IndexView Source # 
Instance details

Defined in IHP.IDE.SchemaDesigner.View.Tables.Index

View NewTableView Source # 
Instance details

Defined in IHP.IDE.SchemaDesigner.View.Tables.New

View ShowView Source # 
Instance details

Defined in IHP.IDE.SchemaDesigner.View.Tables.Show

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 controller. (?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 :: forall controllerAction. (?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 :: (?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

(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 #