Class: Netzke::Base

Overview

The base class for every Netzke component. Its main responsibilities include:

  • Client class generation and inheritance (using Ext JS class system) which reflects the Ruby class inheritance (see Core::ClientCode)

  • Nesting and dynamic loading of child components (see Core::Composition)

  • Ruby-side action declaration (see Actions)

  • I18n

  • Client-server communication (see Core::Services)

  • Session-based persistence (see Core::State)

Client-side methods are documented [here](api.netzke.org/client/classes/Netzke.Base.html).

Referring to JavaScript configuration methods from Ruby

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:

action :do_something

def configure(c)
  super
  c.tbar = [:do_something, :date_selector]
end

While :do_something here is referring to a usual Netzke action, :date_selector is not declared in actions. If our JavaScript include 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`:

{
  dateSelectorConfig: function(config){
    return {
      xtype: 'datefield'
    }
  }
}

This doesn’t necessarily have to be used in toolbars, but also in other places in config (i.e. layouts).

Direct Known Subclasses

Core::Panel, Plugin

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Core::CoreI18n

#i18n_id

Methods included from Core::Actions

#actions, #configure_client, #extend_item

Methods included from Core::Embedding

#js_component_html, #js_component_instance, #js_component_render

Methods included from Core::Stylesheets

#css_missing_code

Methods included from Core::Plugins

#plugins

Methods included from Core::Composition

#component_config, #component_instance, #dependency_classes, #eagerly_loaded_components, #extend_item

Methods included from Core::Services

#component_missing, #has_endpoint?, #invoke_endpoint

Methods included from Core::ClientCode

#configure_client, #js_alias, #js_components, #js_config, #js_endpoints, #js_id, #js_item_id, #js_missing_code, #js_netzke_plugins, #js_path, #js_xtype

Methods included from Core::Configuration

#client_config, #config, #configure

Methods included from Core::State

#persistence_key, #state

Methods included from Core::Session

#component_session

Constructor Details

#initialize(conf = {}, parent = nil) ⇒ Base

Instantiates a component instance. A parent can optionally be provided.



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/netzke/base.rb', line 70

def initialize(conf = {}, parent = nil)
  @passed_config = conf

  # parent component
  @parent = parent

  # name fo the component used in the +component+ DSL block, and is a part of component's +@path+
  @name = conf[:name] || self.class.name.underscore

  # path down the composition hierarchy (composed of names)
  @path = parent.nil? ? @name : "#{parent.path}__#{@name}"

  # JS id in the scope of the parent component. Auto-generated when using multiple instance loading.
  # Full JS id will be built using these along the +@path+
  @item_id = conf[:item_id] || @name

  # Make +client_config+ accessible in +configure+ before calling +super+
  client_config = Netzke::Support.permit_hash_params(conf.delete(:client_config))
  config.client_config = HashWithIndifferentAccess.new(client_config)

  # Build complete component configuration
  configure(config)

  # Check whether the config is valid (as specified in a custom override)
  validate_config(config)

  normalize_config

  config.deep_freeze
end

Instance Attribute Details

#item_idObject (readonly)

Returns the value of attribute item_id.



67
68
69
# File 'lib/netzke/base.rb', line 67

def item_id
  @item_id
end

#nameObject (readonly)

Returns the value of attribute name.



67
68
69
# File 'lib/netzke/base.rb', line 67

def name
  @name
end

#parentObject (readonly)

Returns the value of attribute parent.



67
68
69
# File 'lib/netzke/base.rb', line 67

def parent
  @parent
end

#pathObject (readonly)

Returns the value of attribute path.



67
68
69
# File 'lib/netzke/base.rb', line 67

def path
  @path
end