shakespeare-2.1.0.1: A toolkit for making compile-time interpolated templates

Safe Haskell | None
Language | Haskell2010

Text.Hamlet

Contents

- Plain HTML
- Hamlet
- I18N Hamlet
- Type classes
- Internal, for making more
- Used by generated code
- low-level

Synopsis

- type Html = Markup
- shamlet :: QuasiQuoter
- shamletFile :: FilePath -> Q Exp
- xshamlet :: QuasiQuoter
- xshamletFile :: FilePath -> Q Exp
- type HtmlUrl url = Render url -> Html
- type Render url = url -> [(Text, Text)] -> Text
- hamlet :: QuasiQuoter
- hamletFile :: FilePath -> Q Exp
- hamletFileReload :: FilePath -> Q Exp
- xhamlet :: QuasiQuoter
- xhamletFile :: FilePath -> Q Exp
- type HtmlUrlI18n msg url = Translate msg -> Render url -> Html
- type Translate msg = msg -> Html
- ihamlet :: QuasiQuoter
- ihamletFile :: FilePath -> Q Exp
- ihamletFileReload :: FilePath -> Q Exp
- class ToAttributes a where
  - toAttributes :: a -> [(Text, Text)]
- data HamletSettings = HamletSettings {
  - hamletDoctype :: String
  - hamletNewlines :: NewlineStyle
  - hamletCloseStyle :: String -> CloseStyle
  - hamletDoctypeNames :: [(String, String)]
  }
- data NewlineStyle
  - = NoNewlines
  - | NewlinesText
  - | AlwaysNewlines
  - | DefaultNewlineStyle
- hamletWithSettings :: Q HamletRules -> HamletSettings -> QuasiQuoter
- hamletFileWithSettings :: Q HamletRules -> HamletSettings -> FilePath -> Q Exp
- defaultHamletSettings :: HamletSettings
- xhtmlHamletSettings :: HamletSettings
- data Env = Env {
  - urlRender :: Maybe ((Exp -> Q Exp) -> Q Exp)
  - msgRender :: Maybe ((Exp -> Q Exp) -> Q Exp)
  }
- data HamletRules = HamletRules {
  - hrFromHtml :: Exp
  - hrWithEnv :: (Env -> Q Exp) -> Q Exp
  - hrEmbed :: Env -> Exp -> Q Exp
  }
- hamletRules :: Q HamletRules
- ihamletRules :: Q HamletRules
- htmlRules :: Q HamletRules
- data CloseStyle
  - = NoClose
  - | CloseInside
  - | CloseSeparate
- condH :: Monad m => [(Bool, m ())] -> Maybe (m ()) -> m ()
- maybeH :: Monad m => Maybe v -> (v -> m ()) -> Maybe (m ()) -> m ()
- asHtmlUrl :: HtmlUrl url -> HtmlUrl url
- attrsToHtml :: [(Text, Text)] -> Html
- hamletFromString :: Q HamletRules -> HamletSettings -> String -> Q Exp

# Plain HTML

type Html = Markup #

shamlet :: QuasiQuoter #

"Simple Hamlet" quasi-quoter. May only be used to generate expressions.

Generated expressions have type `Html`.

    >>> putStrLn (renderHtml [shamlet|<div>Hello, world!|])
    <div>Hello, world!</div>

shamletFile :: FilePath -> Q Exp #

xshamlet :: QuasiQuoter #

Like `shamlet`, but produces XHTML.

xshamletFile :: FilePath -> Q Exp #

Like `shamletFile`, but produces XHTML.

# Hamlet

type HtmlUrl url = Render url -> Html #

A function generating an `Html` given a URL-rendering function.

type Render url = url -> [(Text, Text)] -> Text #

hamlet :: QuasiQuoter #

Hamlet quasi-quoter. May only be used to generate expressions.

Generated expression have type ``HtmlUrl` url`, for some `url`.

    data MyRoute = Home

    render :: Render MyRoute
    render Home _ = "/home"

    >>> putStrLn (renderHtml ([hamlet|<a href=@{Home}>Home|] render))
    <a href="/home">Home</a>

hamletFile :: FilePath -> Q Exp #

hamletFileReload :: FilePath -> Q Exp #

Like `hamletFile`, but the external file is parsed at runtime. Allows for more rapid development, but should not be used in production.

xhamlet :: QuasiQuoter #

Like `hamlet`, but produces XHTML.

xhamletFile :: FilePath -> Q Exp #

Like `hamletFile`, but produces XHTML.

# I18N Hamlet

type HtmlUrlI18n msg url = Translate msg -> Render url -> Html #

A function generating an `Html` given a message translator and a URL rendering function.

type Translate msg = msg -> Html #

ihamlet :: QuasiQuoter #

Hamlet quasi-quoter with internationalization. May only be used to generate expressions.

