put the classes back on the screen

This commit is contained in:
Torsten Ruger 2015-08-20 19:40:47 +02:00
parent 1f7c06d626
commit 87c649c622
5 changed files with 53 additions and 37 deletions

View File

@ -1,17 +1,13 @@
class ClassView < ListView
class ClassView < ElementView
def initialize
# page._classes!.clear
all = []
def initialize interpreter
@interpreter = interpreter
@classes = []
Virtual.machine.space.classes.each do |name , claz|
next if [:Kernel,:Module,:MetaClass,:BinaryCode].index name
all << name
end
all.sort.each do |name|
# c = Volt::Model.new :name => name
# page._classes << c
@classes << name
end
@classes.sort!
end
def variables(clas_model)
@ -24,24 +20,27 @@ class ClassView < ListView
end
def draw
div.classes do
h4 {"Classes"}
ul.nav do
#{{page._classes.each do |clas| }}
li do
a { "me "}
# <a href="#">{{ clas._name }}</a>
# {{ unless variables(clas).empty? }}
# <ul>
# {{variables(clas).each do |var| }}
# <li>
# <a href="#">{{var}}</a>
# </li>
# {{ end }}
# </ul>
DOM do |dom|
dom.div.classes do
dom.h4 {"Classes"}
dom.ul.nav! do
@classes.each do |cl|
dom.li do
dom.a { cl }
end
end
end
end
end
end
# <a href="#">{{ clas._name }}</a>
# {{ unless variables(clas).empty? }}
# <ul>
# {{variables(clas).each do |var| }}
# <li>
# <a href="#">{{var}}</a>
# </li>
# {{ end }}
# </ul>
end

View File

@ -3,4 +3,5 @@ require "opal"
require "opal-parser"
require "main_view"
MainView.new()
view = MainView.new()
view.draw.append_to($document.body)

View File

@ -3,4 +3,8 @@ class ElementView
def initialize
@element = nil
end
def draw
raise "implement me to return an Element"
end
end

View File

@ -2,8 +2,19 @@ require "element_view"
class ListView < ElementView
def initialize
def initialize children
@children = children
@elements = []
@container_element = nil
end
def draw on
@container_element = $document.create_element('div')
@elements = @children.collect do | c |
elem = c.draw(@container_element)
elem.append_to(@container_element)
elem
end
@container_element
end
end

View File

@ -16,29 +16,30 @@ class MainView < ListView
# compile_main includes the parse
# parsing generates an ast as seen below and then compiles it.
machine.compile_main "2 + 5"
# machine.compile_main "2 + 5"
# so the code above is functionally equivalent to the one below, minus the parse
# When the ast expression is given all works, so pretty sure it is the parse that fails
# code = Ast::OperatorExpression.new("+", Ast::IntegerExpression.new(2),Ast::IntegerExpression.new(5))
# Virtual::Compiler.compile( code , machine.space.get_main )
code = Ast::OperatorExpression.new("+", Ast::IntegerExpression.new(2),Ast::IntegerExpression.new(5))
Virtual::Compiler.compile( code , machine.space.get_main )
machine.run_before "Register::CallImplementation"
@interpreter = Interpreter::Interpreter.new
@parent = $document.body
puts @parent.parent.name
draw
super( [ClassView.new(@interpreter)] )
end
def draw
node = DOM {
div.info {
span.red "Ready to start."
def draww
node = DOM { |m|
Kernel.puts "DOM #{self.class}"
m.div.info {
Kernel.puts "div #{self.class}" ; ""
m.span.red @interpreter.state
}
}
node.append_to(@parent)
end
def no
body = Native(`window.document.body`)