Skip to content

Instantly share code, notes, and snippets.

View davidvanleeuwen's full-sized avatar
✌️
Sharing is caring

David van Leeuwen davidvanleeuwen

✌️
Sharing is caring
View GitHub Profile
@davidvanleeuwen
davidvanleeuwen / gist:5179205
Created March 17, 2013 01:49
Articles events
define [
'collections/articles'
'views/article'
'views/navigation'
'views/not_found'
], (articles) ->
Blog.App.vent.bind 'article', (slug) ->
article = articles.getArticle(slug)
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)
@davidvanleeuwen
davidvanleeuwen / gist:5241490
Created March 25, 2013 22:38
Stickit bindings
bindings:
'h2': 'title'
'p': 'intro'
'a':
attributes: [
name: 'href'
observe: 'slug'
onGet: (val) -> "/articles/#{val}"
,
name: 'class'
@davidvanleeuwen
davidvanleeuwen / gist:5241820
Created March 25, 2013 23:24
Chapter model
class Blog.Models.Chapter extends Backbone.RelationalModel
relations: [
type: Backbone.HasMany
key: 'articles'
relatedModel: 'Blog.Models.Article'
collectionType: 'Blog.Collections.Articles'
]
@davidvanleeuwen
davidvanleeuwen / gist:5241905
Created March 25, 2013 23:37
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
@davidvanleeuwen
davidvanleeuwen / gist:5241925
Created March 25, 2013 23:40
find article by slug
findArticleBySlug: (slug) ->
@find (chapter) ->
_.any(chapter.get('articles').pluck('slug'), (item) -> item is slug)
@davidvanleeuwen
davidvanleeuwen / gist:5293941
Last active December 15, 2015 17:09
Describe all functionality
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', ->
describe 'Backbone.Modal', ->
view = {}
modal = {}
beforeEach ->
class modal extends Backbone.Modal
viewContainer: ''
cancelEl: ''
submitEl: ''
template: -> ''
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: ->
describe 'views:', ->
view = {}
beforeEach ->
view = new modal()
it 'should trigger the first view when rendered', ->
spyOn(view, 'triggerView')
view.render()