Here i'm going to show you how to build a super simple web app using haskell and yesod. For the purposes of the tutorial, this is a single piece of code, however you would split the code among multiple filesif you were to build on this project. Everyone knows that the internet peaked in the 90s and so today we're going to build somthing that no 90s website can be without, the Guest Book. ``` active haskell web -- show Imports and Pragmas {-# LANGUAGE OverloadedStrings, FlexibleContexts, ScopedTypeVariables, GeneralizedNewtypeDeriving, TemplateHaskell, GADTs, TypeFamilies, QuasiQuotes, MultiParamTypeClasses #-} -- As usual, a generous helping of pragmas and imports. -- These will need to be placed at the top of your source files. -- Everything you need to work with Yesod, exported from one package import Yesod -- Standard platform datatypes & functions import Data.Text (Text) import Data.Time (UTCTime, getCurrentTime) import Data.Time.Format (formatTime) import System.Locale (defaultTimeLocale) -- Using the `persistent` database layer import Database.Persist import Database.Persist.TH import Database.Persist.Sqlite -- Monad helpers import Control.Applicative ((<$>),(<*>)) import Control.Monad.IO.Class (liftIO) import Control.Monad.Logger (runNoLoggingT) import Control.Monad.Trans.Resource (runResourceT) -- show Types.hs -- Our datatype that represents our App -- the fields of this type represent pieces of the -- global environment in which it runs. data GuestBook = GuestBook { _db :: Connection } -- Declare that our App is a Yesod site -- This will provide you with sensible defaults -- and your website's defaultLayout instance Yesod GuestBook where defaultLayout contents = do PageContent title headTags bodyTags <- widgetToPageContent $ do addStylesheetRemote "//netdna.bootstrapcdn.com/twitter-bootstrap/2.3.2/css/bootstrap-combined.min.css" toWidget [cassius| body padding: 0px 10px |] contents hamletToRepHtml [hamlet| $doctype 5
Name | Message | When |
---|---|---|
#{signatureName signature} | #{signatureMessage signature} | #{fTime $ signatureDate signature} |