This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
define [ | |
'collections/articles' | |
'views/article' | |
'views/navigation' | |
'views/not_found' | |
], (articles) -> | |
Blog.App.vent.bind 'article', (slug) -> | |
article = articles.getArticle(slug) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
define ['templates/navigation', 'views/navigation_item'], (template) -> | |
class Blog.Views.Navigation extends Backbone.Marionette.CompositeView | |
itemView: Blog.Views.NavigationItem | |
template: template | |
itemViewContainer: '.bb-items' | |
initialize: -> | |
appendHtml: (collectionView, itemView, index) -> | |
collectionView.$(@itemViewContainer).prepend(itemView.el) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
bindings: | |
'h2': 'title' | |
'p': 'intro' | |
'a': | |
attributes: [ | |
name: 'href' | |
observe: 'slug' | |
onGet: (val) -> "/articles/#{val}" | |
, | |
name: 'class' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Blog.Models.Chapter extends Backbone.RelationalModel | |
relations: [ | |
type: Backbone.HasMany | |
key: 'articles' | |
relatedModel: 'Blog.Models.Article' | |
collectionType: 'Blog.Collections.Articles' | |
] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
findArticleBySlug: (slug) -> | |
@find (chapter) -> | |
_.any(chapter.get('articles').pluck('slug'), (item) -> item is slug) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
describe 'Backbone.Modal', -> | |
it "should have Backbone defined", -> | |
it 'should throw an exception if there is no template or views present', -> | |
it 'should throw an exception if a template and views are defined and | |
no viewContainer is present', -> | |
describe 'views:', -> | |
it 'binds the event to the selector to open a view', -> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
describe 'Backbone.Modal', -> | |
view = {} | |
modal = {} | |
beforeEach -> | |
class modal extends Backbone.Modal | |
viewContainer: '' | |
cancelEl: '' | |
submitEl: '' | |
template: -> '' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
unless Backbone? | |
throw new Error("Backbone is not defined. Please include | |
the latest version from http://documentcloud.github.com/backbone/backbone.js") | |
class Backbone.Modal extends Backbone.View | |
constructor: -> | |
args = Array.prototype.slice.apply(arguments) | |
Backbone.View.prototype.constructor.apply(this, args) | |
render: -> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
describe 'views:', -> | |
view = {} | |
beforeEach -> | |
view = new modal() | |
it 'should trigger the first view when rendered', -> | |
spyOn(view, 'triggerView') | |
view.render() |