Skip to content

Instantly share code, notes, and snippets.

@davidvanleeuwen
Created March 25, 2013 23:37
Show Gist options
  • Save davidvanleeuwen/5241905 to your computer and use it in GitHub Desktop.
Save davidvanleeuwen/5241905 to your computer and use it in GitHub Desktop.
Change events for articles to use chapters
Blog.App.vent.bind 'article', (slug) ->
chapter = chapters.findArticleBySlug(slug)
chapter = chapters.last() unless chapter
article = chapter.get('articles').getArticle(slug)
unless article
Blog.App.vent.trigger('404')
return
Blog.router.navigate("/articles/#{slug}", {trigger: false}) if slug
nav = new Blog.Views.Navigation(model: chapter, collection: chapters)
view = new Blog.Views.Article(model: article)
Blog.layout.navigation.show(nav)
Blog.layout.article.show(view)
Blog.App.vent.bind '404', ->
nav = new Blog.Views.Navigation(collection: chapters)
view = new Blog.Views.NotFound()
Blog.layout.navigation.show(nav)
Blog.layout.article.show(view)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment