aeonscope-btech_rest 0.4.1 → 0.4.2
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.rdoc +4 -0
- data/README.rdoc +3 -3
- data/Rakefile +1 -1
- data/VERSION.yml +1 -1
- data/rails_generators/rest_setup/templates/public/javascripts/rest.js +66 -1
- metadata +3 -3
data/CHANGELOG.rdoc
CHANGED
@@ -21,3 +21,7 @@
|
|
21
21
|
* Shortened the gem summary and added a more detailed description.
|
22
22
|
* Updated the README file with minor setup and usage clarifications.
|
23
23
|
|
24
|
+
= v0.4.x
|
25
|
+
|
26
|
+
* Cleaned up the summary and descriptions for the gem, README, and GitHub data.
|
27
|
+
* Added partial UJS support for new/edit record actions. Nested fields are supported as well.
|
data/README.rdoc
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
= Overview
|
2
2
|
|
3
|
-
|
3
|
+
Enables default REST functionality, more than what you get with Rails out-of-the-box, and keeps your code DRY. This means you can write code like this:
|
4
4
|
|
5
5
|
class Posts < ApplicationController
|
6
6
|
include BTech::Rest
|
@@ -29,8 +29,8 @@ See the CHANGELOG file for more info.
|
|
29
29
|
|
30
30
|
= Requirements
|
31
31
|
|
32
|
-
1. {Ruby on Rails}[http://rubyonrails.org]
|
33
|
-
2. mislav-will_paginate[http://github.com/mislav/will_paginate/tree/master] gem
|
32
|
+
1. {Ruby on Rails}[http://rubyonrails.org] (automatically installed for you if you don't have 2.3.x or higher).
|
33
|
+
2. mislav-will_paginate[http://github.com/mislav/will_paginate/tree/master] gem (automatically installed for you).
|
34
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.
|
35
35
|
|
36
36
|
= Installation
|
data/Rakefile
CHANGED
@@ -5,7 +5,7 @@ begin
|
|
5
5
|
require 'jeweler'
|
6
6
|
Jeweler::Tasks.new do |gem|
|
7
7
|
gem.name = "btech_rest"
|
8
|
-
gem.summary = "Enables REST functionality and keeps your code DRY."
|
8
|
+
gem.summary = "Enables default REST functionality, more than what you get with Rails out-of-the-box, and keeps your code DRY."
|
9
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."
|
10
10
|
gem.authors = ["Brooke Kuhlmann"]
|
11
11
|
gem.email = "aeonscope@gmail.com"
|
data/VERSION.yml
CHANGED
@@ -1,5 +1,43 @@
|
|
1
|
+
// Increments a number embedded in the text by one. If no number is found then the original text is returned.
|
2
|
+
function increment_text(text) {
|
3
|
+
var match = text.match(/\d+/);
|
4
|
+
if (match != null) {
|
5
|
+
var number = new Number(match);
|
6
|
+
var new_number = number + 1;
|
7
|
+
text = text.replace(number, new_number);
|
8
|
+
}
|
9
|
+
return text;
|
10
|
+
};
|
11
|
+
|
12
|
+
// Suffixes text with a number. Accepts the following arguments:
|
13
|
+
// text = Required. The text to suffix.
|
14
|
+
// number = Optional. The number to be suffixed to the text. Defaults to 1.
|
15
|
+
// delimiter = Optional. The delimiter between the text and number. Defaults to '_'.
|
16
|
+
function suffix_num_to_text(text, number, delimiter) {
|
17
|
+
if (text != null) {
|
18
|
+
if (number == undefined) { number = 1; };
|
19
|
+
if (delimiter == undefined) { delimiter = '_'; };
|
20
|
+
return text + delimiter + number;
|
21
|
+
};
|
22
|
+
};
|
23
|
+
|
24
|
+
// Increments the input field ID number by one so ActiveRecord can save new record attributes.
|
25
|
+
function increment_input_id(input) {
|
26
|
+
id = $(input).attr("id");
|
27
|
+
id = increment_text(id);
|
28
|
+
$(input).attr("id", id);
|
29
|
+
};
|
30
|
+
|
31
|
+
// Increments the input field name number by one so ActiveRecord can save new record attributes.
|
32
|
+
function increment_input_name(input) {
|
33
|
+
name = $(input).attr("name");
|
34
|
+
name = increment_text(name);
|
35
|
+
$(input).attr("name", name);
|
36
|
+
};
|
37
|
+
|
38
|
+
// UJS
|
1
39
|
$(document).ready(function(){
|
2
|
-
//
|
40
|
+
// Destroy
|
3
41
|
$("a.destroy").click(function(){
|
4
42
|
var result = confirm("Are you sure you want to delete this?");
|
5
43
|
if (result) {
|
@@ -23,4 +61,31 @@ $(document).ready(function(){
|
|
23
61
|
// Ensure the default event does not fire.
|
24
62
|
return false;
|
25
63
|
});
|
64
|
+
|
65
|
+
// New
|
66
|
+
$("a.new").click(function(){
|
67
|
+
var id = $(this).attr("id");
|
68
|
+
var endIndex = id.lastIndexOf('_');
|
69
|
+
var parent_id = '#' + id.slice(0, endIndex);
|
70
|
+
var clone = $(parent_id + " tr:last").clone(true);
|
71
|
+
var clone_id = clone.attr("id");
|
72
|
+
// Clone for new action.
|
73
|
+
if (clone_id.length > 4 && clone_id.substr(0, 4) == "new_") {
|
74
|
+
clone_id = clone_id.slice(4);
|
75
|
+
clone_id = suffix_num_to_text(clone_id);
|
76
|
+
clone.attr("id", clone_id);
|
77
|
+
}
|
78
|
+
// Clone for edit action.
|
79
|
+
else {
|
80
|
+
clone.attr("id", increment_text(clone_id));
|
81
|
+
}
|
82
|
+
$(parent_id).append(clone);
|
83
|
+
// Ensure all cloned input fields are unique.
|
84
|
+
$.each($('#' + clone.attr("id") + " :input"), function(){
|
85
|
+
increment_input_id(this);
|
86
|
+
increment_input_name(this);
|
87
|
+
$(this).attr("value", '');
|
88
|
+
return this;
|
89
|
+
});
|
90
|
+
});
|
26
91
|
});
|
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.
|
4
|
+
version: 0.4.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brooke Kuhlmann
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-04-
|
12
|
+
date: 2009-04-14 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -85,7 +85,7 @@ rubyforge_project:
|
|
85
85
|
rubygems_version: 1.2.0
|
86
86
|
signing_key:
|
87
87
|
specification_version: 2
|
88
|
-
summary: Enables REST functionality and keeps your code DRY.
|
88
|
+
summary: Enables default REST functionality, more than what you get with Rails out-of-the-box, and keeps your code DRY.
|
89
89
|
test_files:
|
90
90
|
- test/btech_rest_test.rb
|
91
91
|
- test/test_helper.rb
|