netzke-core 0.7.5 → 0.7.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -2,4 +2,5 @@ require "netzke/core_ext/array"
2
2
  require "netzke/core_ext/hash"
3
3
  require "netzke/core_ext/string"
4
4
  require "netzke/core_ext/symbol"
5
- require "netzke/core_ext/time_with_zone"
5
+ require "netzke/core_ext/time_with_zone"
6
+
@@ -12,18 +12,18 @@ module Netzke
12
12
  end
13
13
  end
14
14
 
15
- # Same as +read_inheritable_attribute+ returning a hash, but returns empty hash when it's equal to superclass's
16
- def read_clean_inheritable_hash(attr_name)
17
- res = read_inheritable_attribute(attr_name) || {}
18
- # We don't want here any values from the superclass (which is the consequence of using inheritable attributes).
19
- res == self.superclass.read_inheritable_attribute(attr_name) ? {} : res
15
+ # Same as +class_attribute+ returning a hash, but returns empty hash when it's equal to superclass's
16
+ def clean_class_attribute_hash(attr_name)
17
+ res = self.send(attr_name)
18
+ # We don't want here any values from the superclass (which is the consequence of using class attributes).
19
+ res == self.superclass.send(attr_name) ? {} : res
20
20
  end
21
21
 
22
- # Same as +read_inheritable_attribute+ returning a hash, but returns empty hash when it's equal to superclass's
23
- def read_clean_inheritable_array(attr_name)
24
- res = read_inheritable_attribute(attr_name) || []
25
- # We don't want here any values from the superclass (which is the consequence of using inheritable attributes).
26
- res == self.superclass.read_inheritable_attribute(attr_name) ? [] : res
22
+ # Same as +class_attribute+ returning an array, but returns empty array when it's equal to superclass's
23
+ def clean_class_attribute_array(attr_name)
24
+ res = self.send(attr_name) || []
25
+ # We don't want here any values from the superclass (which is the consequence of using class attributes).
26
+ res == self.superclass.send(attr_name) ? [] : res
27
27
  end
28
28
 
29
29
  end
@@ -20,6 +20,23 @@ module Netzke
20
20
 
21
21
  class_attribute :js_included_files
22
22
  self.js_included_files = []
23
+
24
+ # Returns all JS method definitions in a hash
25
+ class_attribute :js_methods_attr
26
+ self.js_methods_attr = {}
27
+
28
+ class_attribute :js_properties_attr
29
+ self.js_properties_attr = {}
30
+
31
+ # Returns all objects to be mixed in (as array of strings)
32
+ class_attribute :js_mixins_attr
33
+ self.js_mixins_attr = []
34
+
35
+ class_attribute :js_translated_properties_attr
36
+ self.js_translated_properties_attr = {}
37
+
38
+ class_attribute :js_base_class_attr
39
+ self.js_base_class_attr = 'Ext.panel.Panel'
23
40
  end
24
41
 
25
42
  module ClassMethods
@@ -32,7 +49,7 @@ module Netzke
32
49
  #
33
50
  # If called without parameters, returns the JS base class declared for the component.
34
51
  def js_base_class(class_name = nil)
35
- class_name.nil? ? (read_inheritable_attribute(:js_base_class) || "Ext.panel.Panel") : write_inheritable_attribute(:js_base_class, class_name)
52
+ class_name.nil? ? self.js_base_class_attr : self.js_base_class_attr = class_name
36
53
  end
37
54
 
38
55
  # Use it to define a public method of the component's JavaScript class, e.g.:
@@ -46,14 +63,13 @@ module Netzke
46
63
  # This will effectively result in definition of a public method called +doSomething+ in the JavaScript class (note the conversion from underscore_name to camelCaseName).
47
64
  def js_method(name, definition = nil)
48
65
  definition = yield.l if block_given?
