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 :: (?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 CodeView Source # 
Instance details

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

View ShowQueryView Source # 
Instance details

Defined in IHP.IDE.Data.View.ShowQuery

View ShowDatabaseView Source # 
Instance details

Defined in IHP.IDE.Data.View.ShowDatabase

View ShowTableRowsView Source # 
Instance details

Defined in IHP.IDE.Data.View.ShowTableRows

View NewRowView Source # 
Instance details

Defined in IHP.IDE.Data.View.NewRow

View EditValueView Source # 
Instance details

Defined in IHP.IDE.Data.View.EditValue

View EditRowView Source # 
Instance details

Defined in IHP.IDE.Data.View.EditRow

View HtmlView Source # 
Instance details

Defined in IHP.Job.Dashboard.View

View EmptyView 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 ShowView Source # 
Instance details

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

View NewTableView Source # 
Instance details

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

View IndexView Source # 
Instance details

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

View EditTableView Source # 
Instance details

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

View SchemaUpdateFailedView Source # 
Instance details

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

View GeneratedCodeView Source # 
Instance details

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

View ErrorView Source # 
Instance details

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

View ShowEnumView Source # 
Instance details

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

View EditEnumView Source # 
Instance details

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

View NewEnumValueView Source # 
Instance details

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

View EditEnumValueView Source # 
Instance details

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

View NewForeignKeyView Source # 
Instance details

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

View EditForeignKeyView Source # 
Instance details

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

View EditColumnView Source # 
Instance details

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

View NewEnumView Source # 
Instance details

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

View NewColumnView Source # 
Instance details

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

View LogsView Source # 
Instance details

Defined in IHP.IDE.Logs.View.Logs

View NewMigrationView Source # 
Instance details

Defined in IHP.IDE.CodeGen.View.NewMigration

View GeneratorsView Source # 
Instance details

Defined in IHP.IDE.CodeGen.View.Generators

View NewViewView Source # 
Instance details

Defined in IHP.IDE.CodeGen.View.NewView

View NewScriptView Source # 
Instance details

Defined in IHP.IDE.CodeGen.View.NewScript

View NewMailView Source # 
Instance details

Defined in IHP.IDE.CodeGen.View.NewMail

View NewJobView Source # 
Instance details

Defined in IHP.IDE.CodeGen.View.NewJob

View NewControllerView Source # 
Instance details

Defined in IHP.IDE.CodeGen.View.NewController

View NewApplicationView Source # 
Instance details

Defined in IHP.IDE.CodeGen.View.NewApplication

View NewActionView Source # 
Instance details

Defined in IHP.IDE.CodeGen.View.NewAction

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: {get #name user}</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.

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. Uss 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

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

HasField "requestContext" viewContext RequestContext => ConfigProvider viewContext Source # 
Instance details

Methods

getFrameworkConfig :: viewContext -> FrameworkConfig 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 # 
Instance details

Methods

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

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