mirror of
https://github.com/zebrajr/express.git
synced 2025-12-06 12:19:51 +01:00
refactor ejs example
This commit is contained in:
parent
a52b1f121c
commit
d653d2308b
|
|
@ -13,10 +13,6 @@
|
|||
.success {
|
||||
color: green;
|
||||
}
|
||||
footer {
|
||||
margin-top: 50px;
|
||||
color: gray;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -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 %>
|
||||
2
examples/ejs/views/footer.html
Normal file
2
examples/ejs/views/footer.html
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
</body>
|
||||
</html>
|
||||
|
|
@ -1,7 +0,0 @@
|
|||
<footer>
|
||||
<p>
|
||||
<%= title %>
|
||||
</p>
|
||||
</footer>
|
||||
</body>
|
||||
</html>
|
||||
20
examples/ejs/views/header.html
Normal file
20
examples/ejs/views/header.html
Normal 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>
|
||||
|
|
@ -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>
|
||||
|
|
@ -1,3 +0,0 @@
|
|||
<% include all.html %>
|
||||
|
||||
<h1 class="header">Some email address</h1>
|
||||
|
|
@ -1,3 +0,0 @@
|
|||
<% include all.html %>
|
||||
|
||||
<h1 class="header">Some users</h1>
|
||||
|
|
@ -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 %> <<%= user.email %>></li>
|
||||
<% }) %>
|
||||
</ul>
|
||||
|
||||
<p><a href="/next">next</a></p>
|
||||
|
||||
<% include footer/all.html %>
|
||||
<% include footer.html %>
|
||||
|
|
|
|||
|
|
@ -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 <tobi@learnboost.com></li>');
|
||||
res.text.should.include('<li>loki <loki@learnboost.com></li>');
|
||||
res.text.should.include('<li>jane <jane@learnboost.com></li>');
|
||||
done();
|
||||
});
|
||||
})
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user