forked from meteor-blog/meteor-blog
-
Notifications
You must be signed in to change notification settings - Fork 0
/
router.coffee
166 lines (127 loc) · 3.34 KB
/
router.coffee
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
if Meteor.isClient
Router.onBeforeAction 'loading'
Router.onBeforeAction (pause) ->
if @_dataValue is null or typeof @_dataValue is 'undefined'
return
Router.hooks.dataNotFound.call @, pause
Router.map ->
#
# RSS Feed
#
if Meteor.isServer
@route 'rss',
where: 'server'
path: '/rss/posts'
action: ->
@response.write Meteor.call 'serveRSS'
@response.end()
#
# Blog Index
#
@route 'blogIndex',
path: '/blog'
template: 'dynamic'
onRun: ->
if not Session.get('postLimit') and Blog.settings.pageSize
Session.set 'postLimit', Blog.settings.pageSize
waitOn: ->
if (typeof Session isnt 'undefined')
[
Meteor.subscribe 'posts', Session.get('postLimit')
Meteor.subscribe 'authors'
]
fastRender: true
data: ->
posts: Post.where {},
sort: publishedAt: -1
#
# Blog Tag
#
@route 'blogTagged',
path: '/blog/tag/:tag'
template: 'dynamic'
waitOn: -> [
Meteor.subscribe 'taggedPosts', @params.tag
Meteor.subscribe 'authors'
]
fastRender: true
data: ->
posts: Post.where
tags: @params.tag
,
sort: publishedAt: -1
#
# Show Blog
#
@route 'blogShow',
path: '/blog/:slug'
template: 'dynamic'
notFoundTemplate: 'blogNotFound'
onRun: ->
Session.set('slug', @params.slug)
onBeforeAction: ->
if Blog.settings.blogNotFoundTemplate
@notFoundTemplate = Blog.settings.blogNotFoundTemplate
if Blog.settings.blogShowTemplate
tpl = Blog.settings.blogShowTemplate
# If the user has a custom template, and not using the helper, then
# maintain the package Javascript.
pkgFunc = Template.blogShowBody.rendered
userFunc = Template[tpl].rendered
if userFunc
Template[tpl].rendered = ->
pkgFunc.call(@)
userFunc.call(@)
else
Template[tpl].rendered = pkgFunc
action: ->
@render() if @ready()
waitOn: -> [
Meteor.subscribe 'singlePostBySlug', @params.slug
Meteor.subscribe 'commentsBySlug', @params.slug
Meteor.subscribe 'authors'
]
data: ->
Post.first slug: @params.slug
#
# Blog Admin Index
#
@route 'blogAdmin',
path: '/admin/blog'
template: 'dynamic'
onBeforeAction: (pause) ->
if Meteor.loggingIn()
return pause()
Meteor.call 'isBlogAuthorized', (err, authorized) =>
if not authorized
return @redirect('/blog')
waitOn: ->
[ Meteor.subscribe 'postForAdmin'
Meteor.subscribe 'authors' ]
data: ->
true
#
# New/Edit Blog
#
@route 'blogAdminEdit',
path: '/admin/blog/edit/:id'
template: 'dynamic'
onBeforeAction: (pause) ->
if Meteor.loggingIn()
return pause()
Meteor.call 'isBlogAuthorized', @params.id, (err, authorized) =>
if not authorized
return @redirect('/blog')
action: ->
@render() if @ready()
onRun: ->
Session.set 'postId', @params.id
Session.set('editorTemplate', 'visualEditor')
Session.set('currentPost', Post.first(@params.id))
waitOn: -> [
Meteor.subscribe 'singlePostById', @params.id
Meteor.subscribe 'authors'
Meteor.subscribe 'postTags'
]
data: ->
true