type-of-html-1.3.4.0: High performance type driven html generation.

Safe HaskellNone
LanguageHaskell2010

Html.Convert

Synopsis

Documentation

class Convert a where Source #

Convert a type efficienctly to a renderable representation. Add instances if you want use custom types in your document.

{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards   #-}

module Main where

import Html

import Data.Text (Text)
import Data.Monoid

data Person
  = Person
  { name :: Text
  , age :: Int
  , vegetarian :: Bool
  }

-- | This is already very efficient.
-- Wrap the Strings in Raw if you don't want to escape them.
instance Convert Person where
  convert (Person{..})
    =  convert name
    <> " is "
    <> convert age
    <> " years old and likes "
    <> if vegetarian then "oranges." else "meat."

john :: Person
john = Person {name = "John", age = 52, vegetarian = True}

main :: IO ()
main = print (div_ john)

Minimal complete definition

convert

Methods

convert :: a -> Converted Source #