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

Safe HaskellNone
LanguageHaskell2010

Html.Convert

Synopsis

Documentation

newtype Converted Source #

Constructors

Converted 

Fields

Instances
IsString Converted Source # 
Instance details

Defined in Html.Convert

Semigroup Converted Source # 
Instance details

Defined in Html.Convert

Monoid Converted Source # 
Instance details

Defined in Html.Convert

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)

Methods

convert :: a -> Converted Source #

Instances
Convert Char Source # 
Instance details

Defined in Html.Convert

Convert Double Source # 
Instance details

Defined in Html.Convert

Convert Float Source # 
Instance details

Defined in Html.Convert

Convert Int Source # 
Instance details

Defined in Html.Convert

Convert Integer Source # 
Instance details

Defined in Html.Convert

Convert Natural Source # 
Instance details

Defined in Html.Convert

Convert Word Source # 
Instance details

Defined in Html.Convert

Convert () Source # 
Instance details

Defined in Html.Convert

Methods

convert :: () -> Converted Source #

Convert String Source # 
Instance details

Defined in Html.Convert

Convert Text Source # 
Instance details

Defined in Html.Convert

Convert Text Source # 
Instance details

Defined in Html.Convert

Convert (Raw Char) Source # 
Instance details

Defined in Html.Convert

Convert (Raw String) Source # 
Instance details

Defined in Html.Convert

Convert (Raw Builder) Source # 
Instance details

Defined in Html.Convert

Convert (Raw Text) Source # 
Instance details

Defined in Html.Convert

Convert (Raw Text) Source # 
Instance details

Defined in Html.Convert

KnownSymbol a => Convert (Proxy a) Source # 
Instance details

Defined in Html.Convert

Methods

convert :: Proxy a -> Converted Source #