backbonejs-rails 0.0.1 → 0.0.2

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 CHANGED
@@ -1,9 +1,9 @@
1
1
  What Does it do?
2
- ----------------
2
+ ================
3
3
 
4
- Compatible with Rails 3.0.x (Rails 3.1.x support is coming)
4
+ Compatible with Rails 3.0.x (Rails 3.1.x support is coming).
5
5
 
6
- backbonejs-rails is similar to jquery-rails. It adds the Javascript files that you need to create an application that uses backbone.js as a JavaScript MVC. This gem will get the most recent version of these files from their master branches on github.
6
+ backbonejs-rails is similar to [jquery-rails](https://github.com/JangoSteve/jquery-rails). It adds the Javascript files that you need to create an application that uses [backbone.js](http://documentcloud.github.com/backbone/) as a JavaScript MVC. This gem will get the most recent version of these files from their master branches on github.
7
7
 
8
8
  These are:
9
9
 
@@ -13,7 +13,7 @@ These are:
13
13
  * underscore.min.js
14
14
  * json2.js
15
15
 
16
- For templates I have included ICanHaz.js
16
+ For templates I have included [ICanHaz.js](http://icanhazjs.com/)
17
17
 
18
18
  * icanhaz.js
19
19
  * icanhaz.min.js
@@ -21,11 +21,25 @@ For templates I have included ICanHaz.js
21
21
  Upon installation the files are added to your javascript defaults so that you can still use the following in your views/layouts/application.html.erb file:
22
22
 
23
23
  <%= javascript_include_tag :defaults %>
24
+
25
+ What else?
26
+ ----------
27
+
28
+ It also creates a file called "config/initializers/backbone.rb" which contains the line:
29
+
30
+ ActiveRecord::Base.include_root_in_json = false
31
+
32
+ Which is what you need to return JSON to Backbone the way it likes it. Otherwise you would need to do something like this:
33
+
34
+ def create
35
+ render :json => Person.create(:name => params[:name], :age => params[:age])
36
+ end
24
37
 
25
38
  Installation
26
39
  ------------
27
40
 
28
- The best way to install backbone-rails is by adding the following to your Gemfile:
41
+ The best way to install backbonejs-rails is by adding the following to your Gemfile:
42
+
29
43
  gem "jquery-rails"
30
44
  gem "backbonejs-rails"
31
45
 
@@ -39,4 +53,7 @@ Usage
39
53
  $ rails g jquery:install
40
54
  $ rails g backbonejs:install
41
55
 
56
+ If you have already installed jquery and removed prototype then you can skip that step.
57
+
58
+ You can find my [screencast on Backbone.js and Rails 3 here](http://andrewgertig.com/2011/05/rails-backbone-js-example-screencast/)
42
59
 
@@ -1,5 +1,5 @@
1
1
  module Backbonejs
2
2
  module Rails
3
- VERSION = "0.0.1"
3
+ VERSION = "0.0.2"
4
4
  end
5
5
  end
@@ -0,0 +1,66 @@
1
+ require 'rails'
2
+ require 'curb'
3
+
4
+ module Backbonejs
5
+ module Generators
6
+ class InstallGenerator < ::Rails::Generators::Base
7
+ @@backbone_version = "0.3.3"
8
+ @@underscore_version = "1.1.6"
9
+ @@icanhaz_version = "0.9"
10
+
11
+ desc "This generator installs backbone.js #{@@backbone_version}, underscore.js #{@@underscore_version}, json2.js, and (optionally) icanhaz.js #{@@icanhaz_version}"
12
+ class_option :ich, :type => :boolean, :default => false, :desc => "Include ICanHaz.js"
13
+ source_root File.expand_path('../../../../../vendor/assets/javascripts', __FILE__)
14
+
15
+ def fetch_libraries
16
+ url_backbone = "http://documentcloud.github.com/backbone/backbone.js"
17
+ url_backbone_min = "http://documentcloud.github.com/backbone/backbone-min.js"
18
+ url_underscore = "http://documentcloud.github.com/underscore/underscore.js"
19
+ url_underscore_min = "http://documentcloud.github.com/underscore/underscore-min.js"
20
+ url_icanhaz = "https://github.com/andyet/ICanHaz.js/raw/master/ICanHaz.js"
21
+ url_icanhaz_min = "https://github.com/andyet/ICanHaz.js/raw/master/ICanHaz.min.js"
22
+ url_json2 = "https://github.com/douglascrockford/JSON-js/raw/master/json2.js"
23
+
24
+ urls = {"backbone" => url_backbone, "backbone.min" => url_backbone_min, "underscore" => url_underscore, "underscore.min" => url_underscore_min,
25
+ "json2" => url_json2, "icanhaz" => url_icanhaz, "icanhaz.min" => url_icanhaz_min }
26
+
27
+ urls.each do |url|
28
+ file_url = url[1]
29
+ file_name = url[0]
30
+ new_file = "public/javascripts/#{file_name}.js"
31
+
32
+
33
+ begin
34
+ c = Curl::Easy.new(file_url)
35
+ c.perform
36
+
37
+ if File.exist?(new_file)
38
+ puts "Skipping #{file_name}.js because it already exists"
39
+ else
40
+ puts "Generating #{new_file}"
41
+ create_file new_file
42
+ append_to_file new_file, c.body_str
43
+ end
44
+
45
+ rescue
46
+ puts "Connection to #{the_url} failed!"
47
+ puts "Falling back to copying over a, most likely, older version."
48
+
49
+ say_status("copying", "#{file_name}.js", :green)
50
+ copy_file "#{file_name}.js", "public/javascripts/#{file_name}.js"
51
+ end
52
+
53
+ end
54
+ end
55
+
56
+ def copy_json_false
57
+ backbone_rb = "config/initializers/backbone.rb"
58
+ create_file backbone_rb
59
+ say_status("creating", "backbone.rb - excludes root in json return just like Backbone likes it.", :green)
60
+ append_to_file backbone_rb, "ActiveRecord::Base.include_root_in_json = false"
61
+ #copy_file "backbone.js", "public/javascripts/jquery.js"
62
+ end
63
+
64
+ end
65
+ end
66
+ end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: backbonejs-rails
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.0.1
5
+ version: 0.0.2
6
6
  platform: ruby
7
7
  authors:
8
8
  - Andrew Gertig
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-05-20 00:00:00 -04:00
13
+ date: 2011-06-01 00:00:00 -04:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
@@ -99,6 +99,7 @@ files:
99
99
  - lib/backbonejs-rails.rb
100
100
  - lib/backbonejs-rails/railtie.rb
101
101
  - lib/backbonejs-rails/version.rb
102
+ - lib/generators/backbonejs/install/install_generator.rb
102
103
  - vendor/.DS_Store
103
104
  - vendor/assets/.DS_Store
104
105
  - vendor/assets/javascripts/backbone.js