<
" by "`<`".
+Then to show the String inside an %html document, the string is put inside an %html type. Some transformations occurs like replace "<
" by "`<`".
Thanks to yesod, this tedious job is done for us.
@@ -292,7 +292,7 @@ Thanks to yesod, this tedious job is done for us.
↓
"some text" :: String
↓
- "some text <a>" :: HTML
+ "some text <a>" :: Html
Yesod is not only fast, it helps us to remain secure.
@@ -480,10 +480,9 @@ postMirrorR = do
Don't forget to declare it inside `yosog.cabal` and `Application.hs`.
-We will need to use the `reverse` function provided by `Data.Text` which explain the import.
+We will need to use the `reverse` function provided by `Data.Text` which explain the additional import.
The only new thing here is the line that get the POST parameter named "content".
-
If you want to know more detail about it and form in general you can take look at [the yesod book](http://www.yesodweb.com/book/forms).
Create the two corresponding templates:
@@ -558,21 +557,12 @@ module Handler.Blog
where
import Import
-
-To use Html in forms
-
-
+-- to use Html into forms
import Yesod.Form.Nic (YesodNic, nicHtmlField)
instance YesodNic Yosog
-Define a form for adding a new article.
-Don't pay attention to all the syntax.
-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`.
-
entryForm :: Form Article
entryForm = renderDivs $ Article
@@ -580,74 +570,98 @@ entryForm = renderDivs $ Article
<*> areq nicHtmlField "Content" Nothing
+This function defines a form for adding a new article.
+Don't pay attention to all the syntax.
+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`.
+
-- The view showing the list of articles
getBlogR :: Handler RepHtml
getBlogR = do
-- Get the list of articles inside the database.
articles <- runDB $ selectList [] [Desc ArticleTitle]
- -- We'll need the two "objects": entryWidget and enctype
+ -- We'll need the two "objects": articleWidget and enctype
-- to construct the form (see template/articles.hamlet).
- ((_,entryWidget), enctype) <- generateFormPost entryForm
+ ((_,articleWidget), enctype) <- generateFormPost entryForm
defaultLayout $ do
$(widgetFile "articles")
-Just take a look at the content of `template/articles.hamlet`.
+This handler should display a list of articles.
+We get the list from the DB and we construct the form.
+Just take a look at the corresponding template:
Articles
$if null articles
- --
-
There are no article.
+ -- Show a standard message if there is no article
+
_{MsgNoEntries}
$else
- --
+ -- Show the list of articles
$forall article <- articles
-
#{articleTitle (snd article)}
-
-
+
+