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