bit of organizing

This commit is contained in:
Torsten Ruger
2015-08-21 20:05:49 +02:00
parent c49c73bb3d
commit 6925a3fefa
3 changed files with 2 additions and 2 deletions

39
lib/base/element_view.rb Normal file
View File

@ -0,0 +1,39 @@
class ElementView
def initialize
@element = nil
end
def draw
raise "implement me to return an Element"
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

25
lib/base/list_view.rb Normal file
View File

@ -0,0 +1,25 @@
require_relative "element_view"
class ListView < ElementView
def initialize children
@children = children
@elements = []
@container_element = nil
end
def root
"div"
end
def draw on
@container_element = create_element(self.root)
@elements = @children.collect do | c |
elem = c.draw(@container_element)
elem.append_to(@container_element)
elem
end
@container_element
end
end