backbonejs-rails 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -2,3 +2,5 @@
2
2
  .bundle
3
3
  Gemfile.lock
4
4
  pkg/*
5
+ .DS_Store
6
+
data/.rvmrc CHANGED
@@ -1 +1 @@
1
- rvm 1.9.2@backbonejs-rails --create
1
+ rvm use 1.9.2@backbonejs-rails --create
data/README.md CHANGED
@@ -41,7 +41,7 @@ Installation
41
41
  The best way to install backbonejs-rails is by adding the following to your Gemfile:
42
42
 
43
43
  gem "jquery-rails"
44
- gem "backbonejs-rails"
44
+ gem "backbonejs-rails", "~> 0.0.3"
45
45
 
46
46
  Then use Bundler to install:
47
47
 
@@ -16,7 +16,6 @@ Gem::Specification.new do |s|
16
16
 
17
17
  s.add_dependency "railties", "~> 3.0"
18
18
  s.add_dependency "thor", "~> 0.14"
19
- s.add_dependency "curb", "~> 0.7.15"
20
19
  s.add_development_dependency "bundler", "~> 1.0.0"
21
20
  s.add_development_dependency "rails", "~> 3.0"
22
21
  s.add_development_dependency "rake", "~> 0.8.7"
@@ -1,5 +1,5 @@
1
1
  module Backbonejs
2
2
  module Rails
3
- VERSION = "0.0.3"
3
+ VERSION = "0.0.4"
4
4
  end
5
5
  end
@@ -4,6 +4,9 @@ module Backbonejs
4
4
  module Rails #Generators
5
5
  if ::Rails.version < "3.1"
6
6
  require 'backbonejs-rails/railtie'
7
+ else
8
+ require 'backbonejs-rails/engine'
7
9
  end
10
+ require 'backbonejs-rails/version'
8
11
  end
9
12
  end
@@ -1,66 +1,106 @@
1
1
  require 'rails'
2
- require 'curb'
2
+ require 'net/http'
3
+ require 'uri'
3
4
 
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"
5
+ if ::Rails.version < "3.1"
6
+ module Backbonejs
7
+ module Generators
8
+ class InstallGenerator < ::Rails::Generators::Base
9
+ @@backbone_version = '0.5.3'
10
+ @@underscore_version = '1.1.7'
11
+ @@icanhaz_version = '0.9'
10
12
 
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"
13
+ desc "This generator installs backbone.js #{@@backbone_version}, underscore.js #{@@underscore_version}, json2.js, and (optionally) icanhaz.js #{@@icanhaz_version}"
14
+ class_option :ich, :type => :boolean, :default => false, :desc => 'Include ICanHaz.js'
15
+ source_root File.expand_path('../../../../../vendor/assets/javascripts', __FILE__)
23
16
 
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 }
17
+ def fetch_libraries
18
+ urls = {
19
+ 'backbone' => 'http://documentcloud.github.com/backbone/backbone.js',
20
+ 'backbone.min' => 'http://documentcloud.github.com/backbone/backbone-min.js',
21
+ 'underscore' => 'http://documentcloud.github.com/underscore/underscore.js',
22
+ 'underscore.min' => 'http://documentcloud.github.com/underscore/underscore-min.js',
23
+ 'json2' => 'https://raw.github.com/douglascrockford/JSON-js/master/json2.js'
24
+ }
26
25
 
27
- urls.each do |url|
28
- file_url = url[1]
29
- file_name = url[0]
30
- new_file = "public/javascripts/#{file_name}.js"
26
+ if options[:ich]
27
+ urls.merge!(
28
+ 'icanhaz' => 'https://raw.github.com/andyet/ICanHaz.js/master/ICanHaz.js',
29
+ 'icanhaz.min' => 'https://raw.github.com/andyet/ICanHaz.js/master/ICanHaz.min.js'
30
+ )
31
+ end
31
32
 
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
33
+ urls.each do |file_name, file_url|
34
+ new_file = "public/javascripts/#{file_name}.js"
35
+
36
+ say_status('download', file_url, :green)
37
+ begin
38
+ url = URI.parse(file_url)
39
+ http = Net::HTTP.new(url.host, url.port)
40
+ http.use_ssl = true if url.scheme == 'https'
41
+
42
+ request = Net::HTTP::Get.new(url.request_uri)
43
+ response = http.request(request)
44
+
45
+ case response
46
+ when Net::HTTPSuccess
47
+ # No need to check if file already exists.
48
+ # Generator detects conflict and asks for action.
49
+ create_file new_file
50
+ append_to_file new_file, response.body
51
+ else
52
+ res.error!
53
+ end
52
54
 
55
+ rescue
56
+ say_status('failed', "Downloading #{file_url} failed", :red)
57
+ say_status('copying', "#{file_name}.js (from local copy)", :green)
58
+ copy_file "#{file_name}.js", "public/javascripts/#{file_name}.js"
59
+ end
60
+ end
53
61
  end
54
- end
55
62
 
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
+ def copy_json_false
64
+ backbone_rb = 'config/initializers/backbone.rb'
65
+ create_file backbone_rb
66
+ say_status('creating', 'backbone.rb - excludes root in json return just like Backbone likes it.', :green)
67
+ append_to_file backbone_rb, 'ActiveRecord::Base.include_root_in_json = false'
68
+ #copy_file "backbone.js", "public/javascripts/jquery.js"
69
+ end
63
70
 
71
+ end
72
+ end
73
+ end
74
+ else
75
+ module Backbonejs
76
+ module Generators
77
+ class InstallGenerator < ::Rails::Generators::Base
78
+ @@backbone_version = '0.5.3'
79
+ @@underscore_version = '1.1.7'
80
+ @@icanhaz_version = '0.9'
81
+
82
+ desc "This generator installs backbone.js #{@@backbone_version}, underscore.js #{@@underscore_version}, json2.js, and (optionally) icanhaz.js #{@@icanhaz_version}"
83
+ class_option :ich, :type => :boolean, :aliases => "-i", :default => false, :desc => 'Include ICanHaz.js'
84
+
85
+ def insert_backbone_in_applicationjs
86
+ inject_into_file "app/assets/javascripts/application.js", :before => "//= require_tree" do
87
+ "//= require json2\n//= require underscore\n//= require backbone\n"
88
+ end
89
+
90
+ if options[:ich]
91
+ inject_into_file "app/assets/javascripts/application.js", :before => "//= require_tree" do
92
+ "//= require icanhaz\n"
93
+ end
94
+ end
95
+ end
96
+
97
+ def create_dir_layout
98
+ %W{routers models views}.each do |dir|
99
+ empty_directory "app/assets/javascripts/backbone/#{dir}"
100
+ end
101
+ end
102
+
103
+ end
64
104
  end
65
105
  end
66
- end
106
+ end
@@ -0,0 +1,31 @@
1
+ require 'rails'
2
+
3
+ module Backbonejs
4
+ module Generators
5
+ class UninstallGenerator < ::Rails::Generators::Base
6
+ desc "This generator uninstalls backbone.js, underscore.js, json2.js, and (optionally) icanhaz.js"
7
+ class_option :keep, {
8
+ :type => :array,
9
+ :desc => 'Do not remove specified libraries',
10
+ :banner => 'library another-library'
11
+ }
12
+
13
+ def remove_libraries
14
+ ['backbone', 'underscore', 'json2', 'icanhaz'].each do |lib|
15
+ unless [*options[:keep]].include?(lib)
16
+ # Remove full and minified version of library
17
+ ['', '.min'].each do |suffix|
18
+ file = "public/javascripts/#{lib}#{suffix}.js"
19
+ remove_file file if File.exists?(file)
20
+ end
21
+ end
22
+ end
23
+ end
24
+
25
+ def remove_json_false
26
+ remove_file 'config/initializers/backbone.rb'
27
+ end
28
+ end
29
+ end
30
+ end
31
+