Skip to content

bickfordb/hack-contrib-press

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Hack.Contrib.Press

Quickstart

Small.hs

{-# LANGUAGE DeriveDataTypeable #-}
{-# OPTIONS -fglasgow-exts #-}

module Main where

import Hack
import Hack.Contrib.Press (renderToResponse)
import Hack.Handler.Happstack (run)
import Text.JSON.Generic

data Profile = Profile {
    name :: String,
    favoriteMusic :: [String]
} deriving (Data, Typeable)

main = run $ \env -> do renderToResponse env "small.html" context
    where aProfile = Profile "Brandon Bickford" ["Rock"]
          context = [toJSON aProfile]

small.html

<html>
    <body>
        <p>
            Hey <b>{{ name }}</b>, I heard you like:
            <ul>
                {% for music in favoriteMusic %}
                    <li>{{ music }}</li>
                {% endfor %}
            </ul>     
        </p>
    </body>
</html>

Run

  • Run: cabal install hack-contrib-press
  • Add "Small.hs" and "small.html"
  • Run: ghc --make -o small Small.hs
  • Run: ./small
  • In your browser visit: http://localhost:3000

About

Hack utilities to render Text.Press templates to responses

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published