SlideShare ist ein Scribd-Unternehmen logo
1 von 17
Downloaden Sie, um offline zu lesen
Client Side MVC with Backbone & Rails



                                    Tom Zeng
                                   @tomzeng
                             tom@intridea.com
Client Side MV* with Backbone & Rails

• Benefits of Client Side MVC
• Backbone.js Introduction
• Client Side MV* Alternatives
• Backbone + Rails + CoffeeScript - a great combination
• Sample App Walkthrough
• Resources
• Q&A
Benefits of Client Side MVC

• Interactive Responsive Single Page Apps
• Better User Experience
• Provide Structure to Client Side App Development
• More Manageable Apps (vs plain jQuery, etc)
• Large Scale Apps
• Making Use of Standard and Popular Technologies (HTML5 /
  CSS3 / JavaScript)
• ...
Client Side MV* Alternatives

• Backbone.js - Simple, Easy, Popular, Flexible, Extensible
• Ember.js - Data & View Bindings, Computed Fields, Rails like
• Angular.js - Minimal Boilerplates, View Binding and DOM
 Abstraction, Extensible Markups
• Spine.js - Simple, MVC, CoffeeScript, Rails like
• Sencha - Full Featured, Many UI Components, Class System
Client Side MV* Alternatives
Higher Level Frameworks

• Backbone.Marionette
  –   Scale applications out with modular, event driven architecture
  –   Sensible defaults, such as using Underscore templates for view rendering
  –   Easy to modify to make it work with your applicaton's specific needs
  –   Reduce boilerplate for views, with specialized view types
  –   Build on a modular architecture with an Application and modules that attach to it
  –   Compose your application's visuals at runtime, with Region and Layout
  –   Nested views and layouts within visual regions
  –   Built-in memory management and zombie killing in views, regions and layouts
  –   Built-in event clean up with the EventBinder
  –   Event-driven architecture with the EventAggregator
  –   Flexible, "as-needed" architecture allowing you to pick and choose what you need
Higher Level Frameworks

• Chaplin.js
  –   CoffeeScript class hierarchies as well as object composition
  –   Module encapsulation and lazy-loading using AMD modules
  –   Cross-module communication using the Mediator and Publish/Subscribe patterns
  –   Controllers for managing individual UI views
  –   Rails-style routes which map URLs to controller actions
  –   A route dispatcher and a top-level view manager
  –   Extended model, view and collection classes to avoid repetition and enforce conventions
  –   Strict memory management and object disposal
  –   A collection view for easy and intelligent list rendering


• Thorax (by Walmart Labs)
  – An opinionated, battle tested Backbone + Handlebars framework to build large scale web
    applications. It provides a filesystem structure, on demand module loading, model and
    collection view binding, inheritable view and DOM events, data loading helpers, form
    serialization / population and validation
Backbone MV* Basics

• Model - business domain models, key/value properties,
 events, persistence, validation
• Collection - list of models, provides convenience methods for
 sort, find, filter, iterator, add/create/remove/fetch/sync, event
 handling, shuffle, etc (most func from underscore)
• View - Rendering markup, handle app & DOM events
• Router - map routes(url patterns) to handlers
• Template - UI pages that get compiled and rendered to
 browser
Backbone MV* Basics

Backbone              MVC


Model                 Model
View Template (eco)   View (erb)
View + Router         Controller
Backbone + Rails + CoffeeScript

• CoffeeScript/Backbone + Rails is a pleasure to work with
• Server side experience can be easily carried over to the Client
 side
• CoffeeScript - similar to Ruby
• With the backbone-on-rails gem, similar convention is set up
 on the client side
• Jasmine - similar to RSpec
Sample App Walkthrough

• Todo List app
  – Simple app to track todo’s


• Server side setup
  – Rails as the API server
  – RSpec


• Client side setup
  – CoffeeScript (Rails 3 default)
  – Backbone + Twitter Bootstrap + Sass (Compass)
  – Jasmine, Sinon
Gems used in the app

• Backbone.JS
  – gem “backbone-on-rails” # minimal scaffold, CoffeeScript, eco
  – gem “rails-backbone”    # full featured scaffold, JS, ejs


• Twitter Bootstrap
  – gem “twitter-bootstrap-rails” # support Rails scaffold
  – gem “less-rails” # twitter bootstrap uses Less


