extjs-mvc 0.1.14 → 0.1.15

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.14
1
+ 0.1.15
@@ -1,24 +1,50 @@
1
1
  module ExtJS::Helpers
2
2
  module Component
3
- def extjs_create_component(params)
4
- ExtJS::Component.new(params)
3
+ def extjs_component(params)
4
+ ExtJS::Component.new(self, params)
5
5
  end
6
6
  end
7
7
  end
8
8
 
9
9
  class ExtJS::Component
10
-
11
- def initialize(params)
12
- @params = params
13
- @params[:items] = [] if @params[:items].nil?
10
+ attr_accessor :config
11
+ def initialize(controller, config)
12
+ @controller = controller
13
+ @config = config
14
+ @config[:items] = [] if config[:items].nil?
15
+
16
+ if container = @config.delete(:container)
17
+ container.add(self)
18
+ end
19
+ @partial_config = nil
20
+ end
21
+
22
+ def apply(params)
23
+ @config.merge!(params)
14
24
  end
15
25
 
16
- def add(p)
17
- @params[:items] << p
26
+ def add(*config)
27
+ options = config.extract_options!
28
+ if !options.keys.empty?
29
+ if options[:partial]
30
+ # rendering a partial, cache the config until partial calls #add method. @see else.
31
+ url = options.delete(:partial)
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
+ @config[:items] << options
37
+ end
38
+ elsif !config.empty? && config.first.kind_of?(ExtJS::Component)
39
+ cmp = config.first
40
+ cmp.apply(@partial_config) unless @partial_config.nil?
41
+ @config[:items] << cmp.config
42
+ end
43
+ @partial_config = nil
18
44
  end
19
45
 
20
46
  def render
21
- cmp = "Ext.ComponentMgr.create(#{@params.to_json});"
22
- "<script>Ext.onReady(function() {#{cmp}});</script>"
47
+ cmp = "Ext.ComponentMgr.create(#{@config.to_json});"
48
+ "Ext.onReady(function() {#{cmp}});"
23
49
  end
24
50
  end
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.1.14
4
+ version: 0.1.15
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Scott
@@ -49,6 +49,7 @@ files:
49
49
  - test/test_helper.rb
50
50
  has_rdoc: true
51
51
  homepage: http://github.com/extjs/mvc
52
+ licenses:
52
53
  post_install_message:
53
54
  rdoc_options:
54
55
  - --charset=UTF-8
@@ -69,7 +70,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
69
70
  requirements: []
70
71
 
71
72
  rubyforge_project:
72
- rubygems_version: 1.2.0
73
+ rubygems_version: 1.3.5
73
74
  signing_key:
74
75
  specification_version: 2
75
76
  summary: Ruby tools for ExtJS development