2015-08-21 00:37:41 +02:00
|
|
|
class BlocksView < ElementView
|
|
|
|
|
|
|
|
def initialize interpreter
|
|
|
|
@interpreter = interpreter
|
|
|
|
@interpreter.register_event(:instruction_changed, self)
|
|
|
|
end
|
|
|
|
|
|
|
|
def draw
|
|
|
|
DOM do |dom|
|
|
|
|
dom.div.block_view do
|
|
|
|
dom.div do
|
|
|
|
dom.h4 { method_name }
|
|
|
|
dom.h4 {"Block:#{block_name}" }
|
|
|
|
end
|
|
|
|
blocks.each do |b|
|
|
|
|
dom.div do
|
|
|
|
dom.span do # class="{{b._class_name}}">
|
2015-08-22 01:59:29 +02:00
|
|
|
b.class.name
|
2015-08-21 00:37:41 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def blocks
|
|
|
|
return [] unless @interpreter.instruction
|
|
|
|
codes = @interpreter.block.codes.dup
|
|
|
|
slice = codes.index(@interpreter.instruction) #- 1
|
|
|
|
codes.shift( slice ) if slice >= 0
|
|
|
|
codes.pop while(codes.length > 4)
|
|
|
|
codes
|
|
|
|
end
|
|
|
|
|
|
|
|
def instruction_changed
|
|
|
|
puts "Should have done something here to redraw (blocks)"
|
|
|
|
end
|
|
|
|
|
|
|
|
def block_name
|
|
|
|
@interpreter.block ? @interpreter.block.name : ""
|
|
|
|
end
|
|
|
|
def method_name
|
|
|
|
bl = @interpreter.block
|
|
|
|
return "" unless bl
|
|
|
|
return bl.method if bl.method.is_a? String
|
|
|
|
"#{bl.method.for_class.name}.#{bl.method.name}"
|
|
|
|
end
|
|
|
|
end
|
2015-08-21 19:07:27 +02:00
|
|
|
class BlocksModel #< Volt::ArrayModel
|
|
|
|
|
|
|
|
def instruction_changed old , ins
|
|
|
|
self.last._class_name = "inactive" if( self.length > 0)
|
|
|
|
self << { :name => ins.to_s , :class_name => "bright" }
|
|
|
|
#puts "block #{self.length}"
|
|
|
|
self.delete_at(0) if( self.length > 5)
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|