DEPRECATED
# File lib/netzke/composition.rb, line 124 def add_component(aggr) components.merge!(aggr) end
Recursively instantiates a component based on its “path”: e.g. if we have component :component1 which in its turn has component :component2, the path to the latter would be “component1__component2”
# File lib/netzke/composition.rb, line 143 def component_instance(name, strong_config = {}) composite = self name.to_s.split('__').each do |cmp| cmp = cmp.to_sym component_config = composite.components[cmp] raise ArgumentError, "No child component '#{cmp}' defined for component '#{composite.global_id}'" if component_config.nil? component_class_name = component_config[:class_name] raise ArgumentError, "No class_name specified for component #{cmp} of #{composite.global_id}" if component_class_name.nil? component_class = constantize_class_name(component_class_name) raise ArgumentError, "Unknown constant #{component_class_name}" if component_class.nil? instance_config = weak_children_config.merge(component_config).merge(strong_config).merge(:name => cmp) composite = component_class.new(instance_config, composite) # params: config, parent end composite end
Called when the method_missing tries to processes a non-existing component
# File lib/netzke/composition.rb, line 137 def component_missing(aggr) flash :error => "Unknown component #{aggr} for component #{name}" {:feedback => @flash}.to_nifty_json end
All components for this instance, which includes components defined on class level, and components detected in :items
# File lib/netzke/composition.rb, line 115 def components @components ||= self.class.registered_components.inject({}){ |res, name| res.merge(name.to_sym => send(COMPONENT_METHOD_NAME % name)) }.merge(config[:components] || {}) end
All components that we depend on (used to render all necessary JavaScript and stylesheets)
# File lib/netzke/composition.rb, line 167 def dependency_classes res = [] eager_loaded_components.keys.each do |aggr| res += component_instance(aggr).dependency_classes end res += self.class.class_ancestors res << self.class res.uniq end
# File lib/netzke/composition.rb, line 119 def eager_loaded_components components.reject{|k,v| v[:lazy_loading]} end
Returns global id of a component in the hierarchy, based on passed reference that follows the double-underscore notation. Referring to “parent” is allowed. If going to far up the hierarchy will result in nil, while referring to a non-existent component will simply provide an erroneous ID. Example: parent__parent__child__subchild will traverse the hierarchy 2 levels up, then going down to “child”, and further to “subchild”. If such a component exists in the hierarchy, its global id will be returned, otherwise nil will be returned.
# File lib/netzke/composition.rb, line 192 def global_id_by_reference(ref) ref = ref.to_s return parent && parent.global_id if ref == "parent" substr = ref.sub(/^parent__/, "") if substr == ref # there's no "parent__" in the beginning return global_id + "__" + ref else return parent.global_id_by_reference(substr) end end
DEPRECATED in favor of Base.component
# File lib/netzke/composition.rb, line 110 def initial_components {} end
Generated with the Darkfish Rdoc Generator 2.