49
- current_js_methods = read_clean_inheritable_hash(:js_methods)
50
- current_js_methods.merge!(name => definition.l)
51
- write_inheritable_attribute(:js_methods, current_js_methods)
66
+ current_js_methods = clean_class_attribute_hash(:js_methods_attr).dup
67
+ self.js_methods_attr = current_js_methods.merge(name => definition.l)
52
68
  end
53
69
 
54
70
  # Returns all JS method definitions in a hash
55
71
  def js_methods
56
- read_clean_inheritable_hash(:js_methods)
72
+ clean_class_attribute_hash(:js_methods_attr)
57
73
  end
58
74
 
59
75
  # Use it to specify JS files to be loaded before this component's JS code. Useful when using external extensions required by this component.
@@ -72,7 +88,7 @@ module Netzke
72
88
  def js_include(*args)
73
89
  callr = caller.first
74
90
 
75
- self.js_included_files += args.map{ |a| a.is_a?(Symbol) ? expand_js_include_path(a, callr) : a }
91
+ self.js_included_files |= args.map{ |a| a.is_a?(Symbol) ? expand_js_include_path(a, callr) : a }
76
92
  end
77
93
 
78
94
  # Used to define default properties of the JavaScript class, e.g.:
@@ -87,11 +103,10 @@ module Netzke
87
103
  # Note, that not all the configuration options can be defined on the prototype of the class. For example, defining +items+ on the prototype won't take any effect, so, +items+ should be passed as a configuration option at the moment of instantiation (see Netzke::Base#configuration and Netzke::Base#default_config).
88
104
  def js_properties(hsh = nil)
89
105
  if hsh.nil?
90
- read_clean_inheritable_hash(:js_properties)
106
+ clean_class_attribute_hash(:js_properties_attr)
91
107
  else
92
- current_js_properties = read_clean_inheritable_hash(:js_properties)
93
- current_js_properties.merge!(hsh)
94
- write_inheritable_attribute(:js_properties, current_js_properties)
108
+ current_js_properties = clean_class_attribute_hash(:js_properties_attr).dup
109
+ self.js_properties_attr = current_js_properties.merge(hsh)
95
110
  end
96
111
  end
97
112
 
@@ -100,11 +115,11 @@ module Netzke
100
115
  def js_property(name, value = nil)
101
116
  name = name.to_sym
102
117
  if value.nil?
103
- (read_inheritable_attribute(:js_properties) || {})[name]
118
+ clean_class_attribute_hash(:js_properties_attr)[name]
104
119
  else
105
- current_js_properties = read_clean_inheritable_hash(:js_properties)
120
+ current_js_properties = clean_class_attribute_hash(:js_properties_attr).dup
106
121
  current_js_properties[name] = value
107
- write_inheritable_attribute(:js_properties, current_js_properties)
122
+ self.js_properties_attr = current_js_properties
108
123
  end
109
124
  end
110
125
 
@@ -122,9 +137,9 @@ module Netzke
122
137
  # TODO: make the name of the root property configurable
123
138
  def js_translate(*properties)
124
139
  if properties.empty?
125
- read_clean_inheritable_hash(:js_translated_properties)
140
+ clean_class_attribute_hash(:js_translated_properties_attr)
126
141
  else
127
- current_translated_properties = read_clean_inheritable_hash(:js_translated_properties)
142
+ current_translated_properties = clean_class_attribute_hash(:js_translated_properties_attr).dup
128
143
  properties.each do |p|
129
144
  if p.is_a?(Hash)
130
145
  # TODO: make it possible to nest translated objects
@@ -133,7 +148,7 @@ module Netzke
133
148
  end
134
149
  end
135
150
 
136
- write_inheritable_attribute(:js_translated_properties, current_translated_properties)
151
+ self.js_translated_properties_attr = current_translated_properties
137
152
  end
138
153
  end
139
154
 
@@ -160,15 +175,15 @@ module Netzke
160
175
  # With no parameters, will assume :component_class_name_underscored.
161
176
  def js_mixin(*args)
