Basic template group support added
This commit is contained in:
parent
579583c1d2
commit
3cbcac8c41
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,2 +1,3 @@
|
||||
dist
|
||||
*.swp
|
||||
client_session_key.aes
|
||||
|
||||
1
TODO
1
TODO
@ -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
|
||||
|
||||
2
Yesod.hs
2
Yesod.hs
@ -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
|
||||
|
||||
@ -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)
|
||||
]
|
||||
|
||||
@ -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}
|
||||
|
||||
1
examples/real-template.st
Normal file
1
examples/real-template.st
Normal file
@ -0,0 +1 @@
|
||||
This is a more realistic template.
|
||||
@ -62,6 +62,7 @@ library
|
||||
Yesod.Handler
|
||||
Yesod.Resource
|
||||
Yesod.Yesod
|
||||
Yesod.Templates
|
||||
Data.Object.Html
|
||||
Hack.Middleware.MethodOverride
|
||||
Hack.Middleware.ClientSession
|
||||
|
||||
Loading…
Reference in New Issue
Block a user