On Mon, Jul 5, 2010 at 10:43 PM, Simon Michael
<simon@joyful.com> wrote:
Great, thanks for the clarifications. sendFile made this easy. Has using that affected my portability much, eg to windows ?
As far as I know, not at all. I actually run some of this code on Windows system (via wai-handler-webkit[1]) in production environments, and it all works fine. I'm just building on top of the sendfile library[2] which does The Right Thing.
Of course, like anything WAI, it depends on the implementation. If I'm not mistaken, Snap doesn't run on Windows (please correct me if I'm wrong on this, I'd like to know), so using the not-yet-released Snap WAI backend would clearly not work on Windows either.
On Jul 5, 2010, at 12:04 PM, Michael Snoyman wrote:
the rendering details for you. If you point me to the code in question, I'll take a look.
Latest code pushed to http://joyful.com/darcsweb/darcsweb.cgi?r=hledger;a=headblob;f=/Hledger/Cli/Commands/WebYesod.hs
Firstly, very nice code. I especially like how you're able to get an entire interface to fit into just 6 routes... impressive.
I believe the problem is on line 120, where you call "renderHamlet id". If you look at the type of renderHamlet:
renderHamlet :: (url -> String) -> Hamlet url -> L.ByteString
You'll see that:
renderHamlet id :: Hamlet String -> L.ByteString
In general, you don't need to call renderHamlet directly when using Yesod. Instead, you have two better options:
* hamletToRepHtml handles the rendering, calling toContent, and wrapping in a RepHtml. So your line 120 could be rewritten as:
hamletToRepHtml $ template req msg as ps "hledger" s
At which point you'd be able to use type-safe URLs in your Hamlet template (wrapping in the @ signs), and you can forget about URL splicing.
* applyLayout just builds on top of hamletToRepHtml, by also applying your default layout to the returned content. In your case, I wouldn't say it's necessary, but it makes a lot of sense for large sites that want to have a standard look for all pages.
Few other comments:
* On line 228, you use a non-breaking space. I'm not sure if you *need* that, or are just trying to work around Yesod's whitespace rules. If the latter, there's a relatively new feature that allows you to put a backslash at the beginning of the content to bypass the whitespace rules.[3]
* I'm impressed to see you found the getMessage/setMessage API. I keep meaning to blog about it, but haven't had a chance.
* On line 212, I see you drop to plain XHTML syntax. If you just want to get XHTML closing-tag rules and keep the Hamlet syntax, use "$xhamlet" instead of "$hamlet" at the beginning of your quasi-quoter.
Let me know if you have any other questions, I've been interested in hledger for a while now, so it's very gratifying to see it move over to Yesod.
Michael