rails-extjs-direct 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/.project ADDED
@@ -0,0 +1,17 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <projectDescription>
3
+ <name>rails-extjs-direct</name>
4
+ <comment></comment>
5
+ <projects>
6
+ </projects>
7
+ <buildSpec>
8
+ <buildCommand>
9
+ <name>org.rubypeople.rdt.core.rubybuilder</name>
10
+ <arguments>
11
+ </arguments>
12
+ </buildCommand>
13
+ </buildSpec>
14
+ <natures>
15
+ <nature>org.rubypeople.rdt.core.rubynature</nature>
16
+ </natures>
17
+ </projectDescription>
data/History.txt ADDED
@@ -0,0 +1,4 @@
1
+ == 0.0.1 2009-04-29
2
+
3
+ * 1 major enhancement:
4
+ * Initial release
data/Manifest.txt ADDED
@@ -0,0 +1,17 @@
1
+ .project
2
+ History.txt
3
+ Manifest.txt
4
+ PostInstall.txt
5
+ README.rdoc
6
+ Rakefile
7
+ lib/rails-extjs-direct.rb
8
+ lib/rails-extjs-direct/mixins/action_controller/direct_controller.rb
9
+ lib/rails-extjs-direct/rack/remoting_provider.rb
10
+ lib/rails-extjs-direct/xexception.rb
11
+ lib/rails-extjs-direct/xrequest.rb
12
+ lib/rails-extjs-direct/xresponse.rb
13
+ script/console
14
+ script/destroy
15
+ script/generate
16
+ test/test_helper.rb
17
+ test/test_rails-extjs-direct.rb
data/PostInstall.txt ADDED
@@ -0,0 +1,7 @@
1
+
2
+ For more information on rails-extjs-direct, see http://rails-extjs-direct.rubyforge.org
3
+
4
+ NOTE: Change this information in PostInstall.txt
5
+ You can also delete it if you don't want it.
6
+
7
+
data/README.rdoc ADDED
@@ -0,0 +1,75 @@
1
+ = rails-extjs-direct
2
+ THIS GEM IS UNDER DEVELOPMENT AND WILL NOT YET WORK!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
3
+
4
+ http://rubyforge.org/projects/rails-extjs/
5
+ http://www.extjs.com
6
+
7
+ == DESCRIPTION:
8
+
9
+ A series of components for implementing the Ext.Direct API specification in Rails 2.3 and higher.
10
+ Ext.Direct in Rails is implementede with Rack Middleware.
11
+
12
+ == FEATURES/PROBLEMS:
13
+
14
+ == SYNOPSIS:
15
+
16
+ <script>
17
+ Ext.Direct.addProvider({
18
+ url: '/admin/rpc', //<-- Note the url corresponding to Admin above.
19
+ type: 'remoting',
20
+ actions: {
21
+ Users : [
22
+ {name: 'load', len: 1},
23
+ {name: 'save', len: 2},
24
+ {name: 'create', len: 1},
25
+ {name: 'destroy', len: 1}
26
+ ]
27
+ }
28
+ });
29
+ </script>
30
+
31
+ == REQUIREMENTS:
32
+
33
+ merb-parts
34
+
35
+ == INSTALL:
36
+
37
+ sudo gem install merb-extjs-parts
38
+
39
+ IMPORTANT: This gem includes a required javascript file named "merb-extjs-direct.js" in the root of this gem.
40
+ Currently you MUST copy this file to your /public/javascripts directory and included it immediately the ext
41
+ framework's assets (ie: immediately after "ext-all.js").
42
+
43
+ merb-extjs-direct.js contains a couple of simple overrides of the Ext.Direct library which will rename two
44
+ HTTP request parameters to be more Merb/Rails-like. By default, Ext.Direct uses the word "action" where Merb
45
+ uses "controller" and "method" vs "action". Confusing, eh? The HTTP params are actually renamed xcontroller
46
+ and xaction to not interfere with Merb reserved words. If you don't see "xcontroller" / "xaction" params
47
+ in your Ajax requests, make sure you've got merb-ext-direct.js included.
48
+
49
+ In the future, I'll have >rake install automaticlly copy this file to /public/javascripts (Would anyone like to
50
+ contribute some code to do that?)
51
+
52
+ == LICENSE:
53
+
54
+ (The MIT License)
55
+
56
+ Copyright (c) 2009 FIX
57
+
58
+ Permission is hereby granted, free of charge, to any person obtaining
59
+ a copy of this software and associated documentation files (the
60
+ 'Software'), to deal in the Software without restriction, including
61
+ without limitation the rights to use, copy, modify, merge, publish,
62
+ distribute, sublicense, and/or sell copies of the Software, and to
63
+ permit persons to whom the Software is furnished to do so, subject to
64
+ the following conditions:
65
+
66
+ The above copyright notice and this permission notice shall be
67
+ included in all copies or substantial portions of the Software.
68
+
69
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
70
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
71
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
72
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
73
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
74
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
75
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1,28 @@
1
+ %w[rubygems rake rake/clean fileutils newgem rubigen].each { |f| require f }
2
+ require File.dirname(__FILE__) + '/lib/rails-extjs-direct'
3
+
4
+ # Generate all the Rake tasks
5
+ # Run 'rake -T' to see list of generated tasks (from gem root directory)
6
+ $hoe = Hoe.new('rails-extjs-direct', Rails::ExtJS::Direct::VERSION) do |p|
7
+ p.developer('Chris Scott', 'christocracy@gmail.com')
8
+ p.changes = p.paragraphs_of("History.txt", 0..1).join("\n\n")
9
+ p.post_install_message = 'PostInstall.txt' # TODO remove if post-install message not required
10
+ p.rubyforge_name = "rails-extjs"
11
+ # p.extra_deps = [
12
+ # ['activesupport','>= 2.0.2'],
13
+ # ]
14
+ p.extra_dev_deps = [
15
+ ['newgem', ">= #{::Newgem::VERSION}"]
16
+ ]
17
+
18
+ p.clean_globs |= %w[**/.DS_Store tmp *.log]
19
+ path = (p.rubyforge_name == p.name) ? p.rubyforge_name : "\#{p.rubyforge_name}/\#{p.name}"
20
+ p.remote_rdoc_dir = File.join(path.gsub(/^#{p.rubyforge_name}\/?/,''), 'rdoc')
21
+ p.rsync_args = '-av --delete --ignore-errors'
22
+ end
23
+
24
+ require 'newgem/tasks' # load /tasks/*.rake
25
+ Dir['tasks/**/*.rake'].each { |t| load t }
26
+
27
+ # TODO - want other tests/tasks run by default? Add them to the list
28
+ # task :default => [:spec, :features]
@@ -0,0 +1,15 @@
1
+ #$:.unshift(File.dirname(__FILE__)) unless
2
+ # $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
3
+
4
+ module Rails
5
+ module ExtJS
6
+ module Direct
7
+ VERSION = '0.0.1'
8
+ end
9
+ end
10
+ end
11
+ require File.join(File.dirname(__FILE__), 'rails-extjs-direct', 'xresponse')
12
+ require File.join(File.dirname(__FILE__), 'rails-extjs-direct', 'xrequest')
13
+ require File.join(File.dirname(__FILE__), 'rails-extjs-direct', 'xexception')
14
+ require File.join(File.dirname(__FILE__), 'rails-extjs-direct', 'rack', 'remoting_provider')
15
+ require File.join(File.dirname(__FILE__), 'rails-extjs-direct', 'mixins', 'action_controller', 'direct_controller')
@@ -0,0 +1,12 @@
1
+ module Rails::ExtJS::Direct::Controller
2
+
3
+ # standard ruby method called when some class does:
4
+ # include Merb::ExtJS::Direct::RemotingProvider
5
+ def self.included(base)
6
+ base.before_filter :extjs_direct_prepare_request
7
+ end
8
+
9
+ def extjs_direct_prepare_request
10
+ params["xrequest"] = "XRequest.new" # <-- TODO: prepare XRequest
11
+ end
12
+ end
@@ -0,0 +1,49 @@
1
+ require 'json'
2
+ class Rails::ExtJS::Direct::RemotingProvider
3
+ def initialize(app, rpath)
4
+ @app = app
5
+ @router_path = rpath
6
+ @logger = RAILS_DEFAULT_LOGGER
7
+ @params = {}
8
+ end
9
+
10
+ def call(env)
11
+
12
+ if env["PATH_INFO"].match("^"+@router_path)
13
+ parse_params(env)
14
+ @logger.info('chris is here bitches ' + @params["foo"].to_s)
15
+ @logger.info('env: ' + env.to_yaml)
16
+
17
+ output = []
18
+ ["company", "users"].each do |c|
19
+ env["PATH_INFO"] = "/#{c}/load"
20
+ env["REQUEST_URI"] = "/#{c}/load"
21
+ status, headers, response = @app.call(env)
22
+ output << response.body
23
+ @logger.info('---------------------- RESPONSE ----------------------------')
24
+ @logger.info(response.body)
25
+ end
26
+ res = output.join(',')
27
+ res = "[" + res + "]" if output.length > 1
28
+
29
+ #status, headers, response = @app.call(env)
30
+ [200, {"Content-Type" => "text/html"}, res]
31
+
32
+ else
33
+ @app.call(env)
34
+ end
35
+ end
36
+
37
+ def parse_params(env)
38
+ @params = env["REQUEST_METHOD"] == "GET" ? CGI.parse(env["QUERY_STRING"]) : env["rack.request.form_hash"]
39
+ @params.each do |k,v|
40
+ @params[k] = @params[k].first
41
+ end
42
+ #@params["data"] = JSON.parse(@params["data"]) if @params["data"]
43
+ #@logger.info('params: ' + @params.to_yaml)
44
+ #env["QUERY_STRING"] = {}
45
+
46
+ end
47
+
48
+ end
49
+
@@ -0,0 +1,36 @@
1
+ ##
2
+ # XException
3
+ # General exception class for all Ext application exceptions.
4
+ # @author Chris Scott
5
+ #
6
+ class XException < StandardError
7
+ end
8
+
9
+ ##
10
+ # XExceptionResponse
11
+ # A special extension of XResponse for returning responses where an Exception was raised. includes a back-trace in the response which
12
+ # should probably be turned on with a debug switch only.
13
+ # @author Chris Scott
14
+ #
15
+ class XExceptionResponse < XResponse
16
+ attr_accessor :where
17
+
18
+ ##
19
+ # initialize
20
+ # @param {XRequest}
21
+ # @param {StandardError}
22
+ #
23
+ def initialize(req, e)
24
+ super(req)
25
+ @type = 'exception'
26
+ @message = e.message
27
+ @where = e.backtrace
28
+ end
29
+
30
+ def to_h
31
+ data = super
32
+ data[:type] = 'exception'
33
+ data[:where] = @where.join("\n")
34
+ data
35
+ end
36
+ end
@@ -0,0 +1,31 @@
1
+ ###
2
+ # XRequest
3
+ # A standard response class suitable for Ext.Direct requests.
4
+ # @author Chris Scott
5
+ #
6
+ class XRequest
7
+ attr_reader :id, :tid, :controller, :action, :type, :params
8
+
9
+ def initialize(params)
10
+ # TODO: simply setting @id, @params
11
+ @id = (params["id"].to_i > 0) ? params["id"].to_i : (params["data"].kind_of?(Array) && (params["data"].first.kind_of?(Integer) || params["data"].first.nil?)) ? params["data"].shift: nil
12
+ @tid = params["tid"]
13
+ @type = params["type"]
14
+ @params = (params["data"].kind_of?(Array) && params["data"].length == 1 && params["data"].first.kind_of?(Hash)) ? params["data"].first : params["data"] || []
15
+ @controller = params["xcontroller"]
16
+ @action = params["xaction"]
17
+ end
18
+
19
+ ##
20
+ # arg
21
+ # return a request argument at index. can be used to access either [] or {}
22
+ # @param {String/Integer} index
23
+ # @raises XException if params doesn't exist.
24
+ #
25
+ def arg(index)
26
+ if params[index].nil?
27
+ raise XException.new("Attempt to access unknown request argument '#{index.to_s}' on transaction #{@tid}")
28
+ end
29
+ @params[index]
30
+ end
31
+ end
@@ -0,0 +1,26 @@
1
+ ###
2
+ # XResponse
3
+ # A standard response class suitable for Ext.Direct AJAX responses.
4
+ # @author Chris Scott
5
+ #
6
+ class XResponse
7
+ attr_accessor :type, :status, :errors, :success, :message, :result
8
+ attr_reader :tid
9
+
10
+ def initialize(req)
11
+ @tid = req.tid
12
+ @type = req.type
13
+ @status = false
14
+ @message = ''
15
+ @result = []
16
+ @errors = []
17
+ end
18
+
19
+ def to_h
20
+ {:tid => @tid, :status => @status, :type => @type, :message => @message, :result => @result, :errors => @errors}
21
+ end
22
+
23
+ def to_json
24
+ self.to_h.to_json
25
+ end
26
+ end
data/script/console ADDED
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env ruby
2
+ # File: script/console
3
+ irb = RUBY_PLATFORM =~ /(:?mswin|mingw)/ ? 'irb.bat' : 'irb'
4
+
5
+ libs = " -r irb/completion"
6
+ # Perhaps use a console_lib to store any extra methods I may want available in the cosole
7
+ # libs << " -r #{File.dirname(__FILE__) + '/../lib/console_lib/console_logger.rb'}"
8
+ libs << " -r #{File.dirname(__FILE__) + '/../lib/rails-extjs-direct.rb'}"
9
+ puts "Loading rails-extjs-direct gem"
10
+ exec "#{irb} #{libs} --simple-prompt"
data/script/destroy ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+ APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
3
+
4
+ begin
5
+ require 'rubigen'
6
+ rescue LoadError
7
+ require 'rubygems'
8
+ require 'rubigen'
9
+ end
10
+ require 'rubigen/scripts/destroy'
11
+
12
+ ARGV.shift if ['--help', '-h'].include?(ARGV[0])
13
+ RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
14
+ RubiGen::Scripts::Destroy.new.run(ARGV)
data/script/generate ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+ APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
3
+
4
+ begin
5
+ require 'rubigen'
6
+ rescue LoadError
7
+ require 'rubygems'
8
+ require 'rubigen'
9
+ end
10
+ require 'rubigen/scripts/generate'
11
+
12
+ ARGV.shift if ['--help', '-h'].include?(ARGV[0])
13
+ RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
14
+ RubiGen::Scripts::Generate.new.run(ARGV)
@@ -0,0 +1,3 @@
1
+ require 'stringio'
2
+ require 'test/unit'
3
+ require File.dirname(__FILE__) + '/../lib/rails-extjs-direct'
@@ -0,0 +1,11 @@
1
+ require File.dirname(__FILE__) + '/test_helper.rb'
2
+
3
+ class TestRails-extjs-direct < Test::Unit::TestCase
4
+
5
+ def setup
6
+ end
7
+
8
+ def test_truth
9
+ assert true
10
+ end
11
+ end
metadata ADDED
@@ -0,0 +1,94 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rails-extjs-direct
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Chris Scott
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-04-30 00:00:00 -04:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: newgem
17
+ type: :development
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 1.3.0
24
+ version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: hoe
27
+ type: :development
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 1.8.0
34
+ version:
35
+ description: A series of components for implementing the Ext.Direct API specification in Rails 2.3 and higher. Ext.Direct in Rails is implementede with Rack Middleware.
36
+ email:
37
+ - christocracy@gmail.com
38
+ executables: []
39
+
40
+ extensions: []
41
+
42
+ extra_rdoc_files:
43
+ - History.txt
44
+ - Manifest.txt
45
+ - PostInstall.txt
46
+ - README.rdoc
47
+ files:
48
+ - .project
49
+ - History.txt
50
+ - Manifest.txt
51
+ - PostInstall.txt
52
+ - README.rdoc
53
+ - Rakefile
54
+ - lib/rails-extjs-direct.rb
55
+ - lib/rails-extjs-direct/mixins/action_controller/direct_controller.rb
56
+ - lib/rails-extjs-direct/rack/remoting_provider.rb
57
+ - lib/rails-extjs-direct/xexception.rb
58
+ - lib/rails-extjs-direct/xrequest.rb
59
+ - lib/rails-extjs-direct/xresponse.rb
60
+ - script/console
61
+ - script/destroy
62
+ - script/generate
63
+ - test/test_helper.rb
64
+ - test/test_rails-extjs-direct.rb
65
+ has_rdoc: true
66
+ homepage: THIS GEM IS UNDER DEVELOPMENT AND WILL NOT YET WORK!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
67
+ post_install_message: PostInstall.txt
68
+ rdoc_options:
69
+ - --main
70
+ - README.rdoc
71
+ require_paths:
72
+ - lib
73
+ required_ruby_version: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - ">="
76
+ - !ruby/object:Gem::Version
77
+ version: "0"
78
+ version:
79
+ required_rubygems_version: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ version: "0"
84
+ version:
85
+ requirements: []
86
+
87
+ rubyforge_project: rails-extjs
88
+ rubygems_version: 1.3.1
89
+ signing_key:
90
+ specification_version: 2
91
+ summary: A series of components for implementing the Ext.Direct API specification in Rails 2.3 and higher
92
+ test_files:
93
+ - test/test_helper.rb
94
+ - test/test_rails-extjs-direct.rb