netzke-core 0.7.7 → 0.8.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (192) hide show
  1. data/.travis.yml +1 -2
  2. data/CHANGELOG.md +572 -0
  3. data/LICENSE +7 -1
  4. data/README.md +345 -29
  5. data/Rakefile +3 -3
  6. data/app/controllers/netzke_controller.rb +37 -48
  7. data/config/ci/before-travis.sh +3 -4
  8. data/javascripts/base.js +86 -150
  9. data/javascripts/ext.js +180 -210
  10. data/javascripts/{core_extensions.js → js_extensions.js} +0 -0
  11. data/lib/netzke-core.rb +16 -6
  12. data/lib/netzke/base.rb +84 -107
  13. data/lib/netzke/core.rb +7 -41
  14. data/lib/netzke/core/action_config.rb +37 -0
  15. data/lib/netzke/core/actions.rb +123 -0
  16. data/lib/netzke/core/client_class.rb +252 -0
  17. data/lib/netzke/core/component_config.rb +12 -0
  18. data/lib/netzke/core/composition.rb +274 -0
  19. data/lib/netzke/core/config_to_dsl_delegator.rb +69 -0
  20. data/lib/netzke/core/configuration.rb +63 -0
  21. data/lib/netzke/core/css_config.rb +51 -0
  22. data/lib/netzke/core/dynamic_assets.rb +19 -49
  23. data/lib/netzke/{embedding.rb → core/embedding.rb} +4 -6
  24. data/lib/netzke/core/endpoint_response.rb +15 -0
  25. data/lib/netzke/core/javascript.rb +111 -0
  26. data/lib/netzke/core/panel.rb +11 -0
  27. data/lib/netzke/{plugins.rb → core/plugins.rb} +10 -5
  28. data/lib/netzke/core/railz.rb +4 -0
  29. data/lib/netzke/{railz → core/railz}/action_view_ext.rb +22 -18
  30. data/lib/netzke/core/railz/action_view_ext/ext.rb +49 -0
  31. data/lib/netzke/core/railz/controller_extensions.rb +17 -0
  32. data/lib/netzke/core/railz/engine.rb +16 -0
  33. data/lib/netzke/core/railz/routes.rb +10 -0
  34. data/lib/netzke/core/ruby_ext.rb +5 -0
  35. data/lib/netzke/core/ruby_ext/array.rb +23 -0
  36. data/lib/netzke/core/ruby_ext/hash.rb +47 -0
  37. data/lib/netzke/{core_ext → core/ruby_ext}/string.rb +2 -7
  38. data/lib/netzke/core/ruby_ext/symbol.rb +13 -0
  39. data/lib/netzke/{core_ext → core/ruby_ext}/time_with_zone.rb +0 -0
  40. data/lib/netzke/core/services.rb +130 -0
  41. data/lib/netzke/core/session.rb +15 -19
  42. data/lib/netzke/core/state.rb +40 -0
  43. data/lib/netzke/core/stylesheets.rb +48 -0
  44. data/lib/netzke/core/version.rb +2 -2
  45. data/lib/netzke/plugin.rb +8 -11
  46. data/netzke-core.gemspec +69 -59
  47. data/test/core_test_app/Gemfile +2 -20
  48. data/test/core_test_app/Gemfile.lock +65 -74
  49. data/test/core_test_app/app/components/card_component_loader.rb +4 -4
  50. data/test/core_test_app/app/components/component_loader.rb +40 -120
  51. data/test/core_test_app/app/components/component_loader/javascripts/component_loader.js +49 -0
  52. data/test/core_test_app/app/components/component_with_actions.rb +61 -47
  53. data/test/core_test_app/app/components/component_with_custom_css.rb +8 -5
  54. data/test/core_test_app/app/components/component_with_js_mixin.rb +11 -5
  55. data/test/core_test_app/app/components/component_with_js_mixin/javascripts/extra_one.js +1 -1
  56. data/test/core_test_app/app/components/component_with_js_mixin/javascripts/extra_two.js +1 -1
  57. data/test/core_test_app/app/components/component_with_js_mixin/javascripts/method_set_one.js +1 -1
  58. data/test/core_test_app/app/components/component_with_nested_through.rb +2 -2
  59. data/test/core_test_app/app/components/component_with_prebuilt_toolbar_control.rb +12 -0
  60. data/test/core_test_app/app/components/component_with_prebuilt_toolbar_control/javascripts/component_with_prebuilt_toolbar_control.js +12 -0
  61. data/test/core_test_app/app/components/component_with_required_js.rb +24 -0
  62. data/test/core_test_app/app/components/configurable_on_class_level.rb +8 -0
  63. data/test/core_test_app/app/components/dsl_delegated_properties.rb +4 -0
  64. data/test/core_test_app/app/components/dsl_delegated_properties_base.rb +5 -0
  65. data/test/core_test_app/app/components/dynamic_tab_panel/javascripts/dynamic_tab_panel.js +2 -2
  66. data/test/core_test_app/app/components/ext_direct/composite.rb +32 -33
  67. data/test/core_test_app/app/components/ext_direct/details.rb +2 -4
  68. data/test/core_test_app/app/components/ext_direct/selector.rb +20 -22
  69. data/test/core_test_app/app/components/ext_direct/statistics.rb +2 -4
  70. data/test/core_test_app/app/components/extended_component_with_actions.rb +7 -3
  71. data/test/core_test_app/app/components/extended_component_with_js_mixin.rb +7 -4
  72. data/test/core_test_app/app/components/extended_component_with_js_mixin/javascripts/some_method_set.js +1 -1
  73. data/test/core_test_app/app/components/extended_server_caller.rb +20 -14
  74. data/test/core_test_app/app/components/hello_world.rb +23 -0
  75. data/test/core_test_app/app/components/hello_world/javascripts/hello_world.js +12 -0
  76. data/test/core_test_app/app/components/included.js +2 -2
  77. data/test/core_test_app/app/components/kinda_complex_component.rb +1 -3
  78. data/test/core_test_app/app/components/kinda_complex_component/basic_stuff.rb +15 -17
  79. data/test/core_test_app/app/components/kinda_complex_component/extra_stuff.rb +4 -5
  80. data/test/core_test_app/app/components/loader_of_component_with_custom_css.rb +14 -5
  81. data/test/core_test_app/app/components/localized_panel.rb +23 -25
  82. data/test/core_test_app/app/components/multipane_component_loader.rb +19 -20
  83. data/test/core_test_app/app/components/nested_component.rb +4 -5
  84. data/test/core_test_app/app/components/panel_with_plugin.rb +8 -3
  85. data/test/core_test_app/app/components/panel_with_tools.rb +15 -14
  86. data/test/core_test_app/app/components/plugin_with_components.rb +20 -12
  87. data/test/core_test_app/app/components/scoped_components/deep_scoped_components/some_deep_scoped_component.rb +5 -2
  88. data/test/core_test_app/app/components/scoped_components/extended_scoped_component.rb +5 -2
  89. data/test/core_test_app/app/components/scoped_components/some_scoped_component.rb +5 -2
  90. data/test/core_test_app/app/components/server_caller.rb +39 -17
  91. data/test/core_test_app/app/components/server_caller/javascripts/server_caller.js +42 -0
  92. data/test/core_test_app/app/components/server_counter.rb +18 -82
  93. data/test/core_test_app/app/components/server_counter/javascripts/server_counter.js +53 -0
  94. data/test/core_test_app/app/components/simple_authentication_component.rb +46 -0
  95. data/test/core_test_app/app/components/simple_component.rb +8 -3
  96. data/test/core_test_app/app/components/simple_composite.rb +12 -0
  97. data/test/core_test_app/app/components/simple_form_with_file_upload.rb +49 -0
  98. data/test/core_test_app/app/components/simple_panel.rb +2 -2
  99. data/test/core_test_app/app/components/simple_tab_panel.rb +24 -3
  100. data/test/core_test_app/app/components/simple_window.rb +4 -2
  101. data/test/core_test_app/app/components/some_composite.rb +77 -48
  102. data/test/core_test_app/app/components/some_plugin.rb +31 -30
  103. data/test/core_test_app/app/components/stateful_component.rb +46 -0
  104. data/test/core_test_app/app/components/stateful_component_with_shared_state.rb +11 -0
  105. data/test/core_test_app/app/components/window_with_simple_component.rb +14 -0
  106. data/test/core_test_app/app/views/layouts/application.html.erb +1 -1
  107. data/test/core_test_app/app/views/simple_rails/multiple_nested.html.erb +7 -19
  108. data/test/core_test_app/app/views/simple_rails/panel.html.erb +1 -0
  109. data/test/core_test_app/config/database.yml.travis +3 -5
  110. data/test/core_test_app/config/environments/production.rb +1 -1
  111. data/test/core_test_app/config/initializers/netzke.rb +3 -1
  112. data/test/core_test_app/config/locales/en.yml +9 -4
  113. data/test/core_test_app/config/locales/es.yml +4 -2
  114. data/test/core_test_app/config/routes.rb +2 -8
  115. data/test/core_test_app/db/schema.rb +3 -11
  116. data/test/core_test_app/features/actions_and_tools.feature +1 -0
  117. data/test/core_test_app/features/client-server.feature +7 -0
  118. data/test/core_test_app/features/component_loader.feature +13 -13
  119. data/test/core_test_app/features/composition.feature +14 -0
  120. data/test/core_test_app/features/config_to_dsl_delegation.feature +10 -0
  121. data/test/core_test_app/features/file_inclusion.feature +1 -1
  122. data/test/core_test_app/features/i18n.feature +4 -4
  123. data/test/core_test_app/features/js_include.feature +1 -1
  124. data/test/core_test_app/features/persistence.feature +21 -5
  125. data/test/core_test_app/features/step_definitions/generic_steps.rb +14 -0
  126. data/test/core_test_app/features/support/paths.rb +0 -3
  127. data/test/core_test_app/public/images/icons/accept.png +0 -0
  128. data/test/core_test_app/public/images/icons/anchor.png +0 -0
  129. data/test/core_test_app/public/images/icons/tick.png +0 -0
  130. data/test/core_test_app/spec/action_config_spec.rb +15 -0
  131. data/test/core_test_app/spec/{component/actions_spec.rb → actions_spec.rb} +38 -36
  132. data/test/core_test_app/spec/base_spec.rb +35 -0
  133. data/test/core_test_app/spec/client_class_spec.rb +17 -0
  134. data/test/core_test_app/spec/component +0 -0
  135. data/test/core_test_app/spec/composition_spec.rb +118 -0
  136. data/test/core_test_app/spec/core_ext_spec.rb +3 -14
  137. data/test/core_test_app/spec/endpoint_response_spec.rb +17 -0
  138. data/test/core_test_app/spec/javascript_spec.rb +33 -0
  139. data/test/core_test_app/spec/js_class_config_scope.rb +37 -0
  140. data/test/core_test_app/spec/panel_spec.rb +11 -0
  141. data/test/core_test_app/spec/services_spec.rb +16 -0
  142. data/test/core_test_app/spec/state_spec.rb +20 -0
  143. data/test/unit/core_ext_test.rb +0 -53
  144. data/test/unit/netzke_core_test.rb +11 -11
  145. metadata +76 -62
  146. data/CHANGELOG.rdoc +0 -325
  147. data/javascripts/touch.js +0 -58
  148. data/lib/netzke/actions.rb +0 -107
  149. data/lib/netzke/composition.rb +0 -224
  150. data/lib/netzke/config_to_dsl_delegator.rb +0 -43
  151. data/lib/netzke/configuration.rb +0 -195
  152. data/lib/netzke/core/masquerading.rb +0 -34
  153. data/lib/netzke/core_ext.rb +0 -6
  154. data/lib/netzke/core_ext/array.rb +0 -30
  155. data/lib/netzke/core_ext/hash.rb +0 -86
  156. data/lib/netzke/core_ext/symbol.rb +0 -21
  157. data/lib/netzke/ext_component.rb +0 -25
  158. data/lib/netzke/inheritance.rb +0 -31
  159. data/lib/netzke/javascript.rb +0 -382
  160. data/lib/netzke/javascript/scopes.rb +0 -39
  161. data/lib/netzke/railz.rb +0 -4
  162. data/lib/netzke/railz/action_view_ext/ext.rb +0 -64
  163. data/lib/netzke/railz/action_view_ext/touch.rb +0 -52
  164. data/lib/netzke/railz/controller_extensions.rb +0 -33
  165. data/lib/netzke/railz/engine.rb +0 -48
  166. data/lib/netzke/railz/routes.rb +0 -7
  167. data/lib/netzke/services.rb +0 -101
  168. data/lib/netzke/session.rb +0 -54
  169. data/lib/netzke/state.rb +0 -91
  170. data/lib/netzke/stylesheets.rb +0 -65
  171. data/test/core_test_app/app/components/component_with_included_js.rb +0 -16
  172. data/test/core_test_app/app/components/component_with_session_persistence.rb +0 -35
  173. data/test/core_test_app/app/components/deprecated/server_caller.rb +0 -20
  174. data/test/core_test_app/app/components/dynamic_tab_panel.rb +0 -19
  175. data/test/core_test_app/app/components/hello_world_component.rb +0 -31
  176. data/test/core_test_app/app/components/touch/hello_world_component.rb +0 -25
  177. data/test/core_test_app/app/components/touch/server_caller.rb +0 -28
  178. data/test/core_test_app/app/components/touch/simple_carousel.rb +0 -17
  179. data/test/core_test_app/app/controllers/touch_controller.rb +0 -6
  180. data/test/core_test_app/app/helpers/touch_helper.rb +0 -2
  181. data/test/core_test_app/app/views/layouts/touch.html.erb +0 -13
  182. data/test/core_test_app/db/migrate/20110110132720_create_netzke_component_states.rb +0 -20
  183. data/test/core_test_app/features/step_definitions/touch_steps.rb +0 -3
  184. data/test/core_test_app/features/touch.feature +0 -10
  185. data/test/core_test_app/gemfiles/rails3_1.gemfile +0 -16
  186. data/test/core_test_app/gemfiles/rails3_2.gemfile +0 -16
  187. data/test/core_test_app/spec/component/base_spec.rb +0 -36
  188. data/test/core_test_app/spec/component/component_spec.rb +0 -20
  189. data/test/core_test_app/spec/component/composition_spec.rb +0 -132
  190. data/test/core_test_app/spec/component/configuration_spec.rb +0 -61
  191. data/test/core_test_app/spec/component/javascript_spec.rb +0 -16
  192. data/test/core_test_app/spec/component/state_spec.rb +0 -18
