moving functionality in the base classes for all to share
This commit is contained in:
parent
977156ba51
commit
8b743fbcd5
@ -7,4 +7,33 @@ class ElementView
|
|||||||
def draw
|
def draw
|
||||||
raise "implement me to return an Element"
|
raise "implement me to return an Element"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def create_element name_class
|
||||||
|
name , clazz = name_class.split(".")
|
||||||
|
name = "div" if name.empty?
|
||||||
|
element = $document.create_element(name)
|
||||||
|
return element unless clazz
|
||||||
|
if( clazz.is_a? Array )
|
||||||
|
clazz.each { |c| add_class_or_id( element , cl )}
|
||||||
|
else
|
||||||
|
add_class_or_id element , clazz
|
||||||
|
end
|
||||||
|
element
|
||||||
|
end
|
||||||
|
|
||||||
|
def add_class_or_id element , class_or_id
|
||||||
|
return element unless class_or_id
|
||||||
|
if class_or_id[-1] == "!"
|
||||||
|
element.id = class_or_id[0 ... -1]
|
||||||
|
else
|
||||||
|
element.add_class class_or_id
|
||||||
|
end
|
||||||
|
element
|
||||||
|
end
|
||||||
|
|
||||||
|
def wrap_node_with node , wrapper
|
||||||
|
node.replace_with wrapper
|
||||||
|
node.append_to wrapper
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
@ -8,8 +8,12 @@ class ListView < ElementView
|
|||||||
@container_element = nil
|
@container_element = nil
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def root
|
||||||
|
"div"
|
||||||
|
end
|
||||||
|
|
||||||
def draw on
|
def draw on
|
||||||
@container_element = $document.create_element('div')
|
@container_element = create_element(self.root)
|
||||||
@elements = @children.collect do | c |
|
@elements = @children.collect do | c |
|
||||||
elem = c.draw(@container_element)
|
elem = c.draw(@container_element)
|
||||||
elem.append_to(@container_element)
|
elem.append_to(@container_element)
|
||||||
@ -17,4 +21,5 @@ class ListView < ElementView
|
|||||||
end
|
end
|
||||||
@container_element
|
@container_element
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user