• Eco Template
  – gem “eco” # embedded CoffeeScript, similar erb


• Jasmine (RSpec for JS, client side BDD)
  – gem “jasminerice” & gem “jasmine” # embedded CoffeeScript, similar erb
  –
• Sinon.js(server request/response mock/stub)
  – gem “sinon-rails” # or just use jasmine-sinon.js
Sample App Walkthrough

• Server side
  •   rails new todo-backbone
  •   Add necessary gems to Gemfile
  •   rails g rspec:install
  •   rails g backbone:install
  •   rails g bootstrap:install
  •   rails g jasminerice:install
  •   rails g scaffold Task title:string completed:boolean
  •   rake db:migrate
  •   rake db:test:load
  •   rails g controller main index --skip-javascripts
  •   guard # can also run rake jasmine:headless and rake spec
  •   rails s
  •   http://localhost:3000/tasks (Rails scaffold)
  •   http://localhost:3000/main/index (Backbone)
  •   Add RSpec specs and develop Ruby code
Sample App Walkthrough

• Client Side
  •   Update spec/javascripts/support/jasmine.yml to include both js and cs specs
  •   Add spec.css and spec.js.coffee in spec/javascripts
  •   Add Jasmine specs and develop CoffeeScript/JavaScript code

  •   rails g backbone:scaffold task
  •   http://localhost:3000/jasmine




  •   in task view add to events
  •       'click': 'complete'
  •   complete: ->
  •       @model.set("completed", not @model.get("completed"))
  •   in model task spec add
  •     it "should have title", ->
  •       task = new TodoBackbone.Models.Task
  •       task.set("title", "attend DCRUG")
  •       expect(task.get("title")).toEqual "attend DCRUG"
Resources

• Sample app https://github.com/tomz/todo-backbone
• Backbone.js http://backbonejs.org/
• CoffeeScript http://coffeescript.org/
• Backbone on Rails https://github.com/meleyal/backbone-on-rails
• Jasmine http://pivotal.github.com/jasmine/
• Twitter Bootstrap http://twitter.github.com/bootstrap/
• Sinon.JS http://sinonjs.org/
• Backbone.Marionett http://marionettejs.com/
Thank You   Merci

Gracias     Danke

ありがとう       谢谢
Client Side MVC with Backbone and Rails

Weitere ähnliche Inhalte

Was ist angesagt?

Web Developer Roadmap 2014 by Brennan Heyde
Web Developer Roadmap 2014 by Brennan HeydeWeb Developer Roadmap 2014 by Brennan Heyde
Web Developer Roadmap 2014 by Brennan HeydeMiva
 
Dotnet- An overview of ASP.NET & ADO.NET- Mazenet solution
Dotnet- An overview of ASP.NET & ADO.NET- Mazenet solutionDotnet- An overview of ASP.NET & ADO.NET- Mazenet solution
Dotnet- An overview of ASP.NET & ADO.NET- Mazenet solutionMazenetsolution
 
Single page applications - TernopilJS #2
Single page applications - TernopilJS #2Single page applications - TernopilJS #2
Single page applications - TernopilJS #2Andriy Deren'
 
Radiant CMS - Boston.rb 7/12
Radiant CMS - Boston.rb 7/12Radiant CMS - Boston.rb 7/12
Radiant CMS - Boston.rb 7/12joliveira
 
Single Page Apps
Single Page AppsSingle Page Apps
Single Page AppsGil Fink
 
Integrating Angular.js with Rails (Wicked Good Ruby Conf lightening talk)
Integrating Angular.js with Rails (Wicked Good Ruby Conf lightening talk)Integrating Angular.js with Rails (Wicked Good Ruby Conf lightening talk)
Integrating Angular.js with Rails (Wicked Good Ruby Conf lightening talk)Jonathan Linowes
 
Ultraschnelle In-Memory Datenbankanwendungen und Microservices mit Java
Ultraschnelle In-Memory Datenbankanwendungen und Microservices mit JavaUltraschnelle In-Memory Datenbankanwendungen und Microservices mit Java
Ultraschnelle In-Memory Datenbankanwendungen und Microservices mit JavaMarkus Kett
 