data/lib/netzke-core.rb CHANGED
@@ -1,17 +1,20 @@
1
- $LOAD_PATH << File.dirname(__FILE__)
2
-
3
1
  require 'netzke/core'
4
2
  require 'netzke/base'
5
- require 'netzke/plugin'
6
3
 
7
4
  module Netzke
8
- autoload :Core, 'netzke/core'
9
- autoload :ExtComponent, 'netzke/ext_component'
5
+ autoload :Plugin, 'netzke/plugin'
6
+
7
+ module Core
8
+ autoload :ComponentConfig, 'netzke/core/component_config'
9
+ autoload :ActionConfig, 'netzke/core/action_config'
10
+ autoload :Panel, 'netzke/core/panel'
11
+ autoload :EndpointResponse, 'netzke/core/endpoint_response'
12
+ end
10
13
  end
11
14
 
12
15
  # Rails specific
13
16
  if defined? Rails
14
- require 'netzke/railz'
17
+ require 'netzke/core/railz'
15
18
 
16
19
  ActiveSupport.on_load(:action_controller) do
17
20
  include Netzke::Railz::ControllerExtensions
@@ -20,4 +23,11 @@ if defined? Rails
20
23
  ActiveSupport.on_load(:action_view) do
21
24
  include Netzke::Railz::ActionViewExt
