Module: Netzke::Core::ClientCode
Overview
Client class definition and instantiation.
Defined Under Namespace
Modules: ClassMethods
Instance Method Summary collapse
-
#configure_client(c) ⇒ Object
Builds #js_config used for instantiating a client class.
-
#js_alias ⇒ Object
Ext.createByAlias may be used to instantiate the component.
-
#js_components ⇒ Object
(also: #js_netzke_components)
Hash containing configuration for all child components to be instantiated at the JS side.
-
#js_config ⇒ Object
Instance-level client class config.
- #js_endpoints ⇒ Object
-
#js_id ⇒ Object
Global id in the component tree, following the double-underscore notation, e.g.
- #js_item_id ⇒ Object
-
#js_missing_code(cached = []) ⇒ Object
All the JS-code required by this instance of the component to be instantiated in the browser, excluding cached code.
- #js_netzke_plugins ⇒ Object
- #js_path ⇒ Object
- #js_xtype ⇒ Object
Instance Method Details
#configure_client(c) ⇒ Object
Builds #js_config used for instantiating a client class. Override it when you need to extend/modify the config for the JS component intance. It’s not being called when the server class is being instantiated (e.g. to process an endpoint call). With other words, it’s only being called before a component is first being loaded in the browser. so, it’s ok to do heavy stuf fhere, like building a tree panel nodes from the database.
62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/netzke/core/client_code.rb', line 62 def configure_client(c) c.merge!(normalized_config) %w[id item_id path netzke_components endpoints xtype alias i18n netzke_plugins].each do |thing| js_thing = send(:"js_#{thing}") c[thing] = js_thing if js_thing.present? c.client_config = client_config.netzke_literalize_keys # because this is what we'll get back from client side as server config, and the keys must be snake_case end # reset component session # TODO: also remove empty hashes from the global session component_session.clear end |
#js_alias ⇒ Object
Ext.createByAlias may be used to instantiate the component.
94 95 96 |
# File 'lib/netzke/core/client_code.rb', line 94 def js_alias self.class.client_class_config.class_alias end |
#js_components ⇒ Object Also known as: js_netzke_components
Hash containing configuration for all child components to be instantiated at the JS side
113 114 115 116 117 118 |
# File 'lib/netzke/core/client_code.rb', line 113 def js_components @js_components ||= eagerly_loaded_components.inject({}) do |out, name| instance = component_instance(name.to_sym) out.merge(name => instance.js_config) end end |
#js_config ⇒ Object
Instance-level client class config. The result of this method (a hash) is converted to a JSON object and passed as options to the constructor of our JavaScript class. Not to be overridden, override #configure_client instead.
108 109 110 |
# File 'lib/netzke/core/client_code.rb', line 108 def js_config @js_config ||= ActiveSupport::OrderedOptions.new.tap{|c| configure_client(c)} end |
#js_endpoints ⇒ Object
98 99 100 |
# File 'lib/netzke/core/client_code.rb', line 98 def js_endpoints self.class.endpoints.keys.map{ |p| p.to_s.camelcase(:lower) } end |
#js_id ⇒ Object
Global id in the component tree, following the double-underscore notation, e.g. books__config_panel__form
81 82 83 |
# File 'lib/netzke/core/client_code.rb', line 81 def js_id @js_id ||= parent.nil? ? @item_id : [parent.js_id, @item_id].join("__") end |
#js_item_id ⇒ Object
89 90 91 |
# File 'lib/netzke/core/client_code.rb', line 89 def js_item_id @item_id end |
#js_missing_code(cached = []) ⇒ Object
All the JS-code required by this instance of the component to be instantiated in the browser, excluding cached code. It includes JS-classes for the parents, eagerly loaded child components, and itself.
125 126 127 128 129 130 |
# File 'lib/netzke/core/client_code.rb', line 125 def js_missing_code(cached = []) code = dependency_classes.inject("") do |r,k| cached.include?(k.client_class_config.xtype) ? r : r + k.client_class_config.code_with_dependencies end code.blank? ? nil : Netzke::Core::DynamicAssets.minify_js(code) end |
#js_netzke_plugins ⇒ Object
102 103 104 |
# File 'lib/netzke/core/client_code.rb', line 102 def js_netzke_plugins plugins.map{ |p| p.to_s.camelcase(:lower) } end |
#js_path ⇒ Object
76 77 78 |
# File 'lib/netzke/core/client_code.rb', line 76 def js_path @path end |
#js_xtype ⇒ Object
85 86 87 |
# File 'lib/netzke/core/client_code.rb', line 85 def js_xtype self.class.client_class_config.xtype end |