simple-1.0.0: A minimalist web framework for the WAI server interface

Safe Haskell | Trustworthy
Language | Haskell2010

Web.Simple.Templates

Synopsis

- class Monad m => HasTemplates m hs where
  - defaultLayout :: ControllerT hs m (Maybe Template)
  - viewDirectory :: ControllerT hs m FilePath
  - functionMap :: ControllerT hs m FunctionMap
  - getTemplate :: FilePath -> ControllerT hs m Template
  - layoutObject :: (ToJSON pageContent, ToJSON pageVal) => pageContent -> pageVal -> ControllerT hs m Value
- render :: (HasTemplates m hs, Monad m, ToJSON a) => FilePath -> a -> ControllerT hs m ()
- renderPlain :: (HasTemplates m hs, ToJSON a) => FilePath -> a -> ControllerT hs m ()
- renderLayout :: (HasTemplates m hs, ToJSON a) => FilePath -> FilePath -> a -> ControllerT hs m ()
- renderLayoutTmpl :: (HasTemplates m hs, ToJSON a) => Template -> Template -> a -> ByteString -> ControllerT hs m ()
- defaultGetTemplate :: (HasTemplates m hs, MonadIO m) => FilePath -> ControllerT hs m Template
- defaultFunctionMap :: FunctionMap
- defaultLayoutObject :: (HasTemplates m hs, ToJSON pageContent, ToJSON pageVal) => pageContent -> pageVal -> ControllerT hs m Value
- fromList :: (Eq k, Hashable k) => [(k, v)] -> HashMap k v
- newtype Function = Function {
  - call :: [Value] -> Value
  }
- class ToFunction a where
  - toFunction :: a -> Function
- type FunctionMap = HashMap Identifier Function

# Documentation

class Monad m => HasTemplates m hs where Source #

Minimal complete definition

Nothing

Methods

defaultLayout :: ControllerT hs m (Maybe Template) Source #

The layout to use by default. Layouts are just templates that embed views. They are rendered with the a global object containing the rendered view in the "yield" field, and the object the view was rendered with in the "page" field. By default, no template is used.

viewDirectory :: ControllerT hs m FilePath Source #

The directory to look for views passed to `render`. This defaults to "views", so

    render "index.html.tmpl" ...

will look for a view template in "views/index.html.tmpl".

functionMap :: ControllerT hs m FunctionMap Source #

A map of pure functions that can be called from within a template. See `FunctionMap` and `Function` for details.

getTemplate :: FilePath -> ControllerT hs m Template Source #

Function to use to get a template. By default, it looks in the `viewDirectory` for the given file name and compiles the file into a template. This can be overriden to, for example, cache compiled templates in memory.

default getTemplate :: MonadIO m => FilePath -> ControllerT hs m Template Source #

layoutObject :: (ToJSON pageContent, ToJSON pageVal) => pageContent -> pageVal -> ControllerT hs m Value Source #

The `Value` passed to a layout given the rendered view template and the value originally passed to the view template. By default, produces an `Object` with "yield", containing the rendered view, and "page", containing the value originally passed to the view.

render Source #

Arguments

:: (HasTemplates m hs, Monad m, ToJSON a) |
=> FilePath | Template to render
-> a | Aeson `Value` to pass to the template
-> ControllerT hs m () |

Renders a view template with the default layout and a global used to evaluate variables in the template.

renderPlain Source #

Arguments

:: (HasTemplates m hs, ToJSON a) |
=> FilePath | Template to render
-> a | Aeson `Value` to pass to the template
-> ControllerT hs m () |

Same as `render` but without a template.

renderLayout :: (HasTemplates m hs, ToJSON a) => FilePath -> FilePath -> a -> ControllerT hs m () Source #

Render a view using the layout named by the first argument.

renderLayoutTmpl :: (HasTemplates m hs, ToJSON a) => Template -> Template -> a -> ByteString -> ControllerT hs m () Source #

Same as `renderLayout` but uses already compiled layouts.

defaultGetTemplate :: (HasTemplates m hs, MonadIO m) => FilePath -> ControllerT hs m Template Source #

defaultFunctionMap :: FunctionMap Source #

defaultLayoutObject :: (HasTemplates m hs, ToJSON pageContent, ToJSON pageVal) => pageContent -> pageVal -> ControllerT hs m Value Source #

fromList :: (Eq k, Hashable k) => [(k, v)] -> HashMap k v Source #

O(n*log n) Construct a map with the supplied mappings. If the list contains duplicate mappings, the later mappings take precedence.

newtype Function Source #

A funcation that's callable from inside a template

Constructors

Function |

Fields

- call :: [Value] -> Value

class ToFunction a where Source #

Methods

toFunction :: a -> Function Source #

#### Instances

Instances details

FromJSON a => ToFunction (a -> Value) |
Instance details Defined in Web.Simple.Templates.Types Methods toFunction :: (a -> Value) -> Function Source #
(FromJSON a1, FromJSON a2) => ToFunction (a1 -> a2 -> Value) |
Instance details Defined in Web.Simple.Templates.Types Methods toFunction :: (a1 -> a2 -> Value) -> Function Source #
(FromJSON a1, FromJSON a2, FromJSON a3) => ToFunction (a1 -> a2 -> a3 -> Value) |
Instance details Defined in Web.Simple.Templates.Types Methods toFunction :: (a1 -> a2 -> a3 -> Value) -> Function Source #
(FromJSON a1, FromJSON a2, FromJSON a3, FromJSON a4) => ToFunction (a1 -> a2 -> a3 -> a4 -> Value) |
Instance details Defined in Web.Simple.Templates.Types Methods toFunction :: (a1 -> a2 -> a3 -> a4 -> Value) -> Function Source #
(FromJSON a1, FromJSON a2, FromJSON a3, FromJSON a4, FromJSON a5) => ToFunction (a1 -> a2 -> a3 -> a4 -> a5 -> Value) |
Instance details Defined in Web.Simple.Templates.Types Methods toFunction :: (a1 -> a2 -> a3 -> a4 -> a5 -> Value) -> Function Source #
(FromJSON a1, FromJSON a2, FromJSON a3, FromJSON a4, FromJSON a5, FromJSON a6) => ToFunction (a1 -> a2 -> a3 -> a4 -> a5 -> a6 -> Value) |
Instance details Defined in Web.Simple.Templates.Types Methods toFunction :: (a1 -> a2 -> a3 -> a4 -> a5 -> a6 -> Value) -> Function Source #
(FromJSON a1, FromJSON a2, FromJSON a3, FromJSON a4, FromJSON a5, FromJSON a6, FromJSON a7) => ToFunction (a1 -> a2 -> a3 -> a4 -> a5 -> a6 -> a7 -> Value) |
Instance details Defined in Web.Simple.Templates.Types Methods toFunction :: (a1 -> a2 -> a3 -> a4 -> a5 -> a6 -> a7 -> Value) -> Function Source #
(FromJSON a1, FromJSON a2, FromJSON a3, FromJSON a4, FromJSON a5, FromJSON a6, FromJSON a7, FromJSON a8) => ToFunction (a1 -> a2 -> a3 -> a4 -> a5 -> a6 -> a7 -> a8 -> Value) |
Instance details Defined in Web.Simple.Templates.Types Methods toFunction :: (a1 -> a2 -> a3 -> a4 -> a5 -> a6 -> a7 -> a8 -> Value) -> Function Source #

type FunctionMap = HashMap Identifier Function Source #