22
25
  end
26
+
27
+ ActiveSupport.on_load(:after_initialize) do
28
+ Netzke::Base.logger = Rails.logger
29
+ end
30
+ else
31
+ require 'logger'
32
+ Netzke::Base.logger = Logger.new(STDOUT)
23
33
  end
data/lib/netzke/base.rb CHANGED
@@ -1,77 +1,80 @@
1
1
  require 'active_support/core_ext'
2
- require 'netzke/core_ext'
3
- require 'netzke/javascript'
4
- require 'netzke/stylesheets'
5
- require 'netzke/inheritance'
6
- require 'netzke/services'
7
- require 'netzke/composition'
8
- require 'netzke/plugins'
9
- require 'netzke/configuration'
10
- require 'netzke/state'
11
- require 'netzke/embedding'
12
- require 'netzke/actions'
13
- require 'netzke/session'
14
- require 'netzke/config_to_dsl_delegator'
2
+ require 'netzke/core/ruby_ext'
3
+ require 'netzke/core/javascript'
4
+ require 'netzke/core/stylesheets'
5
+ require 'netzke/core/services'
6
+ require 'netzke/core/composition'
7
+ require 'netzke/core/plugins'
8
+ require 'netzke/core/configuration'
9
+ require 'netzke/core/state'
10
+ require 'netzke/core/embedding'
11
+ require 'netzke/core/actions'
12
+ require 'netzke/core/session'
15
13
 