Esposito Ajax Remote
Esposito Ajax RemoteEsposito Ajax Remote
Esposito Ajax Remoteask bills
 
EUGM 2014 - Eufrozina Hoffmann (ChemAxon): Smart Drawing with Marvin JS
EUGM 2014 - Eufrozina Hoffmann (ChemAxon): Smart Drawing with Marvin JS  EUGM 2014 - Eufrozina Hoffmann (ChemAxon): Smart Drawing with Marvin JS
EUGM 2014 - Eufrozina Hoffmann (ChemAxon): Smart Drawing with Marvin JS ChemAxon
 
WebCamp: Developer Day: Single Page Web Application with Scala/Spray- Slava S...
WebCamp: Developer Day: Single Page Web Application with Scala/Spray- Slava S...WebCamp: Developer Day: Single Page Web Application with Scala/Spray- Slava S...
WebCamp: Developer Day: Single Page Web Application with Scala/Spray- Slava S...GeeksLab Odessa
 
MAppMechanic CodeLabs - PolymerJS Elements - Paper, Gold, Neon, Platinum, Mol...
MAppMechanic CodeLabs - PolymerJS Elements - Paper, Gold, Neon, Platinum, Mol...MAppMechanic CodeLabs - PolymerJS Elements - Paper, Gold, Neon, Platinum, Mol...
MAppMechanic CodeLabs - PolymerJS Elements - Paper, Gold, Neon, Platinum, Mol...Rahat Khanna a.k.a mAppMechanic
 
Pros and Cons of developing a Thick Clientside App
Pros and Cons of developing a Thick Clientside AppPros and Cons of developing a Thick Clientside App
Pros and Cons of developing a Thick Clientside AppRavi Teja
 
Single page application
Single page applicationSingle page application
Single page applicationJeremy Lee
 

Was ist angesagt? (20)

Web Developer Roadmap 2014 by Brennan Heyde
Web Developer Roadmap 2014 by Brennan HeydeWeb Developer Roadmap 2014 by Brennan Heyde
Web Developer Roadmap 2014 by Brennan Heyde
 
Dotnet- An overview of ASP.NET & ADO.NET- Mazenet solution
Dotnet- An overview of ASP.NET & ADO.NET- Mazenet solutionDotnet- An overview of ASP.NET & ADO.NET- Mazenet solution
Dotnet- An overview of ASP.NET & ADO.NET- Mazenet solution
 
Single page applications - TernopilJS #2
Single page applications - TernopilJS #2Single page applications - TernopilJS #2
Single page applications - TernopilJS #2
 
Radiant CMS - Boston.rb 7/12
Radiant CMS - Boston.rb 7/12Radiant CMS - Boston.rb 7/12
Radiant CMS - Boston.rb 7/12
 
Single Page Apps
Single Page AppsSingle Page Apps
Single Page Apps
 
Web applications
Web applicationsWeb applications
Web applications
 
Single Page Application
Single Page ApplicationSingle Page Application
Single Page Application
 
Rails Engines
Rails EnginesRails Engines
Rails Engines
 
Integrating Angular.js with Rails (Wicked Good Ruby Conf lightening talk)
Integrating Angular.js with Rails (Wicked Good Ruby Conf lightening talk)Integrating Angular.js with Rails (Wicked Good Ruby Conf lightening talk)
Integrating Angular.js with Rails (Wicked Good Ruby Conf lightening talk)
 
MAppMechanic CodeLabs - PolymerJS Introduction
MAppMechanic CodeLabs - PolymerJS IntroductionMAppMechanic CodeLabs - PolymerJS Introduction
MAppMechanic CodeLabs - PolymerJS Introduction
 
Ultraschnelle In-Memory Datenbankanwendungen und Microservices mit Java
Ultraschnelle In-Memory Datenbankanwendungen und Microservices mit JavaUltraschnelle In-Memory Datenbankanwendungen und Microservices mit Java
Ultraschnelle In-Memory Datenbankanwendungen und Microservices mit Java
 
Esposito Ajax Remote
Esposito Ajax RemoteEsposito Ajax Remote
Esposito Ajax Remote
 
