Copyright(c) digitally induced GmbH 2020
Safe HaskellNone

IHP.ViewSupport

Description

 
Synopsis

Documentation

type HtmlWithContext context = (?viewContext :: context) => Html Source #

classes :: [(Text, Bool)] -> Text Source #

Helper for dynamically generating the class=".." attribute.

Given a list like

[("a", True), ("b", False), ("c", True)]

builds a class name string for all parts where the second value is True.

E.g.

>>> classes [("a", True), ("b", False), ("c", True)]
"a c"

When setting b to True:

>>> classes [("a", True), ("b", True), ("c", True)]
"a b c"

Example:

>>> <div class={classes [("is-active", False)]}>
<div class="">
>>> <div class={classes [("is-active", True)]}>
<div class="is-active">
>>> forEach projects \project -> [hsx|
>>> <div class={classes [("project", True), ("active", get #active project)]}>
>>> {project}
>>> </div>
>>> |]
If project is active:                        <div class="project active">{project}</div>
Otherwise:                                   <div class="project">{project}</div>

class CreateViewContext viewContext where Source #

Associated Types

type ViewApp viewContext Source #

Methods

createViewContext :: (?requestContext :: RequestContext, ?controllerContext :: ControllerContext, ?modelContext :: ModelContext) => IO viewContext Source #

Instances

Instances details
CreateViewContext ViewContext Source # 
Instance details

Defined in IHP.IDE.ToolServer.ViewContext

Associated Types

type ViewApp ViewContext 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 viewContext | theView -> viewContext where Source #

Minimal complete definition

html

Methods

beforeRender :: (?viewContext :: viewContext) => (viewContext, theView) -> (viewContext, theView) Source #

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

json :: theView -> Value Source #

Instances

Instances details
View ShowView ViewContext Source # 
Instance details

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

View NewTableView ViewContext Source # 
Instance details

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

View IndexView ViewContext Source # 
Instance details

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

View EditTableView ViewContext Source # 
Instance details

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

View GeneratedCodeView ViewContext Source # 
Instance details

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

View ErrorView ViewContext Source # 
Instance details

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

View CodeView ViewContext Source # 
Instance details

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

View ShowEnumView ViewContext Source # 
Instance details

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

View NewEnumView ViewContext Source # 
Instance details

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

View EditEnumView ViewContext Source # 
Instance details

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

View NewEnumValueView ViewContext Source # 
Instance details

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

View EditEnumValueView ViewContext Source # 
Instance details

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

View NewForeignKeyView ViewContext Source # 
Instance details

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

View EditForeignKeyView ViewContext Source # 
Instance details

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

View EditColumnView ViewContext Source # 
Instance details

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

View NewColumnView ViewContext Source # 
Instance details

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

View LogsView ViewContext Source # 
Instance details

Defined in IHP.IDE.Logs.View.Logs

View ShowDatabaseView ViewContext Source # 
Instance details

Defined in IHP.IDE.Data.View.ShowDatabase

View ShowTableRowsView ViewContext Source # 
Instance details

Defined in IHP.IDE.Data.View.ShowTableRows

View ShowQueryView ViewContext Source # 
Instance details

Defined in IHP.IDE.Data.View.ShowQuery

View NewRowView ViewContext Source # 
Instance details

Defined in IHP.IDE.Data.View.NewRow

View EditValueView ViewContext Source # 
Instance details

Defined in IHP.IDE.Data.View.EditValue

View EditRowView ViewContext Source # 
Instance details

Defined in IHP.IDE.Data.View.EditRow

View GeneratorsView ViewContext Source # 
Instance details

Defined in IHP.IDE.CodeGen.View.Generators

View NewViewView ViewContext Source # 
Instance details

Defined in IHP.IDE.CodeGen.View.NewView

View NewScriptView ViewContext Source # 
Instance details

Defined in IHP.IDE.CodeGen.View.NewScript

View NewMailView ViewContext Source # 
Instance details

Defined in IHP.IDE.CodeGen.View.NewMail

View NewControllerView ViewContext Source # 
Instance details

Defined in IHP.IDE.CodeGen.View.NewController

View NewApplicationView ViewContext Source # 
Instance details

Defined in IHP.IDE.CodeGen.View.NewApplication

View NewActionView ViewContext Source # 
Instance details

Defined in IHP.IDE.CodeGen.View.NewAction

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)

isActivePath :: (?viewContext :: viewContext, HasField "requestContext" viewContext RequestContext, 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 :: (?viewContext :: viewContext, HasField "requestContext" viewContext RequestContext, 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 :: (?viewContext :: viewContext, HasField "requestContext" viewContext RequestContext) => Request Source #

Returns the current request

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

Alias for ?viewContext

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 viewContext. (?viewContext :: viewContext, HasField "controllerContext" viewContext 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

renderFlashMessages :: forall viewContext. (?viewContext :: viewContext, HasField "flashMessages" viewContext [FlashMessage]) => Html Source #

Displays the flash messages for the current request.

You can add a flash message to the next request by calling setSuccessMessage or setErrorMessage:

action CreateProjectAction = do
    ...
    setSuccessMessage "Your project has been created successfully"
    redirectTo ShowProjectAction { .. }
action CreateTeamAction = do
    unless userOnPaidPlan do
        setErrorMessage "This requires you to be on the paid plan"
        redirectTo NewTeamAction

    ...

For success messages, the text message is wrapped in a class="alert alert-success".../div, which is automatically styled by bootstrap. Errors flash messages are wraped in class="alert alert-danger".../div.

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"

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 #

IsString (Text, Bool) Source #

Allows `("my-class", True)` to be written as `"my-class"`

Useful together with classes

Instance details

Methods

fromString :: String -> (Text, Bool) #