16
14
  module Netzke
17
- # The base for every Netzke component
15
+ # The base class for every Netzke component. Its main responsibilities include:
16
+ # * JavaScript class generation and inheritance (using Ext JS class system) which reflects the Ruby class inheritance (see {Netzke::Core::Javascript})
17
+ # * Nesting and dynamic loading of child components (see {Netzke::Core::Composition})
18
+ # * Ruby-side action declaration (see {Netzke::Actions})
19
+ # * I18n
20
+ # * Client-server communication (see {Netzke::Core::Services})
21
+ # * Session-based persistence (see {Netzke::Core::State})
18
22
  #
19
- # == Class-level configuration
20
- # You can configure component classes in Rails Application, e.g.:
23
+ # == Referring to JavaScript configuration methods from Ruby
21
24
  #
22
- # config.netzke.basepack.grid_panel.column_filters_available = false
25
+ # Netzke allows use Ruby symbols for referring to pre-defined pieces of configuration. Let's say for example, that a toolbar needs to nest a control more complex than a button (say, a date field), and a component should still make it possible to make it's presence and position in the toolbar configurable. We can implement it like this:
23
26
  #
24
- # Optionally, when used outside of Rails, you can also set the values directly on Netzke::Core.config (the Engine does it for you):
27
+ # action :do_something
25
28
  #