162
177
  args << name.split("::").last.underscore.to_sym if args.empty? # if no args provided, component_class_underscored_name is assumed
163
- current_mixins = read_clean_inheritable_array(:js_mixins) || []
178
+ current_mixins = clean_class_attribute_array(:js_mixins_attr)
164
179
  callr = caller.first
165
180
  args.each{ |a| current_mixins << (a.is_a?(Symbol) ? File.read(expand_js_include_path(a, callr)) : File.read(a))}
166
- write_inheritable_attribute(:js_mixins, current_mixins)
181
+ self.js_mixins_attr = current_mixins
167
182
  end
168
183
 
169
184
  # Returns all objects to be mixed in (as array of strings)
170
185
  def js_mixins
171
- read_clean_inheritable_array(:js_mixins) || []
186
+ clean_class_attribute_array(:js_mixins_attr)
172
187
  end
173
188
 
174
189
  # Builds this component's xtype
@@ -286,84 +301,82 @@ Netzke.cache.push('#{js_xtype}');
286
301
 
287
302
  end
288
303
 
289
- module InstanceMethods
290
- # The result of this method (a hash) is converted to a JSON object and passed as options
291
- # to the constructor of our JavaScript class. Override it when you want to pass any extra configuration
292
- # to the JavaScript side.
293
- def js_config
294
- {}.tap do |res|
295
- # Unique id of the component
296
- res[:id] = global_id
297
-
298
- # Non-lazy-loaded components
299
- comp_hash = {}
300
- eager_loaded_components.each_pair do |comp_name, comp_config|
301
- comp_instance = component_instance(comp_name.to_sym)
302
- comp_instance.before_load
303
- comp_hash[comp_name] = comp_instance.js_config
304
- end
304
+ # The result of this method (a hash) is converted to a JSON object and passed as options
305
+ # to the constructor of our JavaScript class. Override it when you want to pass any extra configuration
306
+ # to the JavaScript side.
307
+ def js_config
308
+ {}.tap do |res|
309
+ # Unique id of the component
310
+ res[:id] = global_id
311
+
312
+ # Non-lazy-loaded components
313
+ comp_hash = {}
314
+ eager_loaded_components.each_pair do |comp_name, comp_config|
315
+ comp_instance = component_instance(comp_name.to_sym)
316
+ comp_instance.before_load
317
+ comp_hash[comp_name] = comp_instance.js_config
318
+ end
305
319
 
306
- # Configuration for all of our non-lazy-loaded children specified here. We can refer to them in +items+ so they get instantiated by Ext.
307
- res[:netzke_components] = comp_hash unless comp_hash.empty?
320
+ # Configuration for all of our non-lazy-loaded children specified here. We can refer to them in +items+ so they get instantiated by Ext.
321
+ res[:netzke_components] = comp_hash unless comp_hash.empty?
308
322
 
309
- # Endpoints (besides the default "deliver_component" - JavaScript side already knows about it)
310
- endpoints = self.class.endpoints.keys - [:deliver_component]
311
- res[:endpoints] = endpoints unless endpoints.empty?
323
+ # Endpoints (besides the default "deliver_component" - JavaScript side already knows about it)
324
+ endpoints = self.class.endpoints.keys - [:deliver_component]
325
+ res[:endpoints] = endpoints unless endpoints.empty?
312
326
 
313
- # Inform the JavaScript side if persistent_config is enabled
314
- # res[:persistent_config] = persistence_enabled?
327
+ # Inform the JavaScript side if persistent_config is enabled
328
+ # res[:persistent_config] = persistence_enabled?
315
329
 
316
- # Include our xtype
317
- res[:xtype] = self.class.js_xtype
330
+ # Include our xtype
331
+ res[:xtype] = self.class.js_xtype
318
332
 
319
- # Include our alias: Ext.createByAlias may be used to instantiate the component.
320
- res[:alias] = self.class.js_alias
333
+ # Include our alias: Ext.createByAlias may be used to instantiate the component.
334
+ res[:alias] = self.class.js_alias
321
335
 