Generated expressions have type ``HtmlUrlI18n` msg url`, for some `msg` and `url`.

    data MyMsg = Hi | Bye

    data MyRoute = Home

    renderEnglish :: Translate MyMsg
    renderEnglish Hi  = "hi"
    renderEnglish Bye = "bye"

    renderUrl :: Render MyRoute
    renderUrl Home _ = "/home"

    >>> putStrLn (renderHtml ([ihamlet|@{Home} _{Hi} _{Bye}|] renderEnglish renderUrl))
    <div>/home hi bye <div>

ihamletFile :: FilePath -> Q Exp #

ihamletFileReload :: FilePath -> Q Exp #

Like `ihamletFile`, but the external file is parsed at runtime. Allows for more rapid development, but should not be used in production.

# Type classes

class ToAttributes a where #

Convert some value to a list of attribute pairs.

Methods

toAttributes :: a -> [(Text, Text)] #

#### Instances

Instances details

ToAttributes [(Text, Text)] # |
Instance details Defined in Text.Hamlet Methods toAttributes :: [(Text, Text)] -> [(Text, Text)] #
ToAttributes [(String, String)] # |
Instance details Defined in Text.Hamlet Methods toAttributes :: [(String, String)] -> [(Text, Text)] #
ToAttributes (Text, Text) # |
Instance details Defined in Text.Hamlet Methods toAttributes :: (Text, Text) -> [(Text, Text)] #
ToAttributes (String, String) # |
Instance details Defined in Text.Hamlet Methods toAttributes :: (String, String) -> [(Text, Text)] #

# Internal, for making more

data HamletSettings #

Settings for parsing of a hamlet document.

Constructors

HamletSettings |
Fields hamletDoctype :: String The value to replace a "!!!" with. Do not include the trailing newline. hamletNewlines :: NewlineStyle Should we add newlines to the output, making it more human-readable? Useful for client-side debugging but may alter browser page layout. hamletCloseStyle :: String -> CloseStyle How a tag should be closed. Use this to switch between HTML, XHTML or even XML output. hamletDoctypeNames :: [(String, String)] Mapping from short names in "$doctype" statements to full doctype.

#### Instances

Instances details

Lift HamletSettings # |
Instance details Defined in Text.Hamlet.Parse Methods lift :: Quote m => HamletSettings -> m Exp # liftTyped :: forall (m :: Type -> Type). Quote m => HamletSettings -> Code m HamletSettings #

data NewlineStyle #

Constructors

NoNewlines | never add newlines
NewlinesText | add newlines between consecutive text lines
AlwaysNewlines | add newlines everywhere
DefaultNewlineStyle |

#### Instances

Instances details

Show NewlineStyle # |
Instance details Defined in Text.Hamlet.Parse Methods showsPrec :: Int -> NewlineStyle -> ShowS # show :: NewlineStyle -> String # showList :: [NewlineStyle] -> ShowS #
Lift NewlineStyle # |
Instance details Defined in Text.Hamlet.Parse Methods lift :: Quote m => NewlineStyle -> m Exp # liftTyped :: forall (m :: Type -> Type). Quote m => NewlineStyle -> Code m NewlineStyle #

hamletWithSettings :: Q HamletRules -> HamletSettings -> QuasiQuoter #

hamletFileWithSettings :: Q HamletRules -> HamletSettings -> FilePath -> Q Exp #

defaultHamletSettings :: HamletSettings #

Defaults settings: HTML5 doctype and HTML-style empty tags.

xhtmlHamletSettings :: HamletSettings #

data Env #

Constructors

Env |
Fields urlRender :: Maybe ((Exp -> Q Exp) -> Q Exp) msgRender :: Maybe ((Exp -> Q Exp) -> Q Exp)

data HamletRules #

Constructors

HamletRules |
Fields hrFromHtml :: Exp hrWithEnv :: (Env -> Q Exp) -> Q Exp hrEmbed :: Env -> Exp -> Q Exp

hamletRules :: Q HamletRules #

ihamletRules :: Q HamletRules #

htmlRules :: Q HamletRules #

data CloseStyle #

Constructors

NoClose |
CloseInside |
CloseSeparate |

#### Instances

Instances details

Lift (String -> CloseStyle) # |
Instance details Defined in Text.Hamlet.Parse Methods lift :: Quote m => (String -> CloseStyle) -> m Exp # liftTyped :: forall (m :: Type -> Type). Quote m => (String -> CloseStyle) -> Code m (String -> CloseStyle) #

# Used by generated code

condH :: Monad m => [(Bool, m ())] -> Maybe (m ()) -> m () #

Checks for truth in the left value in each pair in the first argument. If a true exists, then the corresponding right action is performed. Only the first is performed. In there are no true values, then the second argument is performed, if supplied.

maybeH :: Monad m => Maybe v -> (v -> m ()) -> Maybe (m ()) -> m () #

Runs the second argument with the value in the first, if available. Otherwise, runs the third argument, if available.

asHtmlUrl :: HtmlUrl url -> HtmlUrl url #

attrsToHtml :: [(Text, Text)] -> Html #

# low-level

hamletFromString :: Q HamletRules -> HamletSettings -> String -> Q Exp #