ext_direct 0.1.1 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +1 -0
- data/VERSION +1 -1
- data/ext_direct.gemspec +4 -2
- data/lib/ext_direct/api.rb +19 -0
- data/lib/ext_direct/router.rb +1 -1
- data/lib/ext_direct/service/configuration.rb +39 -0
- data/lib/ext_direct/service/provider.rb +4 -0
- metadata +6 -4
data/README.rdoc
CHANGED
@@ -21,6 +21,7 @@ Install as a gem:
|
|
21
21
|
Then in "config/environment.rb" require middleware:
|
22
22
|
|
23
23
|
config.middleware.use "ExtDirect::Router", "/direct"
|
24
|
+
config.middleware.use "ExtDirect::API", "/direct_api", "/direct"
|
24
25
|
|
25
26
|
Great job! Now you are ready to use this library. Remember, this release is tested and runs with Rails 2.3.
|
26
27
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.2.0
|
data/ext_direct.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{ext_direct}
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.2.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Marcin Lewandowski"]
|
12
|
-
s.date = %q{2010-06-
|
12
|
+
s.date = %q{2010-06-13}
|
13
13
|
s.description = %q{The Ext Direct plugin is a simple implementation of Ext Direct router to call server-side methods on the client-side.}
|
14
14
|
s.email = %q{marcin.martio.lewandowski@gmail.com}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -25,11 +25,13 @@ Gem::Specification.new do |s|
|
|
25
25
|
"ext_direct.gemspec",
|
26
26
|
"install.rb",
|
27
27
|
"lib/ext_direct.rb",
|
28
|
+
"lib/ext_direct/api.rb",
|
28
29
|
"lib/ext_direct/dispatcher.rb",
|
29
30
|
"lib/ext_direct/request.rb",
|
30
31
|
"lib/ext_direct/response.rb",
|
31
32
|
"lib/ext_direct/router.rb",
|
32
33
|
"lib/ext_direct/service/base.rb",
|
34
|
+
"lib/ext_direct/service/configuration.rb",
|
33
35
|
"lib/ext_direct/service/provider.rb",
|
34
36
|
"rails/init.rb",
|
35
37
|
"test/ext_direct_test.rb",
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'json'
|
2
|
+
|
3
|
+
module ExtDirect
|
4
|
+
class API
|
5
|
+
def initialize(app, api_path = "/api", route_path = "/direct", constant_name = "Ext.app.REMOTING_API")
|
6
|
+
@app, @api_path, @route_path, @constant_name = app, api_path, route_path, constant_name
|
7
|
+
end
|
8
|
+
|
9
|
+
def call(env)
|
10
|
+
if env["PATH_INFO"].match("^#{@api_path}$")
|
11
|
+
response = ExtDirect::Response.new("", 200, {"Content-Type" => "text/javascript"})
|
12
|
+
response.write("#{@constant_name} = #{ExtDirect::Service::Configuration.generate(@route_path).to_json}")
|
13
|
+
response.finish
|
14
|
+
else
|
15
|
+
@app.call(env)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
data/lib/ext_direct/router.rb
CHANGED
@@ -0,0 +1,39 @@
|
|
1
|
+
module ExtDirect
|
2
|
+
module Service
|
3
|
+
class Configuration
|
4
|
+
class << self
|
5
|
+
def generate(route_path)
|
6
|
+
config = {}
|
7
|
+
config['url'] = route_path
|
8
|
+
config['type'] = "remoting"
|
9
|
+
config['actions'] = {}
|
10
|
+
|
11
|
+
services = ExtDirect::Service::Provider.fetch
|
12
|
+
services.each do |action,methods|
|
13
|
+
action = normalize_action(action)
|
14
|
+
config['actions'][action] = []
|
15
|
+
methods.each do |method,params|
|
16
|
+
config['actions'][action] << {:name => normalize_method(method), :len => 1} if params[:type] == :remoting
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
config
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def normalize_action(name)
|
26
|
+
camelize(name)
|
27
|
+
end
|
28
|
+
|
29
|
+
def normalize_method(name)
|
30
|
+
(name.to_s)[0].chr.downcase + (camelize(name.to_s))[1..-1]
|
31
|
+
end
|
32
|
+
|
33
|
+
def camelize(name)
|
34
|
+
name.to_s.gsub(/\/(.?)/) { "::#{$1.upcase}" }.gsub(/(?:^|_)(.)/) { $1.upcase }
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
metadata
CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
|
|
4
4
|
prerelease: false
|
5
5
|
segments:
|
6
6
|
- 0
|
7
|
-
-
|
8
|
-
-
|
9
|
-
version: 0.
|
7
|
+
- 2
|
8
|
+
- 0
|
9
|
+
version: 0.2.0
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Marcin Lewandowski
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-06-
|
17
|
+
date: 2010-06-13 00:00:00 +02:00
|
18
18
|
default_executable:
|
19
19
|
dependencies: []
|
20
20
|
|
@@ -36,11 +36,13 @@ files:
|
|
36
36
|
- ext_direct.gemspec
|
37
37
|
- install.rb
|
38
38
|
- lib/ext_direct.rb
|
39
|
+
- lib/ext_direct/api.rb
|
39
40
|
- lib/ext_direct/dispatcher.rb
|
40
41
|
- lib/ext_direct/request.rb
|
41
42
|
- lib/ext_direct/response.rb
|
42
43
|
- lib/ext_direct/router.rb
|
43
44
|
- lib/ext_direct/service/base.rb
|
45
|
+
- lib/ext_direct/service/configuration.rb
|
44
46
|
- lib/ext_direct/service/provider.rb
|
45
47
|
- rails/init.rb
|
46
48
|
- test/ext_direct_test.rb
|