322
- # Merge with the rest of config options, besides those that are only meant for the server side
323
- res.merge!(config.reject{ |k,v| self.class.server_side_config_options.include?(k.to_sym) })
336
+ # Merge with the rest of config options, besides those that are only meant for the server side
337
+ res.merge!(config.reject{ |k,v| self.class.server_side_config_options.include?(k.to_sym) })
324
338
 
325
- if config[:ext_config].present?
326
- ::ActiveSupport::Deprecation.warn("Using ext_config option is deprecated. All config options must be specified at the same level in the hash.", caller)
327
- res.merge!(config[:ext_config])
328
- end
339
+ if config[:ext_config].present?
340
+ ::ActiveSupport::Deprecation.warn("Using ext_config option is deprecated. All config options must be specified at the same level in the hash.", caller)
341
+ res.merge!(config[:ext_config])
342
+ end
329
343
 
330
- # Items (nested Ext/Netzke components)
331
- res[:items] = items unless items.blank?
344
+ # Items (nested Ext/Netzke components)
345
+ res[:items] = items unless items.blank?
332
346
 
333
- # So we can use getComponent(<component_name>) to retrieve a child component
334
- res[:item_id] ||= name
347
+ # So we can use getComponent(<component_name>) to retrieve a child component
348
+ res[:item_id] ||= name
335
349
 
336
- res[:i18n] = js_translate_properties if js_translate_properties.present?
350
+ res[:i18n] = js_translate_properties if js_translate_properties.present?
337
351
 
338
- res[:netzke_plugins] = plugins.map{ |p| p.to_s.camelcase(:lower) } if plugins.present?
339
- end
352
+ res[:netzke_plugins] = plugins.map{ |p| p.to_s.camelcase(:lower) } if plugins.present?
340
353
  end
354
+ end
341
355
 
342
- # All the JS-code required by this instance of the component to be instantiated in the browser.
343
- # It includes JS-classes for the parents, non-lazy-loaded child components, and itself.
344
- def js_missing_code(cached = [])
345
- code = dependency_classes.inject("") do |r,k|
346
- cached.include?(k.js_xtype) ? r : r + k.js_code#.strip_js_comments
347
- end
348
- code.blank? ? nil : code
356
+ # All the JS-code required by this instance of the component to be instantiated in the browser.
357
+ # It includes JS-classes for the parents, non-lazy-loaded child components, and itself.
358
+ def js_missing_code(cached = [])
359
+ code = dependency_classes.inject("") do |r,k|
360
+ cached.include?(k.js_xtype) ? r : r + k.js_code#.strip_js_comments
349
361
  end
362
+ code.blank? ? nil : code
363
+ end
350
364
 
351
- # DEPRECATED. Helper to access config[:ext_config].
352
- def ext_config
353
- ::ActiveSupport::Deprecation.warn("Using ext_config is deprecated. All config options must be specified at the same level in the hash.", caller)
354
- config[:ext_config] || {}
355
- end
365
+ # DEPRECATED. Helper to access config[:ext_config].
366
+ def ext_config
367
+ ::ActiveSupport::Deprecation.warn("Using ext_config is deprecated. All config options must be specified at the same level in the hash.", caller)
368
+ config[:ext_config] || {}
369
+ end
356
370
 
357
- private
371
+ private
358
372
 
359
- # Merges all the translations in the class hierarchy
360
- def js_translate_properties
361
- @js_translate_properties ||= self.class.class_ancestors.inject({}) do |r,klass|
362
- hsh = klass.js_translate.keys.inject({}) { |h,t| h.merge(t => I18n.t("#{klass.i18n_id}.#{t}")) }
363
- r.merge(hsh)
364
- end
373
+ # Merges all the translations in the class hierarchy
374
+ def js_translate_properties
375
+ @js_translate_properties ||= self.class.class_ancestors.inject({}) do |r,klass|
376
+ hsh = klass.js_translate.keys.inject({}) { |h,t| h.merge(t => I18n.t("#{klass.i18n_id}.#{t}")) }
377
+ r.merge(hsh)
365
378
  end
