aeonscope-btech_rest 0.3.0 → 0.4.1
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.rdoc +6 -0
- data/README.rdoc +9 -4
- data/Rakefile +7 -5
- data/VERSION.yml +2 -2
- data/rails_generators/rest_setup/USAGE +11 -0
- data/rails_generators/rest_setup/rest_setup_generator.rb +18 -0
- data/rails_generators/rest_setup/templates/README +17 -0
- data/rails_generators/rest_setup/templates/app/controllers/javascripts_controller.rb +7 -0
- data/rails_generators/rest_setup/templates/app/views/javascripts/ujs.js.erb +18 -0
- data/rails_generators/rest_setup/templates/public/javascripts/rest.js +26 -0
- metadata +20 -4
data/CHANGELOG.rdoc
CHANGED
@@ -14,4 +14,10 @@
|
|
14
14
|
* Fixed the btech_rest.rb requirements so that they are platform agnostic.
|
15
15
|
* Added partial support for Rails 2.3 nested forms. You can at least build nested forms and this gem will handle them properly.
|
16
16
|
|
17
|
+
= v0.4.0
|
18
|
+
|
19
|
+
* Fixed an issue where the rest_setup Rails generator was not being packaged properly with the gem.
|
20
|
+
* Added Rails 2.3.2 and above as a gem dependency as this gem will no longer work with previous versions.
|
21
|
+
* Shortened the gem summary and added a more detailed description.
|
22
|
+
* Updated the README file with minor setup and usage clarifications.
|
17
23
|
|
data/README.rdoc
CHANGED
@@ -29,15 +29,20 @@ See the CHANGELOG file for more info.
|
|
29
29
|
|
30
30
|
= Requirements
|
31
31
|
|
32
|
-
1.
|
32
|
+
1. {Ruby on Rails}[http://rubyonrails.org]
|
33
33
|
2. mislav-will_paginate[http://github.com/mislav/will_paginate/tree/master] gem. This is automatically installed/updated for you unless the correct version is detected.
|
34
|
+
3. Knowledge of the {Representational State Transfer (REST)}[http://en.wikipedia.com/wiki/REST]. Download and read {RESTful Rails}[http://www.b-simple.de/documents] if you need further info.
|
34
35
|
|
35
36
|
= Installation
|
36
37
|
|
37
38
|
Type the following from the command line to install:
|
38
39
|
|
39
|
-
* *UNIX*: sudo gem install btech_rest
|
40
|
-
* *Windows*: gem install btech_rest
|
40
|
+
* *UNIX*: sudo gem install aeonscope-btech_rest
|
41
|
+
* *Windows*: gem install aeonscope-btech_rest
|
42
|
+
|
43
|
+
Update your environment.rb file to include the new gem:
|
44
|
+
|
45
|
+
* config.gem "btech_rest"
|
41
46
|
|
42
47
|
Type the following from the command line to setup:
|
43
48
|
|
@@ -47,7 +52,7 @@ Type the following from the command line to setup:
|
|
47
52
|
|
48
53
|
As mentioned in the overview, simply add the following line of code to your controller(s) to make them RESTful:
|
49
54
|
|
50
|
-
|
55
|
+
include BTech::Rest
|
51
56
|
|
52
57
|
Example:
|
53
58
|
|
data/Rakefile
CHANGED
@@ -5,14 +5,16 @@ begin
|
|
5
5
|
require 'jeweler'
|
6
6
|
Jeweler::Tasks.new do |gem|
|
7
7
|
gem.name = "btech_rest"
|
8
|
-
gem.summary = "
|
9
|
-
|
10
|
-
gem.add_dependency "mislav-will_paginate", ">= 2.3.7"
|
11
|
-
gem.rdoc_options << "CHANGELOG.rdoc"
|
8
|
+
gem.summary = "Enables REST functionality and keeps your code DRY."
|
9
|
+
gem.description = "Ruby on Rails supports RESTful routing out-of-the-box. However, as you move along, you will often find yourself repeating the code for the seven REST actions: index, show, new, create, edit, update, destroy. This gem allows you to get all of the code for free by simply typing 'include BTech::Rest' at top of your controller code. That's it! Even better, you can have nested resources as well by adding a 'belongs_to' statement to your controllers much like you would for ActiveRecord models. This is just the tip of the iceburg so make sure to read the RDoc for more info."
|
12
10
|
gem.authors = ["Brooke Kuhlmann"]
|
13
11
|
gem.email = "aeonscope@gmail.com"
|
14
12
|
gem.homepage = "http://github.com/aeonscope/btech-rest"
|
15
|
-
|
13
|
+
gem.required_ruby_version = ">= 1.8.6"
|
14
|
+
gem.add_dependency "rails", ">= 2.3.2"
|
15
|
+
gem.add_dependency "mislav-will_paginate", ">= 2.3.7"
|
16
|
+
gem.rdoc_options << "CHANGELOG.rdoc"
|
17
|
+
gem.files = FileList["[A-Z]*", "{bin,lib,generators,rails_generators,test,spec}/**/*"]
|
16
18
|
end
|
17
19
|
rescue LoadError
|
18
20
|
puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
|
data/VERSION.yml
CHANGED
@@ -0,0 +1,18 @@
|
|
1
|
+
class RestSetupGenerator < Rails::Generator::Base
|
2
|
+
def manifest
|
3
|
+
record do |m|
|
4
|
+
# Controllers
|
5
|
+
m.file "app/controllers/javascripts_controller.rb", "app/controllers/javascripts_controller.rb"
|
6
|
+
|
7
|
+
# Views
|
8
|
+
m.directory "app/views/javascripts"
|
9
|
+
m.file "app/views/javascripts/ujs.js.erb", "app/views/javascripts/ujs.js.erb"
|
10
|
+
|
11
|
+
# JavaScripts
|
12
|
+
m.file "public/javascripts/rest.js", "public/javascripts/rest.js"
|
13
|
+
|
14
|
+
# Instructions
|
15
|
+
m.readme "README"
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
|
2
|
+
Overview
|
3
|
+
REST setup is complete.
|
4
|
+
|
5
|
+
Tasks You Need to Complete:
|
6
|
+
1. Update your layouts/application.html.erb as follows:
|
7
|
+
|
8
|
+
<%= javascript_include_tag "jquery" %>
|
9
|
+
<%= javascript_include_tag "jquery-ui" %>
|
10
|
+
<%= javascript_include_tag "ujs" %>
|
11
|
+
<%= javascript_include_tag "rest" %>
|
12
|
+
|
13
|
+
2. Add the following to the very bottom of your config/routes.rb file:
|
14
|
+
|
15
|
+
# Defaults
|
16
|
+
map.connect ":controller/:action/.:format"
|
17
|
+
|
@@ -0,0 +1,7 @@
|
|
1
|
+
# Enables the ability to serve up dynamic javascript, namely Unobtrusive JavaScript
|
2
|
+
# support for jQuery.
|
3
|
+
class JavascriptsController < ApplicationController
|
4
|
+
# Serves global jQuery UJS settings. See the /views/layouts/application.html.erb for usage.
|
5
|
+
def ujs
|
6
|
+
end
|
7
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
// Ensures AJAX requests are properly formated so that Rails knows how to respond to them.
|
2
|
+
$.ajaxSetup({
|
3
|
+
beforeSend: function(xhr) {xhr.setRequestHeader("Accept", "text/javascript")}
|
4
|
+
});
|
5
|
+
|
6
|
+
/* Ensures AJAX requests have the proper Rails authenticity token. See the following
|
7
|
+
for more info:
|
8
|
+
|
9
|
+
http://henrik.nyh.se/2008/05/rails-authenticity-token-with-jquery
|
10
|
+
http://dev.jquery.com/ticket/3387
|
11
|
+
*/
|
12
|
+
$(document).ajaxSend(function(event, request, settings){
|
13
|
+
var authToken = "<%= form_authenticity_token %>";
|
14
|
+
if (authToken != null){
|
15
|
+
settings.data = settings.data || "";
|
16
|
+
settings.data += (settings.data ? "&" : "") + "authenticity_token=" + encodeURIComponent(authToken);
|
17
|
+
};
|
18
|
+
});
|
@@ -0,0 +1,26 @@
|
|
1
|
+
$(document).ready(function(){
|
2
|
+
// UJS Destroy
|
3
|
+
$("a.destroy").click(function(){
|
4
|
+
var result = confirm("Are you sure you want to delete this?");
|
5
|
+
if (result) {
|
6
|
+
try {
|
7
|
+
var id = $(this).attr("id");
|
8
|
+
// Parent ID is determined from link ID. Example: post_3_link (link ID) yields post_3 (parent ID).
|
9
|
+
var endIndex = id.lastIndexOf('_');
|
10
|
+
if (endIndex > 1) {
|
11
|
+
var parent_id = '#' + id.slice(0, endIndex);
|
12
|
+
$(parent_id).animate({backgroundColor: "#FF0000"}, 500);
|
13
|
+
$(parent_id).fadeOut(500);
|
14
|
+
} else {
|
15
|
+
throw "Invalid ID";
|
16
|
+
}
|
17
|
+
// Finally, call the destroy action.
|
18
|
+
$.post($(this).attr("href"), "_method=delete");
|
19
|
+
} catch (e) {
|
20
|
+
alert("Error: " + e + ". Check that parent ID is defined and/or the link ID includes parent ID as part of the link ID.");
|
21
|
+
}
|
22
|
+
}
|
23
|
+
// Ensure the default event does not fire.
|
24
|
+
return false;
|
25
|
+
});
|
26
|
+
});
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: aeonscope-btech_rest
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brooke Kuhlmann
|
@@ -9,9 +9,19 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-04-
|
12
|
+
date: 2009-04-13 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: rails
|
17
|
+
type: :runtime
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 2.3.2
|
24
|
+
version:
|
15
25
|
- !ruby/object:Gem::Dependency
|
16
26
|
name: mislav-will_paginate
|
17
27
|
type: :runtime
|
@@ -22,7 +32,7 @@ dependencies:
|
|
22
32
|
- !ruby/object:Gem::Version
|
23
33
|
version: 2.3.7
|
24
34
|
version:
|
25
|
-
description:
|
35
|
+
description: "Ruby on Rails supports RESTful routing out-of-the-box. However, as you move along, you will often find yourself repeating the code for the seven REST actions: index, show, new, create, edit, update, destroy. This gem allows you to get all of the code for free by simply typing 'include BTech::Rest' at top of your controller code. That's it! Even better, you can have nested resources as well by adding a 'belongs_to' statement to your controllers much like you would for ActiveRecord models. This is just the tip of the iceburg so make sure to read the RDoc for more info."
|
26
36
|
email: aeonscope@gmail.com
|
27
37
|
executables: []
|
28
38
|
|
@@ -41,6 +51,12 @@ files:
|
|
41
51
|
- lib/btech_rest.rb
|
42
52
|
- lib/class_methods.rb
|
43
53
|
- lib/resource_helper.rb
|
54
|
+
- rails_generators/rest_setup/USAGE
|
55
|
+
- rails_generators/rest_setup/rest_setup_generator.rb
|
56
|
+
- rails_generators/rest_setup/templates/README
|
57
|
+
- rails_generators/rest_setup/templates/app/controllers/javascripts_controller.rb
|
58
|
+
- rails_generators/rest_setup/templates/app/views/javascripts/ujs.js.erb
|
59
|
+
- rails_generators/rest_setup/templates/public/javascripts/rest.js
|
44
60
|
- test/btech_rest_test.rb
|
45
61
|
- test/test_helper.rb
|
46
62
|
has_rdoc: true
|
@@ -69,7 +85,7 @@ rubyforge_project:
|
|
69
85
|
rubygems_version: 1.2.0
|
70
86
|
signing_key:
|
71
87
|
specification_version: 2
|
72
|
-
summary:
|
88
|
+
summary: Enables REST functionality and keeps your code DRY.
|
73
89
|
test_files:
|
74
90
|
- test/btech_rest_test.rb
|
75
91
|
- test/test_helper.rb
|