Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Views: Write Draft For Introduction #27618

Merged
merged 56 commits into from May 5, 2024
Merged

Conversation

jasonHYLam
Copy link
Contributor

Because

This is a draft of the introduction of the new "Views" lesson for the NodeJS revamp.

This PR

  • Explains what Views are, in context of MVC.
  • Introduced EJS as a template engine to create views.

Issue

Related to #27616
Closes #XXXXX

Additional Information

Pull Request Requirements

  • I have thoroughly read and understand The Odin Project Contributing Guide
  • The title of this PR follows the location of change: brief description of change format, e.g. Intro to HTML and CSS lesson: Fix link text
  • The Because section summarizes the reason for this PR
  • The This PR section has a bullet point list describing the changes in this PR
  • If this PR addresses an open issue, it is linked in the Issue section
  • If any lesson files are included in this PR, they have been previewed with the Markdown preview tool to ensure it is formatted correctly
  • If any lesson files are included in this PR, they follow the Layout Style Guide

@github-actions github-actions bot added Content: JavaScript Involves the JavaScript course Content: NodeJS Involves the NodeJS course labels Mar 15, 2024
@CouchofTomato CouchofTomato marked this pull request as draft March 18, 2024 14:00
@jasonHYLam jasonHYLam marked this pull request as ready for review March 19, 2024 14:35
@01zulfi 01zulfi added the Project Node Revamp Issues/PRs related to the Node Revamp project label Mar 19, 2024
@01zulfi 01zulfi self-requested a review March 19, 2024 17:15
prodijay777 added 12 commits March 20, 2024 10:40
Removed the sentence stating that "views are the UI that the user
interacts with", which I thought might be misleading.
Added an explanation that views need to be rendered at the end of
controller functions.
I was unable to get the example to work using the Script tag, so this
example will be rewritten with a different method of passing data.
Previously the EJS with Express example was written with data defined in
a script tag. However this did not work, and so was modified such that
data is defined in app.js, and passed down into the navbar component.
@01zulfi 01zulfi self-assigned this Mar 28, 2024
Copy link
Member

@01zulfi 01zulfi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jasonHYLam Amazing lesson 🔥 🔥 🔥

I've left a lot of comments, check them out below.

I particularly like the reusable section and the code examples are great as well. This is going to be a great addition to the curriculum.

nodeJS/express/views.md Outdated Show resolved Hide resolved
nodeJS/express/views.md Outdated Show resolved Hide resolved
nodeJS/express/views.md Outdated Show resolved Hide resolved
nodeJS/express/views.md Outdated Show resolved Hide resolved
nodeJS/express/views.md Outdated Show resolved Hide resolved
nodeJS/express/views.md Outdated Show resolved Hide resolved
nodeJS/express/views.md Outdated Show resolved Hide resolved
nodeJS/express/views.md Show resolved Hide resolved
nodeJS/express/views.md Outdated Show resolved Hide resolved
Comment on lines 142 to 149
<div class="lesson-content__panel" markdown="1">

1. A RESOURCE ITEM
- AN INSTRUCTION ITEM
1. A PRACTICE ITEM
- A TASK ITEM

</div>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should add relevant documentation from the Express site, and a couple of practice assignment items, like: "Add a view for an about page which should render on the /about route"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've just added a few assignment items, including a resource from Express regarding template engines (I've addressed that it uses Pug rather than EJS), and to create and add some components. Sorry for the delay!

@01zulfi 01zulfi removed the Content: JavaScript Involves the JavaScript course label Mar 30, 2024
Copy link
Contributor

@MaoShizhong MaoShizhong left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small thing - as of #27720 and #27723, we now have a formal rule to use the full name for languages like js with codeblocks.
So if you could change any ```js to ```javascript, that'd be awesome.
The same will apply for rb => ruby, md => markdown and txt => text, for reference.

jasonHYLam and others added 7 commits April 13, 2024 14:07
Co-authored-by: 01zulfi <85733202+01zulfi@users.noreply.github.com>
Co-authored-by: 01zulfi <85733202+01zulfi@users.noreply.github.com>
Co-authored-by: 01zulfi <85733202+01zulfi@users.noreply.github.com>
Co-authored-by: 01zulfi <85733202+01zulfi@users.noreply.github.com>
Co-authored-by: MaoShizhong <122839503+MaoShizhong@users.noreply.github.com>
nodeJS/express/views.md Outdated Show resolved Hide resolved
Comment on lines 161 to 163
1. Read through the [Express resource on template engines](https://expressjs.com/en/guide/using-template-engines.html). The resource uses Pug for the examples which has a different syntax, however the information should still be a useful supplement to this lesson.
2. Add a view for an about page, which should render on the `/about` route.
3. Create a reusuable footer component and render it in the `/` route.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Linting errors here will need addressing

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure what the linting error is, is it regarding the extra space at end of the 3rd line? I'll resolve that but please let me know if there are any other errors.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The 3 linting errors for this part at not using lazy numbering for ordered lists and the trailing space at the end of line 163.

You can see the linting errors as annotations in the Files changed tab up top.

nodeJS/express/views.md Outdated Show resolved Hide resolved
nodeJS/express/views.md Outdated Show resolved Hide resolved
nodeJS/express/views.md Show resolved Hide resolved
@MaoShizhong
Copy link
Contributor

Just a note that we're not really sure why GitHub is flagging the "unchanged files with check annotations" thing all of a sudden (it's happened midway through a few other PRs as well). Not entirely sure if there's anything we can do on our end since it's a GH beta feature (but there've already been issues elsewhere from other annoyed people about the feature XD Would be nice if they just noted those files but not also force an action run on them, contaminating the PR with unrelated files...)

Copy link
Contributor

@MaoShizhong MaoShizhong left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mainly just linting/formatting-related matters.

There are also still a fair few mentions of "components" which will probably be better called "templates" as per the docs' terminology.

Amazing work, I really must stress. These are all mainly just consistency/style things.

nodeJS/express/views.md Outdated Show resolved Hide resolved
nodeJS/express/views.md Outdated Show resolved Hide resolved
nodeJS/express/views.md Outdated Show resolved Hide resolved
nodeJS/express/views.md Outdated Show resolved Hide resolved
nodeJS/express/views.md Outdated Show resolved Hide resolved
jasonHYLam and others added 9 commits April 16, 2024 12:30
Co-authored-by: MaoShizhong <122839503+MaoShizhong@users.noreply.github.com>
Co-authored-by: MaoShizhong <122839503+MaoShizhong@users.noreply.github.com>
Co-authored-by: MaoShizhong <122839503+MaoShizhong@users.noreply.github.com>
Co-authored-by: MaoShizhong <122839503+MaoShizhong@users.noreply.github.com>
Co-authored-by: MaoShizhong <122839503+MaoShizhong@users.noreply.github.com>
Comment on lines +146 to +158
<div class="lesson-note lesson-note--tip" markdown="1">

#### Directories within the views folder

We can have nested directories of EJS template files within the views. For example, to render the template file `./views/user/show.ejs`, we'll need to provide the relative path like so:

```javascript
// in res.render
res.render("user/show");

// in include
include("user/show");
```
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we missed the closing div tag for this.

image

can you add it please

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for spotting that, I've added a closing div tag just above Serving Static Assets. Let me know if that's correct or if it was needed somewhere else.

Copy link
Member

@01zulfi 01zulfi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm 🚀 🚀

@01zulfi 01zulfi merged commit a2313fb into TheOdinProject:main May 5, 2024
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Content: NodeJS Involves the NodeJS course Project Node Revamp Issues/PRs related to the Node Revamp project
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants