railsy_backbone 0.0.3 → 0.0.4

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a846e920a5dad426c7c7e892cf4af5c5e7a85e45
4
- data.tar.gz: 37d9f658a1c1b61f45aa144a5393429134ac6474
3
+ metadata.gz: a60b10150fbc85539a6081d94fa22531453cecd1
4
+ data.tar.gz: 8c72b9aec92541d08d742e5c7ff5235d61c65d5a
5
5
  SHA512:
6
- metadata.gz: 5fae32e260f47e893775010bbe983361126644085e70391d5013b533d6c586f53a883fc6eef3e6a349aad38339e76369b0308535a4d57b8be55e662a01bdd54d
7
- data.tar.gz: fd9f382bbbe0a082ceafdc937ba33dd80d2f7de9f3a033d129c07a763ae176086d7fb93995296b66f237d0d9c727341c1f720dd853d4772faf7e286531e44dbb
6
+ metadata.gz: 8d5af02700098e358931772710eb49b6b07b211b1bb9ded35bd5ec43913fe2a2ea6746134ef9ea5b750f62f983b749cc8cdd8022d808e195f7ebcbed2a5b55a9
7
+ data.tar.gz: f563f3ac772cc65bb7105f71c6636fe415e39dd4b3504d3c7142f100c68e152d1b4b3b1cedb55afa4d88d897a906bc852aac6efa44dfb321ca50a2270e3f9f5f
data/CHANGELOG.md CHANGED
@@ -1,3 +1,21 @@
1
+ ## next
2
+
3
+ ## 0.0.4
4
+
5
+ - Remove Rails unofficially reserved `created_at` and `updated_at` so they're
6
+ included in HTTP PUT/PATCH request.
7
+ (westonplatter)
8
+
9
+ - Finished docs for `railsy_backbone.sync`.
10
+ (westonplatter)
11
+
12
+ - Account for application.js and application.js.coffee Javascript require differences.
13
+ (Nicholas Zaillian - https://github.com/nzaillian/backbone-rails/commit/24fb49d4c941821307ccdec7160ec218e7475706)
14
+
15
+ - Added install instructions to README.
16
+ (westonplatter)
17
+
18
+
1
19
  ## 0.0.3
2
20
 
3
21
  - copied Backbone model generator from backbone-rails
data/README.md CHANGED
@@ -4,6 +4,85 @@ Underscore 1.5.1
4
4
 
5
5
  [![Build Status](https://travis-ci.org/westonplatter/railsy_backbone.png?branch=master)](https://travis-ci.org/westonplatter/railsy_backbone)
6
6
 
7
+ Questions/Suggestions   =>   [open a GitHub issue - 24 hr response time](https://github.com/westonplatter/railsy_backbone/issues/new)
8
+
9
+ ## Rails Setup
10
+
11
+ ### Install
12
+
13
+ Add this line to Gemfile,
14
+
15
+ gem 'railsy_backbone'
16
+
17
+ And then,
18
+
19
+ $ bundle install
20
+ $ rails g backbone:install
21
+
22
+ This requires `underscore`, `backbone`, and JS customizations to make Backbone play nice with Rails (see Javscript files with `rails_backbone.` prefix regarding what changed).
23
+
24
+ //= require jquery
25
+ //= require jquery_ujs
26
+ //= require underscore
27
+ //= require backbone
28
+ //= require railsy_backbone.sync
29
+ //= require railsy_backbone.datalink
30
+ //= require backbone/<your_application_name_here>
31
+ //= require_tree .
32
+
33
+ ### Generators
34
+ Rails Install
35
+ Backbone Model
36
+ Backbone Router
37
+ Backbone Scaffold
38
+
39
+ ### Example Usage
40
+
41
+ Create new rails app,
42
+
43
+ rails new library
44
+ cd library
45
+
46
+ Install `railsy_backbone`,
47
+
48
+ # add railsy_backbone to Gemfile
49
+ bundle install
50
+ rails g backbone:install
51
+
52
+ Generate a standard Rails scaffold,
53
+
54
+ rails g scaffold Book title:string author:string
55
+ rake db:migrate
56
+
57
+ Generate a `Backbone` scaffold,
58
+
59
+ rails g backbone:scaffold Book title:string author:string
60
+
61
+ Edit `books/index.html` to execute actions through the Backbone scaffold UI rather than routing to different pages.
62
+
63
+ ### ERB
64
+
65
+ <div id="books"></div>
66
+
67
+ <script type="text/javascript">
68
+ $(function() {
69
+ window.router = new Library.Routers.BooksRouter({books: <%= @books.to_json.html_safe -%>});
70
+ Backbone.history.start();
71
+ });
72
+ </script>
73
+
74
+
75
+ ### HAML
76
+
77
+ #books
78
+
79
+ :javascript
80
+ $(function() {
81
+ window.router = new Library.Routers.BooksRouter({books: #{@books.to_json.html_safe}});
82
+ Backbone.history.start();
83
+ });
84
+
85
+
7
86
  ## Features
8
87
 
9
88
  1. [Nested Model Attributes](#nested-model-attributes)
@@ -26,32 +105,29 @@ Allows you to specify a namespace for model attributes by defining a ```paramRo
26
105
 
27
106
  This will cause the HTTP POST to look like this,
28
107
 
29
- Started POST "/books" for 127.0.0.1 at 2013-08-03 18:08:56 -0600
108
+ Started POST "/books" for 127.0.0.1
30
109
  Processing by BooksController#create as JSON
31
- Parameters: { "book" => { "title" => "the illiad", "author" => "homer" }}
110
+ Parameters: { "book" => {
111
+ "title" => "the illiad",
112
+ "author" => "homer",
113
+ "id" => 1}
114
+ }
32
115
 
33
116
 
34
117
  ### Automatic Rails CSRF Integration
35
118
  Automatically handles the Rails `authenticity_token`. Or, more technically, sets the `xhr.setRequestHeader` to the Rails CSRF token supplied in the HTML `header` meta tag.
36
119
 
37
- <br>
38
-
39
- ## Installation
40
-
41
- Add this line to your application's Gemfile:
42
-
43
- gem 'railsy_backbone', '~> 0.0.3'
44
-
45
- And then execute:
46
-
47
- $ bundle
48
120
 
49
121
  ## Docs
50
122
 
51
123
  [Here's the link to our docs](http://westonplatter.github.io/railsy_backbone/).
52
124
 
53
- __We really value clear communication__ (we're serious!). If you think something is missing in the docs, __please__ let us know via a GitHub issue ([create issues here](https://github.com/westonplatter/railsy_backbone/issues)), and we'll look at adding it.
125
+ __I really value clear communication__ (I'm serious!). If you think something is missing in the docs, __please__ let me know via a GitHub issue ([create issues here](https://github.com/westonplatter/railsy_backbone/issues)), and I'll look at adding it.
126
+
127
+
54
128
 
129
+ ## Contributions
130
+ [Nicholas Zaillian](https://github.com/nzaillian)
55
131
 
56
132
  ## Credits
57
133
  See LICENSE
@@ -4,21 +4,36 @@ module Backbone
4
4
  module Generators
5
5
  class InstallGenerator < Rails::Generators::Base
6
6
  include Backbone::Generators::Helpers
7
-
7
+
8
8
  source_root File.expand_path("../templates", __FILE__)
9
9
 
10
10
  desc "This generator installs backbone.js with a default folder layout in app/assets/javascripts/backbone"
11
11
 
12
- class_option :skip_git, :type => :boolean, :aliases => "-G", :default => false,
13
- :desc => "Skip Git ignores and keeps"
12
+ class_option :skip_git, type: :boolean,
13
+ aliases: '-G',
14
+ default: false,
15
+ desc: 'Skip Git ignores and keeps'
14
16
 
15
17
  def inject_backbone
16
- inject_into_file "app/assets/javascripts/application.js", :before => "//= require_tree" do
17
- "//= require underscore
18
- //= require backbone
19
- //= require railsy_backbone.sync
20
- //= require railsy_backbone.datalink
21
- //= require backbone/#{application_name.underscore}\n"
18
+ # when Rails app has application.js
19
+ if File.exists? "#{Rails.root}/app/assets/javascripts/application.js"
20
+ inject_into_file "app/assets/javascripts/application.js", before: "//= require_tree" do
21
+ result = "//= require underscore\n"
22
+ result += "//= require backbone\n"
23
+ result += "//= require railsy_backbone.sync\n"
24
+ result += "//= require railsy_backbone.datalink\n"
25
+ result += "//= require backbone/#{application_name.underscore}\n"
26
+ end
27
+ # when Rails app has application.js.coffee
28
+ elsif File.exists? "#{Rails.root}/app/assets/javascripts/application.js.coffee"
29
+ inject_into_file "app/assets/javascripts/application.js.coffee", before: '#= require_tree' do
30
+ result = "#= require underscore\n"
31
+ result += "#= require backbone\n"
32
+ result += "#= require railsy_backbone.sync\n"
33
+ result += "#= require railsy_backbone.datalink\n"
34
+ result += "#= require backbone/#{application_name.underscore}\n"
35
+ result
36
+ end
22
37
  end
23
38
  end
24
39
 
@@ -1,3 +1,3 @@
1
1
  module RailsyBackbone
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
@@ -24,12 +24,12 @@
24
24
  // select the HTML input `name` attribute
25
25
  name = el.attr("name");
26
26
 
27
- // TODO describe what this does
27
+ // jQuery select the HTML input element for next code chunk
28
28
  model.bind("change:" + name, function() {
29
29
  return el.val(model.get(name));
30
30
  });
31
31
 
32
- // re-set model specifical attribute when changed
32
+ // re-set model's specific attribute when changed
33
33
  return $(this).bind("change", function() {
34
34
  var attrs;
35
35
  el = $(this);
@@ -85,15 +85,26 @@
85
85
  //
86
86
  // Started POST "/books" for 127.0.0.1
87
87
  // Processing by BooksController#create as JSON
88
- // { "book" => { "title" => "the illiad", "author" => "home" } }
88
+ // { "book" => { "title" => "the illiad", "author" => "home", "id" => 1} }
89
89
  //
90
- if(model.paramRoot) {
90
+ if(model.paramRoot) {
91
91
  var model_attributes = {}
92
- model_attributes[model.paramRoot] = model.toJSON(options);
93
- params.data = JSON.stringify(options.attrs || model_attributes );
92
+
93
+ // Store model instance in JSON format.
94
+ var attrs = model.toJSON(options);
95
+
96
+ // Remove Rails unofficially reserved `created_at` and `updated_at` so
97
+ // they're included in HTTP PUT/PATCH request.
98
+ delete attrs["created_at"];
99
+ delete attrs["updated_at"];
100
+
101
+ // Nest model attributes within model's `paramRoot` key-value pair.
102
+ model_attributes[model.paramRoot] = attrs;
103
+
104
+ params.data = JSON.stringify(options.attrs || model_attributes);
94
105
  } else {
95
106
  // If model does not define a `paramRoot`, use the original Backbone
96
- // implementation
107
+ // implementation.
97
108
  params.data = JSON.stringify(options.attrs || model.toJSON(options) );
98
109
  }
99
110
  // railsy_backbone (end)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: railsy_backbone
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Weston Platter
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-09-19 00:00:00.000000000 Z
11
+ date: 2013-10-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: railties