diff --git a/multi/blog/Yesod-tutorial-for-newbies.md b/multi/blog/Yesod-tutorial-for-newbies.md index 04370f468..f42c4d906 100644 --- a/multi/blog/Yesod-tutorial-for-newbies.md +++ b/multi/blog/Yesod-tutorial-for-newbies.md @@ -200,7 +200,7 @@ Obviously: | `config/routes` | is where you'll configure the map %url → Code. | | `Handler/` | contains the files that will contain the code called when a %url is accessed. | -| `templates/` | contains HTML, JS and %css templates. | +| `templates/` | contains %html, js and %css templates. | | `config/models` | is where you'll configure the persistent objects (database tables). | During this tutorial we'll modify other files as well, @@ -260,7 +260,7 @@ getEchoR theText = do Don't worry if you find all of this a bit cryptic. In short it just declare a function named `getEchoR` with one argument (`theText`) of type String. When this function is called, it return a `Handler RepHtml` whatever it is. -But mainly this will encapsulate our expected result inside an HTML text. +But mainly this will encapsulate our expected result inside an %html text. After saving the file, you should see yesod recompile the application. When the compilation is finished you'll see the message: `Starting devel application`. @@ -284,7 +284,7 @@ A malicious user could not hide some bad script inside. This behavior is a direct consequence of _type safety_. The %url string is put inside a %url type. Then the interesting part in the %url is put inside a String type. To pass from %url type to String type some transformation are made. For example, replace all "`%20`" by space characters. -Then to show the String inside an HTML document, the string is put inside an HTML type. Some transformations occurs like replace "<" 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