fixing blog example
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by TJ Holowaychuk · committed by TJ Holowaychuk · parent 196a1eb · Browse files · 6 files·+11 added−78 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
6 files+11 added−78 removed
- other:+11 added−78 removed
Provenance
- Commit
b6bc01a- Tree
d1671cd- Author
TJ Holowaychuk <tj@vision-media.ca>- Committer
TJ Holowaychuk <tj@vision-media.ca>- Parent
196a1eb
6 files changed+11 added−78 removed
deleted:examples/blog/middleware/locals.js-59 removed
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
/** * Module dependencies. */var format = require('util').format , 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 example // it adjusts to /blog/post/add res.locals.base = '/' == app.route ? '' : app.route;
// all we wanted to do was assign some view locals // so pass control to the next middleware next();};No newline at end of filemodified:examples/blog/views/post/form.jade+4 added-6 removed
1 extends ../layout2 3 block content4- - if (post.title)4+ if post.title5 h1 Editing #{post.title}6- - else6+ else7 h1 New Post8 9- != messages()10-11- form#post(action=base + '/post' + (post.title ? '/' + post.id : ''), method='post')12- - if (post.title)9+ form#post(action='/post' + (post.title ? '/' + post.id : ''), method='post')10+ if post.title11 input(type='hidden', name='_method', value='put')12 p13 label(for='post[title]') Title:14 input(type='text', name='post[title]', value=post.title)6 unmodified linesmodified:examples/blog/views/post/index.jade+2 added-5 removed
3 unmodified lines4 .post5 // title6 h27 = post.title8- a.edit(href=base + '/post/' + post.id + '/edit') Edit8+ a.edit(href='/post/' + post.id + '/edit') Edit9 10- // flash messages11- != messages()12- 10 // dates11 p.date.created Created at #{post.createdAt}15- - if (post.updatedAt)12+ if post.updatedAt13 p.date.updated Updated at #{post.updatedAt}14 15 // body16 pre.body= post.bodymodified:examples/blog/views/index.jade+4 added-6 removed
1 unmodified line2 3 block content4 h1 Blog5 6- != messages()7-8- - if (count)6+ if count7 p Display all #{count} post(s)8 #posts11- - each post in posts9+ each post in posts10 include post/index13- - else11+ else12 p 13 | It looks like you have no posts!14 p15 | Click18- a(href=base + '/post/add') here 16+ a(href='/post/add') here 17 | to create a post. Login18 | as19 em "admin" 20 | and2 unmodified linesmodified:examples/blog/views/layout.jade+1 added-1 removed
1 !!! 52 html3 head4 title Blog5- link(rel='stylesheet', href=base + '/style.css')5+ link(rel='stylesheet', href='/style.css')6 body7 #container8 block contentmodified:examples/blog/app.js-1 removed
20 unmodified lines21222324252526272810 unmodified lines20 unmodified lines app.use(express.bodyParser()); app.use(express.methodOverride()); app.use(express.cookieParser('keyboard cat')); app.use(express.session()); app.use(require('./middleware/locals')); app.use(app.router); app.use(express.static(__dirname + '/public')); app.use(express.errorHandler({ dumpExceptions: true, showStack: true }));});10 unmodified lines