Text in better place + Regen

This commit is contained in:
Yann Esposito (Yogsototh) 2012-01-19 16:02:53 +01:00
parent 010b4606f5
commit 335cfad8ea
5 changed files with 38 additions and 30 deletions

View file

@ -585,6 +585,13 @@ import Yesod.Form.Nic (YesodNic, nicHtmlField)
instance YesodNic Yosog
</code>
<small>Remark: it is a best practice to add the YesodNic instance inside `Foundation.hs`.
I put this definition here to make things easier but you should see a warning about this orphan instance.
To put the include inside Foundation.hs is left as an exercice to the reader.</small>
<small>_Hint: Do not forget to put `YesodNic` and `nicHtmlField` inside the exported objects of the module._
</small>
<code class="haskell">
entryForm :: Form Article
entryForm = renderDivs $ Article
@ -598,13 +605,6 @@ If you are curious you can take a look at Applicative Functor.
You just have to remember `areq` is for required form input.
Its arguments being: `areq type label default_value`.
<small>Remark: it is a best practice to add the YesodNic instance inside `Foundation.hs`.
I put this definition here to make things easier but you should see a warning about this orphan instance.
To put the include inside Foundation.hs is left as an exercice to the reader.</small>
<small>_Hint: Do not forget to put `YesodNic` and `nicHtmlField` inside the exported objects of the module._
</small>
<code class="haskell">
-- The view showing the list of articles
getBlogR :: Handler RepHtml

View file

@ -586,6 +586,13 @@ import Yesod.Form.Nic (YesodNic, nicHtmlField)
instance YesodNic Yosog
</code>
<small>Remark: it is a best practice to add the YesodNic instance inside `Foundation.hs`.
I put this definition here to make things easier but you should see a warning about this orphan instance.
To put the include inside Foundation.hs is left as an exercice to the reader.</small>
<small>_Hint: Do not forget to put `YesodNic` and `nicHtmlField` inside the exported objects of the module._
</small>
<code class="haskell">
entryForm :: Form Article
entryForm = renderDivs $ Article
@ -654,17 +661,14 @@ postBlogR = do
case res of
FormSuccess article -> do
articleId <- runDB $ insert article
setMessage $ (articleTitle article) ++. " created"
setMessage $ toHtml $ (articleTitle article) <> " created"
redirect RedirectPermanent $ ArticleR articleId
_ -> defaultLayout $ do
setTitle "Please correct your entry form"
$(widgetFile "articleAddError")
where
(++.) t s = toHtml $ T.append t (T.pack s)
</code>
This function should be used to create a new article.
The `(++.)` local function is just a trick to make an append occurs within the right type.
We handle the form response.
If there is an error we display an error page.
For example if we left some required value blank.

View file

@ -591,6 +591,13 @@ import Yesod.Form.Nic (YesodNic, nicHtmlField)
instance YesodNic Yosog
</code>
<small>Remark: it is a best practice to add the YesodNic instance inside `Foundation.hs`.
I put this definition here to make things easier but you should see a warning about this orphan instance.
To put the include inside Foundation.hs is left as an exercice to the reader.</small>
<small>_Hint: Do not forget to put `YesodNic` and `nicHtmlField` inside the exported objects of the module._
</small>
<code class="haskell">
entryForm :: Form Article
entryForm = renderDivs $ Article
@ -604,13 +611,6 @@ If you are curious you can take a look at Applicative Functor.
You just have to remember `areq` is for required form input.
Its arguments being: `areq type label default_value`.
<small>Remark: it is a best practice to add the YesodNic instance inside `Foundation.hs`.
I put this definition here to make things easier but you should see a warning about this orphan instance.
To put the include inside Foundation.hs is left as an exercice to the reader.</small>
<small>_Hint: Do not forget to put `YesodNic` and `nicHtmlField` inside the exported objects of the module._
</small>
<code class="haskell">
-- The view showing the list of articles
getBlogR :: Handler RepHtml

View file

