Sha256: 9416952da09877259ff7b8c31be5e05bba633152dfa463561241b67eb6df353f
Contents?: true
Size: 1.93 KB
Versions: 1
Compression:
Stored size: 1.93 KB
Contents
module Rocx module Elements class BaseContainer < BaseElement attr_reader :children class << self def properties_tag(*args) @properties_tag = args.first if args.any? @properties_tag end def value_property(name) attr_reader name class_eval <<-CODE, __FILE__, __LINE__ + 1 def #{name}=(value) class_name = "#{name}".split.map(&:capitalize).join prop_class = Rocx::Properties.const_get class_name instance_variable_set "@#{name}", prop_class.new(value) end CODE properties << name end def property(name) class_eval <<-CODE, __FILE__, __LINE__ + 1 def #{name} class_name = "#{name}".split("_").map(&:capitalize).join prop_class = Rocx::Properties.const_get class_name if instance_variable_get("@#{name}").nil? instance_variable_set "@#{name}", prop_class.new end instance_variable_get "@#{name}" end CODE properties << name end def properties @properties ||= [] end end def initialize(**args) @children = [] super args end def <<(child) children << child end def to_xml(xml) (namespace ? xml[namespace] : xml).public_send(tag_name, xml_attributes) { property_xml(xml) children.each { |child| child.to_xml(xml) } } end protected def property_xml(xml) props = properties.map(&method(:send)).compact return if props.none?(&:render?) xml[namespace].public_send(properties_tag) { props.each { |prop| prop.to_xml(xml) } } end def properties self.class.properties end def properties_tag self.class.properties_tag end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
rocx-0.5.8 | lib/rocx/elements/base_container.rb |