Basic template group support added

This commit is contained in:
Michael Snoyman 2009-12-29 02:55:26 +02:00
parent 579583c1d2
commit 3cbcac8c41
7 changed files with 21 additions and 4 deletions

1
.gitignore vendored
View File

@ -1,2 +1,3 @@
dist
*.swp
client_session_key.aes

1
TODO
View File

@ -3,3 +3,4 @@ Cleanup Parameter stuff. Own module? Interface with formlets?
Authentication via e-mail address built in. (eaut.org)
OpenID 2 stuff (for direct Google login).
Native support for HStringTemplate groups.
Use Text for HStringTemplate throughout

View File

@ -21,6 +21,7 @@ module Yesod
, module Yesod.Resource
, module Data.Object.Html
, module Yesod.Rep
, module Yesod.Templates
, module Data.Convertible.Text
, Application
) where
@ -33,5 +34,6 @@ import Yesod.Handler
import Yesod.Resource
import Hack (Application)
import Yesod.Rep
import Yesod.Templates
import Data.Object.Html
import Data.Convertible.Text

View File

@ -47,6 +47,7 @@ module Yesod.Rep
import Data.ByteString.Lazy (ByteString)
import qualified Data.ByteString.Lazy as BL
import Data.Text.Lazy (Text)
import qualified Data.Text.Lazy as TL
import Data.Maybe (mapMaybe)
import Data.Function (on)
@ -161,11 +162,11 @@ instance HasReps Plain where
plain :: ConvertSuccess x Text => x -> Plain
plain = Plain . cs
data Template = Template (StringTemplate String) HtmlObject
data Template = Template (StringTemplate Text) HtmlObject
instance HasReps Template where
reps = [ (TypeHtml,
\(Template t h) ->
return $ cs $ toString $ setAttribute "o" h t)
return $ cs $ render $ setAttribute "o" h t)
, (TypeJson, \(Template _ ho) ->
return $ cs $ unJsonDoc $ cs ho)
]

View File

@ -4,19 +4,29 @@
import Yesod
import Hack.Handler.SimpleServer
data HelloWorld = HelloWorld
data HelloWorld = HelloWorld TemplateGroup
instance Yesod HelloWorld where
handlers = [$resources|
/:
Get: helloWorld
/groups:
Get: helloGroup
|]
instance YesodTemplates HelloWorld where
templates (HelloWorld g) = g
helloWorld :: Handler HelloWorld TemplateFile
helloWorld = return $ TemplateFile "examples/template.html" $ cs
[ ("title", "Hello world!")
, ("content", "Hey look!! I'm <auto escaped>!")
]
helloGroup = template "real-template" $ cs "foo"
main :: IO ()
main = putStrLn "Running..." >> run 3000 (toHackApp HelloWorld)
main = do
putStrLn "Running..."
stg <- loadTemplates "examples"
run 3000 (toHackApp $ HelloWorld stg)
\end{code}

View File

@ -0,0 +1 @@
This is a more realistic template.

View File

@ -62,6 +62,7 @@ library
Yesod.Handler
Yesod.Resource
Yesod.Yesod
Yesod.Templates
Data.Object.Html
Hack.Middleware.MethodOverride
Hack.Middleware.ClientSession