railsy_backbone 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/MIT-LICENSE +47 -0
- data/README.md +53 -0
- data/Rakefile +31 -0
- data/lib/generators/backbone/install/install_generator.rb +35 -0
- data/lib/generators/resource_helper.rb +55 -0
- data/lib/railsy_backbone/version.rb +3 -0
- data/lib/railsy_backbone.rb +7 -0
- data/vendor/assets/javascripts/backbone.js +1571 -0
- data/vendor/assets/javascripts/railsy_backbone.sync.js +148 -0
- data/vendor/assets/javascripts/underscore.js +1246 -0
- metadata +196 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 9ad0d174182ac789558d034c46d226013ed98591
|
4
|
+
data.tar.gz: c3aba51217b0e118c426efb83bd2f5c53b1a67e9
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 186d95ee4b5bb78b0c26f8620779bd6af3136d181e97ffac565fd5f8632b20fd456c9eeb441e6a2c321caf2be7fa65b044e1b3ccce066ed4799dfabbed9a268c
|
7
|
+
data.tar.gz: 21b35ab1f8cbd3539dff440d375b53eefdbd353a5b117628417a79e51986dbe4dc6eee6fefae5f997225e8546458c7296c6ac0972a6a7fe86dc041ea6fef9af0
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
Copyright (c) 2013 Weston Platter
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
23
|
+
|
24
|
+
|
25
|
+
|
26
|
+
For code pulled from https://github.com/codebrew/backbone-rails
|
27
|
+
|
28
|
+
Copyright 2011 Ryan Fitzgerald
|
29
|
+
|
30
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
31
|
+
a copy of this software and associated documentation files (the
|
32
|
+
"Software"), to deal in the Software without restriction, including
|
33
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
34
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
35
|
+
permit persons to whom the Software is furnished to do so, subject to
|
36
|
+
the following conditions:
|
37
|
+
|
38
|
+
The above copyright notice and this permission notice shall be
|
39
|
+
included in all copies or substantial portions of the Software.
|
40
|
+
|
41
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
42
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
43
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
44
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
45
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
46
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
47
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
# RailsyBackbone
|
2
|
+
Backbone 1.0.0
|
3
|
+
Underscore 1.5.1
|
4
|
+
|
5
|
+
## Features
|
6
|
+
|
7
|
+
### Nested Model Attributes
|
8
|
+
Allows you to specify a namespace for model attributes by defining a ```paramRoot``` attribute. For example,
|
9
|
+
|
10
|
+
```javascript
|
11
|
+
var Book = Backbone.Model.extend({
|
12
|
+
url: '/books',
|
13
|
+
paramRoot: 'book'
|
14
|
+
});
|
15
|
+
|
16
|
+
var book_instance = new Book({
|
17
|
+
title: 'the illiad',
|
18
|
+
author: 'homer'
|
19
|
+
});
|
20
|
+
|
21
|
+
book_instance.sync();
|
22
|
+
```
|
23
|
+
|
24
|
+
This will cause the HTTP POST to look like this,
|
25
|
+
|
26
|
+
```sh
|
27
|
+
Started POST "/books" for 127.0.0.1 at 2013-08-03 18:08:56 -0600
|
28
|
+
Processing by BooksController#create as JSON
|
29
|
+
Parameters: { "book" => { "title" => "the illiad", "author" => "homer" }}
|
30
|
+
```
|
31
|
+
|
32
|
+
### Works with Rails CSRF
|
33
|
+
Sets the ```xhr.setRequestHeader``` to the Rails CSRF token in the header.
|
34
|
+
|
35
|
+
<br>
|
36
|
+
|
37
|
+
## Installation
|
38
|
+
|
39
|
+
Add this line to your application's Gemfile:
|
40
|
+
|
41
|
+
gem 'railsy_backbone', github: 'westonplatter/railsy_backbone'
|
42
|
+
|
43
|
+
And then execute:
|
44
|
+
|
45
|
+
$ bundle
|
46
|
+
|
47
|
+
## Contributing
|
48
|
+
|
49
|
+
1. Fork it
|
50
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
51
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
52
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
53
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
#!/usr/bin/env rake
|
2
|
+
begin
|
3
|
+
require 'bundler/setup'
|
4
|
+
rescue LoadError
|
5
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
6
|
+
end
|
7
|
+
|
8
|
+
require 'bundler/gem_tasks'
|
9
|
+
|
10
|
+
task :default => :test
|
11
|
+
|
12
|
+
namespace :backbone do
|
13
|
+
desc "Download the latest released versions of underscore and backbone.js"
|
14
|
+
task :download_latest do
|
15
|
+
files = {
|
16
|
+
'underscore.js'=>'http://underscorejs.org/underscore.js',
|
17
|
+
'backbone.js' => 'http://backbonejs.org/backbone.js'
|
18
|
+
}
|
19
|
+
|
20
|
+
vendor_dir = "vendor/assets/javascripts"
|
21
|
+
|
22
|
+
require 'open-uri'
|
23
|
+
files.each do |local,remote|
|
24
|
+
puts "Downloading #{local}"
|
25
|
+
File.open "#{vendor_dir}/#{local}", 'w' do |f|
|
26
|
+
f.write open(remote).read
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# require 'generators/backbone/resource_helpers'
|
2
|
+
|
3
|
+
module Backbone
|
4
|
+
module Generators
|
5
|
+
class InstallGenerator < Rails::Generators::Base
|
6
|
+
# include Backbone::Generators::ResourceHelpers
|
7
|
+
#
|
8
|
+
# source_root File.expand_path("../templates", __FILE__)
|
9
|
+
|
10
|
+
desc "This generator installs backbone.js with a default folder layout in app/assets/javascripts/backbone"
|
11
|
+
|
12
|
+
# class_option :skip_git, :type => :boolean, :aliases => "-G", :default => false,
|
13
|
+
# :desc => "Skip Git ignores and keeps"
|
14
|
+
|
15
|
+
def inject_backbone
|
16
|
+
inject_into_file "app/assets/javascripts/application.js", :before => "//= require_tree" do
|
17
|
+
# "//= require underscore\n//= require backbone\n//= require backbone_rails_sync\n//= require backbone_datalink\n//= require backbone/#{application_name.underscore}\n"
|
18
|
+
"//= require underscore\n//= require backbone\n//= require railsy_backbone.sync"
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
# def create_dir_layout
|
23
|
+
# %W{routers models views templates}.each do |dir|
|
24
|
+
# empty_directory "app/assets/javascripts/backbone/#{dir}"
|
25
|
+
# create_file "app/assets/javascripts/backbone/#{dir}/.gitkeep" unless options[:skip_git]
|
26
|
+
# end
|
27
|
+
# end
|
28
|
+
|
29
|
+
# def create_app_file
|
30
|
+
# template "app.coffee", "app/assets/javascripts/backbone/#{application_name.underscore}.js.coffee"
|
31
|
+
# end
|
32
|
+
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
module Backbone
|
2
|
+
module Generators
|
3
|
+
module ResourceHelpers
|
4
|
+
|
5
|
+
def backbone_path
|
6
|
+
"app/assets/javascripts/backbone"
|
7
|
+
end
|
8
|
+
|
9
|
+
def model_namespace
|
10
|
+
[js_app_name, "Models", class_name].join(".")
|
11
|
+
end
|
12
|
+
|
13
|
+
def singular_model_name
|
14
|
+
uncapitalize singular_name.camelize
|
15
|
+
end
|
16
|
+
|
17
|
+
def plural_model_name
|
18
|
+
uncapitalize(plural_name.camelize)
|
19
|
+
end
|
20
|
+
|
21
|
+
def collection_namespace
|
22
|
+
[js_app_name, "Collections", plural_name.camelize].join(".")
|
23
|
+
end
|
24
|
+
|
25
|
+
def view_namespace
|
26
|
+
[js_app_name, "Views", plural_name.camelize].join(".")
|
27
|
+
end
|
28
|
+
|
29
|
+
def router_namespace
|
30
|
+
[js_app_name, "Routers", plural_name.camelize].join(".")
|
31
|
+
end
|
32
|
+
|
33
|
+
def jst(action)
|
34
|
+
"backbone/templates/#{plural_name}/#{action}"
|
35
|
+
end
|
36
|
+
|
37
|
+
def js_app_name
|
38
|
+
application_name.camelize
|
39
|
+
end
|
40
|
+
|
41
|
+
def application_name
|
42
|
+
if defined?(Rails) && Rails.application
|
43
|
+
Rails.application.class.name.split('::').first
|
44
|
+
else
|
45
|
+
"application"
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def uncapitalize(str)
|
50
|
+
str[0, 1].downcase << str[1..-1]
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|