Skip to content

Commit 159b44d

Browse files
author
Docker
committed
rename 'render' and 'all_posts' to 'home' to avoid renaming
1 parent 36eab01 commit 159b44d

File tree

11 files changed

+19
-20
lines changed

11 files changed

+19
-20
lines changed

README.md

+9-10
Original file line numberDiff line numberDiff line change
@@ -136,12 +136,12 @@ let render param =
136136

137137
This runs `dream_eml` on the `template.eml.html` template to generate the corresponding `template.ml` OCaml file.
138138

139-
The function `render` from `template.eml.html` can now be used in your program like this: `Template.render`.
139+
The function `home` from `template.eml.html` can now be used in your program like this: `Template.home`.
140140

141141
3. Change `main.ml` by replacing the string "Hello world!" with
142142

143143
```ocaml
144-
(Template.render "world")
144+
(Template.home "world")
145145
```
146146

147147
to use the new template.
@@ -213,9 +213,9 @@ This is, for now, a list of blog posts that have a `title`, a `slug`, a `html_bo
213213

214214
Now, `Post.t` is a type that represents a single blog post, and `Post.all : t list` is the list of all blog posts.
215215

216-
2. Rename the `render` function in `template.eml.html` to `all_posts` and change the HTML template to render a list of blog posts.
216+
2. Change the `home` function in `template.eml.hml` to render a list of blog posts.
217217

218-
Instead of taking a `param` parameter, the new `all_posts` function takes a parameter `(posts: Post.t list)`.
218+
Instead of taking `param` as parameter, the new `home` function takes a parameter `(posts: Post.t list)`.
219219

220220
Instead of showing `Hello <%s param %>! This is a HTML Template.`, you can iterate over the list of posts using the `List.iter` function like this:
221221

@@ -224,6 +224,7 @@ Instead of showing `Hello <%s param %>! This is a HTML Template.`, you can itera
224224
... TODO: write HTML here ...
225225
<% ); %>
226226
```
227+
227228
Render a `<ul>` and iterate over the list to render a `<li>` tag that contains the title of the blog post.
228229

229230
Hint: <%s ... %> is used to render an OCaml string.
@@ -232,9 +233,7 @@ Hint: <%s ... %> is used to render an OCaml string.
232233

233234
### Step 5: Subpage for individual posts
234235

235-
All we did in the last step was render a list of titles of the blog posts, but now we want to give every blog post its own HTML page under the URL `/post/:slug`, where `:slug` is the value of the `slug` field of the particular blog post. This would allow people to link to or bookmark a specific blog post.
236-
237-
We will need a new template for the
236+
All we did in the last step was render a list of titles of the blog posts, but now we want to give every blog post its own HTML page under the URL `/post/:slug`, where `:slug` is the value of the `slug` field of the particular blog post. This will allow people to link to or bookmark a specific blog post.
238237

239238
**Tasks:**
240239

@@ -276,7 +275,7 @@ match post with
276275

277276
to render `Template.post` when a post was found, and return a 404 response when no post with the given slug was found.
278277

279-
4. Modify `Template.all_posts` so that every blog post has an `<a>` tag around the title that links to the new route.
278+
4. Modify `Template.home` so that every blog post has an `<a>` tag around the title that links to the new route.
280279

281280
You will need to use `<%s ... %>` again to render `post.slug` as part of the URL.
282281

@@ -302,14 +301,14 @@ See https://aantron.github.io/dream/#static-files for an example of how to do th
302301

303302
3. Add a `<div class="container">` right inside the body of both templates, to wrap the existing elements.
304303

305-
3a. (optional) Having the basic structure / layout of the page repeated in every template is repetitive. Can you see how to move the `<html>, <head>, <link>, <body>, <div class="container">` to a separate function that can be used by both the `post` and the `all_posts` template?
304+
3a. (optional) Having the basic structure / layout of the page repeated in every template is repetitive. Can you see how to move the `<html>, <head>, <link>, <body>, <div class="container">` to a separate function that can be used by both the `post` and the `home` template?
306305

