diff --git a/yesod-examples/src/ajax.lhs b/yesod-examples/src/ajax.lhs
index 3618204f..9396aef1 100644
--- a/yesod-examples/src/ajax.lhs
+++ b/yesod-examples/src/ajax.lhs
@@ -5,15 +5,14 @@
> {-# LANGUAGE TypeFamilies, QuasiQuotes, TemplateHaskell, MultiParamTypeClasses, OverloadedStrings #-}
> import Yesod
> import Yesod.Static
-> import Data.Monoid (mempty)
-> import Text.Blaze (string)
+> import Data.Text (Text, unpack)
Like the blog example, we'll define some data first.
> data Page = Page
-> { pageName :: String
-> , pageSlug :: String
-> , pageContent :: String
+> { pageName :: Text
+> , pageSlug :: Text
+> , pageContent :: Text
> }
> loadPages :: IO [Page]
@@ -36,7 +35,7 @@ Now the routes; we'll have a homepage, a pattern for the pages, and use a static
> mkYesod "Ajax" [parseRoutes|
> / HomeR GET
-> /page/#String PageR GET
+> /page/#Text PageR GET
> /static StaticR Static ajaxStatic
> |]
@@ -49,7 +48,7 @@ Now the routes; we'll have a homepage, a pattern for the pages, and use a static
> defaultLayout widget = do
> Ajax pages _ <- getYesod
> content <- widgetToPageContent widget
-> hamletToRepHtml [$hamlet|
+> hamletToRepHtml [hamlet|
> \
>
>
@@ -80,23 +79,23 @@ Now the routes; we'll have a homepage, a pattern for the pages, and use a static
And now the cool part: a handler that returns either HTML or JSON data, depending on the request headers.
-> getPageR :: String -> Handler RepHtmlJson
+> getPageR :: Text -> Handler RepHtmlJson
> getPageR slug = do
> Ajax pages _ <- getYesod
> case filter (\e -> pageSlug e == slug) pages of
> [] -> notFound
> page:_ -> defaultLayoutJson (do
-> setTitle $ string $ pageName page
+> setTitle $ toHtml $ pageName page
> addHamlet $ html page
> ) (json page)
> where
-> html page = [$hamlet|
+> html page = [hamlet|
>
#{pageName page}
> #{pageContent page}
> |]
> json page = jsonMap
-> [ ("name", jsonScalar $ pageName page)
-> , ("content", jsonScalar $ pageContent page)
+> [ ("name", jsonScalar $ unpack $ pageName page)
+> , ("content", jsonScalar $ unpack $ pageContent page)
> ]
We first try and find the appropriate Page, returning a 404 if it's not there. We then use the applyLayoutJson function, which is really the heart of this example. It allows you an easy way to create responses that will be either HTML or JSON, and which use the default layout in the HTML responses. It takes four arguments: 1) the title of the HTML page, 2) some value, 3) a function from that value to a Hamlet value, and 4) a function from that value to a Json value.
@@ -110,3 +109,8 @@ And now the cool part: a handler that returns either HTML or JSON data, dependin
> pages <- loadPages
> s <- static "static/yesod/ajax"
> warpDebug 3000 $ Ajax pages s
+
+And just to avoid some warnings...
+
+> _ignored :: Widget
+> _ignored = undefined ajaxPages
diff --git a/yesod-examples/src/blog.lhs b/yesod-examples/src/blog.lhs
index 65fd2bdd..8e59cdd9 100644
--- a/yesod-examples/src/blog.lhs
+++ b/yesod-examples/src/blog.lhs
@@ -113,3 +113,8 @@ All that's left now is the main function. Yesod is built on top of WAI, so you c
> main = do
> entries <- loadEntries
> warpDebug 3000 $ Blog entries
+
+And this is just to avoid some warnings...
+
+> _ignored :: Widget
+> _ignored = undefined blogEntries
diff --git a/yesod-examples/src/chat.hs b/yesod-examples/src/chat.hs
index d0551238..eb138906 100644
--- a/yesod-examples/src/chat.hs
+++ b/yesod-examples/src/chat.hs
@@ -9,8 +9,6 @@ import Yesod
import Yesod.Static
import Control.Concurrent.STM
-import Control.Concurrent.STM.TChan
-import Control.Concurrent.STM.TVar
import Control.Arrow ((***))
import Data.Text (Text, unpack)
@@ -27,7 +25,7 @@ data Chat = Chat
staticFiles "static"
-mkYesod "Chat" [$parseRoutes|
+mkYesod "Chat" [parseRoutes|
/ HomeR GET
/check CheckR GET
/post PostR GET
@@ -38,18 +36,17 @@ instance Yesod Chat where
approot _ = ""
defaultLayout widget = do
content <- widgetToPageContent widget
- hamletToRepHtml [$hamlet|\
- \
+ hamletToRepHtml [hamlet|
+!!!
-
-
- #{pageTitle content}
-