extjs-extjs-mvc 0.1.0
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/LICENSE +20 -0
- data/README +0 -0
- data/README.rdoc +18 -0
- data/Rakefile +60 -0
- data/VERSION +1 -0
- data/lib/action_controller/controller.rb +58 -0
- data/lib/action_view/helpers/data/store.rb +39 -0
- data/lib/active_record/model.rb +63 -0
- data/lib/dm/model.rb +0 -0
- data/lib/extjs-mvc.rb +18 -0
- data/test/mvc_test.rb +7 -0
- data/test/test_helper.rb +10 -0
- metadata +75 -0
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 Chris Scott
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README
ADDED
File without changes
|
data/README.rdoc
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
= mvc
|
2
|
+
|
3
|
+
Description goes here.
|
4
|
+
|
5
|
+
== Note on Patches/Pull Requests
|
6
|
+
|
7
|
+
* Fork the project.
|
8
|
+
* Make your feature addition or bug fix.
|
9
|
+
* Add tests for it. This is important so I don't break it in a
|
10
|
+
future version unintentionally.
|
11
|
+
* Commit, do not mess with rakefile, version, or history.
|
12
|
+
(if you want to have your own version, that is fine but
|
13
|
+
bump version in a commit by itself I can ignore when I pull)
|
14
|
+
* Send me a pull request. Bonus points for topic branches.
|
15
|
+
|
16
|
+
== Copyright
|
17
|
+
|
18
|
+
Copyright (c) 2009 Chris Scott. See LICENSE for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
gem.name = "extjs-mvc"
|
8
|
+
gem.summary = %Q{Ruby tools for ExtJS development}
|
9
|
+
gem.description = %Q{MVC tools to assist with ExtJS development in Rails and Merb}
|
10
|
+
gem.email = "christocracy@gmail.com"
|
11
|
+
gem.homepage = "http://github.com/extjs/mvc"
|
12
|
+
gem.authors = ["Chris Scott"]
|
13
|
+
gem.add_development_dependency "thoughtbot-shoulda"
|
14
|
+
gem.test_files = []
|
15
|
+
gem.files = FileList["[A-Z]*", "{bin,generators,lib,test}/**/*", 'lib/jeweler/templates/.gitignore']
|
16
|
+
|
17
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
18
|
+
end
|
19
|
+
rescue LoadError
|
20
|
+
puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
|
21
|
+
end
|
22
|
+
|
23
|
+
|
24
|
+
require 'rake/testtask'
|
25
|
+
Rake::TestTask.new(:test) do |test|
|
26
|
+
test.libs << 'lib' << 'test'
|
27
|
+
test.pattern = 'test/**/*_test.rb'
|
28
|
+
test.verbose = true
|
29
|
+
end
|
30
|
+
|
31
|
+
begin
|
32
|
+
require 'rcov/rcovtask'
|
33
|
+
Rcov::RcovTask.new do |test|
|
34
|
+
test.libs << 'test'
|
35
|
+
test.pattern = 'test/**/*_test.rb'
|
36
|
+
test.verbose = true
|
37
|
+
end
|
38
|
+
rescue LoadError
|
39
|
+
task :rcov do
|
40
|
+
abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
task :test => :check_dependencies
|
45
|
+
|
46
|
+
task :default => :test
|
47
|
+
|
48
|
+
require 'rake/rdoctask'
|
49
|
+
Rake::RDocTask.new do |rdoc|
|
50
|
+
if File.exist?('VERSION')
|
51
|
+
version = File.read('VERSION')
|
52
|
+
else
|
53
|
+
version = ""
|
54
|
+
end
|
55
|
+
|
56
|
+
rdoc.rdoc_dir = 'rdoc'
|
57
|
+
rdoc.title = "mvc #{version}"
|
58
|
+
rdoc.rdoc_files.include('README*')
|
59
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
60
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.0
|
@@ -0,0 +1,58 @@
|
|
1
|
+
module ExtJS::Controller
|
2
|
+
|
3
|
+
def self.included(controller)
|
4
|
+
controller.send(:extend, ClassMethods)
|
5
|
+
controller.class_eval do
|
6
|
+
helper ExtJS::Data
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
##
|
11
|
+
# Controller class methods
|
12
|
+
#
|
13
|
+
module ClassMethods
|
14
|
+
|
15
|
+
def extjs_reader(model)
|
16
|
+
{
|
17
|
+
"successProperty" => extjs_success_property,
|
18
|
+
"root" => extjs_root,
|
19
|
+
"messageProperty" => extjs_message_property
|
20
|
+
}.merge(model.extjs_record)
|
21
|
+
end
|
22
|
+
|
23
|
+
def extjs_proxy(params)
|
24
|
+
proxy = {}
|
25
|
+
if params[:proxy] === 'direct'
|
26
|
+
actions = ['create', 'read', 'update', 'destroy']
|
27
|
+
proxy["api"] = {}
|
28
|
+
direct_actions.each_index do |n|
|
29
|
+
proxy["api"][actions[n]] = direct_actions[n][:name]
|
30
|
+
end
|
31
|
+
else
|
32
|
+
if params[:config]["api"]
|
33
|
+
proxy["api"] = {}
|
34
|
+
params[:config]["api"].each {|k,v| proxy["api"][k] = "/#{params[:controller]}/#{v}" }
|
35
|
+
else
|
36
|
+
proxy["url"] = "/#{params[:controller]}.#{params[:format].to_s}"
|
37
|
+
end
|
38
|
+
end
|
39
|
+
proxy
|
40
|
+
end
|
41
|
+
|
42
|
+
def extjs_root(value=nil)
|
43
|
+
ExtJS::MVC.root = value unless value.nil?
|
44
|
+
ExtJS::MVC.root
|
45
|
+
end
|
46
|
+
|
47
|
+
def extjs_success_property(value=nil)
|
48
|
+
ExtJS::MVC.success_property = value unless value.nil?
|
49
|
+
ExtJS::MVC.success_property
|
50
|
+
end
|
51
|
+
|
52
|
+
def extjs_message_property(value=nil)
|
53
|
+
ExtJS::MVC.message_property = value unless value.nil?
|
54
|
+
ExtJS::MVC.message_property
|
55
|
+
end
|
56
|
+
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
module ExtJS::Data
|
2
|
+
module Store
|
3
|
+
def extjs_store(params)
|
4
|
+
params[:format] = 'json' if params[:format].nil?
|
5
|
+
params[:proxy] = 'http' if params[:proxy].nil?
|
6
|
+
|
7
|
+
controller = "#{params[:controller].to_s.capitalize}Controller".constantize
|
8
|
+
model = ((params[:model]) ? params[:model] : params[:controller].singularize).capitalize.constantize
|
9
|
+
|
10
|
+
reader = controller.extjs_reader(model)
|
11
|
+
proxy = controller.extjs_proxy(params)
|
12
|
+
|
13
|
+
params[:config]["storeId"] = model.to_s.downcase
|
14
|
+
params[:config].merge!(reader)
|
15
|
+
params[:config].merge!(proxy)
|
16
|
+
|
17
|
+
type = (params[:proxy] === 'direct' ? params[:proxy] : params[:format]).capitalize
|
18
|
+
|
19
|
+
script = ''
|
20
|
+
# ugly hack for DirectProxy API. Have to add an Ext.onReady() after the Store constructor to set API
|
21
|
+
if params[:proxy] === 'direct'
|
22
|
+
auto_load = params[:config].delete("autoLoad")
|
23
|
+
cname = params[:controller].capitalize
|
24
|
+
script = "Ext.onReady(function() { var s = Ext.StoreMgr.get('#{model.to_s.downcase}');"
|
25
|
+
if (params[:config]["directFn"])
|
26
|
+
script += "s.proxy.directFn = #{cname}.#{params[:config]["directFn"]};"
|
27
|
+
else
|
28
|
+
script += "s.proxy.setApi({create:#{cname}.#{params[:config]["api"]["create"]},read:#{cname}.#{params[:config]["api"]["read"]},update:#{cname}.#{params[:config]["api"]["update"]},destroy:#{cname}.#{params[:config]["api"]["destroy"]}});"
|
29
|
+
end
|
30
|
+
if auto_load
|
31
|
+
script += "s.load();"
|
32
|
+
end
|
33
|
+
script += "});"
|
34
|
+
end
|
35
|
+
"new Ext.data.#{type}Store(#{params[:config].to_json});#{script}"
|
36
|
+
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
module ExtJS
|
2
|
+
module Model
|
3
|
+
def self.included(model)
|
4
|
+
model.send(:extend, ClassMethods)
|
5
|
+
model.send(:include, InstanceMethods)
|
6
|
+
end
|
7
|
+
|
8
|
+
##
|
9
|
+
# InstanceMethods
|
10
|
+
#
|
11
|
+
module InstanceMethods
|
12
|
+
def to_record
|
13
|
+
data = {self.class.primary_key => self.send(self.class.primary_key)}
|
14
|
+
self.class.extjs_fields.each do |f|
|
15
|
+
data[f] = self.send(f)
|
16
|
+
end
|
17
|
+
data
|
18
|
+
end
|
19
|
+
end
|
20
|
+
##
|
21
|
+
# ClassMethods
|
22
|
+
#
|
23
|
+
module ClassMethods
|
24
|
+
@@fields = []
|
25
|
+
##
|
26
|
+
# Defines the subset of AR columns used to create Ext.data.Record def'n.
|
27
|
+
# @param {Array/Hash} list-of-fields to include, :only, or :exclude
|
28
|
+
#
|
29
|
+
def extjs_fields(*params)
|
30
|
+
options = params.extract_options!
|
31
|
+
if !options.keys.empty?
|
32
|
+
if options[:only]
|
33
|
+
@@fields = options[:only]
|
34
|
+
elsif options[:exclude]
|
35
|
+
@@fields = self.columns.reject {|c| options[:exclude].find {|ex| c.name.to_sym === ex}}.collect {|c| c.name.to_sym}
|
36
|
+
end
|
37
|
+
elsif !params.empty?
|
38
|
+
@@fields = params
|
39
|
+
else
|
40
|
+
@@fields
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
##
|
45
|
+
# render AR columns to Ext.data.Record.create format
|
46
|
+
# eg: {name:'foo', type: 'string'}
|
47
|
+
#
|
48
|
+
def extjs_record
|
49
|
+
@@fields = self.columns.collect {|c| c.name.to_sym } if @@fields.empty?
|
50
|
+
{
|
51
|
+
"fields" => @@fields.collect {|f|
|
52
|
+
col = self.columns.find {|c| c.name.to_sym === f}
|
53
|
+
field = {:name => col.name, :allowBlank => col.null, :type => col.type}
|
54
|
+
field[:dateFormat] = "c" if col.type === :datetime || col.type === :date # <-- ugly hack for date
|
55
|
+
field
|
56
|
+
},
|
57
|
+
"idProperty" => self.primary_key
|
58
|
+
}
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
data/lib/dm/model.rb
ADDED
File without changes
|
data/lib/extjs-mvc.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
module ExtJS
|
2
|
+
class MVC
|
3
|
+
@@success_property = :success
|
4
|
+
@@message_property = :message
|
5
|
+
@@root = :data
|
6
|
+
cattr_accessor :success_property
|
7
|
+
cattr_accessor :message_property
|
8
|
+
cattr_accessor :root
|
9
|
+
|
10
|
+
if defined?(ActiveRecord)
|
11
|
+
require 'active_record/model'
|
12
|
+
end
|
13
|
+
require 'action_controller/controller'
|
14
|
+
require 'action_view/helpers/data/store'
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
|
data/test/mvc_test.rb
ADDED
data/test/test_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,75 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: extjs-extjs-mvc
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Chris Scott
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-08-27 00:00:00 -07:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: thoughtbot-shoulda
|
17
|
+
type: :development
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: "0"
|
24
|
+
version:
|
25
|
+
description: MVC tools to assist with ExtJS development in Rails and Merb
|
26
|
+
email: christocracy@gmail.com
|
27
|
+
executables: []
|
28
|
+
|
29
|
+
extensions: []
|
30
|
+
|
31
|
+
extra_rdoc_files:
|
32
|
+
- LICENSE
|
33
|
+
- README
|
34
|
+
- README.rdoc
|
35
|
+
files:
|
36
|
+
- LICENSE
|
37
|
+
- README
|
38
|
+
- README.rdoc
|
39
|
+
- Rakefile
|
40
|
+
- VERSION
|
41
|
+
- lib/action_controller/controller.rb
|
42
|
+
- lib/action_view/helpers/data/store.rb
|
43
|
+
- lib/active_record/model.rb
|
44
|
+
- lib/dm/model.rb
|
45
|
+
- lib/extjs-mvc.rb
|
46
|
+
- test/mvc_test.rb
|
47
|
+
- test/test_helper.rb
|
48
|
+
has_rdoc: true
|
49
|
+
homepage: http://github.com/extjs/mvc
|
50
|
+
post_install_message:
|
51
|
+
rdoc_options:
|
52
|
+
- --charset=UTF-8
|
53
|
+
require_paths:
|
54
|
+
- lib
|
55
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
56
|
+
requirements:
|
57
|
+
- - ">="
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
version: "0"
|
60
|
+
version:
|
61
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
62
|
+
requirements:
|
63
|
+
- - ">="
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: "0"
|
66
|
+
version:
|
67
|
+
requirements: []
|
68
|
+
|
69
|
+
rubyforge_project:
|
70
|
+
rubygems_version: 1.2.0
|
71
|
+
signing_key:
|
72
|
+
specification_version: 2
|
73
|
+
summary: Ruby tools for ExtJS development
|
74
|
+
test_files: []
|
75
|
+
|