extjs-mvc 0.0.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -11,12 +11,16 @@ begin
11
11
  gem.homepage = "http://github.com/extjs/mvc"
12
12
  gem.authors = ["Chris Scott"]
13
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
+
14
17
  # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
15
18
  end
16
19
  rescue LoadError
17
20
  puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
18
21
  end
19
22
 
23
+
20
24
  require 'rake/testtask'
21
25
  Rake::TestTask.new(:test) do |test|
22
26
  test.libs << 'lib' << 'test'
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.2
@@ -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,39 @@
1
+ module ExtJS::Helpers
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/mvc.rb CHANGED
@@ -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/store'
15
+ end
16
+ end
17
+
18
+
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: extjs-mvc
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Scott
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-08-26 00:00:00 -07:00
12
+ date: 2009-08-28 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -33,14 +33,16 @@ extra_rdoc_files:
33
33
  - README
34
34
  - README.rdoc
35
35
  files:
36
- - .document
37
- - .gitignore
38
36
  - LICENSE
39
37
  - README
40
38
  - README.rdoc
41
39
  - Rakefile
40
+ - VERSION
41
+ - lib/action_controller/controller.rb
42
+ - lib/action_view/helpers/store.rb
43
+ - lib/active_record/model.rb
44
+ - lib/dm/model.rb
42
45
  - lib/mvc.rb
43
- - mvc.gemspec
44
46
  - test/mvc_test.rb
45
47
  - test/test_helper.rb
46
48
  has_rdoc: true
@@ -70,6 +72,5 @@ rubygems_version: 1.3.5
70
72
  signing_key:
71
73
  specification_version: 2
72
74
  summary: Ruby tools for ExtJS development
73
- test_files:
74
- - test/test_helper.rb
75
- - test/mvc_test.rb
75
+ test_files: []
76
+
data/.document DELETED
@@ -1,5 +0,0 @@
1
- README.rdoc
2
- lib/**/*.rb
3
- bin/*
4
- features/**/*.feature
5
- LICENSE
data/.gitignore DELETED
@@ -1,5 +0,0 @@
1
- *.sw?
2
- .DS_Store
3
- coverage
4
- rdoc
5
- pkg
data/mvc.gemspec DELETED
@@ -1,55 +0,0 @@
1
- # Generated by jeweler
2
- # DO NOT EDIT THIS FILE
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run `rake gemspec`
4
- # -*- encoding: utf-8 -*-
5
-
6
- Gem::Specification.new do |s|
7
- s.name = %q{mvc}
8
- s.version = "0.0.1"
9
-
10
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
- s.authors = ["Chris Scott"]
12
- s.date = %q{2009-08-26}
13
- s.description = %q{MVC tools to assist with ExtJS development in Rails and Merb}
14
- s.email = %q{christocracy@gmail.com}
15
- s.extra_rdoc_files = [
16
- "LICENSE",
17
- "README",
18
- "README.rdoc"
19
- ]
20
- s.files = [
21
- ".document",
22
- ".gitignore",
23
- "LICENSE",
24
- "README",
25
- "README.rdoc",
26
- "Rakefile",
27
- "lib/mvc.rb",
28
- "mvc.gemspec",
29
- "test/mvc_test.rb",
30
- "test/test_helper.rb"
31
- ]
32
- s.has_rdoc = true
33
- s.homepage = %q{http://github.com/extjs/mvc}
34
- s.rdoc_options = ["--charset=UTF-8"]
35
- s.require_paths = ["lib"]
36
- s.rubygems_version = %q{1.3.1}
37
- s.summary = %q{Ruby tools for ExtJS development}
38
- s.test_files = [
39
- "test/test_helper.rb",
40
- "test/mvc_test.rb"
41
- ]
42
-
43
- if s.respond_to? :specification_version then
44
- current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
45
- s.specification_version = 2
46
-
47
- if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
48
- s.add_development_dependency(%q<thoughtbot-shoulda>, [">= 0"])
49
- else
50
- s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
51
- end
52
- else
53
- s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
54
- end
55
- end