rails-backbone 0.1.2 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +12 -1
 - data/lib/backbone-rails.rb +0 -6
 - data/lib/generators/backbone/scaffold/templates/views/new_view.coffee +14 -2
 - data/lib/rails-backbone.rb +2 -0
 - metadata +5 -4
 
    
        data/README.md
    CHANGED
    
    | 
         @@ -11,12 +11,23 @@ This gem vendors the latest version of underscore.js and backbones.js for Rails 
     | 
|
| 
       11 
11 
     | 
    
         | 
| 
       12 
12 
     | 
    
         
             
            In your Gemfile, add this line:
         
     | 
| 
       13 
13 
     | 
    
         | 
| 
       14 
     | 
    
         
            -
                gem "backbone 
     | 
| 
      
 14 
     | 
    
         
            +
                gem "rails-backbone"
         
     | 
| 
       15 
15 
     | 
    
         | 
| 
       16 
16 
     | 
    
         
             
            Then run the following commands:
         
     | 
| 
       17 
17 
     | 
    
         | 
| 
       18 
18 
     | 
    
         
             
                bundle install
         
     | 
| 
       19 
19 
     | 
    
         
             
                rails g backbone:install
         
     | 
| 
      
 20 
     | 
    
         
            +
             
     | 
| 
      
 21 
     | 
    
         
            +
            ### Layout and namespacing
         
     | 
| 
      
 22 
     | 
    
         
            +
             
     | 
| 
      
 23 
     | 
    
         
            +
            Running `rails g backbone:install` will create the following directory structure under `app/assets/javascripts/backbone`:
         
     | 
| 
      
 24 
     | 
    
         
            +
              
         
     | 
| 
      
 25 
     | 
    
         
            +
                controllers/
         
     | 
| 
      
 26 
     | 
    
         
            +
                models/
         
     | 
| 
      
 27 
     | 
    
         
            +
                templates/
         
     | 
| 
      
 28 
     | 
    
         
            +
                views/
         
     | 
| 
      
 29 
     | 
    
         
            +
                
         
     | 
| 
      
 30 
     | 
    
         
            +
            It will also create a toplevel app_name.coffee file to setup namespacing and setup initial requires.
         
     | 
| 
       20 
31 
     | 
    
         | 
| 
       21 
32 
     | 
    
         
             
            ## Generators
         
     | 
| 
       22 
33 
     | 
    
         
             
            backbone-rails provides 3 simple generators to help get you started using bacbone.js with rails 3.1
         
     | 
    
        data/lib/backbone-rails.rb
    CHANGED
    
    | 
         @@ -2,11 +2,5 @@ require 'rails' 
     | 
|
| 
       2 
2 
     | 
    
         | 
| 
       3 
3 
     | 
    
         
             
            module BackboneRails
         
     | 
| 
       4 
4 
     | 
    
         
             
              class Engine < Rails::Engine
         
     | 
| 
       5 
     | 
    
         
            -
                # config.autoload_paths << File.expand_path("../backbone-rails", __FILE__)
         
     | 
| 
       6 
     | 
    
         
            -
                
         
     | 
| 
       7 
     | 
    
         
            -
                config.after_initialize do |app|
         
     | 
| 
       8 
     | 
    
         
            -
                  # app.assets.register_engine '.jst', Tilt::UnderscoreTemplate
         
     | 
| 
       9 
     | 
    
         
            -
                end
         
     | 
| 
       10 
5 
     | 
    
         
             
              end
         
     | 
| 
       11 
     | 
    
         
            -
                
         
     | 
| 
       12 
6 
     | 
    
         
             
            end
         
     | 
| 
         @@ -1,23 +1,35 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            <%= view_namespace %> ||= {}
         
     | 
| 
       2 
2 
     | 
    
         | 
| 
       3 
     | 
    
         
            -
            class <%= view_namespace %>.NewView extends Backbone.View
         
     | 
| 
      
 3 
     | 
    
         
            +
            class <%= view_namespace %>.NewView extends Backbone.View    
         
     | 
| 
       4 
4 
     | 
    
         
             
              template: JST["<%= jst 'new' %>"]
         
     | 
| 
       5 
5 
     | 
    
         | 
| 
       6 
6 
     | 
    
         
             
              events:
         
     | 
| 
       7 
7 
     | 
    
         
             
                "submit #new-<%= singular_name %>": "save"
         
     | 
| 
       8 
8 
     | 
    
         | 
| 
      
 9 
     | 
    
         
            +
              constructor: (options) ->
         
     | 
| 
      
 10 
     | 
    
         
            +
                super(options)
         
     | 
| 
      
 11 
     | 
    
         
            +
                @options.model = new @options.collection.model()
         
     | 
| 
      
 12 
     | 
    
         
            +
             
     | 
| 
      
 13 
     | 
    
         
            +
                @options.model.bind("change:errors", () =>
         
     | 
| 
      
 14 
     | 
    
         
            +
                  this.render()
         
     | 
| 
      
 15 
     | 
    
         
            +
                )
         
     | 
| 
      
 16 
     | 
    
         
            +
                
         
     | 
| 
       9 
17 
     | 
    
         
             
              save: (e) ->
         
     | 
| 
       10 
18 
     | 
    
         
             
                e.preventDefault()
         
     | 
| 
       11 
19 
     | 
    
         
             
                e.stopPropagation()
         
     | 
| 
       12 
20 
     | 
    
         | 
| 
      
 21 
     | 
    
         
            +
                @options.model.unset("errors")
         
     | 
