Module: Netzke::Core::Configuration
Overview
Components can implement class-level config options by using class_attribute, e.g.:
class MyComponent < Netzke::Base
class_attribute :title
self.title = "Title for all descendants of MyComponent"
client_class do |c|
c.title = title
end
end
Then before using MyComponent (e.g. in Rails' initializers), you can configure it like this:
MyComponent.title = "Better title"
Alternatively, you can use the Base.setup method:
MyComponent.setup do |config|
config.title = "Better title"
end
Defined Under Namespace
Modules: ClassMethods
Instance Method Summary collapse
-
#client_config ⇒ Object
Config options that have been set on the fly on the client side of the component in the
serverConfigobject. -
#config ⇒ Object
Complete configuration for server class instance.
-
#configure(c) ⇒ Object
Override to auto-configure components.
Instance Method Details
#client_config ⇒ Object
Config options that have been set on the fly on the client side of the component in the serverConfig object. Can be
used to dynamically change component configuration. Those changes won't affect the way component is rendered, of
course, but can be useful to reconfigure child components, e.g.:
// Client
initConfig: function() {
this.callParent();
this.netzkeGetComponent('authors').on('rowclick', function(grid, record) {
this.serverConfig. = record.getId();
this.netzkeGetComponent('book_grid').getStore().load();
}
}
# Server
component :book_grid do |c|
c.scope = { author_id: client_config. }
end
97 98 99 |
# File 'lib/netzke/core/configuration.rb', line 97 def client_config @client_config ||= HashWithIndifferentAccess.new(config.client_config) end |
#config ⇒ Object
Complete configuration for server class instance. Can be accessed from within endpoint, component, and action blocks, as well as any other instance method, for example:
action :do_something do |c|
c.title = "Do it for #{config.title}"
end
75 76 77 |
# File 'lib/netzke/core/configuration.rb', line 75 def config @config ||= ActiveSupport::OrderedOptions.new end |
#configure(c) ⇒ Object
Override to auto-configure components. Example:
class BookGrid < Netzke::Basepack::Grid
def configure(c)
super
c.model = "Book"
end
end
65 66 67 |
# File 'lib/netzke/core/configuration.rb', line 65 def configure(c) c.merge!(@passed_config) end |