Skip to content

Instantly share code, notes, and snippets.

@scottbaggett
Created September 4, 2013 23:02
Show Gist options
  • Select an option

  • Save scottbaggett/6443987 to your computer and use it in GitHub Desktop.

Select an option

Save scottbaggett/6443987 to your computer and use it in GitHub Desktop.
Meteor.startup ->
#----------------------------------------------------------
# Iron-Router Config
# https://github.com/EventedMind/iron-router
#----------------------------------------------------------
Router.configure
layout: 'layout'
loadingTemplate: 'loading'
before: ->
limit = @params.limit or pageData.limit
if @params.page
Session.set 'pageData', page: @params.page, limit: limit
Session.set 'currentRoute', @context.route.name
# only force authentication for non-public routes.
publicRoutes = [
'signin',
'frontpage',
'articlesList',
'articlesShow',
'articlesByCategory'
]
@wait userSub, ->
signIn = ->
Session.set 'nextRoute', Router.current().path
Router.go 'signIn'
route = @context.route.name
unless _.contains publicRoutes, routeName
user = Meteor.user()
signIn() unless user
Router.map ->
#----------------------------------------------------------
# Front Page
#----------------------------------------------------------
@route 'frontpage',
path: '/'
waiton: articlesListSub
#----------------------------------------------------------
# Articles List
#----------------------------------------------------------
@route 'articlesList',
path: '/articles'
waitOn: articlesListSub
data: -> frontpageArticles()
#----------------------------------------------------------
# New Article Form
#----------------------------------------------------------
@route 'articlesNew',
path: '/articles/new'
#----------------------------------------------------------
# Edit Article Form
#----------------------------------------------------------
@route 'articlesEdit',
path: '/articles/:_id/edit'
data: ->
Session.set 'currentArticleId', @params._id
Articles.findOne(@params._id)
#----------------------------------------------------------
# List of articles in cateogry
#----------------------------------------------------------
@route 'articlesByCategory',
path: '/articles/in/:slug'
data: ->
Session.set 'currentCategorySlug', @params.slug
@params
#----------------------------------------------------------
# Article Page
#----------------------------------------------------------
@route 'articlesShow',
path: '/articles/:slug'
notFoundTemplate: 'notFound'
# waitOn: articleBySlugSub
waitOn: ->
Meteor.subscribe 'articleBySlug', @params.slug
data: ->
article = Articles.findOne slug: @params.slug
run: ->
Session.set('currentArticleId', @_id)
#----------------------------------------------------------
# Edit Categories Page
#----------------------------------------------------------
@route 'categoriesEdit', path: '/categories/edit', data: -> Categories.find()
#----------------------------------------------------------
# Users List & Permissions
#----------------------------------------------------------
@route 'usersList', path: '/users', data: -> Meteor.users.find()
#----------------------------------------------------------
# Individual User Profile
#----------------------------------------------------------
@route 'usersProfile', path: '/profile', data: -> Meteor.user().profile or {}
@route 'usersProfile', path: '/users/:_id/edit', data: -> Meteor.users.findOne(@params._id).profile
#----------------------------------------------------------
# Content Submission
#----------------------------------------------------------
@route 'submissions', path: '/submissions'
#----------------------------------------------------------
# Sign-In
#----------------------------------------------------------
@route 'signIn', path: '/sign-in'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment