[yesod] how convert Content to String or Text

Hello All.
I have following code:
getMyRoute :: String -> Handler RepXml
getMyRoute r = liftM RepXml $ hamletToContent [hamlet|

On Wed, Jul 6, 2011 at 12:18 PM, Dmitriy Nikitinskiy
Hello All.
I have following code:
getMyRoute :: String -> Handler RepXml getMyRoute r = liftM RepXml $ hamletToContent [hamlet|
getOtherRoute :: Handler () getOtherRoute = do (RepXml mycontent) <- getMyRoute "something" -- how write mycontent to file here? -- let str = ???? or str <- ???? -- liftIO $ writeFile "myfile.xml" str return ()
How convert Yesod.Content.Content to String or Text?
Hi Dmitry,
I would try to convert the Content. Instead, I'd write a helper function:
myXml :: String -> Hamlet MyRoute
myXml r = [hamlet|

07.07.2011 00:02, Michael Snoyman пишет:
On Wed, Jul 6, 2011 at 12:18 PM, Dmitriy Nikitinskiy
wrote: Hello All.
I have following code:
getMyRoute :: String -> Handler RepXml getMyRoute r = liftM RepXml $ hamletToContent [hamlet|
getOtherRoute :: Handler () getOtherRoute = do (RepXml mycontent)<- getMyRoute "something" -- how write mycontent to file here? -- let str = ???? or str<- ???? -- liftIO $ writeFile "myfile.xml" str return ()
How convert Yesod.Content.Content to String or Text? Hi Dmitry,
I would try to convert the Content. Instead, I'd write a helper function:
myXml :: String -> Hamlet MyRoute myXml r = [hamlet|
Then you could use myXml from both getMyRotue and getOtherRoute. In order to render a Hamlet, you'll need to get a URL rendering function[1]. So getOtherRoute would look something like:
getOtherRoute = do renderUrl<- getUrlRenderParams let lbs = renderHamlet renderUrl $ myXml "something" liftIO $ Data.ByteString.Lazy.writeFile "myfile.xml" lbs
HTH, Michael
[1] It's a function that converts a type-safe URL into a String.
Thanks Michael, it's helped me a lot. Best regards, Dmitriy.
participants (2)
-
Dmitriy Nikitinskiy
-
Michael Snoyman