379
+ end
366
380
 
367
- end
368
381
  end
369
382
  end
@@ -2,6 +2,12 @@ module Netzke
2
2
  module Plugins
3
3
  extend ActiveSupport::Concern
4
4
 
5
+ included do
6
+ # Returns registered plugins
7
+ class_attribute :registered_plugins
8
+ self.registered_plugins = []
9
+ end
10
+
5
11
  module ClassMethods
6
12
  # Defines a plugin
7
13
  def plugin(name, config = {}, &block)
@@ -11,15 +17,9 @@ module Netzke
11
17
 
12
18
  # Register a plugin
13
19
  def register_plugin(name)
14
- current_plugins = read_inheritable_attribute(:plugins) || []
15
- current_plugins << name
16
- write_inheritable_attribute(:plugins, current_plugins.uniq)
20
+ self.registered_plugins |= [name]
17
21
  end
18
22
 
19
- # Returns registered plugins
20
- def registered_plugins
21
- read_inheritable_attribute(:plugins) || []
22
- end
23
23
  end
24
24
 
25
25
  def plugins
@@ -3,6 +3,12 @@ module Netzke
3
3
  module Services
4
4
  extend ActiveSupport::Concern
5
5
 
6
+ included do
7
+ # Returns all endpoints as a hash
8
+ class_attribute :endpoints
9
+ self.endpoints = {}
10
+ end
11
+
6
12
  module ClassMethods
7
13
  # Defines an endpoint - a connection point between the client side of a component and its server side. For example:
8
14
  #
@@ -44,11 +50,6 @@ module Netzke
44
50
  end
45
51
  end
46
52
 
47
- # Returns all endpoints as a hash
48
- def endpoints
49
- read_inheritable_attribute(:endpoints) || {}
50
- end
51
-
52
53
  def api(*api_points) #:nodoc:
53
54
  ::ActiveSupport::Deprecation.warn("Using the 'api' call has no longer effect. Define endpoints instead.", caller)
54
55
  end
@@ -57,9 +58,7 @@ module Netzke
57
58
 
58
59
  # Registers an endpoint
59
60
  def register_endpoint(ep, options)
60
- current_endpoints = read_inheritable_attribute(:endpoints) || {}
61
- current_endpoints.merge!(ep => options)
62
- write_inheritable_attribute(:endpoints, current_endpoints)
61
+ self.endpoints = self.endpoints.dup.merge(ep => options)
63
62
  end
64
63
 
65
64
  end
@@ -54,14 +54,12 @@ module Netzke
54
54
 
55
55
  end
56
56
 
57
- module InstanceMethods
58
- def css_missing_code(cached = [])
59
- code = dependency_classes.inject("") do |r,k|
60
- cached.include?(k.js_xtype) ? r : r + k.css_code(cached)
61
- end
62
- code.blank? ? nil : code
57
+ def css_missing_code(cached = [])
58
+ code = dependency_classes.inject("") do |r,k|
59
+ cached.include?(k.js_xtype) ? r : r + k.css_code(cached)
63
60
  end
64
-
61
+ code.blank? ? nil : code
65
62
  end
63
+
66
64
  end
67
- end
65
+ end
data/netzke-core.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "netzke-core"
8
- s.version = "0.7.5"
8
+ s.version = "0.7.6"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["NomadCoder"]
12
- s.date = "2012-03-05"
12
+ s.date = "2012-07-27"
13
13
  s.description = "Allows building DRY ExtJS/Rails applications by enabling modular development"
14
14
  s.email = "nmcoder@gmail.com"
15
15
  s.extra_rdoc_files = [
@@ -18,6 +18,7 @@ Gem::Specification.new do |s|
18
18
  ]