26
- # Netzke::Core.config.netzke.basepack.grid_panel.column_filters_available = false
29
+ # def configure(c)
30
+ # super
31
+ # c.tbar = [:do_something, :date_selector]
32
+ # end
27
33
  #
28
- # If both default and overriding values are hashes, the default value gets deep-merged with the overriding value.
34
+ # While :do_something here is referring to a usual Netzke action, :date_selector is not declared in actions. If our JavaScript mixin file contains a method called `dateSelectorConfig`, it will be executed at the moment of configuring `tbar` at client side, and it's result, a config object, will substitute `date_selector`:
29
35
  #
30
- # Netzke::Base provides the following class-level configuration options:
31
- # * default_instance_config - a hash that will be used as default configuration for ALL of this component's instances.
36
+ # {
37
+ # dateSelectorConfig: function(config){
38
+ # return {
39
+ # xtype: 'datefield'
40
+ # }
41
+ # }
42
+ # }
43
+ #
44
+ # This doesn't necessarily have to be used in toolbars, but also in other places in config (i.e. layouts).
32
45
  class Base
33
- include Session
34
- include State
35
- include Configuration
36
- include Javascript
37
- include Inheritance
38
- include Services
39
- include Composition
40
- include Plugins
41
- include Stylesheets
42
- include Embedding
43
- include Actions
44
- include ConfigToDslDelegator
45
-
46
- delegates_to_dsl :title, :items
47
-
48
- class_config_option :default_instance_config, {}
46
+ include Core::Session
47
+ include Core::State
48
+ include Core::Configuration
49
+ include Core::Javascript
50
+ include Core::Services
51
+ include Core::Composition
52
+ include Core::Plugins
53
+ include Core::Stylesheets
54
+ include Core::Embedding
55
+ include Core::Actions
56
+
57
+ class_attribute :default_instance_config
58
+ self.default_instance_config = {}
59
+
60
+ # set during initializations
61
+ mattr_accessor :session
62
+ mattr_accessor :controller
63
+ mattr_accessor :logger
49
64
 
50
65
  # Parent component
51
66
  attr_reader :parent
52
67
 
53
- # Name that the parent can reference us by. The last part of +global_id+
68
+ # Name that the parent can reference us by. The last part of +js_id+
54
69
  attr_reader :name
55
70
 
56
71
  # Global id in the components tree, following the double-underscore notation, e.g. +books__config_panel__form+
57
- attr_reader :global_id
72
+ attr_reader :js_id
58
73
 
59
74
  class << self
60
- # Component's short class name, e.g.:
61
- # "Netzke::Module::SomeComponent" => "Module::SomeComponent"
62
- def short_component_class_name
63
- self.name.sub(/^Netzke::/, "")
64
- end
65
-
66
- # Component's class, given its name.
67
- def constantize_class_name(class_name)
68
- class_name.constantize # used to be more complex than this, but appeared to be difficult to debug
69
- end
70
-
71
75
  # Instance of component by config
72
76
  def instance_by_config(config)
73
- klass = config[:klass] || constantize_class_name(config[:class_name])
74
- raise NameError, "Netzke: Unknown component #{config[:class_name]}" if klass.nil?
77
+ klass = config[:klass] || config[:class_name].constantize
75
78
  klass.new(config)
76
79
  end
77
80
 
@@ -80,6 +83,23 @@ module Netzke
80
83
  name.split("::").map{|c| c.underscore}.join(".")
