The base for every Netzke component
You can configure component classes in Rails Application, e.g.:
config.netzke.basepack.grid_panel.column_filters_available = false
Optionally, when used outside of Rails, you can also set the values directly on Netzke::Core.config (the Engine does it for you):
Netzke::Core.config.netzke.basepack.grid_panel.column_filters_available = false
If both default and overriding values are hashes, the default value gets deep-merged with the overriding value.
Netzke::Base provides the following class-level configuration options:
default_instance_config - a hash that will be used as default configuration for ALL of this component’s instances.
Component’s class, given its name. Note: this method will be memoized if Rails.configuration.cache_classes is true.
# File lib/netzke/base.rb, line 67 def constantize_class_name(class_name) "#{class_name}".constantize rescue NameError begin "Netzke::#{class_name}".constantize rescue NameError nil end end
The ID used to locate this component’s block in locale files
# File lib/netzke/base.rb, line 85 def i18n_id name.split("::").map{|c| c.underscore}.join(".") end
# File lib/netzke/base.rb, line 139 def self.increase_total_instances @@instances ||= 0 @@instances += 1 end
Instance of component by config
# File lib/netzke/base.rb, line 78 def instance_by_config(config) klass = config[:klass] || constantize_class_name(config[:class_name]) raise NameError, "Netzke: Unknown component #{config[:class_name]}" if klass.nil? klass.new(config) end
Instantiates a component instance. A parent can optionally be provided.
# File lib/netzke/base.rb, line 92 def initialize(conf = {}, parent = nil) @passed_config = conf # configuration passed at the moment of instantiation @passed_config.deep_freeze @parent = parent @name = conf[:name].nil? ? short_component_class_name.underscore : conf[:name].to_s @global_id = parent.nil? ? @name : "#{parent.global_id}__#{@name}" @flash = [] # initialize @components and @items normalize_components_in_items # auto_collect_actions_from_config_and_js_properties self.class.increase_total_instances end
# File lib/netzke/base.rb, line 135 def self.reset_total_instances @@instances = 0 end
Override this method to do stuff at the moment of first-time loading
# File lib/netzke/base.rb, line 118 def before_load end
# File lib/netzke/base.rb, line 121 def clean_up component_session.clear components.keys.each { |k| component_instance(k).clean_up } end
Proxy to the equally named class method
# File lib/netzke/base.rb, line 108 def constantize_class_name(class_name) self.class.constantize_class_name(class_name) end
Generated with the Darkfish Rdoc Generator 2.