EUGM 2014 - Eufrozina Hoffmann (ChemAxon): Smart Drawing with Marvin JS
EUGM 2014 - Eufrozina Hoffmann (ChemAxon): Smart Drawing with Marvin JS  EUGM 2014 - Eufrozina Hoffmann (ChemAxon): Smart Drawing with Marvin JS
EUGM 2014 - Eufrozina Hoffmann (ChemAxon): Smart Drawing with Marvin JS
 
WebCamp: Developer Day: Single Page Web Application with Scala/Spray- Slava S...
WebCamp: Developer Day: Single Page Web Application with Scala/Spray- Slava S...WebCamp: Developer Day: Single Page Web Application with Scala/Spray- Slava S...
WebCamp: Developer Day: Single Page Web Application with Scala/Spray- Slava S...
 
MAppMechanic CodeLabs - PolymerJS Elements - Paper, Gold, Neon, Platinum, Mol...
MAppMechanic CodeLabs - PolymerJS Elements - Paper, Gold, Neon, Platinum, Mol...MAppMechanic CodeLabs - PolymerJS Elements - Paper, Gold, Neon, Platinum, Mol...
MAppMechanic CodeLabs - PolymerJS Elements - Paper, Gold, Neon, Platinum, Mol...
 
Building SPA’s (Single Page App) with Backbone.js
Building SPA’s (Single Page App) with Backbone.jsBuilding SPA’s (Single Page App) with Backbone.js
Building SPA’s (Single Page App) with Backbone.js
 
webscarab
webscarabwebscarab
webscarab
 
Pros and Cons of developing a Thick Clientside App
Pros and Cons of developing a Thick Clientside AppPros and Cons of developing a Thick Clientside App
Pros and Cons of developing a Thick Clientside App
 
Single page application
Single page applicationSingle page application
Single page application
 
JSP Part 2
JSP Part 2JSP Part 2
JSP Part 2
 

Andere mochten auch

Andere mochten auch (6)

Pluto & Other Minor Worlds Mc Neely 2010
Pluto & Other Minor Worlds Mc Neely 2010Pluto & Other Minor Worlds Mc Neely 2010
Pluto & Other Minor Worlds Mc Neely 2010
 
Office 365 Saturday Europe 2014 - Microsoft Azure : Central component of your...
Office 365 Saturday Europe 2014 - Microsoft Azure : Central component of your...Office 365 Saturday Europe 2014 - Microsoft Azure : Central component of your...
Office 365 Saturday Europe 2014 - Microsoft Azure : Central component of your...
 
DevOps for SharePoint (What, Why, How)
DevOps for SharePoint (What, Why, How)DevOps for SharePoint (What, Why, How)
DevOps for SharePoint (What, Why, How)
 
Top 10 devops values
Top 10 devops valuesTop 10 devops values
Top 10 devops values
 
Onwards and Upwards - Good Morning, Pluto!
Onwards and Upwards - Good Morning, Pluto!Onwards and Upwards - Good Morning, Pluto!
Onwards and Upwards - Good Morning, Pluto!
 
[aOS N°2] DevOps & SharePoint - Michel Hubert
[aOS N°2] DevOps & SharePoint - Michel Hubert[aOS N°2] DevOps & SharePoint - Michel Hubert
[aOS N°2] DevOps & SharePoint - Michel Hubert
 

Ähnlich wie Client Side MVC with Backbone and Rails

Ruby On Rails
Ruby On RailsRuby On Rails
Ruby On Railsiradarji
 
The future of web development write once, run everywhere with angular js an...
The future of web development   write once, run everywhere with angular js an...The future of web development   write once, run everywhere with angular js an...
The future of web development write once, run everywhere with angular js an...Mark Leusink
 
The future of web development write once, run everywhere with angular.js and ...
The future of web development write once, run everywhere with angular.js and ...The future of web development write once, run everywhere with angular.js and ...
The future of web development write once, run everywhere with angular.js and ...Mark Roden
 
Ruby on Rails + AngularJS + Twitter Bootstrap
Ruby on Rails + AngularJS + Twitter BootstrapRuby on Rails + AngularJS + Twitter Bootstrap
Ruby on Rails + AngularJS + Twitter BootstrapMarcio Marinho
 
MV* presentation frameworks in Javascript: en garde, pret, allez!
MV* presentation frameworks in Javascript: en garde, pret, allez!MV* presentation frameworks in Javascript: en garde, pret, allez!
MV* presentation frameworks in Javascript: en garde, pret, allez!Roberto Messora
 