81
84
  end
82
85
 
86
+ # Do class-level config of a component, e.g.:
87
+ #
88
+ # Netzke::Basepack::GridPanel.setup do |c|
89
+ # c.rows_reordering_available = false
90
+ # end
91
+ def self.setup
92
+ yield self
93
+ end
94
+
95
+ # Ancestor classes in the Netzke class hierarchy up to (and excluding) +Netzke::Base+, including self; in comparison to Ruby's own Class.ancestors, the order is reversed.
96
+ def netzke_ancestors
97
+ if self == Netzke::Base
98
+ []
99
+ else
100
+ superclass.netzke_ancestors + [self]
101
+ end
102
+ end
83
103
  end
84
104
 
85
105
  # Instantiates a component instance. A parent can optionally be provided.
@@ -87,70 +107,27 @@ module Netzke
87
107
  @passed_config = conf # configuration passed at the moment of instantiation
88
108
  @passed_config.deep_freeze
89
109
  @parent = parent
90
- @name = conf[:name].nil? ? short_component_class_name.underscore : conf[:name].to_s
91
- @global_id = parent.nil? ? @name : "#{parent.global_id}__#{@name}"
110
+ @name = conf[:name] || self.class.name.underscore
111
+ @js_id = parent.nil? ? @name : "#{parent.js_id}__#{@name}"
92
112
  @flash = []
93
113
 
94
- # initialize @components and @items
95
- normalize_components_in_items
96
- # auto_collect_actions_from_config_and_js_properties
97
-
98
- self.class.increase_total_instances
99
- end
100
-
101
- # Proxy to the equally named class method
102
- def constantize_class_name(class_name)
103
- self.class.constantize_class_name(class_name)
104
- end
105
-
106
- # Proxy to the equally named class method
107
- def short_component_class_name
108
- self.class.short_component_class_name
109
- end
110
-
111
- # Override this method to do stuff at the moment of first-time loading
112
- def before_load
113
- end
114
-
115
- def clean_up
116
- component_session.clear
117
- components.keys.each { |k| component_instance(k).clean_up }
114
+ # Build complete component configuration
115
+ configure(config)
118
116
  end
119
117
 
120
118
  def i18n_id
121
119
  self.class.i18n_id
122
120
  end
123
121
 
124
- # Used for performance measurments
125
- def self.total_instances
126
- @@instances || 0
127
- end
128
-
129
- def self.reset_total_instances
130
- @@instances = 0
131
- end
122
+ private
132
123
 
133
- def self.increase_total_instances
134
- @@instances ||= 0
135
- @@instances += 1
124
+ # TODO: needs rework
125
+ # TODO: rename to smth more appropriate
126
+ def flash(flash_hash)
127
+ level = flash_hash.keys.first
128
+ raise "Unknown message level for flash" unless %(notice warning error).include?(level.to_s)
129
+ @flash << {:level => level, :msg => flash_hash[level]}
136
130
  end
137
131
 
138
- private
139
-
140
- def logger #:nodoc:
141
- if defined?(::Rails)
142
- ::Rails.logger
143
- else
144
- require 'logger'
145
- Logger.new(STDOUT)
146
- end
147
- end
148
-
149
- def flash(flash_hash) #:nodoc:
150
- level = flash_hash.keys.first
151
- raise "Unknown message level for flash" unless %(notice warning error).include?(level.to_s)
152
- @flash << {:level => level, :msg => flash_hash[level]}
153
- end
154
-
155
132
  end
156
133
  end
data/lib/netzke/core.rb CHANGED
@@ -1,9 +1,10 @@
1
1
  require 'active_support/core_ext'
2
2
  require 'netzke/core/options_hash'
3
3
  require 'netzke/core/version'
4
- require 'netzke/core/session'
5
- require 'netzke/core/masquerading'
6
4
  require 'netzke/core/dynamic_assets'
5
+ require 'netzke/core/client_class'
6
+ require 'netzke/core/css_config'
7
+ require 'netzke/core/config_to_dsl_delegator'
7
8
 
8
9
  module Netzke
9
10
  # This module implements high-level configuration for Netzke Core.
@@ -11,36 +12,19 @@ module Netzke
11
12
  # You can configure Netzke::Core like this:
12
13
  #
13
14
  # Netzke::Core.setup do |config|
14
- # config.ext_location = "/home/netzke/ext-3.3.0"
15
+ # config.ext_location = "/home/netzke/ext-4.1.1"
15
16
  # config.icons_uri = "/images/famfamfam/icons"
