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 +2 -0
- data/.rvmrc +1 -1
- data/README.md +1 -1
- data/backbonejs-rails.gemspec +0 -1
- data/lib/backbonejs-rails/version.rb +1 -1
- data/lib/backbonejs-rails.rb +3 -0
- data/lib/generators/backbonejs/install/install_generator.rb +94 -54
- data/lib/generators/backbonejs/uninstall/uninstall_generator.rb +31 -0
- data/vendor/assets/javascripts/backbone.js +340 -193
- data/vendor/assets/javascripts/backbone.min.js +29 -23
- data/vendor/assets/javascripts/underscore.js +49 -17
- data/vendor/assets/javascripts/underscore.min.js +19 -18
- metadata +58 -78
- data/.DS_Store +0 -0
- data/vendor/.DS_Store +0 -0
- data/vendor/assets/.DS_Store +0 -0
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
data/backbonejs-rails.gemspec
CHANGED
@@ -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"
|
data/lib/backbonejs-rails.rb
CHANGED
@@ -1,66 +1,106 @@
|
|
1
1
|
require 'rails'
|
2
|
-
require '
|
2
|
+
require 'net/http'
|
3
|
+
require 'uri'
|
3
4
|
|
4
|
-
|
5
|
-
module
|
6
|
-
|
7
|
-
|
8
|
-
|
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
|
-
|
12
|
-
|
13
|
-
|
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
|
-
|
25
|
-
|
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
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
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
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
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
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
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
|
+
|