Introduction to web application development with Vue (for absolute beginners)...
Introduction to web application development with Vue (for absolute beginners)...Introduction to web application development with Vue (for absolute beginners)...
Introduction to web application development with Vue (for absolute beginners)...Lucas Jellema
 
6 weeks 6 months live project summer industrial training in cmc limited 2012
6 weeks  6 months live project summer industrial training in cmc limited  20126 weeks  6 months live project summer industrial training in cmc limited  2012
6 weeks 6 months live project summer industrial training in cmc limited 2012CMC Limited
 
Paa sing a java ee 6 application kshitiz saxena
Paa sing a java ee 6 application   kshitiz saxenaPaa sing a java ee 6 application   kshitiz saxena
Paa sing a java ee 6 application kshitiz saxenaIndicThreads
 
Evolution of a cloud start up: From C# to Node.js
Evolution of a cloud start up: From C# to Node.jsEvolution of a cloud start up: From C# to Node.js
Evolution of a cloud start up: From C# to Node.jsSteve Jamieson
 
Next Generation Spring MVC with Spring Roo
Next Generation Spring MVC with Spring RooNext Generation Spring MVC with Spring Roo
Next Generation Spring MVC with Spring RooStefan Schmidt
 
Backbone JS for mobile apps
Backbone JS for mobile appsBackbone JS for mobile apps
Backbone JS for mobile appsIvano Malavolta
 
Using MVC with Kentico 8
Using MVC with Kentico 8Using MVC with Kentico 8
Using MVC with Kentico 8Thomas Robbins
 
Mobile and IBM Worklight Best Practices
Mobile and IBM Worklight Best PracticesMobile and IBM Worklight Best Practices
Mobile and IBM Worklight Best PracticesAndrew Ferrier
 
Ruby On Rails Basics
Ruby On Rails BasicsRuby On Rails Basics
Ruby On Rails BasicsAmit Solanki
 
Tutorial, Part 2: SharePoint 101: Jump-Starting the Developer by Rob Windsor ...
Tutorial, Part 2: SharePoint 101: Jump-Starting the Developer by Rob Windsor ...Tutorial, Part 2: SharePoint 101: Jump-Starting the Developer by Rob Windsor ...
Tutorial, Part 2: SharePoint 101: Jump-Starting the Developer by Rob Windsor ...SPTechCon
 
Server and client rendering of single page apps
Server and client rendering of single page appsServer and client rendering of single page apps
Server and client rendering of single page appsThomas Heymann
 
Jasig rubyon rails
Jasig rubyon railsJasig rubyon rails
Jasig rubyon rails_zaMmer_
 

Ähnlich wie Client Side MVC with Backbone and Rails (20)

Ruby On Rails
Ruby On RailsRuby On Rails
Ruby On Rails
 
The future of web development write once, run everywhere with angular js an...
The future of web development   write once, run everywhere with angular js an...The future of web development   write once, run everywhere with angular js an...
The future of web development write once, run everywhere with angular js an...
 
The future of web development write once, run everywhere with angular.js and ...
The future of web development write once, run everywhere with angular.js and ...The future of web development write once, run everywhere with angular.js and ...
The future of web development write once, run everywhere with angular.js and ...
 
Ruby on Rails + AngularJS + Twitter Bootstrap
Ruby on Rails + AngularJS + Twitter BootstrapRuby on Rails + AngularJS + Twitter Bootstrap
Ruby on Rails + AngularJS + Twitter Bootstrap
 
JavaScript MVC Frameworks: Backbone, Ember and Angular JS
JavaScript MVC Frameworks: Backbone, Ember and Angular JSJavaScript MVC Frameworks: Backbone, Ember and Angular JS
JavaScript MVC Frameworks: Backbone, Ember and Angular JS
 
MV* presentation frameworks in Javascript: en garde, pret, allez!
MV* presentation frameworks in Javascript: en garde, pret, allez!MV* presentation frameworks in Javascript: en garde, pret, allez!
MV* presentation frameworks in Javascript: en garde, pret, allez!
 
