mvc 0.1.29
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +20 -0
- data/README +0 -0
- data/README.rdoc +112 -0
- data/Rakefile +60 -0
- data/VERSION +1 -0
- data/lib/action_controller/controller.rb +55 -0
- data/lib/active_record/model.rb +89 -0
- data/lib/dm/model.rb +0 -0
- data/lib/extjs-mvc.rb +19 -0
- data/lib/extjs/component.rb +62 -0
- data/lib/extjs/data/store.rb +67 -0
- data/lib/helpers/component.rb +38 -0
- data/lib/helpers/store.rb +7 -0
- data/lib/mvc.rb +22 -0
- data/test/mvc_test.rb +7 -0
- data/test/test_helper.rb +10 -0
- metadata +81 -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,112 @@
|
|
1
|
+
= mvc
|
2
|
+
|
3
|
+
A collection of helpers, MVC mixins and PORs (plain-old-ruby-object) to assist with auto-generating ExtJS javascript component definitions.
|
4
|
+
|
5
|
+
|
6
|
+
===Installation
|
7
|
+
|
8
|
+
% gem sources -a http://gems.github.com (you only have to do this once)
|
9
|
+
% sudo gem install extjs-mvc
|
10
|
+
|
11
|
+
In <tt>environment.rb</tt>
|
12
|
+
|
13
|
+
Rails::Initializer.run do |config|
|
14
|
+
.
|
15
|
+
.
|
16
|
+
.
|
17
|
+
end
|
18
|
+
require 'extjs-mvc'
|
19
|
+
|
20
|
+
|
21
|
+
=== An ActiveRecord mixin: ExtJS::Model
|
22
|
+
|
23
|
+
include it in your model. Use the class-method <tt>extjs_fields</tt> to specify those
|
24
|
+
fields with will be used to render the <tt>Ext.data.Record.create</tt> field-def'n.
|
25
|
+
class User < ActiveRecord::Base
|
26
|
+
include ExtJS::Model
|
27
|
+
|
28
|
+
extjs_fields :exclude => [:password, :password_confirmation]
|
29
|
+
end
|
30
|
+
|
31
|
+
In script/console
|
32
|
+
>> User.extjs_fields
|
33
|
+
>> User.extjs_record
|
34
|
+
=> { "idProperty"=>"id", "fields"=>[
|
35
|
+
{:type=>:int, :allowBlank=>true, :name=>"id"},
|
36
|
+
{:type=>:string, :allowBlank=>false, :name=>"first"},
|
37
|
+
{:type=>:string, :allowBlank=>false, :name=>"last"},
|
38
|
+
{:type=>:string, :allowBlank=>false, :name=>"email"}
|
39
|
+
]}
|
40
|
+
|
41
|
+
=== An ActionController mixin: ExtJS::Controller
|
42
|
+
|
43
|
+
<b>usage:</b>
|
44
|
+
|
45
|
+
class UsersController < ActionController::Base
|
46
|
+
include ExtJS::Controller
|
47
|
+
end
|
48
|
+
|
49
|
+
=== View Helper: ExtJS::Helpers::Component
|
50
|
+
|
51
|
+
<b>usage:</b>
|
52
|
+
|
53
|
+
class UserController < ActionController::Base
|
54
|
+
include ExtJS::Controller
|
55
|
+
helper ExtJS::Helpers::Component
|
56
|
+
end
|
57
|
+
|
58
|
+
Now render Ext components using helper method <tt>extjs_component</tt>
|
59
|
+
|
60
|
+
@viewport = extjs_component(
|
61
|
+
"xtype" => "viewport",
|
62
|
+
"frame" => true,
|
63
|
+
"layout" => "border")
|
64
|
+
@viewport.add("xtype" => "panel", "contentEl" => "hd", "region" => "north", "height" => 30)
|
65
|
+
@viewport.add(:partial => "/users/grid", "itemId" => "users-grid", "region" => "west")
|
66
|
+
@viewport.add(:partial => "/tasks/grid", "itemId" => "tasks-grid", "region" => "center")
|
67
|
+
@viewport.add("xtype" => "panel", "contentEl" => "ft", "region" => "south", "height" => 20)
|
68
|
+
|
69
|
+
Note how it can also render partials. Partials will be invoked with a local-variable named "container", a reference to the
|
70
|
+
parent Ext::Component instance which added the partial. If no "container" is specified, it would be expected that your partial
|
71
|
+
would provide its own "renderTo" or "contentEl" property, just as in Ext.Component from ExtJS javascript library.
|
72
|
+
|
73
|
+
|
74
|
+
=== View Helper: ExtJS::Helpers::Store
|
75
|
+
|
76
|
+
Renders an Ext.data.Store with helper method <tt>extjs_store</tt>
|
77
|
+
|
78
|
+
class UserController < ActionController::Base
|
79
|
+
include ExtJS::Controller
|
80
|
+
helper ExtJS::Helpers::Store
|
81
|
+
end
|
82
|
+
|
83
|
+
|
84
|
+
@store = extjs_store(
|
85
|
+
:controller => "users",
|
86
|
+
:proxy => "http" # <-- default
|
87
|
+
:format => "json" # <-- default
|
88
|
+
:model => "user", # <-- default: controller_name.singularize.camelize.constantize
|
89
|
+
:writer => {:encode => false},
|
90
|
+
:config => { # <-- standard Ext.data.Store config-params
|
91
|
+
"autoLoad" => true
|
92
|
+
"autoSave" => true
|
93
|
+
}
|
94
|
+
)
|
95
|
+
|
96
|
+
%= @store.render %
|
97
|
+
|
98
|
+
|
99
|
+
== Note on Patches/Pull Requests
|
100
|
+
|
101
|
+
* Fork the project.
|
102
|
+
* Make your feature addition or bug fix.
|
103
|
+
* Add tests for it. This is important so I don't break it in a
|
104
|
+
future version unintentionally.
|
105
|
+
* Commit, do not mess with rakefile, version, or history.
|
106
|
+
(if you want to have your own version, that is fine but
|
107
|
+
bump version in a commit by itself I can ignore when I pull)
|
108
|
+
* Send me a pull request. Bonus points for topic branches.
|
109
|
+
|
110
|
+
== Copyright
|
111
|
+
|
112
|
+
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 = "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.29
|
@@ -0,0 +1,55 @@
|
|
1
|
+
module ExtJS::Controller
|
2
|
+
|
3
|
+
def self.included(controller)
|
4
|
+
controller.send(:extend, ClassMethods)
|
5
|
+
end
|
6
|
+
|
7
|
+
##
|
8
|
+
# Controller class methods
|
9
|
+
#
|
10
|
+
module ClassMethods
|
11
|
+
|
12
|
+
def extjs_reader(model)
|
13
|
+
{
|
14
|
+
"successProperty" => extjs_success_property,
|
15
|
+
"root" => extjs_root,
|
16
|
+
"messageProperty" => extjs_message_property
|
17
|
+
}.merge(model.extjs_record)
|
18
|
+
end
|
19
|
+
|
20
|
+
def extjs_proxy(params)
|
21
|
+
proxy = {}
|
22
|
+
if params[:proxy] === 'direct'
|
23
|
+
actions = ['create', 'read', 'update', 'destroy']
|
24
|
+
proxy["api"] = {}
|
25
|
+
direct_actions.each_index do |n|
|
26
|
+
proxy["api"][actions[n]] = direct_actions[n][:name]
|
27
|
+
end
|
28
|
+
else
|
29
|
+
if params[:config]["api"]
|
30
|
+
proxy["api"] = {}
|
31
|
+
params[:config]["api"].each {|k,v| proxy["api"][k] = "/#{params[:controller]}/#{v}" }
|
32
|
+
else
|
33
|
+
proxy["url"] = "/#{params[:controller]}.#{params[:format].to_s}"
|
34
|
+
end
|
35
|
+
end
|
36
|
+
proxy
|
37
|
+
end
|
38
|
+
|
39
|
+
def extjs_root(value=nil)
|
40
|
+
ExtJS::MVC.root = value unless value.nil?
|
41
|
+
ExtJS::MVC.root
|
42
|
+
end
|
43
|
+
|
44
|
+
def extjs_success_property(value=nil)
|
45
|
+
ExtJS::MVC.success_property = value unless value.nil?
|
46
|
+
ExtJS::MVC.success_property
|
47
|
+
end
|
48
|
+
|
49
|
+
def extjs_message_property(value=nil)
|
50
|
+
ExtJS::MVC.message_property = value unless value.nil?
|
51
|
+
ExtJS::MVC.message_property
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,89 @@
|
|
1
|
+
module ExtJS
|
2
|
+
module Model
|
3
|
+
def self.included(model)
|
4
|
+
model.send(:extend, ClassMethods)
|
5
|
+
model.send(:include, InstanceMethods)
|
6
|
+
model.class_eval do
|
7
|
+
cattr_accessor :extjs_record_fields
|
8
|
+
end
|
9
|
+
model.extjs_record_fields = []
|
10
|
+
end
|
11
|
+
|
12
|
+
##
|
13
|
+
# InstanceMethods
|
14
|
+
#
|
15
|
+
module InstanceMethods
|
16
|
+
def to_record
|
17
|
+
data = {self.class.primary_key => self.send(self.class.primary_key)}
|
18
|
+
self.class.extjs_record_fields.each do |f|
|
19
|
+
if refl = self.class.reflections[f]
|
20
|
+
if refl.macro === :belongs_to
|
21
|
+
data[f] = self.send(f).to_record
|
22
|
+
elsif refl.macro === :has_many
|
23
|
+
data[f] = self.send(f).collect {|r| r.to_record}
|
24
|
+
end
|
25
|
+
else
|
26
|
+
data[f] = self.send(f)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
data
|
30
|
+
end
|
31
|
+
end
|
32
|
+
##
|
33
|
+
# ClassMethods
|
34
|
+
#
|
35
|
+
module ClassMethods
|
36
|
+
##
|
37
|
+
# Defines the subset of AR columns used to create Ext.data.Record def'n.
|
38
|
+
# @param {Array/Hash} list-of-fields to include, :only, or :exclude
|
39
|
+
#
|
40
|
+
def extjs_fields(*params)
|
41
|
+
options = params.extract_options!
|
42
|
+
if !options.keys.empty?
|
43
|
+
if options[:exclude]
|
44
|
+
self.extjs_record_fields = self.columns.reject {|c| options[:exclude].find {|ex| c.name.to_sym === ex}}.collect {|c| c.name.to_sym}
|
45
|
+
end
|
46
|
+
elsif !params.empty?
|
47
|
+
self.extjs_record_fields = params
|
48
|
+
else
|
49
|
+
self.extjs_record_fields
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
##
|
54
|
+
# render AR columns to Ext.data.Record.create format
|
55
|
+
# eg: {name:'foo', type: 'string'}
|
56
|
+
#
|
57
|
+
def extjs_record
|
58
|
+
if self.extjs_record_fields.empty?
|
59
|
+
self.extjs_record_fields = self.columns.collect {|c| c.name.to_sym }
|
60
|
+
self.extjs_record_fields.concat(self.reflect_on_all_associations.collect {|assn| assn.name})
|
61
|
+
end
|
62
|
+
|
63
|
+
return {
|
64
|
+
"fields" => self.extjs_record_fields.collect {|f|
|
65
|
+
if col = self.columns_hash[f.to_s]
|
66
|
+
type = col.type
|
67
|
+
case col.type
|
68
|
+
when :datetime || :date || :time || :timestamp
|
69
|
+
type = :date
|
70
|
+
when :text
|
71
|
+
type = :string
|
72
|
+
when :integer
|
73
|
+
type = :int
|
74
|
+
end
|
75
|
+
field = {:name => col.name, :allowBlank => (col.primary) ? true : col.null, :type => type}
|
76
|
+
field[:dateFormat] = "c" if col.type === :datetime || col.type === :date # <-- ugly hack for date
|
77
|
+
field
|
78
|
+
elsif self.reflections[f]
|
79
|
+
assn = self.reflections[f]
|
80
|
+
field = {:name => assn.name, :allowBlank => true, :type => 'auto'}
|
81
|
+
end
|
82
|
+
},
|
83
|
+
"idProperty" => self.primary_key
|
84
|
+
}
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
data/lib/dm/model.rb
ADDED
File without changes
|
data/lib/extjs-mvc.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
module ExtJS
|
2
|
+
class MVC
|
3
|
+
cattr_accessor :success_property
|
4
|
+
cattr_accessor :message_property
|
5
|
+
cattr_accessor :root
|
6
|
+
|
7
|
+
if defined?(ActiveRecord)
|
8
|
+
require 'active_record/model'
|
9
|
+
end
|
10
|
+
require 'extjs/component'
|
11
|
+
require 'extjs/data/store'
|
12
|
+
|
13
|
+
require 'helpers/component'
|
14
|
+
require 'helpers/store'
|
15
|
+
|
16
|
+
require 'action_controller/controller'
|
17
|
+
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
##
|
2
|
+
# @class ExtJS::Component
|
3
|
+
#
|
4
|
+
class ExtJS::Component
|
5
|
+
attr_accessor :config
|
6
|
+
def initialize(params)
|
7
|
+
@config = params#params.extract_options!
|
8
|
+
@controller = @config.delete(:controller) unless @config[:controller].nil?
|
9
|
+
|
10
|
+
@config[:items] = [] if config[:items].nil?
|
11
|
+
|
12
|
+
if container = @config.delete(:container)
|
13
|
+
container.add(self)
|
14
|
+
end
|
15
|
+
@partial_config = nil
|
16
|
+
end
|
17
|
+
|
18
|
+
def apply(params)
|
19
|
+
@config.merge!(params)
|
20
|
+
end
|
21
|
+
|
22
|
+
##
|
23
|
+
# Adds a config {} or ExtJS::Component instance to this component's items collection.
|
24
|
+
# NOTE: When :partial option is used a String will of course be returned. Otherwise an ExtJS::Component
|
25
|
+
# instance will be returned.
|
26
|
+
# @return {String/ExtJS::Component}
|
27
|
+
def add(*config)
|
28
|
+
options = config.extract_options!
|
29
|
+
if !options.keys.empty?
|
30
|
+
if url = options.delete(:partial)
|
31
|
+
# rendering a partial, cache the config until partial calls #add method. @see else.
|
32
|
+
@partial_config = options
|
33
|
+
return @controller.render(:partial => url, :locals => {:container => self})
|
34
|
+
else
|
35
|
+
options.merge!(@partial_config) unless @partial_config.nil?
|
36
|
+
options[:controller] = @controller unless @controller.nil?
|
37
|
+
cmp = ExtJS::Component.new(options)
|
38
|
+
@partial_config = nil
|
39
|
+
@config[:items] << cmp
|
40
|
+
return cmp
|
41
|
+
end
|
42
|
+
elsif !config.empty? && config.first.kind_of?(ExtJS::Component)
|
43
|
+
cmp = config.first
|
44
|
+
cmp.apply(@partial_config) unless @partial_config.nil?
|
45
|
+
@partial_config = nil
|
46
|
+
@config[:items] << cmp.config
|
47
|
+
return cmp
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def to_json
|
52
|
+
config.to_json
|
53
|
+
end
|
54
|
+
|
55
|
+
def render
|
56
|
+
# If there are any listeners attached in json, we have to get rid of double-quotes in order to expose
|
57
|
+
# the javascript object.
|
58
|
+
# eg: "listeners":"SomeController.listeners.grid" -> {"listeners":SomeController.listeners.grid, ...}
|
59
|
+
json = @config.to_json.gsub(/\"(listeners|handler|scope)\":\s?\"([a-zA-Z\.\[\]\(\)]+)\"/, '"\1":\2')
|
60
|
+
"Ext.ComponentMgr.create(#{json});"
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
##
|
2
|
+
# ExtJS::Data::Store
|
3
|
+
#
|
4
|
+
module ExtJS::Data
|
5
|
+
class Store
|
6
|
+
attr_accessor :id, :format, :type, :controller, :model
|
7
|
+
|
8
|
+
def initialize(*params)
|
9
|
+
options = params.extract_options!
|
10
|
+
options[:format] = 'json' if options[:format].nil?
|
11
|
+
|
12
|
+
@config = options[:config]
|
13
|
+
|
14
|
+
@format = options[:format]
|
15
|
+
@proxy = options[:proxy] || 'http'
|
16
|
+
@writer = options[:writer]
|
17
|
+
@type = (@proxy === 'direct' ? @proxy : @format).capitalize
|
18
|
+
@controller = "#{options[:controller].to_s.camelize}Controller".constantize
|
19
|
+
@model = ((options[:model]) ? options[:model] : @controller.controller_name.singularize).camelize.constantize
|
20
|
+
|
21
|
+
# Merge Reader/Proxy config
|
22
|
+
@config.merge!(@controller.extjs_reader(@model))
|
23
|
+
@config.merge!(@controller.extjs_proxy(options))
|
24
|
+
|
25
|
+
# Set storeId implicitly based upon Model name if not set explicitly
|
26
|
+
@id = @config["storeId"] = @model.to_s.downcase unless @config["storeId"]
|
27
|
+
end
|
28
|
+
|
29
|
+
##
|
30
|
+
# pre-load a store with data. Not yet tested. In theory, this *should* work.
|
31
|
+
#
|
32
|
+
def load(*params)
|
33
|
+
#@config["loadData"] = @model.all(params).collect {|rec| rec.to_record }
|
34
|
+
end
|
35
|
+
|
36
|
+
##
|
37
|
+
# renders the configured store
|
38
|
+
# @param {Boolean} script_tag [true] Not yet implemented. Always renders <script></script> tags.
|
39
|
+
def render(script_tag = true)
|
40
|
+
script = ''
|
41
|
+
# ugly hack for DirectProxy API. Have to add an Ext.onReady() after the Store constructor to set API
|
42
|
+
if @proxy === 'direct'
|
43
|
+
auto_load = @config.delete("autoLoad")
|
44
|
+
cname = @controller.controller_name.capitalize
|
45
|
+
script = "Ext.onReady(function() { var s = Ext.StoreMgr.get('#{@config["storeId"]}');"
|
46
|
+
if (@config["directFn"])
|
47
|
+
script += "s.proxy.directFn = #{cname}.#{@config["directFn"]};"
|
48
|
+
else
|
49
|
+
script += "s.proxy.setApi({create:#{cname}.#{@config["api"]["create"]},read:#{cname}.#{@config["api"]["read"]},update:#{cname}.#{@config["api"]["update"]},destroy:#{cname}.#{@config["api"]["destroy"]}});"
|
50
|
+
end
|
51
|
+
if auto_load
|
52
|
+
script += "s.load();"
|
53
|
+
end
|
54
|
+
script += "});"
|
55
|
+
end
|
56
|
+
|
57
|
+
if @writer # <-- ugly hack because 3.0.1 can't deal with Writer as config-param
|
58
|
+
json = @config.to_json
|
59
|
+
json[json.length-1] = ','
|
60
|
+
json += "writer:new Ext.data.#{@format.capitalize}Writer(#{@writer.to_json})}"
|
61
|
+
"<script>new Ext.data.#{@type}Store(#{json});#{script}</script>"
|
62
|
+
else
|
63
|
+
"<script>new Ext.data.#{@type}Store(#{@config.to_json});#{script}</script>"
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
##
|
2
|
+
# ExtJS::Helpers::Component
|
3
|
+
#
|
4
|
+
module ExtJS::Helpers
|
5
|
+
module Component
|
6
|
+
##
|
7
|
+
# add class-var @@extjs_on_ready
|
8
|
+
def self.included(helper)
|
9
|
+
|
10
|
+
end
|
11
|
+
|
12
|
+
def extjs_component(*params)
|
13
|
+
options = params.extract_options!
|
14
|
+
options[:controller] = self
|
15
|
+
ExtJS::Component.new(options)
|
16
|
+
end
|
17
|
+
|
18
|
+
##
|
19
|
+
# Adds a script or ExtJS::Component instance to on_ready queue. The queue is emptied and rendered to
|
20
|
+
# <script></script> via #extjs_render
|
21
|
+
#
|
22
|
+
def extjs_onready(*params)
|
23
|
+
@onready_queue = [] if @onready_queue.nil?
|
24
|
+
|
25
|
+
params.each do |cmp|
|
26
|
+
@onready_queue << cmp
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
##
|
31
|
+
# Empties the on_ready queue. Renders within <script></script> tags
|
32
|
+
#
|
33
|
+
def extjs_render
|
34
|
+
@onready_queue = [] if @onready_queue.nil? # <--- ugly, ugh...having trouble with initializing my instance vars.
|
35
|
+
"<script>\nExt.onReady(function() {\n\t#{@onready_queue.collect {|cmp| (cmp.kind_of?(ExtJS::Component)) ? cmp.render : cmp}.join("\n\t")}\n });\n</script>"
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
data/lib/mvc.rb
ADDED
@@ -0,0 +1,22 @@
|
|
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 'extjs/component'
|
14
|
+
require 'extjs/data/store'
|
15
|
+
|
16
|
+
require 'helpers/component'
|
17
|
+
require 'helpers/store'
|
18
|
+
|
19
|
+
require 'action_controller/controller'
|
20
|
+
|
21
|
+
end
|
22
|
+
end
|
data/test/mvc_test.rb
ADDED
data/test/test_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,81 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: mvc
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.29
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Chris Scott
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-09-29 00:00:00 -04: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/active_record/model.rb
|
43
|
+
- lib/dm/model.rb
|
44
|
+
- lib/extjs-mvc.rb
|
45
|
+
- lib/extjs/component.rb
|
46
|
+
- lib/extjs/data/store.rb
|
47
|
+
- lib/helpers/component.rb
|
48
|
+
- lib/helpers/store.rb
|
49
|
+
- lib/mvc.rb
|
50
|
+
- test/mvc_test.rb
|
51
|
+
- test/test_helper.rb
|
52
|
+
has_rdoc: true
|
53
|
+
homepage: http://github.com/extjs/mvc
|
54
|
+
licenses: []
|
55
|
+
|
56
|
+
post_install_message:
|
57
|
+
rdoc_options:
|
58
|
+
- --charset=UTF-8
|
59
|
+
require_paths:
|
60
|
+
- lib
|
61
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
62
|
+
requirements:
|
63
|
+
- - ">="
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: "0"
|
66
|
+
version:
|
67
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
68
|
+
requirements:
|
69
|
+
- - ">="
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
version: "0"
|
72
|
+
version:
|
73
|
+
requirements: []
|
74
|
+
|
75
|
+
rubyforge_project:
|
76
|
+
rubygems_version: 1.3.5
|
77
|
+
signing_key:
|
78
|
+
specification_version: 3
|
79
|
+
summary: Ruby tools for ExtJS development
|
80
|
+
test_files: []
|
81
|
+
|