Skip to content

Commit

Permalink
Built a made up project with a bunch of hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
tmeasday committed Feb 26, 2014
1 parent 13c4af0 commit 2ac871a
Show file tree
Hide file tree
Showing 10 changed files with 181 additions and 0 deletions.
1 change: 1 addition & 0 deletions examples/basic/packages/iron-location-single-page
1 change: 1 addition & 0 deletions examples/hooks/.meteor/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
local
11 changes: 11 additions & 0 deletions examples/hooks/.meteor/packages
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Meteor packages used by this project, one per line.
#
# 'meteor add' and 'meteor remove' will edit this file for you,
# but you can also edit it by hand.

standard-app-packages
autopublish
insecure
preserve-inputs
iron-router
accounts-password
1 change: 1 addition & 0 deletions examples/hooks/.meteor/release
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0.7.1.1
1 change: 1 addition & 0 deletions examples/hooks/hooks.css
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/* CSS declarations go here */
27 changes: 27 additions & 0 deletions examples/hooks/hooks.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<head>
<title>hooks</title>
</head>

<template name="loading">
Loading template
</template>

<template name="404">
404
</template>

<template name="adminRequired">
ADMIN REQUIRED!
</template>

<template name="login">
{{loginButtons}}
</template>

<template name="userPage">
Hey, you've logged in, here's your dashboard
</template>

<template name="adminPage">
This is an admin only page!
</template>
94 changes: 94 additions & 0 deletions examples/hooks/hooks.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
var ScrollPositions = new Meteor.Collection(null);

Router.map(function() {
this.route('userPage', {
path: '/',

// 9. Redirecting
before: function() {
if (Meteor.user() && Meteor.user().admin)
this.redirect('adminPage');
}
});

// if someone wants to explicitly go there
this.route('login', {
path: '/login',
// 7. Session vars
load: function() {
Session.set('somethingExpanded', false);
}
});

this.route('adminPage', {
path: '/admin',

// 10. 3rd party API calls that are similar to waitOns:
waitOn: function() {
return {
// this is made up but I do have code conceptually similar to this
ready: promiseToReady(GoogleApi.call('/foo/bar'));
}
}
});

this.route('post', {
path: '/posts/:_id',
// 2. subscribing
waitOn: function() { return Meteor.subscribe('post', this.params._id); },
data: function() { return Posts.findOne(this.params._id); },

before: function() {
// 2.b. complex subscription (join)
if (this.data())
this.subscribe('author', this.data().authorId).wait();
}
});
});

// 1. waiting filter
Router.before(function() {
if (! this.ready())
this.render('loading')
});

// 3. Tracking page views
Router.load(function() {
mixpanel.track(this.path());
});

// 4. 404 filter
Router.before(function() {
if (this.ready() && ! this.data())
this.render('404');
}, {only: 'post'});

// 5. login filter
Router.before(function() {
if (! Meteor.loggingIn() && ! Meteor.user()) {
this.render('login');
}
}, {except: 'login'});


// 6. admin filter
Router.before(function() {
if (! Metoer.user() || ! Metoer.user().admin)
this.render('accessDenied');
}, {only: 'adminPage'});


// 8. scroll to top of screen
Router.before(function() {
$(window).scrollTop(0);
});

// 11. recording views
Router.load(function() {
Views.insert(this.path());
});

// 12. recording scroll position
Router.unload(function() {
ScrollPositions.insert({ path: this.path(), position: $(window).scrollTop() });
});
2 changes: 2 additions & 0 deletions examples/hooks/packages/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/iron-router
/blaze-layout
15 changes: 15 additions & 0 deletions examples/hooks/smart.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"meteor": {
"git": "https://github.com/meteor/meteor.git",
"branch": "shark"
},
"packages": {
"iron-router": {
"path": "../../"
},
"blaze-layout": {
"git": "https://github.com/EventedMind/blaze-layout.git",
"branch": "devel"
}
}
}
28 changes: 28 additions & 0 deletions examples/hooks/smart.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"meteor": {
"git": "https://github.com/meteor/meteor.git",
"branch": "shark",
"commit": "5671eaa2b77eae2c63f6c179b65ade1e85211a63"
},
"dependencies": {
"basePackages": {
"iron-router": {
"path": "../.."
},
"blaze-layout": {
"git": "https://github.com/EventedMind/blaze-layout.git",
"branch": "devel"
}
},
"packages": {
"iron-router": {
"path": "../.."
},
"blaze-layout": {
"git": "https://github.com/EventedMind/blaze-layout.git",
"branch": "devel",
"commit": "91f3948edac11c28328630c6a7ab769d34fb35a0"
}
}
}
}

0 comments on commit 2ac871a

Please sign in to comment.