Skip to content
Myr

improved ejs Example

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by sakateka · committed by TJ Holowaychuk · parent 8e12dd9 · Browse files · 11 files+123 added−40 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

11 files+123 added−40 removed

  • other:+123 added−40 removed

11 files+123 added−40 removed

added:examples/auth/views/foot.ejs+11 added
1 <footer>2 <p>3 <% if (user) { %>4 Authenticated as <%= user %>, click to <a href="/logout">logout</a>.5 <%} else {%>6 <%= title %>7 <% } %>8 </p>9 </footer>10 </body>11</html>
added:examples/auth/views/head.ejs+22 added
1<!DOCTYPE html>2<html>3 <head>4 <title><%= title %></title>5 <style>6 body {7 padding: 50px;8 font: 13px Helvetica, Arial, sans-serif;9 }10 .error {11 color: red12 }13 .success {14 color: green;15 }16 footer {17 margin-top: 50px;18 color: gray;19 }20 </style>21 </head>22 <body>
modified:examples/auth/views/login.ejs+20 added-36 removed
1<!DOCTYPE html>2<html>3 <head>4 <title>Authentication Example</title>5 <style>6 body {7 padding: 50px;8 font: 13px Helvetica, Arial, sans-serif;9 }10 .error {11 color: red12 }13 .success {14 color: green;15 }16 </style>17 </head>18 <body>19 <h1>Login</h1>20 <%- message %>21 Try accessing <a href="/restricted">/restricted</a>, then authenticate with "tj" and "foobar".22 <form method="post" action="/login">23 <p>24 <label>Username:</label>25 <input type="text" name="username">26 </p>27 <p>28 <label>Password:</label>29 <input type="text" name="password">30 </p>31 <p>32 <input type="submit" value="Login">33 </p>34 </form>35 </body>36</html>1<% include head %>23<h1>Login</h1>4<%- message %>5Try accessing <a href="/restricted">/restricted</a>, then authenticate with "tj" and "foobar".6<form method="post" action="/login">7 <p>8 <label>Username:</label>9 <input type="text" name="username">10 </p>11 <p>12 <label>Password:</label>13 <input type="text" name="password">14 </p>15 <p>16 <input type="submit" value="Login">17 </p>18</form>1920<% include foot %>
modified:examples/auth/app.js+4 added-1 removed
added:examples/ejs/views/footer/all.html+7 added
added:examples/ejs/views/header/all.html+20 added
added:examples/ejs/views/header/emails.html+3 added
added:examples/ejs/views/header/users.html+3 added
added:examples/ejs/views/emails.html+12 added
1<% include header/emails.html %>23<h1>Emails</h1>4<ul id="emails">5 <% users.forEach(function(user){ %>6 <li><%= user.email %> by <%= user.name %></li>7 <% }) %>8</ul>910<p><a href="/">back</a></p> 1112<% include footer/all.html %>
modified:examples/ejs/views/users.html+7 added-1 removed
1<% include header/users.html %>23<h1>Users</h1>4<ul id="users">5 <% users.forEach(function(user){ %>6 <li><%= user.name %> <%= user.email %></li>7 <% }) %>6</ul>8</ul>910<p><a href="/next">next</a></p> 1112<% include footer/all.html %>
modified:examples/ejs/index.js+14 added-2 removed
35 unmodified lines
36 , { name: 'jane', email: 'jane@learnboost.com' }37];3839app.get('/', function(req, res){40 res.render('users', { users: users });40 res.render('users', {41 users: users,42 title: "EJS example",43 header: "Some users"44 });45});4647app.get('/next', function(req, res){48 res.render('emails', {49 users: users,50 title: "EJS example",51 header: "Some email address"52 });53});5455if (!module.parent) {56 app.listen(3000);57 console.log('Express app started on port 3000');46}58}