Created
July 18, 2013 23:10
-
-
Save w33ble/6033875 to your computer and use it in GitHub Desktop.
Backbone.Giraffe requirejs example
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
require.config | |
baseUrl: 'js' | |
paths: | |
'jquery': '../vendor/jquery/jquery.min' | |
'underscore': '../vendor/lodash/dist/lodash.underscore.min' | |
'backbone': '../vendor/backbone/backbone-min' | |
'giraffe': '../vendor/giraffe/dist/backbone.giraffe.min' | |
'jade': '../vendor/jade/runtime.min' | |
'handlebars': '../vendor/handlebars.js/dist/handlebars.runtime' | |
shim: | |
'backbone': | |
deps: ['underscore', 'jquery'] | |
exports: 'Backbone' | |
'giraffe': | |
deps: ['backbone', 'templates'] | |
exports: 'Giraffe' | |
init: (Backbone, T) -> | |
Backbone.Giraffe.View.setTemplateStrategy -> | |
if @template? | |
data = @serialize() | |
template = T[@template] | |
template data | |
Backbone.Giraffe.View.prototype.serialize = -> | |
return @model.toJSON() if @model? | |
return @collection.toJSON() if @collection? | |
return {} | |
Backbone.Giraffe | |
'handlebars': | |
exports: 'Handlebars' | |
'jade': | |
exports: 'jade' | |
require ['backbone', 'giraffe'], (Backbone, Giraffe) -> | |
app = new Giraffe.App | |
el: '#content' | |
# app.attachTo 'body' | |
class ExampleView extends Giraffe.View | |
template: 'example' | |
# serialize: | |
myModel = new Giraffe.Model | |
name: 'myName' | |
example = new ExampleView model: myModel | |
app.attach example | |
Backbone.history.start | |
pushState: true | |
hashChange: if Modernizr.history then true else false |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment