Hello,<br><br>I'm using the combination happstack + digestive-functors + web-routes + blazeHTML.<br>I'm not finding any examples on the net...<br><br>I've tried to adapt your example (thanks):<br><br><span style="font-family: courier new,monospace;">type NomicForm a = HappstackForm IO String BlazeFormHtml a</span><br style="font-family: courier new,monospace;">
<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"></span><span style="font-family: courier new,monospace;">demoForm :: NomicForm (Text, Text)</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">demoForm =</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> (,) <$> ((TDB.label "greeting: " ++> inputNonEmpty Nothing) <* br)</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> <*> ((TDB.label "noun: " ++> inputNonEmpty Nothing) <* br)</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> <* (submit "submit")</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> where</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> br :: NomicForm ()</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> br = view H.br</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> -- make sure the fields are not blank, show errors in line if they are</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> inputNonEmpty :: Maybe Text -> NomicForm Text</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> inputNonEmpty v =</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> (inputText v `validate` (TD.check "You can not leave this field blank." (not . T.null)) <++ errors)</span><br><br><br>But I've got a problem on submit and inputTex<span style="font-family: arial,helvetica,sans-serif;">t. I don't see how they are compatible with </span><span style="font-family: courier new,monospace;"><span style="font-family: arial,helvetica,sans-serif;">HappstackForm.</span><br>
</span><span style="font-family: courier new,monospace;"><span style="font-family: arial,helvetica,sans-serif;">NomicForm a reduces to:<br><span style="font-family: courier new,monospace;">Form (ServerPartT IO) Input String BlazeFormHtml a</span></span><br style="font-family: arial,helvetica,sans-serif;">
<span style="font-family: arial,helvetica,sans-serif;"><br>whereas the type of submit is:</span><br></span><pre><span style="font-family: courier new,monospace;" class="hs-definition">submit</span><span style="font-family: courier new,monospace;"> </span><span style="font-family: courier new,monospace;" class="hs-keyglyph">::</span><span style="font-family: courier new,monospace;"> </span><span style="font-family: courier new,monospace;" class="hs-conid">Monad</span><span style="font-family: courier new,monospace;"> </span><span style="font-family: courier new,monospace;" class="hs-varid">m</span><br style="font-family: courier new,monospace;">
<a style="font-family: courier new,monospace;" name="line-134"></a><span style="font-family: courier new,monospace;"> </span><span style="font-family: courier new,monospace;" class="hs-keyglyph">=></span><span style="font-family: courier new,monospace;"> </span><span style="font-family: courier new,monospace;" class="hs-conid">String</span><span style="font-family: courier new,monospace;"> </span><span style="font-family: courier new,monospace;" class="hs-comment">-- ^ Text on the submit button</span><br style="font-family: courier new,monospace;">
<a style="font-family: courier new,monospace;" name="line-135"></a><span style="font-family: courier new,monospace;"> </span><span style="font-family: courier new,monospace;" class="hs-keyglyph">-></span><span style="font-family: courier new,monospace;"> </span><span style="font-family: courier new,monospace;" class="hs-conid">Form</span><span style="font-family: courier new,monospace;"> </span><span style="font-family: courier new,monospace;" class="hs-varid">m</span><span style="font-family: courier new,monospace;"> </span><span style="font-family: courier new,monospace;" class="hs-conid">String</span><span style="font-family: courier new,monospace;"> </span><span style="font-family: courier new,monospace;" class="hs-varid">e</span><span style="font-family: courier new,monospace;"> </span><span style="font-family: courier new,monospace;" class="hs-conid">BlazeFormHtml</span><span style="font-family: courier new,monospace;"> </span><span style="font-family: courier new,monospace;" class="hs-conid">()</span><span style="font-family: courier new,monospace;"> </span><span style="font-family: courier new,monospace;" class="hs-comment">-- ^ Submit button</span><br>
<br>Maybe I miss some instance?<br><br>BTW, I also tried to execute your exemple, but I can't install some packages.<br><br><span style="font-family: courier new,monospace;">> cabal install digestive-functors-hsp</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">cabal: Unknown build tool trhsx</span><br><br>Whereas trhsx is in my PATH (under linux).<br></pre>You said I need the latest happstack from darcs, why?<br><br>Cheers,<br>Corentin<br>
<br><div class="gmail_quote">On Sun, Jan 9, 2011 at 8:36 PM, Jeremy Shaw <span dir="ltr"><<a href="mailto:jeremy@n-heptane.com">jeremy@n-heptane.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
Hello,<br>
<br>
newRule also needs to have the type, RoutedNomicServer. The<br>
transformation of RoutedNomicServer into NomicServer is done in the<br>
handleSite function. Something like this:<br>
<br>
<br>
nomicSpec :: ServerHandle -> Site Route (ServerPartT IO Response)<br>
nomicSpec sh =<br>
Site { handleSite = \f url -> unRouteT (nomicSite sh url) f<br>
...<br>
<br>
main =<br>
do ...<br>
simpleHTTP nullConf $ siteImpl (nomicSpec sh)<br>
<br>
Or something like that -- it's hard to tell exactly what is going on<br>
in your app based on the snippets you provided.<br>
<br>
Also, I highly recommend using digestive functors instead of formlets.<br>
It is the successor to formlets. Same core idea, better implementation<br>
and actively maintained.<br>
<br>
I have attached a quick demo of using:<br>
<br>
happstack+digestive-functors+web-routes+HSP<br>
<br>
To use it you will need the latest happstack from darcs plus:<br>
<br>
hsp<br>
web-routes<br>
web-routes-hsp<br>
web-routes-happstack<br>
web-routes-mtl<br>
digestive-functors<br>
digestive-functors-hsp<br>
<br>
I plan to clean up this example and document it better in the crash<br>
course for the upcoming release. Clearly things like the FormInput<br>
instance and the formPart function belong a library.<br>
<br>
let me know if you have more questions.<br>
- jeremy<br>
<br>
On Sat, Jan 8, 2011 at 6:44 PM, Corentin Dupont<br>
<div><div></div><div class="h5"><<a href="mailto:corentin.dupont@gmail.com">corentin.dupont@gmail.com</a>> wrote:<br>
> Hello,<br>
><br>
> I have difficulties mixing web-routes and forms:<br>
> I have put routes in all my site, except for forms which remains with the<br>
> type ServerPartT IO Response.<br>
> How to make them work together?<br>
><br>
> I have:<br>
> type NomicServer = ServerPartT IO<br>
> type RoutedNomicServer = RouteT PlayerCommand NomicServer<br>
><br>
> newRule :: ServerHandle -> NomicServer Response<br>
> newRule sh = do<br>
> methodM POST -- only accept a post method<br>
> mbEntry <- getData -- get the data<br>
> case mbEntry of<br>
> Nothing -> error $ "error: newRule"<br>
> Just (NewRule name text code pn) -> do<br>
> html <- nomicPageComm pn sh (submitRule name text code pn))<br>
> ok $ toResponse html<br>
><br>
><br>
> nomicPageComm :: PlayerNumber -> ServerHandle -> Comm () -><br>
> RoutedNomicServer Html<br>
> nomicPageComm pn sh comm =<br>
> (..)<br>
><br>
><br>
> launchWebServer :: ServerHandle -> IO ()<br>
> launchWebServer sh = do<br>
> putStrLn "Starting web server...\nTo connect, drive your browser to<br>
> \"<a href="http://localhost:8000/Login%5C" target="_blank">http://localhost:8000/Login\</a>""<br>
> d <- liftIO getDataDir<br>
> simpleHTTP nullConf $ mconcat [dir "postLogin" $ postLogin,<br>
> fileServe [] d,<br>
> dir "Login" $ ok $ toResponse $ loginPage,<br>
> dir "NewRule" $ newRule sh,<br>
> dir "NewGame" $ newGameWeb sh,<br>
> dir "Nomic" $ do<br>
> html <- implSite<br>
> "<a href="http://localhost:8000/Nomic/" target="_blank">http://localhost:8000/Nomic/</a>" "" (nomicSite sh)<br>
> ok $ toResponse html<br>
> ]<br>
><br>
><br>
> The red line doesn't compile. I don't know how to transform a<br>
> RoutedNomicServer into a NomicServer.<br>
><br>
> For the future I intend to use formlets: is these some examples of programs<br>
> using happstack + web-routes + formlets?<br>
><br>
> Thanks,<br>
> Corentin<br>
><br>
><br>
><br>
><br>
> On Fri, Jan 7, 2011 at 5:10 PM, Jeremy Shaw <<a href="mailto:jeremy@n-heptane.com">jeremy@n-heptane.com</a>> wrote:<br>
>><br>
>> Hello,<br>
>><br>
>> The [(String, String)] argument is for adding query parameters.<br>
>><br>
>> > encodePathInfo ["foo", "bar", "baz"] [("key","value")]<br>
>><br>
>> "foo/bar/baz?key=value"<br>
>><br>
>> Instead of showURL you would use showURLParams.<br>
>><br>
>> hope this helps!d<br>
>> - jeremy<br>
>><br>
>> On Fri, Jan 7, 2011 at 8:12 AM, Corentin Dupont<br>
>> <<a href="mailto:corentin.dupont@gmail.com">corentin.dupont@gmail.com</a>> wrote:<br>
>> > Hello Jeremy,<br>
>> > I'm using Web routes with happstack.<br>
>> > I'm following this tutorial:<br>
>> > <a href="http://tutorialpedia.org/tutorials/Happstack+type+safe+URLs.html" target="_blank">http://tutorialpedia.org/tutorials/Happstack+type+safe+URLs.html</a><br>
>> ><br>
>> > But It seems out of synch with the latest version of web-routes: 0.23.2.<br>
>> > The haddock documentation seems out of date also:<br>
>> ><br>
>> > encodePathInfo :: [String] -> [(String, String)] -> String<br>
>> ><br>
>> > For example:<br>
>> ><br>
>> > encodePathInfo [\"foo\", \"bar\", \"baz\"]<br>
>> ><br>
>> > "foo/bar/baz"<br>
>> ><br>
>> > And I can't figure out what this [(String, String)] is for ;)<br>
>> ><br>
>> > Thanks,<br>
>> ><br>
>> > Corentin<br>
>> ><br>
><br>
><br>
</div></div></blockquote></div><br>