2015-08-20 14:48:45 +02:00
|
|
|
class ElementView
|
|
|
|
|
|
|
|
def initialize
|
2015-08-20 16:07:44 +02:00
|
|
|
@element = nil
|
2015-08-20 14:48:45 +02:00
|
|
|
end
|
2015-08-20 19:40:47 +02:00
|
|
|
|
|
|
|
def draw
|
|
|
|
raise "implement me to return an Element"
|
|
|
|
end
|
2015-08-21 19:07:02 +02:00
|
|
|
|
2015-08-22 01:05:35 +02:00
|
|
|
def div name_class , text = nil
|
2015-08-21 19:07:02 +02:00
|
|
|
name , clazz = name_class.split(".")
|
|
|
|
name = "div" if name.empty?
|
|
|
|
element = $document.create_element(name)
|
2015-08-22 01:05:35 +02:00
|
|
|
element.text = text if text
|
2015-08-21 19:07:02 +02:00
|
|
|
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
|
|
|
|
|
2015-08-22 01:05:35 +02:00
|
|
|
def create_element class_or_id , text = nil
|
|
|
|
@element = div( class_or_id , text)
|
|
|
|
end
|
|
|
|
|
|
|
|
def add class_or_id , tex = nil
|
|
|
|
element = div( class_or_id , tex)
|
|
|
|
element.append_to @element
|
|
|
|
element
|
|
|
|
end
|
2015-08-20 14:48:45 +02:00
|
|
|
end
|