| 
      
 22 
     | 
    
         
            +
                
         
     | 
| 
       13 
23 
     | 
    
         
             
                @options.collection.create(@options.model.toJSON(), 
         
     | 
| 
       14 
24 
     | 
    
         
             
                  success: (model) =>
         
     | 
| 
       15 
25 
     | 
    
         
             
                    @options.model = model
         
     | 
| 
       16 
26 
     | 
    
         
             
                    window.location.hash = "/#{@options.model.id}"
         
     | 
| 
      
 27 
     | 
    
         
            +
                    
         
     | 
| 
      
 28 
     | 
    
         
            +
                  error: (model, jqXHR) =>
         
     | 
| 
      
 29 
     | 
    
         
            +
                    @options.model.set({errors: $.parseJSON(jqXHR.responseText)})
         
     | 
| 
       17 
30 
     | 
    
         
             
                )
         
     | 
| 
       18 
31 
     | 
    
         | 
| 
       19 
32 
     | 
    
         
             
              render: ->
         
     | 
| 
       20 
     | 
    
         
            -
                @options.model = new @options.collection.model()
         
     | 
| 
       21 
33 
     | 
    
         
             
                $(this.el).html(this.template(@options.model.toJSON() ))
         
     | 
| 
       22 
34 
     | 
    
         | 
| 
       23 
35 
     | 
    
         
             
                this.$("form").backboneLink(@options.model)
         
     | 
    
        metadata
    CHANGED
    
    | 
         @@ -2,7 +2,7 @@ 
     | 
|
| 
       2 
2 
     | 
    
         
             
            name: rails-backbone
         
     | 
| 
       3 
3 
     | 
    
         
             
            version: !ruby/object:Gem::Version 
         
     | 
| 
       4 
4 
     | 
    
         
             
              prerelease: 
         
     | 
| 
       5 
     | 
    
         
            -
              version: 0. 
     | 
| 
      
 5 
     | 
    
         
            +
              version: 0.2.0
         
     | 
| 
       6 
6 
     | 
    
         
             
            platform: ruby
         
     | 
| 
       7 
7 
     | 
    
         
             
            authors: 
         
     | 
| 
       8 
8 
     | 
    
         
             
            - Ryan Fitzgerald
         
     | 
| 
         @@ -11,7 +11,7 @@ autorequire: 
     | 
|
| 
       11 
11 
     | 
    
         
             
            bindir: bin
         
     | 
| 
       12 
12 
     | 
    
         
             
            cert_chain: []
         
     | 
| 
       13 
13 
     | 
    
         | 
| 
       14 
     | 
    
         
            -
            date: 2011-06- 
     | 
| 
      
 14 
     | 
    
         
            +
            date: 2011-06-19 00:00:00 -04:00
         
     | 
| 
       15 
15 
     | 
    
         
             
            default_executable: 
         
     | 
| 
       16 
16 
     | 
    
         
             
            dependencies: 
         
     | 
| 
       17 
17 
     | 
    
         
             
            - !ruby/object:Gem::Dependency 
         
     | 
| 
         @@ -80,6 +80,7 @@ files: 
     | 
|
| 
       80 
80 
     | 
    
         
             
            - lib/generators/backbone/scaffold/templates/views/model_view.coffee
         
     | 
| 
       81 
81 
     | 
    
         
             
            - lib/generators/backbone/scaffold/templates/views/new_view.coffee
         
     | 
| 
       82 
82 
     | 
    
         
             
            - lib/generators/backbone/scaffold/templates/views/show_view.coffee
         
     | 
| 
      
 83 
     | 
    
         
            +
            - lib/rails-backbone.rb
         
     | 
| 
       83 
84 
     | 
    
         
             
            - lib/tasks/backbone-rails_tasks.rake
         
     | 
| 
       84 
85 
     | 
    
         
             
            - vendor/assets/javascripts/backbone.js
         
     | 
| 
       85 
86 
     | 
    
         
             
            - vendor/assets/javascripts/backbone_datalink.js
         
     | 
| 
         @@ -102,7 +103,7 @@ required_ruby_version: !ruby/object:Gem::Requirement 
     | 
|
| 
       102 
103 
     | 
    
         
             
              requirements: 
         
     | 
| 
       103 
104 
     | 
    
         
             
              - - ">="
         
     | 
| 
       104 
105 
     | 
    
         
             
                - !ruby/object:Gem::Version 
         
     | 
| 
       105 
     | 
    
         
            -
                  hash:  
     | 
| 
      
 106 
     | 
    
         
            +
                  hash: 1804076716045259291
         
     | 
| 
       106 
107 
     | 
    
         
             
                  segments: 
         
     | 
| 
       107 
108 
     | 
    
         
             
                  - 0
         
     | 
| 
       108 
109 
     | 
    
         
             
                  version: "0"
         
     | 
| 
         @@ -111,7 +112,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement 
     | 
|
| 
       111 
112 
     | 
    
         
             
              requirements: 
         
     | 
| 
       112 
113 
     | 
    
         
             
              - - ">="
         
     | 
| 
       113 
114 
     | 
    
         
             
                - !ruby/object:Gem::Version 
         
     | 
| 
       114 
     | 
    
         
            -
                  hash:  
     | 
| 
      
 115 
     | 
    
         
            +
                  hash: 1804076716045259291
         
     | 
| 
       115 
116 
     | 
    
         
             
                  segments: 
         
     | 
| 
       116 
117 
     | 
    
         
             
                  - 0
         
     | 
| 
       117 
118 
     | 
    
         
             
                  version: "0"
         
     |