Merge pull request #2067 from swrh/mvc-example-ejs-to-jade
Before adoption: this commit came in with the history the project adopted, so no landing records it.
MVC example: EJS -> Jade.
authored by Roman Shtylman · committed by Roman Shtylman · parents 5480cb9, ce17efd · Browse files · 12 files·+45 added−54 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
12 files+45 added−54 removed
- other:+45 added−54 removed
Provenance
- Commit
29e8cce- Tree
92a1a18- Author
Roman Shtylman <shtylman@gmail.com>- Committer
Roman Shtylman <shtylman@gmail.com>- Parent 1
5480cb9- Parent 2
ce17efd
12 files changed+45 added−54 removed
modified:examples/mvc/controllers/pet/index.js-2 removed
2 unmodified lines3456787891017 unmodified lines2 unmodified lines */
var db = require('../../db');
exports.engine = 'jade';
exports.before = function(req, res, next){ var pet = db.pets[req.params.pet_id]; if (!pet) return next(new Error('Pet not found')); req.pet = pet;17 unmodified linesdeleted:examples/mvc/controllers/user/views/edit.html-12 removed
123456789101112<link rel="stylesheet" href="/style.css" /><h1><%= user.name %></h1><form action='/user/<%= user.id %>' method='post'> <input type="hidden" name="_method" value="put" /> <label>Name: <input type="text" name="user[name]" value="<%= user.name %>" /></label> <input type="submit" value="Update" /></form>
<form action='/user/<%= user.id %>/pet' method='post'> <label>Pet: <input type="text" name="pet[name]" placeholder="name" /></label> <input type="submit" value="Add" /></form>No newline at end of fileadded:examples/mvc/controllers/user/views/edit.jade+12 added
1+link(rel='stylesheet', href='/style.css')2+h1= user.name3+form(action='/user/#{user.id}', method='post')4+ input(type='hidden', name='_method', value='put')5+ label= 'Name: '6+ input(type='text', name='user[name]', value='#{user.name}')7+ input(type='submit', value='Update')8+9+form(action='/user/#{user.id}/pet', method='post')10+ label= 'Pet: '11+ input(type='text', name='pet[name]', placeholder='Name')12+ input(type='submit', value='Add')deleted:examples/mvc/controllers/user/views/list.html-8 removed
12345678<link rel="stylesheet" href="/style.css" /><h1>Users</h1><p>Click a user below to view their pets.</p><ul> <% users.forEach(function(user){ %> <li><a href="/user/<%= user.id %>"><%= user.name %></a></li> <% }) %></ul>No newline at end of fileadded:examples/mvc/controllers/user/views/list.jade+7 added
1+link(rel='stylesheet', href='/style.css')2+h1 Users3+p Click a user below to view their pets.4+ul5+ each user in users6+ li7+ a(href='/user/#{user.id}')= user.namedeleted:examples/mvc/controllers/user/views/show.html-21 removed
123456789101112131415161718192021<link rel="stylesheet" href="/style.css" /><h1><%= user.name %> <a href="/user/<%= user.id %>/edit">edit</a></h1>
<% if (hasMessages) { %> <ul id="messages"> <% messages.forEach(function(msg){ %> <li><%= msg %></li> <% }) %> </ul><% } %>
<% if (user.pets.length) { %> <p>View <%= user.name %>s pets:</p> <ul> <% user.pets.forEach(function(pet){ %> <li><a href="/pet/<%= pet.id %>"><%= pet.name %></a></li> <% }) %> </ul><% } else { %> <p>No pets!</p><% } %>No newline at end of fileadded:examples/mvc/controllers/user/views/show.jade+17 added
1+link(rel='stylesheet', href='/style.css')2+h1= user.name + ' '3+ a(href='/user/#{user.id}/edit') edit4+5+if (hasMessages)6+ ul#messages7+ each msg in messages8+ li= msg9+10+if (user.pets.length)11+ p View #{user.name}'s pets:12+ ul13+ each pet in user.pets14+ li15+ a(href='/pet/#{pet.id}')= pet.name16+else17+ p No pets!deleted:examples/mvc/views/404.html-3 removed
123<link rel="stylesheet" href="/style.css" /><h1>404: Not Found</h1><p>Sorry we can't find <%= url %></p>No newline at end of fileadded:examples/mvc/views/404.jade+3 added
1+link(rel='stylesheet', href='/style.css')2+h1 404: Not Found3+p Sorry we can't find #{url}deleted:examples/mvc/views/5xx.html-3 removed
1-<link rel="stylesheet" href="/style.css" />2-<h1>500: Internal Server Error</h1>3-<p>Looks like something blew up!</p>added:examples/mvc/views/5xx.jade+3 added
1+link(rel='stylesheet', href='/style.css')2+h1 500: Internal Server Error3+p Looks like something blew up!modified:examples/mvc/index.js+3 added-5 removed
11 unmodified lines12 var app = module.exports = express();13 14 // settings15 16-// map .renderFile to ".html" files17-app.engine('html', require('ejs').renderFile);16+// set our default template engine to "jade"17+// which prevents the need for extensions18+app.set('view engine', 'jade');19 19-// make ".html" the default20-app.set('view engine', 'html');21-20 // set views for error and 404 pages21 app.set('views', __dirname + '/views');22 23 // define a custom res.message() method76 unmodified lines