Introduction to web application development with Vue (for absolute beginners)...
Introduction to web application development with Vue (for absolute beginners)...Introduction to web application development with Vue (for absolute beginners)...
Introduction to web application development with Vue (for absolute beginners)...
 
6 weeks 6 months live project summer industrial training in cmc limited 2012
6 weeks  6 months live project summer industrial training in cmc limited  20126 weeks  6 months live project summer industrial training in cmc limited  2012
6 weeks 6 months live project summer industrial training in cmc limited 2012
 
Paa sing a java ee 6 application kshitiz saxena
Paa sing a java ee 6 application   kshitiz saxenaPaa sing a java ee 6 application   kshitiz saxena
Paa sing a java ee 6 application kshitiz saxena
 
Evolution of a cloud start up: From C# to Node.js
Evolution of a cloud start up: From C# to Node.jsEvolution of a cloud start up: From C# to Node.js
Evolution of a cloud start up: From C# to Node.js
 
Next Generation Spring MVC with Spring Roo
Next Generation Spring MVC with Spring RooNext Generation Spring MVC with Spring Roo
Next Generation Spring MVC with Spring Roo
 
Backbone JS for mobile apps
Backbone JS for mobile appsBackbone JS for mobile apps
Backbone JS for mobile apps
 
Backbone.js
Backbone.jsBackbone.js
Backbone.js
 
Using MVC with Kentico 8
Using MVC with Kentico 8Using MVC with Kentico 8
Using MVC with Kentico 8
 
Mobile and IBM Worklight Best Practices
Mobile and IBM Worklight Best PracticesMobile and IBM Worklight Best Practices
Mobile and IBM Worklight Best Practices
 
[2015/2016] Backbone JS
[2015/2016] Backbone JS[2015/2016] Backbone JS
[2015/2016] Backbone JS
 
Ruby On Rails Basics
Ruby On Rails BasicsRuby On Rails Basics
Ruby On Rails Basics
 
Tutorial, Part 2: SharePoint 101: Jump-Starting the Developer by Rob Windsor ...
Tutorial, Part 2: SharePoint 101: Jump-Starting the Developer by Rob Windsor ...Tutorial, Part 2: SharePoint 101: Jump-Starting the Developer by Rob Windsor ...
Tutorial, Part 2: SharePoint 101: Jump-Starting the Developer by Rob Windsor ...
 
Server and client rendering of single page apps
Server and client rendering of single page appsServer and client rendering of single page apps
Server and client rendering of single page apps
 
Jasig rubyon rails
Jasig rubyon railsJasig rubyon rails
Jasig rubyon rails
 