16
17
  # # ...
17
18
  # end
18
19
  #
19
20
  # The following configuration options are available:
20
- # * ext_location - absolute path to your Ext code root
21
+ # * ext_path - absolute path to your Ext code root
21
22
  # * icons_uri - relative URI to the icons
22
23
  module Core
23
- extend Session
24
- extend Masquerading
25
-
26
- # Use Ext 3 compatibility layer
27
- mattr_accessor :ext3_compat_uri
28
-
29
- # Configuration specified at the initialization times (set in the Engine in case of Rails)
30
- mattr_accessor :config
31
- @@config = {}
32
-
33
- # :ext or :touch
24
+ # :ext (or :touch - when and if ever implemented)
34
25
  mattr_accessor :platform
35
26
  @@platform = :ext
36
27
 
37
- # set in Netzke::ControllerExtensions
38
- mattr_accessor :controller
39
-
40
- # set in Netzke::ControllerExtensions
41
- mattr_accessor :session
42
- @@session = {}
43
-
44
28
  mattr_accessor :ext_javascripts
45
29
  @@ext_javascripts = []
46
30
 
@@ -59,36 +43,18 @@ module Netzke
59
43
 
60
44
  mattr_accessor :ext_path
61
45
 
62
- mattr_accessor :current_user_method
63
- @@current_user_method = :current_user
64
-
65
- mattr_accessor :persistence_manager
66
- @@persistence_manager = "NetzkeComponentState"
67
-
68
46
  # The amount of retries that the direct remoting provider will attempt in case of failure
69
47
  mattr_accessor :js_direct_max_retries
70
48
  @@js_direct_max_retries = 0
71
49
 
72
50
  mattr_accessor :with_icons
73
51
 
74
- mattr_accessor :persistence_manager_class
75
-
76
- # Sencha Touch specific
77
- mattr_accessor :touch_javascripts
78
- @@touch_javascripts = []
79
-
80
- mattr_accessor :touch_stylesheets
81
- @@touch_stylesheets = []
82
-
83
- mattr_accessor :touch_uri
84
- @@touch_uri = "/sencha-touch"
85
-
86
52
  def self.setup
87
53
  yield self
88
54
  end
89
55
 
90
56
  def self.reset_components_in_session
91
- Netzke::Core.session[:netzke_components].try(:clear)
57
+ Netzke::Base.session[:netzke_components].try(:clear)
92
58
  end
93
59
  end
94
60
  end