307306
Hint: You can create a `layout` function that takes a string parameter `inner_html` and renders it inside the template with `<%s! inner_html %>`.
308307

309308
Hint 2: It is possible to pass a HTML template to the `layout` function like this:
310309

311310
```ocaml
312-
let all_posts =
311+
let home =
313312
layout (
314313
<h1>All Posts</h1>
315314
...

solutions/2-sending-html/main.ml

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@
44
dune exec solution2
55
*)
66

7-
let () = Dream.run (fun _ -> Dream.html (Template.render "world"))
7+
let () = Dream.run (fun _ -> Dream.html (Template.home "world"))

solutions/2-sending-html/template.eml.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
let render param =
1+
let home param =
22
<html>
33
<body>
44
<h1>Hello <%s param %>! This is a HTML Template.</h1>

solutions/3-introducing-routes/main.ml

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@ let () =
88
Dream.run @@ Dream.logger
99
@@ Dream.router
1010
[
11-
Dream.get "/" (fun _ -> Dream.html (Template.render "world"));
11+
Dream.get "/" (fun _ -> Dream.html (Template.home "world"));
1212
Dream.get "**" (fun _ -> Dream.html ~code:404 "404 Not Found");
1313
]

solutions/3-introducing-routes/template.eml.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
let render param =
1+
let home param =
22
<html>
33
<body>
44
<h1>Hello <%s param %>! This is a HTML Template.</h1>

solutions/4-render-list-of-posts/main.ml

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@ let () =
88
Dream.run @@ Dream.logger
99
@@ Dream.router
1010
[
11-
Dream.get "/" (fun _ -> Dream.html (Template.all_posts Post.all));
11+
Dream.get "/" (fun _ -> Dream.html (Template.home Post.all));
1212
Dream.get "**" (fun _ -> Dream.html ~code:404 "404 Not Found");
1313
]

solutions/4-render-list-of-posts/template.eml.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
let all_posts (posts : Post.t list) =
1+
let home (posts : Post.t list) =
22
<html>
33
<body>
44
<h1>All Posts</h1>

solutions/5-create-a-page-for-each-post/main.ml

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ let () =
88
Dream.run @@ Dream.logger
99
@@ Dream.router
1010
[
11-
Dream.get "/" (fun _ -> Dream.html (Template.all_posts Post.all));
11+
Dream.get "/" (fun _ -> Dream.html (Template.home Post.all));
1212
Dream.get "/post/:slug" (fun request ->
1313
let slug = Dream.param request "slug" in
1414
let post = List.find_opt (fun p -> p.Post.slug = slug) Post.all in

solutions/5-create-a-page-for-each-post/template.eml.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ <h1><%s post.title %></h1>
99
</body>
1010
</html>
1111

12-
let all_posts (posts : Post.t list) =
12+
let home (posts : Post.t list) =
1313
<html>
1414
<body>
1515
<h1>All Posts</h1>

solutions/6-making-it-pretty/main.ml

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ let () =
88
Dream.run @@ Dream.logger
99
@@ Dream.router
1010
[
11-
Dream.get "/" (fun _ -> Dream.html (Template.all_posts Post.all));
11+
Dream.get "/" (fun _ -> Dream.html (Template.home Post.all));
1212
Dream.get "/post/:slug" (fun request ->
1313
let slug = Dream.param request "slug" in
1414
let post = List.find_opt (fun p -> p.Post.slug = slug) Post.all in

solutions/6-making-it-pretty/template.eml.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ <h1><%s post.title %></h1>
2020
</div>
2121
)
2222

23-
let all_posts (posts : Post.t list) =
23+
let home (posts : Post.t list) =
2424
layout (
2525
<h1>All Posts</h1>
2626
<ul>

0 commit comments

Comments
 (0)