@ -683,6 +683,13 @@ handle Html in forms.</p>
<span class="Keyword">instance</span> <span class="Constant">YesodNic</span> <span class="Constant">Yosog</span>
</pre>
<p><small>Remark: it is a best practice to add the YesodNic instance inside <code>Foundation.hs</code>.
I put this definition here to make things easier but you should see a warning about this orphan instance.
To put the include inside Foundation.hs is left as an exercice to the reader.</small></p>
<p><small><em>Hint: Do not forget to put <code>YesodNic</code> and <code>nicHtmlField</code> inside the exported objects of the module.</em>
</small></p>
<pre class="twilight">
<span class="Entity">entryForm</span> :: <span class="Constant">Form</span> <span class="Constant">Article</span>
entryForm = renderDivs $ <span class="Constant">Article</span>
@ -696,13 +703,6 @@ If you are curious you can take a look at Applicative Functor.
You just have to remember <code>areq</code> is for required form input.
Its arguments being: <code>areq type label default_value</code>.</p>
<p><small>Remark: it is a best practice to add the YesodNic instance inside <code>Foundation.hs</code>.
I put this definition here to make things easier but you should see a warning about this orphan instance.
To put the include inside Foundation.hs is left as an exercice to the reader.</small></p>
<p><small><em>Hint: Do not forget to put <code>YesodNic</code> and <code>nicHtmlField</code> inside the exported objects of the module.</em>
</small></p>
<pre class="twilight">
<span class="Comment"><span class="Comment">--</span> The view showing the list of articles</span>
<span class="Entity">getBlogR</span> :: <span class="Constant">Handler</span> <span class="Constant">RepHtml</span>
@ -934,7 +934,7 @@ The example on also add a comment system.</p>
</div>
<div id="lastmod">
Created: 01/15/2012
Modified: 01/18/2012
Modified: 01/19/2012
</div>
<div>
Entirely done with

View file

@ -684,6 +684,13 @@ handle Html in forms.</p>
<span class="Keyword">instance</span> <span class="Constant">YesodNic</span> <span class="Constant">Yosog</span>
</pre>
<p><small>Remark: it is a best practice to add the YesodNic instance inside <code>Foundation.hs</code>.
I put this definition here to make things easier but you should see a warning about this orphan instance.
To put the include inside Foundation.hs is left as an exercice to the reader.</small></p>
<p><small><em>Hint: Do not forget to put <code>YesodNic</code> and <code>nicHtmlField</code> inside the exported objects of the module.</em>
</small></p>
<pre class="twilight">
<span class="Entity">entryForm</span> :: <span class="Constant">Form</span> <span class="Constant">Article</span>
entryForm = renderDivs $ <span class="Constant">Article</span>
@ -754,17 +761,14 @@ postBlogR = <span class="Keyword">do</span>
<span class="Keyword">case</span> res <span class="Keyword">of</span>
<span class="Constant">FormSuccess</span> article -&gt; <span class="Keyword">do</span>
articleId &lt;- runDB $ insert article
setMessage $ (articleTitle article) ++. <span class="String"><span class="String">&quot;</span> created<span class="String">&quot;</span></span>
setMessage $ toHtml $ (articleTitle article) &lt;&gt; <span class="String"><span class="String">&quot;</span> created<span class="String">&quot;</span></span>
redirect <span class="Constant">RedirectPermanent</span> $ <span class="Constant">ArticleR</span> articleId
_ -&gt; defaultLayout $ <span class="Keyword">do</span>
setTitle <span class="String"><span class="String">&quot;</span>Please correct your entry form<span class="String">&quot;</span></span>
$(widgetFile <span class="String"><span class="String">&quot;</span>articleAddError<span class="String">&quot;</span></span>)
<span class="Keyword">where</span>
<span class="Entity">(++.)</span> t s = toHtml $ <span class="Constant">T</span>.append t (<span class="Constant">T</span>.pack s)
</pre>
<p>This function should be used to create a new article.
The <code>(++.)</code> local function is just a trick to make an append occurs within the right type.
We handle the form response.
If there is an error we display an error page.
For example if we left some required value blank.