refactor ejs example

This commit is contained in:
TJ Holowaychuk 2012-10-09 19:26:17 -07:00
parent a52b1f121c
commit d653d2308b
11 changed files with 32 additions and 69 deletions

View File

@ -13,10 +13,6 @@
.success {
color: green;
}
footer {
margin-top: 50px;
color: gray;
}
</style>
</head>
<body>

View File

@ -31,24 +31,16 @@ app.set('view engine', 'html');
// Dummy users
var users = [
{ name: 'tobi', email: 'tobi@learnboost.com' }
, { name: 'loki', email: 'loki@learnboost.com' }
, { name: 'jane', email: 'jane@learnboost.com' }
{ name: 'tobi', email: 'tobi@learnboost.com' },
{ name: 'loki', email: 'loki@learnboost.com' },
{ name: 'jane', email: 'jane@learnboost.com' }
];
app.get('/', function(req, res){
res.render('users', {
users: users,
title: "EJS example",
header: "Some users"
});
});
app.get('/next', function(req, res){
res.render('emails', {
users: users,
title: "EJS example",
header: "Some email address"
header: "Some users"
});
});

View File

@ -1,12 +0,0 @@
<% include header/emails.html %>
<h1>Emails</h1>
<ul id="emails">
<% users.forEach(function(user){ %>
<li><%= user.email %> by <%= user.name %></li>
<% }) %>
</ul>
<p><a href="/">back</a></p>
<% include footer/all.html %>

View File

@ -0,0 +1,2 @@
</body>
</html>

View File

@ -1,7 +0,0 @@
<footer>
<p>
<%= title %>
</p>
</footer>
</body>
</html>

View File

@ -0,0 +1,20 @@
<!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>

View File

@ -1,20 +0,0 @@
<!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>

View File

@ -1,3 +0,0 @@
<% include all.html %>
<h1 class="header">Some email address</h1>

View File

@ -1,3 +0,0 @@
<% include all.html %>
<h1 class="header">Some users</h1>

View File

@ -1,12 +1,10 @@
<% include header/users.html %>
<% include header.html %>
<h1>Users</h1>
<ul id="users">
<% users.forEach(function(user){ %>
<li><%= user.name %> <%= user.email %></li>
<li><%= user.name %> &lt;<%= user.email %>&gt;</li>
<% }) %>
</ul>
<p><a href="/next">next</a></p>
<% include footer/all.html %>
<% include footer.html %>

View File

@ -10,9 +10,9 @@ describe('ejs', function(){
.end(function(err, res){
res.should.have.status(200);
res.should.have.header('Content-Type', 'text/html; charset=utf-8');
res.text.should.include('<li>tobi tobi@learnboost.com</li>');
res.text.should.include('<li>loki loki@learnboost.com</li>');
res.text.should.include('<li>jane jane@learnboost.com</li>');
res.text.should.include('<li>tobi &lt;tobi@learnboost.com&gt;</li>');
res.text.should.include('<li>loki &lt;loki@learnboost.com&gt;</li>');
res.text.should.include('<li>jane &lt;jane@learnboost.com&gt;</li>');
done();
});
})