Client Side MVC with Backbone and Rails

  • 1. Client Side MVC with Backbone & Rails Tom Zeng @tomzeng tom@intridea.com
  • 2. Client Side MV* with Backbone & Rails • Benefits of Client Side MVC • Backbone.js Introduction • Client Side MV* Alternatives • Backbone + Rails + CoffeeScript - a great combination • Sample App Walkthrough • Resources • Q&A
  • 3. Benefits of Client Side MVC • Interactive Responsive Single Page Apps • Better User Experience • Provide Structure to Client Side App Development • More Manageable Apps (vs plain jQuery, etc) • Large Scale Apps • Making Use of Standard and Popular Technologies (HTML5 / CSS3 / JavaScript) • ...
  • 4. Client Side MV* Alternatives • Backbone.js - Simple, Easy, Popular, Flexible, Extensible • Ember.js - Data & View Bindings, Computed Fields, Rails like • Angular.js - Minimal Boilerplates, View Binding and DOM Abstraction, Extensible Markups • Spine.js - Simple, MVC, CoffeeScript, Rails like • Sencha - Full Featured, Many UI Components, Class System
  • 5. Client Side MV* Alternatives
  • 6. Higher Level Frameworks • Backbone.Marionette – Scale applications out with modular, event driven architecture – Sensible defaults, such as using Underscore templates for view rendering – Easy to modify to make it work with your applicaton's specific needs – Reduce boilerplate for views, with specialized view types – Build on a modular architecture with an Application and modules that attach to it – Compose your application's visuals at runtime, with Region and Layout – Nested views and layouts within visual regions – Built-in memory management and zombie killing in views, regions and layouts – Built-in event clean up with the EventBinder – Event-driven architecture with the EventAggregator – Flexible, "as-needed" architecture allowing you to pick and choose what you need
  • 7. Higher Level Frameworks • Chaplin.js – CoffeeScript class hierarchies as well as object composition – Module encapsulation and lazy-loading using AMD modules – Cross-module communication using the Mediator and Publish/Subscribe patterns – Controllers for managing individual UI views – Rails-style routes which map URLs to controller actions – A route dispatcher and a top-level view manager – Extended model, view and collection classes to avoid repetition and enforce conventions – Strict memory management and object disposal – A collection view for easy and intelligent list rendering • Thorax (by Walmart Labs) – An opinionated, battle tested Backbone + Handlebars framework to build large scale web applications. It provides a filesystem structure, on demand module loading, model and collection view binding, inheritable view and DOM events, data loading helpers, form serialization / population and validation
  • 8. Backbone MV* Basics • Model - business domain models, key/value properties, events, persistence, validation • Collection - list of models, provides convenience methods for sort, find, filter, iterator, add/create/remove/fetch/sync, event handling, shuffle, etc (most func from underscore) • View - Rendering markup, handle app & DOM events • Router - map routes(url patterns) to handlers • Template - UI pages that get compiled and rendered to browser
  • 9. Backbone MV* Basics Backbone MVC Model Model View Template (eco) View (erb) View + Router Controller
  • 10. Backbone + Rails + CoffeeScript • CoffeeScript/Backbone + Rails is a pleasure to work with • Server side experience can be easily carried over to the Client side • CoffeeScript - similar to Ruby • With the backbone-on-rails gem, similar convention is set up on the client side • Jasmine - similar to RSpec
  • 11. Sample App Walkthrough • Todo List app – Simple app to track todo’s • Server side setup – Rails as the API server – RSpec • Client side setup – CoffeeScript (Rails 3 default) – Backbone + Twitter Bootstrap + Sass (Compass) – Jasmine, Sinon
  • 12. Gems used in the app • Backbone.JS – gem “backbone-on-rails” # minimal scaffold, CoffeeScript, eco – gem “rails-backbone” # full featured scaffold, JS, ejs • Twitter Bootstrap – gem “twitter-bootstrap-rails” # support Rails scaffold – gem “less-rails” # twitter bootstrap uses Less • Eco Template – gem “eco” # embedded CoffeeScript, similar erb • Jasmine (RSpec for JS, client side BDD) – gem “jasminerice” & gem “jasmine” # embedded CoffeeScript, similar erb – • Sinon.js(server request/response mock/stub) – gem “sinon-rails” # or just use jasmine-sinon.js
  • 13. Sample App Walkthrough • Server side • rails new todo-backbone • Add necessary gems to Gemfile • rails g rspec:install • rails g backbone:install • rails g bootstrap:install • rails g jasminerice:install • rails g scaffold Task title:string completed:boolean • rake db:migrate • rake db:test:load • rails g controller main index --skip-javascripts • guard # can also run rake jasmine:headless and rake spec • rails s • http://localhost:3000/tasks (Rails scaffold) • http://localhost:3000/main/index (Backbone) • Add RSpec specs and develop Ruby code
  • 14. Sample App Walkthrough • Client Side • Update spec/javascripts/support/jasmine.yml to include both js and cs specs • Add spec.css and spec.js.coffee in spec/javascripts • Add Jasmine specs and develop CoffeeScript/JavaScript code • rails g backbone:scaffold task • http://localhost:3000/jasmine • in task view add to events • 'click': 'complete' • complete: -> • @model.set("completed", not @model.get("completed")) • in model task spec add • it "should have title", -> • task = new TodoBackbone.Models.Task • task.set("title", "attend DCRUG") • expect(task.get("title")).toEqual "attend DCRUG"
  • 15. Resources • Sample app https://github.com/tomz/todo-backbone • Backbone.js http://backbonejs.org/ • CoffeeScript http://coffeescript.org/ • Backbone on Rails https://github.com/meleyal/backbone-on-rails • Jasmine http://pivotal.github.com/jasmine/ • Twitter Bootstrap http://twitter.github.com/bootstrap/ • Sinon.JS http://sinonjs.org/ • Backbone.Marionett http://marionettejs.com/
  • 16. Thank You Merci Gracias Danke ありがとう 谢谢