@@ -0,0 +1,37 @@
1
+ module Netzke::Core
2
+ # This class is responsible for configuring an action. It is passed as a block parameter to the +action+ DSL method:
3
+ #
4
+ # class MyComponent < Netzke::Base
5
+ # action :do_something do |c|
6
+ # c.text = "Do it!"
7
+ # end
8
+ # end
9
+ class ActionConfig < ActiveSupport::OrderedOptions
10
+ def initialize(name, component)
11
+ @component = component
12
+ @name = name.to_s
13
+ @text = @tooltip = @icon = ""
14
+
15
+ build_localized_attributes
16
+
17
+ self.text = @text.presence || @name.humanize
18
+ self.tooltip = @tooltip.presence || @name.humanize
19
+ self.icon = @icon.to_sym if @icon.present?
20
+ end
21
+
22
+ def icon=(path)
23
+ self[:icon] = path.is_a?(Symbol) ? Netzke::Base.uri_to_icon(path) : path
24
+ end
25
+
26
+ private
27
+
28
+ def build_localized_attributes
29
+ @component.class.netzke_ancestors.each do |c|
30
+ i18n_id = c.i18n_id
31
+ @text = I18n.t("#{i18n_id}.actions.#{@name}.text", default: "").presence || @text
32
+ @tooltip = I18n.t("#{i18n_id}.actions.#{@name}.tooltip", default: "").presence || @tooltip
33
+ @icon = I18n.t("#{i18n_id}.actions.#{@name}.icon", default: "").presence || @icon
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,123 @@
1
+ module Netzke::Core
2
+ # Netzke components allow specifying Ext actions (see http://docs.sencha.com/ext-js/4-1/#!/api/Ext.Action) in Ruby code.
3
+ #
4
+ # == Defining actions
5
+ #
6
+ # An action is defined with the +action+ class method that accepts a block:
7
+ #
8
+ # action :destroy do |c|
9
+ # c.text = "Destroy!"
10
+ # c.tooltip = "Destroying it all"
11
+ # c.icon = :delete
12
+ # c.handler = :destroy_something # destroySomething will be called on JavaScript side
13
+ # end
14
+ #
15
+ # All config settings for an action are optional. When omitted, the locale files will be consulted first (see "I18n of actions"), falling back to the defaults.
16
+ #
17
+ # [+icon+]
18
+ # Can be set to either a String (which will be interpreted as a full URI to the icon file), or as a Symbol, which will be expanded to +Netzke::Core.icons_uri+ + "/(icon).png". Defaults to nil (no icon)
19
+ # [+handler+]
20
+ # A symbol that represents the JavaScript public method (snake-case), which will be called in the scope of the component instance. Defaults to +on_(action_name)+, which on JavaScript side will result in a call to +on(CamelCaseActionName)+
21
+ # +text+ and +tooltip+ default to "Humanized action name"
22
+ #
23
+ # When no block is given, the defaults will be used:
24
+ #
25
+ # action :my_cool_action
26
+ #
27
+ # is equivalent (unless localization is found for this action) to:
28
+ #
29
+ # action :my_cool_action do |c|
30
+ # c.text = c.tooltip = "My cool action"
31
+ # c.handler = :on_my_cool_action
32
+ # end
33
+ #
34
+ # == Accessing component configuration from action block
35
+ #
36
+ # Because the action block get transformed into an instance method, it's possible to access the `config` method of the component itself:
37
+ #
38
+ # action :show_report do |c|
39
+ # c.text = "Show report"
40
+ # c.icon = :report
41
+ # c.disabled = !config[:can_see_report]
42
+ # end
43
+ #
44
+ # == Overriding an action
45
+ #
46
+ # When extending a component, it's possible to override its actions. You'll need to call the +super+ method passing the configuration object to it in order to get the super-class' action configuration:
47
+ #
48
+ # action :destroy do |c|
49
+ # super(c) # original config
50
+ # c.text = "Destroy (extended)" # overriding the text
51
+ # end
52
+ #
53
+ # == I18n of actions
54
+ #
55
+ # +text+, +tooltip+ and +icon+ for an action will be picked up from a locale file (if located there) whenever they are not specified in the config.
56
+ # E.g., an action named "some_action" and defined in the component +MyComponents::CoolComponent+, will look for its text in:
57
+ #
58
+ # I18n.t('my_components.cool_component.actions.some_action.text')
59
+ #
60
+ # for its tooltip in:
61
+ #
62
+ # I18n.t('my_components.cool_component.actions.some_action.tooltip')
63
+ #
64
+ # and for its icon in:
65
+ #
66
+ # I18n.t('my_components.cool_component.actions.some_action.icon')
67
+ module Actions
68
+ extend ActiveSupport::Concern
69
+
70
+ ACTION_METHOD_NAME = "%s_action"
71
+
72
+ included do
73
+ # Returns registered actions
74
+ class_attribute :registered_actions
75
+ self.registered_actions = []
76
+ end
77
+
78
+ module ClassMethods
79
+ def action(name, &block)
80
+ self.registered_actions |= [name]
81
+
82
+ method_name = ACTION_METHOD_NAME % name
83
+
84
+ if block_given?
85
+ define_method(method_name, &block)
86
+ else
87
+ define_method(method_name) do |action_config|
88
+ action_config
89
+ end
90
+ end
91
+ end
92
+
93
+ # Must stay public, used from ActionConfig
94
+ # @return [String|nil] full URI to an icon file by its name (provided we have a controller)
95
+ def uri_to_icon(icon)
96
+ Netzke::Core.with_icons ? [(controller && controller.config.relative_url_root), Netzke::Core.icons_uri, '/', icon.to_s, ".png"].join : nil
97
+ end
98
+ end
99
+
100
+ # All actions for this instance
101
+ def actions
102
+ @actions ||= self.class.registered_actions.inject({}) do |res, name|
103
+ action_config = Netzke::Core::ActionConfig.new(name, self)
104
+ send(ACTION_METHOD_NAME % name, action_config)
105
+ if action_config.excluded
106
+ res.merge(name.to_sym => {excluded: true})
107
+ else
108
+ res.merge(name.to_sym => action_config)
109
+ end
110
+ end
111
+ end
112
+
113
+ def js_configure(c)
114
+ super
115
+ c.actions = actions
116
+ end
117
+
118
+ private
119
+ def uri_to_icon(icon)
120
+ self.class.uri_to_icon(icon)
121
+ end
122
+ end
123
+ end