19
19
  s.files = [
20
20
  ".autotest",
21
+ ".travis.yml",
21
22
  "CHANGELOG.rdoc",
22
23
  "LICENSE",
23
24
  "Manifest",
@@ -25,6 +26,7 @@ Gem::Specification.new do |s|
25
26
  "Rakefile",
26
27
  "TODO.md",
27
28
  "app/controllers/netzke_controller.rb",
29
+ "config/ci/before-travis.sh",
28
30
  "init.rb",
29
31
  "install.rb",
30
32
  "javascripts/base.js",
@@ -71,6 +73,7 @@ Gem::Specification.new do |s|
71
73
  "netzke-core.gemspec",
72
74
  "stylesheets/core.css",
73
75
  "test/core_test_app/.gitignore",
76
+ "test/core_test_app/.powrc",
74
77
  "test/core_test_app/.rvmrc",
75
78
  "test/core_test_app/Gemfile",
76
79
  "test/core_test_app/Gemfile.lock",
@@ -150,6 +153,7 @@ Gem::Specification.new do |s|
150
153
  "test/core_test_app/config/application.rb",
151
154
  "test/core_test_app/config/boot.rb",
152
155
  "test/core_test_app/config/database.yml",
156
+ "test/core_test_app/config/database.yml.travis",
153
157
  "test/core_test_app/config/environment.rb",
154
158
  "test/core_test_app/config/environments/development.rb",
155
159
  "test/core_test_app/config/environments/production.rb",
@@ -192,6 +196,8 @@ Gem::Specification.new do |s|
192
196
  "test/core_test_app/features/support/env.rb",
193
197
  "test/core_test_app/features/support/paths.rb",
194
198
  "test/core_test_app/features/touch.feature",
199
+ "test/core_test_app/gemfiles/rails3_1.gemfile",
200
+ "test/core_test_app/gemfiles/rails3_2.gemfile",
195
201
  "test/core_test_app/lib/tasks/.gitkeep",
196
202
  "test/core_test_app/public/404.html",
197
203
  "test/core_test_app/public/422.html",
@@ -212,12 +218,9 @@ Gem::Specification.new do |s|
212
218
  "test/core_test_app/spec/spec_helper.rb",
213
219
  "test/core_test_app/tmp/restart.txt",
214
220
  "test/core_test_app/vendor/plugins/.gitkeep",
215
- "test/fixtures/roles.yml",
216
- "test/fixtures/users.yml",
217
221
  "test/test_helper.rb",
218
222
  "test/unit/core_ext_test.rb",
219
223
  "test/unit/netzke_core_test.rb",
220
- "test/unit/netzke_preference_test.rb",
221
224
  "uninstall.rb"
222
225
  ]
223
226
  s.homepage = "http://netzke.org"
@@ -0,0 +1,4 @@
1
+ if [ -f "$rvm_path/scripts/rvm" ] && [ -f ".rvmrc" ]; then
2
+ source "$rvm_path/scripts/rvm"
3
+ source ".rvmrc"
4
+ fi
@@ -1 +1 @@
1
- rvm 1.9.2
1
+ rvm 1.9.3
@@ -1,6 +1,7 @@
1
1
  source 'http://rubygems.org'
2
2
 
3
- gem 'rails', '3.1.0'
3
+ gem 'rails', '3.2.3'
4
+ gem 'netzke-persistence'
4
5
 
5
6
  gem 'sqlite3'
6
7
 
@@ -22,10 +23,10 @@ gem 'sqlite3'
22
23
  # Bundle gems for the local environment. Make sure to
23
24
  # put test-only gems in this group so their generators
24
25
  # and rake tasks are available in development mode:
25
- group :development, :test do
26
+ group :test do
26
27
  gem 'capybara'
27
28
  gem 'database_cleaner'
28
- gem 'cucumber-rails'
29
+ gem 'cucumber-rails', :require => false
29
30
  gem 'cucumber'
30
31
  gem 'rspec-rails'
31
32
  gem 'spork'