Skip to content

Instantly share code, notes, and snippets.

View superchris's full-sized avatar

Chris Nelson superchris

View GitHub Profile
@superchris
superchris / Foo.coffee
Created March 14, 2011 03:02
A hypothetical foo model
class Foo extends Backbone.Model
toJSON: ->
{ foo: @attributes }
@superchris
superchris / FooView.coffee
Created May 14, 2011 21:01
A backbone view creating another view using the same element
class FooView extends Backbone.View
"#button click": "displayBarView"
displayBarView: ->
new BarView(el: @$("#bar_view")).render()
@superchris
superchris / FooView2.coffee
Created May 14, 2011 21:09
A FooView that creates his BarView during render and reuses it
class FooView extends Backbone.View
"#button click": "displayBarView"
render: ->
# Do the normal rendering
@barView = new BarView(el: @$("#bar_view"))
displayBarView: ->
@barView.display()
@superchris
superchris / Foo.coffee
Created May 15, 2011 17:16
Example model with a defaults with an array property
class Foo extends Backbone.Model
defaults:
name: "joe"
bazzes: []
describe "Foo", ->
beforeEach ->
@foo1 = new Foo
@foo2 = new Foo
@foo1.get("bazzes").push "baz"
it "should not put foo1's bazzes in foo2", ->
expect(@foo2.get("bazzes").length).toEqual 0
@superchris
superchris / Foo.coffee
Created May 15, 2011 17:30
Foo model with defaults as a function
class Foo extends Backbone.Model
defaults: ->
name: "joe"
bazzes: []
@superchris
superchris / asset_server.rb
Created May 21, 2011 18:01
asset server initializer
require 'tilt'
ENV['COFFEESCRIPT_SOURCE_PATH'] = Rails.root.join(
"app", "assets", "javascripts", "vendor", "coffee-script.js")
class BareCoffeeScriptTemplate < Sprockets::CoffeeScriptTemplate
def evaluate(scope, locals, &block)
@output ||= CoffeeScript.compile(data, :bare => true)
end
end
@superchris
superchris / application.js
Created May 29, 2011 22:41
rails 3.1 application.js
// This is a manifest file that'll be compiled into including all the files listed below.
// Add new JavaScript/Coffee code in separate files in this directory and they'll automatically
// be included in the compiled file accessible from http://example.com/assets/application.js
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
// the compiled file.
//
//= require jquery
//= require jquery_ujs
//= require_tree .
@superchris
superchris / fruit.coffee
Created May 30, 2011 16:00
fruit coffee class
class Fruit
plant: -> alert "I am in the ground"
class Apple extends Fruit
plant: -> alert "I am an apple tree"