Skip to content

Instantly share code, notes, and snippets.

View searls's full-sized avatar
💚

Justin Searls searls

💚
View GitHub Profile
@searls
searls / childserver_hook.rb
Created February 5, 2012 19:07
Wanted to run a sinatra app as a child of the cucumber process.
require 'childprocess'
Before do
@process = ChildProcess.build "bundle exec shotgun -p 9394"
@process.environment['RACK_ENV'] = "test"
@process.start
sleep 3
end
After do
FIXTURES = {}
FIXTURES.someXml =
"""
<xml>
...
</xml>
"""
#to use JST's as rails gives them to you
Backbone.LayoutManager.configure
fetch: (name) -> window.JST[name]
render: (template, context) -> template(context)
Backbone.LayoutManager.configure
fetch: (name) -> OE.template[name]
render: (template, context) -> template(context)
class App.SerializableView extends Backbone.View
render: (layout) ->
if layout
layout(@).render(@serialize?() or @serialize).then =>
_.defer => @trigger('rendered')
else
$(@el).html(JST[@template](@serialize?() or @serialize))
@trigger('rendered')
@
class App.CollectionView extends App.SerializableView
constructor: (options) ->
@bind('rendered', => @__renderItems() unless @__itemsHaveBeenInitiallyRendered)
super(options)
@collection.bind('add',@__renderAddedItem)
ensureAtLeastOneItem: =>
if @collection.size() == 0
@collection.add({})
class App.SomeCollectionView extends App.CollectionView
template: "templates/some_collection"
itemContainerSelector: '.some-stuff'
wrapItemsIn: $('<li></li>')
initialize: ->
@itemViewType = App.SomeView
serialize: -> some: @collection
#Boring Models
class Fruit extends Backbone.Model
class AppleTree extends Backbone.Model
defaults:
pantothenicAcid: 0.061
fruitName: "apple"
class OrangeTree extends Backbone.Model
defaults:
src_files:
- "application.js"
stylesheets:
helpers:
- "helpers/**/*.{js,coffee}"
spec_files:
- "**/*[Ss]pec.{js,coffee}"
@searls
searls / with_backbone_rails.txt
Created February 14, 2012 22:04
Backbone Syncing
POST /inquiries HTTP/1.1
Host: localhost:3000
Connection: keep-alive
Content-Length: 714
Origin: http://localhost:3000
X-CSRF-Token: hyxAFmqN6aK4KwwnMHDzL8gmnwhJ0a3L0rHlQUrdpHE=
X-Requested-With: XMLHttpRequest
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_3) AppleWebKit/535.11 (KHTML, like Gecko) Chrome/17.0.963.46 Safari/535.11
Content-Type: application/json
Accept: application/json, text/javascript, */*; q=0.01
door.open "A", (room) ->
room.explore()
door.open("B", (room) ->
room.explore()
)