merb-extjs-direct 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +4 -0
- data/Manifest.txt +1 -0
- data/README.txt +141 -0
- data/lib/merb-extjs-direct.rb +1 -1
- metadata +3 -1
data/History.txt
CHANGED
data/Manifest.txt
CHANGED
data/README.txt
ADDED
@@ -0,0 +1,141 @@
|
|
1
|
+
= merb-extjs-direct
|
2
|
+
|
3
|
+
http://rubyforge.org/projects/merb-extjs/
|
4
|
+
http://www.extjs.com
|
5
|
+
|
6
|
+
== DESCRIPTION:
|
7
|
+
|
8
|
+
A series of components for implementing the Ext.Direct API specification in Merb. Ext.Direct in Merb utilizes
|
9
|
+
merb-parts. Each part can define a CRUD api which router will dispatch requests to.
|
10
|
+
|
11
|
+
Includes a Controller mixin for giving a controller the ability to act as an Ext.Direct RemotingProvider. This mixin
|
12
|
+
turns the Controller into an Ext.Direct router.
|
13
|
+
|
14
|
+
== FEATURES/PROBLEMS:
|
15
|
+
|
16
|
+
== SYNOPSIS:
|
17
|
+
|
18
|
+
First include the RemotingProvider mixin into a high-level controller non-specific to any particular model. This
|
19
|
+
mixin will turn the controller into a Router, routing requests into a Merb::PartController.
|
20
|
+
|
21
|
+
|
22
|
+
This mixin will add a callable action named "rpc" to the whichever included into. You can then set this as the
|
23
|
+
url for your Ext.Direct configuration in javascript. For the Admin controller above, the url would be
|
24
|
+
"/admin/rpc"
|
25
|
+
|
26
|
+
class Admin < Application
|
27
|
+
include Merb::ExtJS::Direct::RemotingProvider
|
28
|
+
end
|
29
|
+
|
30
|
+
<script>
|
31
|
+
Ext.Direct.addProvider({
|
32
|
+
url: '/admin/rpc', //<-- Note the url corresponding to Admin above.
|
33
|
+
type: 'remoting',
|
34
|
+
actions: {
|
35
|
+
UserPart : [ // <-- UserPart is a Merb::PartController
|
36
|
+
{name: 'load', len: 1},
|
37
|
+
{name: 'save', len: 2},
|
38
|
+
{name: 'create', len: 1},
|
39
|
+
{name: 'destroy', len: 1}
|
40
|
+
]
|
41
|
+
}
|
42
|
+
});
|
43
|
+
</script>
|
44
|
+
|
45
|
+
When an Ext.Direct request is serviced by the RemotingProvider mixin, it will create an XRequest instance and attach
|
46
|
+
it to the Controller's params upon the symbol :xrequest.
|
47
|
+
|
48
|
+
Following is a typical PartController receiving Ext.Direct requests. Notice each request begins by retrieving
|
49
|
+
the XRequest instance from params then instantiating an XResponse feeding it the XRequest instance into the
|
50
|
+
constructor.
|
51
|
+
|
52
|
+
Each request ends by simply calling the to_json method upon the XResponse instance.
|
53
|
+
|
54
|
+
class UserPart < Merb::PartController
|
55
|
+
def create
|
56
|
+
req = params[:xrequest]
|
57
|
+
res = XResponse.new(req)
|
58
|
+
res.success = User.create(req.params)
|
59
|
+
res.message = "Created user"
|
60
|
+
res.to_json
|
61
|
+
end
|
62
|
+
|
63
|
+
def load
|
64
|
+
req = params[:xrequest]
|
65
|
+
res = XResponse.new(req)
|
66
|
+
res.data = User.all.collect{|u|u.to_hash}
|
67
|
+
res.success = true
|
68
|
+
res.message = "Loaded stuff"
|
69
|
+
end
|
70
|
+
|
71
|
+
def save
|
72
|
+
req = params[:xrequest]
|
73
|
+
res = XResponse.new(req)
|
74
|
+
if u = User.first(:id => req.id)
|
75
|
+
res.success = u.update_attributes(req.params)
|
76
|
+
res.message = "Saved User"
|
77
|
+
else
|
78
|
+
raise XException.new("Failed to load that user")
|
79
|
+
end
|
80
|
+
res.to_json
|
81
|
+
end
|
82
|
+
|
83
|
+
def destroy
|
84
|
+
req = params[:xrequest]
|
85
|
+
res = XResponse.new(req)
|
86
|
+
if u = User.first(:id => req.id)
|
87
|
+
res.success = u.destroy
|
88
|
+
res.message = "Destroyed User"
|
89
|
+
else
|
90
|
+
raise XException.new("Failed to load that User"
|
91
|
+
end
|
92
|
+
res.to_json
|
93
|
+
end
|
94
|
+
|
95
|
+
end
|
96
|
+
|
97
|
+
== REQUIREMENTS:
|
98
|
+
|
99
|
+
merb-parts
|
100
|
+
|
101
|
+
== INSTALL:
|
102
|
+
|
103
|
+
sudo gem install merb-extjs-parts
|
104
|
+
|
105
|
+
IMPORTANT: This gem includes a required javascript file named "merb-extjs-direct.js" in the root of this gem.
|
106
|
+
Currently you MUST copy this file to your /public/javascripts directory and included it immediately the ext
|
107
|
+
framework's assets (ie: immediately after "ext-all.js").
|
108
|
+
|
109
|
+
merb-extjs-direct.js contains a couple of simple overrides of the Ext.Direct library which will rename two
|
110
|
+
HTTP request parameters to be more Merb/Rails-like. By default, Ext.Direct uses the word "action" where Merb
|
111
|
+
uses "controller" and "method" vs "action". Confusing, eh? The HTTP params are actually renamed xcontroller
|
112
|
+
and xaction to not interfere with Merb reserved words. If you don't see "xcontroller" / "xaction" params
|
113
|
+
in your Ajax requests, make sure you've got merb-ext-direct.js included.
|
114
|
+
|
115
|
+
In the future, I'll have >rake install automaticlly copy this file to /public/javascripts (Would anyone like to
|
116
|
+
contribute some code to do that?)
|
117
|
+
|
118
|
+
== LICENSE:
|
119
|
+
|
120
|
+
(The MIT License)
|
121
|
+
|
122
|
+
Copyright (c) 2009 FIX
|
123
|
+
|
124
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
125
|
+
a copy of this software and associated documentation files (the
|
126
|
+
'Software'), to deal in the Software without restriction, including
|
127
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
128
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
129
|
+
permit persons to whom the Software is furnished to do so, subject to
|
130
|
+
the following conditions:
|
131
|
+
|
132
|
+
The above copyright notice and this permission notice shall be
|
133
|
+
included in all copies or substantial portions of the Software.
|
134
|
+
|
135
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
136
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
137
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
138
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
139
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
140
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
141
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/lib/merb-extjs-direct.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: merb-extjs-direct
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- christocracy
|
@@ -32,10 +32,12 @@ extensions: []
|
|
32
32
|
extra_rdoc_files:
|
33
33
|
- History.txt
|
34
34
|
- Manifest.txt
|
35
|
+
- README.txt
|
35
36
|
files:
|
36
37
|
- History.txt
|
37
38
|
- Manifest.txt
|
38
39
|
- README.rdoc
|
40
|
+
- README.txt
|
39
41
|
- Rakefile
|
40
42
|
- merb-extjs-direct.js
|
41
43
|
- lib/merb-extjs-direct.rb
|