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
Provenance
- Commit
be7ec8b- Tree
8b6e074- Author
sakateka <S.Kacheev@gmail.com>- Committer
TJ Holowaychuk <tj@vision-media.ca>- Parent
8e12dd9
11 files changed+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 %>2+3+<h1>Login</h1>4+<%- message %>5+Try 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>19+20+<% include foot %>modified:examples/auth/app.js+4 added-1 removed
88 unmodified lines89909192939394959697989910026 unmodified lines88 unmodified lines });});
app.get('/login', function(req, res){ res.render('login'); res.render('login', { title: "Authentication Example", user: req.session.user ? req.session.user.name : undefined });});
app.post('/login', function(req, res){ authenticate(req.body.username, req.body.password, function(err, user){26 unmodified linesadded:examples/ejs/views/footer/all.html+7 added
1234567 <footer> <p> <%= title %> </p> </footer></body></html>added:examples/ejs/views/header/all.html+20 added
1234567891011121314151617181920<!DOCTYPE HTML><html lang="en"><head> <meta charset="UTF-8"> <title> <%= title %> </title> <style type="text/css"> body { padding: 50px; font: 13px Helvetica, Arial, sans-serif; } .header { font-size: 4em; } footer { margin-top: 50px; color: gray; } </style></head><body>added:examples/ejs/views/header/emails.html+3 added
123<% include all.html %>
<h1 class="header">Some email address</h1>added:examples/ejs/views/header/users.html+3 added
123<% include all.html %>
<h1 class="header">Some users</h1>added:examples/ejs/views/emails.html+12 added
1+<% include header/emails.html %>2+3+<h1>Emails</h1>4+<ul id="emails">5+ <% users.forEach(function(user){ %>6+ <li><%= user.email %> by <%= user.name %></li>7+ <% }) %>8+</ul>9+10+<p><a href="/">back</a></p> 11+12+<% include footer/all.html %>modified:examples/ejs/views/users.html+7 added-1 removed
1+<% include header/users.html %>2+3 <h1>Users</h1>4 <ul id="users">5 <% users.forEach(function(user){ %>6 <li><%= user.name %> <%= user.email %></li>7 <% }) %>6-</ul>8+</ul>9+10+<p><a href="/next">next</a></p> 11+12+<% include footer/all.html %>modified:examples/ejs/index.js+14 added-2 removed
35 unmodified lines36 , { name: 'jane', email: 'jane@learnboost.com' }37 ];38 39 app.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 });46 47+app.get('/next', function(req, res){48+ res.render('emails', {49+ users: users,50+ title: "EJS example",51+ header: "Some email address"52+ });53+});54+55 if (!module.parent) {56 app.listen(3000);57 console.log('Express app started on port 3000');46-}58+}