rangular 0.1.0.alpha
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +1 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +278 -0
- data/Rakefile +1 -0
- data/lib/rangular.rb +8 -0
- data/lib/rangular/version.rb +5 -0
- data/rangular.gemspec +26 -0
- data/vendor/assets/javascripts/rangular.js +294 -0
- metadata +83 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: c08df91fade02fcbcfab98cea5b4fafc0f778653
|
4
|
+
data.tar.gz: 9e086a1a49172a35db85bab0e89489c18f789d81
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 4921c32475e03b40213397152356ce6e789a6bcba69cc03c5b10f1152cf442c4caf7e0b3cbbd54f7014c7d705ed441bbcf56c5d03f358ed738d5af098e30463c
|
7
|
+
data.tar.gz: d009a0523603404b9283c7b631fb44c2b9ea7b5c0976309c127f4490452d10c5348ae9e9f8296314d0fbb7830f2fb7395866d1799ef52d2e9a92eee3277f9447
|
data/.gitignore
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
**.swp
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Lee Nathan
|
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.
|
data/README.md
ADDED
@@ -0,0 +1,278 @@
|
|
1
|
+
About
|
2
|
+
-----
|
3
|
+
Rangular is a script that allows AJAX calls to be made without writing Javascript. (OK, maybe one line)
|
4
|
+
It is based on the Angular framework and designed to be plugged into Rails web apps.
|
5
|
+
However, it can be modified to work with any RESTful framework.
|
6
|
+
|
7
|
+
Rangular works by telling Angular how to talk to Rails and creates convenience methods and variables for RESTful server communication.
|
8
|
+
The variables and methods are available directly from HTML with no configuration required. (OK, maybe one line)
|
9
|
+
|
10
|
+
When I first started using Angular, I was amazed.
|
11
|
+
It only took 10 minutes to learn enough Angular to allow me to do some amazing, dynamic things with little or no Javascript.
|
12
|
+
However, I found the next step up, where things get really useful, to be extremely difficult.
|
13
|
+
It was my intention in creating this tool to shelter new Angular users from some of the more daunting aspects of the framework while allowing them to continue doing even more amazing things within that "first 10 minute" window.
|
14
|
+
|
15
|
+
I do however assume a solid understanding of Rails development.
|
16
|
+
It is my hope that this tool can be useful for anybody wanting to add an AJAX kick to an application all the way up to people wanting to create simple one page apps.
|
17
|
+
|
18
|
+
Quick Start
|
19
|
+
-----------
|
20
|
+
|
21
|
+
Javascript:
|
22
|
+
|
23
|
+
angular.module("yourApp", ['rangular'])
|
24
|
+
|
25
|
+
HTML:
|
26
|
+
|
27
|
+
<body ng-app="yourApp">
|
28
|
+
<div ra-controller="notes">
|
29
|
+
<ul>
|
30
|
+
<li ng-repeat="note in notes.index">
|
31
|
+
{{ note.name }}
|
32
|
+
-
|
33
|
+
{{ note.content }}
|
34
|
+
</li>
|
35
|
+
</ul>
|
36
|
+
</div>
|
37
|
+
</body>
|
38
|
+
|
39
|
+
AJAX!
|
40
|
+
|
41
|
+
Example App
|
42
|
+
-----------
|
43
|
+
Here is a working example that incorporates all of the features it can without having to write any JS.
|
44
|
+
As it stand's it's a complete and functional product that incorporates full CRUD in one page.
|
45
|
+
|
46
|
+
### [notejax](http://notejax.herokuapp.com/)
|
47
|
+
|
48
|
+
Usage
|
49
|
+
-----
|
50
|
+
Let's assume we have a Rails Controller called Notes and it's all set up to respond to and return JSON.
|
51
|
+
You'll also need to make sure that rangular and any other necessary scripts are available from the asset pipeline.
|
52
|
+
|
53
|
+
First, you need to define your Angular application, or at least include the rangular module in it.
|
54
|
+
Add the `ng-app` directive to any surrounding html element.
|
55
|
+
Usually like `<body ng-app="yourApp">`.
|
56
|
+
|
57
|
+
Now create a Javascript or Coffeescript file and add the following line.
|
58
|
+
|
59
|
+
angular.module("yourApp", ['rangular']);
|
60
|
+
|
61
|
+
Next, create an HTML element that will contain everything Notes related and add the `ra-controller` directive to it.
|
62
|
+
|
63
|
+
<div ra-controller="notes">
|
64
|
+
This is all the notes.
|
65
|
+
</div>
|
66
|
+
|
67
|
+
When you reload your page, if everything is wired up properly, you should now have access to all your RESTful methods.
|
68
|
+
Some data has already been retrieved for you, namely the index and a new Note to be used in a form.
|
69
|
+
|
70
|
+
You can see the index data by dropping this into your html inside of the `ra-controller` element:
|
71
|
+
|
72
|
+
{{ notes.index }}
|
73
|
+
|
74
|
+
You can display all of your notes with the `ng-repeat` directive.
|
75
|
+
|
76
|
+
<ul>
|
77
|
+
<li ng-repeat="note in notes.index">
|
78
|
+
{{ note.name }}
|
79
|
+
-
|
80
|
+
{{ note.content }}
|
81
|
+
</li>
|
82
|
+
</ul>
|
83
|
+
|
84
|
+
There are more methods and variables that allow full access to the Rails REST methods.
|
85
|
+
But that really is all you need to get started.
|
86
|
+
You can use `ng-click` to change visibility variables.
|
87
|
+
And you can use `ng-show` and `ng-hide` to `toggle` the visibility of elements.
|
88
|
+
|
89
|
+
Remember that you can pass variables from Rails to Javascript, but not the other way around (not easily anyway).
|
90
|
+
So `<div ra-controller="<%= controller_name %>">` should work.
|
91
|
+
But `<%= link_to {{ note.name }}, {{ note }} %>` will not.
|
92
|
+
|
93
|
+
Core Concepts
|
94
|
+
-------------
|
95
|
+
Calling `ra-controller` creates an object with the same name as the controller.
|
96
|
+
The controller name is assumed to be a Rails controller and all restful connections are automatically created.
|
97
|
+
So `<div ra-controller="contacts">` will create a `contacts` object available to the view.
|
98
|
+
Any elements inside of the element that called ra-controller will have access to that object.
|
99
|
+
Calling `ra-controller` also calls the server's index and new actions so that data is immediately available.
|
100
|
+
|
101
|
+
Data returned from the server is stored in restfully named variables.
|
102
|
+
|
103
|
+
Server calls are made via restfully named functions.
|
104
|
+
Rangular functions should be run only as needed and not displayed like model data.
|
105
|
+
Attempting to display functions as model data will create an infinite loop of server calls.
|
106
|
+
That's a very bad thing.
|
107
|
+
|
108
|
+
* Good:
|
109
|
+
`<button ng-click="contacts.callIndex()">`
|
110
|
+
* Bad:
|
111
|
+
`{{ contacts.callIndex() }}`
|
112
|
+
|
113
|
+
Show and edit actions are both called by providing Rangular with an id via `setId(id)`.
|
114
|
+
Show and edit data are cleared with the `clearId()` function.
|
115
|
+
|
116
|
+
Each restful action has a corresponding loading variable to change what is displayed as your data is loading.
|
117
|
+
|
118
|
+
And for the more adventurous, each function calls a broadcaster that you can set up listeners for upon success or failure.
|
119
|
+
Each function allows for success and failure functions to be passed in as well.
|
120
|
+
|
121
|
+
Options
|
122
|
+
-------
|
123
|
+
These options can be used with the rangular controller declaration:
|
124
|
+
|
125
|
+
* `ra-query`
|
126
|
+
Used to pass extra params to the server.
|
127
|
+
Pass in params with the JS object syntax.
|
128
|
+
example: `<div ra-controller="notes" ra-query="{page:4, limit:10}">`
|
129
|
+
|
130
|
+
* `ra-show`
|
131
|
+
Used to render a single element by default instead of an index.
|
132
|
+
example: `<div ra-controller="notes" ra-show="42">`
|
133
|
+
|
134
|
+
Functions
|
135
|
+
---------
|
136
|
+
All functions are called like `controller_name.callIndex` where controller_name is the name of your controller.
|
137
|
+
|
138
|
+
`callIndex([query], [success_function, [failure_function]])`
|
139
|
+
|
140
|
+
* automatically called when `ra-controller="controller_name"` is called
|
141
|
+
* ignores `query.id` and any id set by `setId()`
|
142
|
+
* sets variable `indexLoading` while waiting for server
|
143
|
+
* broadcasts "controller_name.index ready" when finished successfully
|
144
|
+
* broadcasts "controller_name.index error" when finished with errors
|
145
|
+
* calls success_function when finished successfully
|
146
|
+
* calls failure_function when finished with errors
|
147
|
+
|
148
|
+
`callShow([query], [success_function, [failure_function]])`
|
149
|
+
|
150
|
+
* automatically called when id is set
|
151
|
+
* sets variable `showLoading` while waiting for server
|
152
|
+
* broadcasts "controller_name.show ready" when finished successfully
|
153
|
+
* broadcasts "controller_name.show error" when finished with errors
|
154
|
+
* calls success_function when finished successfully
|
155
|
+
* calls failure_function when finished with errors
|
156
|
+
|
157
|
+
`callNew([query], [success_function, [failure_function]])`
|
158
|
+
|
159
|
+
* automatically called when `ra-controller="controller_name"` is called
|
160
|
+
* sets variable `newLoading` while waiting for server
|
161
|
+
* broadcasts "controller_name.new ready" when finished successfully
|
162
|
+
* broadcasts "controller_name.new error" when finished with errors
|
163
|
+
* calls success_function when finished successfully
|
164
|
+
* calls failure_function when finished with errors
|
165
|
+
|
166
|
+
`callCreate([query], [success_function, [failure_function]])`
|
167
|
+
|
168
|
+
* sets variable `createLoading` while waiting for server
|
169
|
+
* broadcasts "controller_name.create success" when finished successfully
|
170
|
+
* broadcasts "controller_name.create failure" when finished with errors
|
171
|
+
* calls success_function when finished successfully
|
172
|
+
* calls failure_function when finished with errors
|
173
|
+
* calls index and new upon success
|
174
|
+
|
175
|
+
`callEdit([query], [success_function, [failure_function]])`
|
176
|
+
|
177
|
+
* automatically called when id is set
|
178
|
+
* sets variable `editLoading` while waiting for server
|
179
|
+
* broadcasts "controller_name.edit ready" when finished successfully
|
180
|
+
* broadcasts "controller_name.edit error" when finished with errors
|
181
|
+
* calls success_function when finished successfully
|
182
|
+
* calls failure_function when finished with errors
|
183
|
+
|
184
|
+
`callUpdate([query], [success_function, [failure_function]])`
|
185
|
+
|
186
|
+
* sets variable `updateLoading` while waiting for server
|
187
|
+
* broadcasts "controller_name.update success" when finished successfully
|
188
|
+
* broadcasts "controller_name.update failure" when finished with errors
|
189
|
+
* calls success_function when finished successfully
|
190
|
+
* calls failure_function when finished with errors
|
191
|
+
* calls index and new upon success
|
192
|
+
|
193
|
+
`callDelete(id, [query])`
|
194
|
+
|
195
|
+
* sets variable `deleteLoading` while waiting for server
|
196
|
+
* broadcasts "controller_name.delete success" when finished successfully
|
197
|
+
* broadcasts "controller_name.delete failure" when finished with errors
|
198
|
+
* calls index and new upon success
|
199
|
+
|
200
|
+
`setId(id)`
|
201
|
+
|
202
|
+
* sets variable `id`
|
203
|
+
* makes id available from any function
|
204
|
+
|
205
|
+
|
206
|
+
|
207
|
+
`clearId()`
|
208
|
+
|
209
|
+
* clears variable `id`
|
210
|
+
|
211
|
+
|
212
|
+
|
213
|
+
Variables
|
214
|
+
---------
|
215
|
+
All variables are called like `controller_name.index` where controller_name is the name of your controller.
|
216
|
+
|
217
|
+
The restful variables are index, show, edit, and new.
|
218
|
+
These variables contain the JSON that was returned from the server during a successful call.
|
219
|
+
|
220
|
+
The error variables are createError and updateError.
|
221
|
+
These variables contain error data that was returned from rails.
|
222
|
+
The errors come in the form of a hash where the keys are field names and the values are arrays of errors.
|
223
|
+
Example:
|
224
|
+
|
225
|
+
"createError":{"name": ["can't be blank","is too short (minimum is 5 characters)"],
|
226
|
+
"content": ["is too short (minimum is 20 characters)"],
|
227
|
+
"user": ["can't be blank"]}
|
228
|
+
|
229
|
+
Other variables are query and id.
|
230
|
+
These probably shouldn't be changed directly as it can interfere with the internal workings of Rangular.
|
231
|
+
The query can be set as an option and the id can be changed with the `setId(id)` and `clearId()` functions.
|
232
|
+
Also, queries can be passed in to any of the restful call functions.
|
233
|
+
|
234
|
+
Callbacks and Broadcasters
|
235
|
+
--------------------------
|
236
|
+
#### Callbacks
|
237
|
+
Callbacks may be buggy, have unforseen concequences, and summon unknowable horrors from the darkest pits.
|
238
|
+
Proceed with caution or use broadcasters.
|
239
|
+
|
240
|
+
Callbacks (success and failure functions) should be declared as variables in JS.
|
241
|
+
I don't believe it's even possible to pass a function through HTML using Angular.
|
242
|
+
And even if you can, that's a very bad practice.
|
243
|
+
|
244
|
+
If you want to hide a form after a successfull server call, it would look something like this:
|
245
|
+
|
246
|
+
var shutNew = function() {
|
247
|
+
$scope.showNewNotes = false;
|
248
|
+
}
|
249
|
+
|
250
|
+
Then in HTML:
|
251
|
+
|
252
|
+
<form ng-show="showNewNotes">
|
253
|
+
<button ng-click="notes.callCreate(shutNew)">
|
254
|
+
</form>
|
255
|
+
|
256
|
+
Rangular uses scope without the dollar sign internally.
|
257
|
+
So if you want to access rangular variables from inside your own JS:
|
258
|
+
|
259
|
+
if(scope.notes.id) {
|
260
|
+
do.something.awesome;
|
261
|
+
}
|
262
|
+
|
263
|
+
#### Broadcasters
|
264
|
+
Rangular uses `$broadcast` instead of `$emit` as broadcast sends messages down the scope stack to all the children.
|
265
|
+
Whereas emit sends messages up the scope stack to all the ancestors.
|
266
|
+
It was my goal in creating Rangular to allow controllers to be used multiple times during a page and to allow multiple controllers in a page.
|
267
|
+
As that's the case, I didn't want broadcasters to interfere with any other controllers.
|
268
|
+
|
269
|
+
In your JS:
|
270
|
+
|
271
|
+
$scope.$on('notes.show ready', function() {
|
272
|
+
do.something.awesome;
|
273
|
+
});
|
274
|
+
|
275
|
+
Planned Features and Bug Fixes
|
276
|
+
----------------------------
|
277
|
+
* implement callbacks in callDelete() function
|
278
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/lib/rangular.rb
ADDED
data/rangular.gemspec
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'rangular/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "rangular"
|
8
|
+
spec.version = Rangular::Rails::VERSION
|
9
|
+
spec.authors = ["Lee Nathan"]
|
10
|
+
spec.email = ["leetheguy@gmail.com"]
|
11
|
+
spec.description = %q{put AJAX data updates in your HTML without writing JS}
|
12
|
+
spec.summary = %q{
|
13
|
+
Rangular empowers skilled Rails developers to add AJAX to their sites quickly and easily.
|
14
|
+
Rangular uses the power of the Angular framework to allow AJAX calls to be made to a Rails server without writing Javascript.
|
15
|
+
}
|
16
|
+
spec.homepage = "https://github.com/leetheguy/rangular"
|
17
|
+
spec.license = "MIT"
|
18
|
+
|
19
|
+
spec.files = `git ls-files`.split($/)
|
20
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
21
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
22
|
+
spec.require_paths = ["lib"]
|
23
|
+
|
24
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
25
|
+
spec.add_development_dependency "rake"
|
26
|
+
end
|
@@ -0,0 +1,294 @@
|
|
1
|
+
var railsRoutesSet, rangular;
|
2
|
+
|
3
|
+
rangular = angular.module('rangular', ["ngResource"]);
|
4
|
+
|
5
|
+
railsRoutesSet = {
|
6
|
+
index: {
|
7
|
+
method: "GET",
|
8
|
+
isArray: true
|
9
|
+
},
|
10
|
+
show: {
|
11
|
+
method: "GET"
|
12
|
+
},
|
13
|
+
"new": {
|
14
|
+
method: "GET",
|
15
|
+
params: {
|
16
|
+
verb: "new"
|
17
|
+
}
|
18
|
+
},
|
19
|
+
create: {
|
20
|
+
method: "POST"
|
21
|
+
},
|
22
|
+
edit: {
|
23
|
+
method: "GET",
|
24
|
+
params: {
|
25
|
+
verb: "edit"
|
26
|
+
}
|
27
|
+
},
|
28
|
+
update: {
|
29
|
+
method: "PUT"
|
30
|
+
},
|
31
|
+
destroy: {
|
32
|
+
method: "DELETE"
|
33
|
+
},
|
34
|
+
info: {
|
35
|
+
method: "GET",
|
36
|
+
params: {
|
37
|
+
verb: "info"
|
38
|
+
}
|
39
|
+
}
|
40
|
+
};
|
41
|
+
|
42
|
+
rangular.config([
|
43
|
+
"$httpProvider", function($httpProvider) {
|
44
|
+
$httpProvider.defaults.headers.common['X-CSRF-Token'] = $('meta[name=csrf-token]').attr('content');
|
45
|
+
$httpProvider.defaults.headers.common["X-Requested-With"] = 'XMLHttpRequest';
|
46
|
+
}
|
47
|
+
]);
|
48
|
+
|
49
|
+
rangular.factory("railsResource", [
|
50
|
+
"$resource", function($resource) {
|
51
|
+
return $resource("/:controller/:id/:verb", {
|
52
|
+
id: '@id'
|
53
|
+
}, railsRoutesSet);
|
54
|
+
}
|
55
|
+
]);
|
56
|
+
|
57
|
+
rangular.directive('raController', [
|
58
|
+
"railsResource", function(railsResource) {
|
59
|
+
return function(scope, element, attrs) {
|
60
|
+
var callShowAndEdit, rctrl;
|
61
|
+
rctrl = attrs.raController;
|
62
|
+
scope[rctrl] = {};
|
63
|
+
scope[rctrl].query = attrs.raQuery === void 0 ? {} : eval('(' + attrs.raQuery + ')');
|
64
|
+
scope[rctrl].query.controller = rctrl;
|
65
|
+
|
66
|
+
// [query], [success, [failure]]
|
67
|
+
processArgs = function() {
|
68
|
+
rargs = ({query:null, success:null, failure:null});
|
69
|
+
args = arguments[0]
|
70
|
+
|
71
|
+
if (args[0] !== undefined) {
|
72
|
+
if (Object.prototype.toString.call(args[0]) == "[object Function]") {
|
73
|
+
rargs.success = args[0];
|
74
|
+
} else {
|
75
|
+
rargs.query = args[0];
|
76
|
+
}
|
77
|
+
if (args[1] !== undefined) {
|
78
|
+
if (Object.prototype.toString.call(args[1]) == "[object Function]") {
|
79
|
+
if (!!rargs.success) {
|
80
|
+
rargs.failure = args[1];
|
81
|
+
} else {
|
82
|
+
rargs.success = args[1];
|
83
|
+
}
|
84
|
+
}
|
85
|
+
if (args[2] !== undefined) {
|
86
|
+
if (Object.prototype.toString.call(args[2]) == "[object Function]") {
|
87
|
+
if (!!!rargs.failure) {
|
88
|
+
rargs.failure = args[2];
|
89
|
+
}
|
90
|
+
}
|
91
|
+
}
|
92
|
+
}
|
93
|
+
}
|
94
|
+
return rargs;
|
95
|
+
};
|
96
|
+
|
97
|
+
scope[rctrl].callIndex = function() {
|
98
|
+
scope.indexRargs = processArgs(arguments);
|
99
|
+
|
100
|
+
scope[rctrl].indexLoading = true;
|
101
|
+
if (scope.indexRargs.query == null) {
|
102
|
+
scope.indexRargs.query = scope[rctrl].query;
|
103
|
+
}
|
104
|
+
scope.indexRargs.query.id = null;
|
105
|
+
scope[rctrl].index = railsResource.index(scope.indexRargs.query, function() {
|
106
|
+
scope.$broadcast(rctrl + '.index ready');
|
107
|
+
if(scope.indexRargs.success) {
|
108
|
+
scope.indexRargs.success();
|
109
|
+
}
|
110
|
+
scope.indexRargs = null;
|
111
|
+
scope[rctrl].indexLoading = false;
|
112
|
+
}, function() {
|
113
|
+
scope.$broadcast(rctrl + '.index error');
|
114
|
+
if(scope.indexRargs.failure) {
|
115
|
+
scope.indexRargs.failure();
|
116
|
+
}
|
117
|
+
scope.indexRargs = null;
|
118
|
+
scope[rctrl].indexLoading = false;
|
119
|
+
});
|
120
|
+
};
|
121
|
+
|
122
|
+
callShowAndEdit = function() {
|
123
|
+
rargs = processArgs(arguments);
|
124
|
+
|
125
|
+
if (rargs.query == null) {
|
126
|
+
rargs.query = scope[rctrl].query;
|
127
|
+
}
|
128
|
+
scope[rctrl].callShow(rargs.query);
|
129
|
+
scope[rctrl].callEdit(rargs.query);
|
130
|
+
};
|
131
|
+
|
132
|
+
|
133
|
+
scope[rctrl].callShow = function() {
|
134
|
+
scope.showRargs = processArgs(arguments);
|
135
|
+
|
136
|
+
if (scope.showRargs.query == null) {
|
137
|
+
scope.showRargs.query = scope[rctrl].query;
|
138
|
+
}
|
139
|
+
if (!!scope[rctrl].id) {
|
140
|
+
scope.showRargs.query.id = scope[rctrl].id;
|
141
|
+
scope[rctrl].show = railsResource.show(scope.showRargs.query, function() {
|
142
|
+
scope[rctrl].showLoading = false;
|
143
|
+
scope.$broadcast(rctrl + '.show ready');
|
144
|
+
}, function() {
|
145
|
+
scope[rctrl].showLoading = false;
|
146
|
+
});
|
147
|
+
scope.showRargs = null;
|
148
|
+
scope[rctrl].showLoading = true;
|
149
|
+
} else {
|
150
|
+
scope[rctrl].show = null;
|
151
|
+
scope.$broadcast(rctrl + '.show error');
|
152
|
+
scope.showRargs = null;
|
153
|
+
scope[rctrl].showLoading = false;
|
154
|
+
}
|
155
|
+
};
|
156
|
+
|
157
|
+
scope[rctrl].callNew = function() {
|
158
|
+
scope.newRargs = processArgs(arguments);
|
159
|
+
|
160
|
+
scope[rctrl].newLoading = true;
|
161
|
+
if (scope.newRargs.query == null) {
|
162
|
+
scope.newRargs.query = scope[rctrl].query;
|
163
|
+
}
|
164
|
+
if (!!!scope.newRargs.query.controller) {
|
165
|
+
scope.newRargs.query.controller = rctrl;
|
166
|
+
}
|
167
|
+
scope[rctrl]["new"] = railsResource["new"](scope.newRargs.query, function() {
|
168
|
+
scope[rctrl].createError = null;
|
169
|
+
scope.$broadcast(rctrl + '.new ready');
|
170
|
+
scope.newRargs = null;
|
171
|
+
scope[rctrl].newLoading = false;
|
172
|
+
}, function() {
|
173
|
+
scope.$broadcast(rctrl + '.new error');
|
174
|
+
scope.newRargs = null;
|
175
|
+
scope[rctrl].newLoading = false;
|
176
|
+
});
|
177
|
+
};
|
178
|
+
|
179
|
+
scope[rctrl].callEdit = function() {
|
180
|
+
scope.editRargs = processArgs(arguments);
|
181
|
+
|
182
|
+
if (scope.editRargs.query == null) {
|
183
|
+
scope.editRargs.query = scope[rctrl].query;
|
184
|
+
}
|
185
|
+
if (!!!scope.editRargs.query.controller) {
|
186
|
+
scope.editRargs.query.controller = rctrl;
|
187
|
+
}
|
188
|
+
if (!!scope[rctrl].id) {
|
189
|
+
scope[rctrl].editLoading = true;
|
190
|
+
scope.editRargs.query.id = scope[rctrl].id;
|
191
|
+
scope[rctrl].edit = railsResource.edit(scope.editRargs.query, function() {
|
192
|
+
scope[rctrl].updateError = null;
|
193
|
+
scope[rctrl].editLoading = false;
|
194
|
+
scope.$broadcast(rctrl + '.edit ready');
|
195
|
+
}, function() {
|
196
|
+
scope.$broadcast(rctrl + '.edit error');
|
197
|
+
});
|
198
|
+
scope.editRargs = null;
|
199
|
+
} else {
|
200
|
+
scope[rctrl].editLoading = false;
|
201
|
+
scope[rctrl].edit = null;
|
202
|
+
scope.editRargs = null;
|
203
|
+
}
|
204
|
+
};
|
205
|
+
|
206
|
+
scope[rctrl].callCreate = function() {
|
207
|
+
scope.createRargs = processArgs(arguments);
|
208
|
+
|
209
|
+
scope[rctrl].createLoading = true;
|
210
|
+
if (scope.createRargs.query == null) {
|
211
|
+
scope.createRargs.query = scope[rctrl].query;
|
212
|
+
}
|
213
|
+
scope[rctrl]["new"].$create(scope.createRargs.query, function() {
|
214
|
+
scope[rctrl].callNew();
|
215
|
+
scope[rctrl].callIndex();
|
216
|
+
scope[rctrl].createError = null;
|
217
|
+
scope.$broadcast(rctrl + '.create success');
|
218
|
+
scope.createRargs = null;
|
219
|
+
scope[rctrl].createLoading = false;
|
220
|
+
}, function(object) {
|
221
|
+
if (object.data) {
|
222
|
+
scope[rctrl].createError = object.data;
|
223
|
+
}
|
224
|
+
scope.$broadcast(rctrl + '.create failure');
|
225
|
+
scope.createRargs = null;
|
226
|
+
scope[rctrl].createLoading = false;
|
227
|
+
});
|
228
|
+
};
|
229
|
+
|
230
|
+
scope[rctrl].callUpdate = function() {
|
231
|
+
scope.updateRargs = processArgs(arguments);
|
232
|
+
|
233
|
+
scope[rctrl].updateLoading = true;
|
234
|
+
if (scope.updateRargs.query == null) {
|
235
|
+
scope.updateRargs.query = scope[rctrl].query;
|
236
|
+
}
|
237
|
+
scope[rctrl]["edit"].$update(scope.updateRargs.query, function() {
|
238
|
+
scope[rctrl].updateError = null;
|
239
|
+
scope[rctrl].callIndex();
|
240
|
+
scope.$broadcast(rctrl + '.update success');
|
241
|
+
scope.updateRargs = null;
|
242
|
+
scope[rctrl].updateLoading = false;
|
243
|
+
}, function(object) {
|
244
|
+
if (object.data) {
|
245
|
+
scope[rctrl].updateError = object.data;
|
246
|
+
}
|
247
|
+
scope.$broadcast(rctrl + '.update failure');
|
248
|
+
scope.updateRargs = null;
|
249
|
+
scope[rctrl].updateLoading = false;
|
250
|
+
});
|
251
|
+
};
|
252
|
+
|
253
|
+
scope[rctrl].callDelete = function(id, query) {
|
254
|
+
scope[rctrl].deleteLoading = true;
|
255
|
+
if (query == null) {
|
256
|
+
query = scope[rctrl].query;
|
257
|
+
}
|
258
|
+
if (!query.id) {
|
259
|
+
query.id = id;
|
260
|
+
}
|
261
|
+
railsResource["delete"](query, function() {
|
262
|
+
scope[rctrl].callIndex();
|
263
|
+
scope.$broadcast(rctrl + '.delete success');
|
264
|
+
scope.updateRargs = null;
|
265
|
+
scope[rctrl].deleteLoading = false;
|
266
|
+
}, function() {
|
267
|
+
scope.$broadcast(rctrl + '.delete failure');
|
268
|
+
scope[rctrl].deleteLoading = false;
|
269
|
+
});
|
270
|
+
};
|
271
|
+
|
272
|
+
scope[rctrl].clearId = function() {
|
273
|
+
scope[rctrl].id = null;
|
274
|
+
callShowAndEdit();
|
275
|
+
};
|
276
|
+
|
277
|
+
scope[rctrl].setId = function(id) {
|
278
|
+
if (id == null) {
|
279
|
+
id = attrs.raShow;
|
280
|
+
}
|
281
|
+
scope[rctrl].id = id;
|
282
|
+
callShowAndEdit();
|
283
|
+
};
|
284
|
+
|
285
|
+
scope[rctrl].callNew();
|
286
|
+
if (!!!attrs.raShow) {
|
287
|
+
scope[rctrl].callIndex();
|
288
|
+
scope[rctrl].clearId();
|
289
|
+
} else {
|
290
|
+
scope[rctrl].setId();
|
291
|
+
}
|
292
|
+
};
|
293
|
+
}
|
294
|
+
]);
|
metadata
ADDED
@@ -0,0 +1,83 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rangular
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0.alpha
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Lee Nathan
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-01-05 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.3'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
description: put AJAX data updates in your HTML without writing JS
|
42
|
+
email:
|
43
|
+
- leetheguy@gmail.com
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- ".gitignore"
|
49
|
+
- Gemfile
|
50
|
+
- LICENSE.txt
|
51
|
+
- README.md
|
52
|
+
- Rakefile
|
53
|
+
- lib/rangular.rb
|
54
|
+
- lib/rangular/version.rb
|
55
|
+
- rangular.gemspec
|
56
|
+
- vendor/assets/javascripts/rangular.js
|
57
|
+
homepage: https://github.com/leetheguy/rangular
|
58
|
+
licenses:
|
59
|
+
- MIT
|
60
|
+
metadata: {}
|
61
|
+
post_install_message:
|
62
|
+
rdoc_options: []
|
63
|
+
require_paths:
|
64
|
+
- lib
|
65
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - ">="
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - ">"
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: 1.3.1
|
75
|
+
requirements: []
|
76
|
+
rubyforge_project:
|
77
|
+
rubygems_version: 2.2.0
|
78
|
+
signing_key:
|
79
|
+
specification_version: 4
|
80
|
+
summary: Rangular empowers skilled Rails developers to add AJAX to their sites quickly
|
81
|
+
and easily. Rangular uses the power of the Angular framework to allow AJAX calls
|
82
|
+
to be made to a Rails server without writing Javascript.
|
83
|
+
test_files: []
|