Updated blog example for Jade inheritence. Passes tests.
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Robert Sköld · committed by TJ Holowaychuk · parent 2432a0d · Browse files · 8 files·+102 added−60 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
8 files+102 added−60 removed
- other:+102 added−60 removed
Provenance
- Commit
ad3f1e8- Tree
af68df3- Author
Robert Sköld <robert@publicclass.se>- Committer
TJ Holowaychuk <tj@vision-media.ca>- Parent
2432a0d
8 files changed+102 added−60 removed
modified:examples/auth/app.js+4 added-3 removed
114 unmodified linesExpand all115116117118119120121119120121122114 unmodified linesExpand all } });});
app.listen(3000);if( process.env.NODE_ENV !== 'test' ) console.log('Express started on port 3000');No newline at end of fileif (!module.parent) { app.listen(3000); console.log('Express started on port 3000');}No newline at end of filemodified:examples/blog/middleware/locals.js+29 added-1 removed
1234567689101112131415161718192021222324252627282930313233343536373839404142434445464748495051527 unmodified lines
/** * Module dependencies. */var format = require('util').format , messages = require('express-messages');
var messages = require('express-messages');
module.exports = function(req, res, next){ // access the app without passing it into // this file explicitly var app = req.app;
// while express-messages is still 2.x and // req.flash() is a 2.x thing we roll our own // for now (ported from ye olde req.notify). req.flash = function(type, msg){ var sess = this.session; if (null == sess) throw Error('req.notify() requires sessions'); var msgs = sess.notifications = sess.notifications || {}; switch (arguments.length) { // flush all messages case 0: sess.notifications = {}; return msgs // flush messages for a specific type case 1: var arr = msgs[type]; delete msgs[type]; return arr || []; // set notification message default: var args = Array.prototype.slice.call(arguments,1); msg = format.apply({},args); return (msgs[type] = msgs[type] || []).push(msg); } };
// express-messages returns a function which // when called will flush the session-based // notification messages as HTML. Because of // this "flushing" action it must be a function // otherwise any view render would remove the // notifications regardless of their delay. res.locals.messages = messages(req, res);
// expose the app's mount-point // so that urls can adjust. For example // if you run this example /post/add works // however if you run the mounting example7 unmodified linesmodified:examples/blog/routes/post.js+2 added-2 removed
40 unmodified lines41 * Save a post.42 */43 44 app.post('/post', function(req, res){45- var data = req.body.post45+ var data = req.body.post || {}46 , post = new Post(data.title, data.body);47-47+ 48 post.validate(function(err){49 if (err) {50 req.flash('error', err.message);51 return res.redirect('back');44 unmodified linesmodified:examples/blog/views/post/form.jade+19 added-17 removed
1+extends ../layout2 3+block content2-- if (post.title)3- h1 Editing #{post.title}4-- else5- h1 New Post4+ - if (post.title)5+ h1 Editing #{post.title}6+ - else7+ h1 New Post8 7-!= messages()9+ != messages()10 9-form#post(action=base + '/post' + (post.title ? '/' + post.id : ''), method='post')10- - if (post.title)11- input(type='hidden', name='_method', value='put')12- p13- label(for='post[title]') Title:14- input(type='text', name='post[title]', value=post.title)15- p16- label(for='post[body]') Body:17- textarea(name='post[body]')= post.body || ''18- p19- input(type='submit', value=post.title ? 'Update' : 'Create')20- 11+ form#post(action=base + '/post' + (post.title ? '/' + post.id : ''), method='post')12+ - if (post.title)13+ input(type='hidden', name='_method', value='put')14+ p15+ label(for='post[title]') Title:16+ input(type='text', name='post[title]', value=post.title)17+ p18+ label(for='post[body]') Body:19+ textarea(name='post[body]')= post.body || ''20+ p21+ input(type='submit', value=post.title ? 'Update' : 'Create')22+ modified:examples/blog/views/post/index.jade+19 added-16 removed
1+extends ../layout2+3+block content1-.post2- // title3- h24- = post.title5- a.edit(href=base + '/post/' + post.id + '/edit') Edit6- 7- // flash messages8- != messages()9- 10- // dates11- p.date.created Created at #{post.createdAt}12- - if (post.updatedAt)13- p.date.updated Updated at #{post.updatedAt}14- 15- // body16- pre.body= post.body4+ .post5+ // title6+ h27+ = post.title8+ a.edit(href=base + '/post/' + post.id + '/edit') Edit9+ 10+ // flash messages11+ != messages()12+ 13+ // dates14+ p.date.created Created at #{post.createdAt}15+ - if (post.updatedAt)16+ p.date.updated Updated at #{post.updatedAt}17+ 18+ // body19+ pre.body= post.bodymodified:examples/blog/views/index.jade+22 added-17 removed
1-h1 Blog1+extends layout2 3-!= messages()3+block content4+ h1 Blog5 6+ != messages()7+8+ - if (count)9+ p Display all #{count} post(s)5-- if (count)6- p Display all #{count} post(s)7- #posts!= partial('post', posts)8-- else9- p 10- | It looks like you have no posts!11- p12- | Click13- a(href=base + '/post/add') here 14- | to create a post. Login15- | as16- em "admin" 17- | and18- em "express"19- | .10+ #posts11+ - each post in posts12+ include post/index13+ - else14+ p 15+ | It looks like you have no posts!16+ p17+ | Click18+ a(href=base + '/post/add') here 19+ | to create a post. Login20+ | as21+ em "admin" 22+ | and23+ em "express"24+ | .modified:examples/blog/views/layout.jade+2 added-1 removed
2 unmodified lines3 head4 title Blog5 link(rel='stylesheet', href=base + '/style.css')6 body7- #container!= body7+ #container8+ block contentmodified:examples/blog/app.js+5 added-3 removed
2 unmodified lines3 * Module dependencies.4 */5 6 var express = require('../../')7- , app = express();7+ , app = module.exports = express();8 9 // config10 11 app.set('views', __dirname + '/views');12 app.set('view engine', 'jade');13 14 // middleware15 16-app.configure(function(){16+app.configure('development',function(){17 app.use(express.logger('dev'));18+})19+20+app.configure(function(){21 app.use(express.bodyParser());22 app.use(express.methodOverride());23 app.use(express.cookieParser('keyboard cat'));24 app.use(express.session());25 app.use(require('./middleware/locals'));23- app.use(messages());26 app.use(app.router);27 app.use(express.static(__dirname + '/public'));28 app.use(express.errorHandler({ dumpExceptions: true, showStack: true }));29 });10 unmodified lines