fix blocks to change

This commit is contained in:
Torsten Ruger 2015-08-22 18:37:42 +02:00
parent b43bffc940
commit b8a0e5f8a3
4 changed files with 32 additions and 25 deletions

View File

@ -14,7 +14,7 @@ class ListView < ElementView
end
# create a root node acording to the "root" function (default div)
# draw all chilren and keep the elements as @elements
# draw all children and keep the elements as @elements
# return (as per base class) the single root of the collection
def draw
@element = div(self.root)
@ -34,4 +34,11 @@ class ListView < ElementView
@elements[index] = rendered
old.replace_with rendered
end
def append view
@children << view
rendered = view.draw
@elements << rendered
@element << rendered
end
end

12
lib/block_view.rb Normal file
View File

@ -0,0 +1,12 @@
class BlockView < ElementView
def initialize block
@block = block
end
attr_reader :block
def draw
@element = div("div") << div("span.bright" , @block.name )
end
end

View File

@ -1,36 +1,35 @@
#require_relative "block_view"
require_relative "base/constant_view"
require_relative "block_view"
class BlocksView < ListView
def initialize interpreter
@interpreter = interpreter
@interpreter.register_event(:instruction_changed, self)
super([ConstantView.new("div" , "Block name1") , ConstantView.new("div" , "Block name2")])
super([BlockView.new(@interpreter.block)])
end
def draw
super()
wrap_element div("div.block_view") << div("h4" , "Method #{method_name}") << div("h4" , "Block:#{block_name}" )
wrap_element div("div.block_view") << div("h4" , "Method #{method_name}") << div("h4" , "Block" )
return @element
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
def instruction_changed
return if @interpreter.block.name == active_block_name
puts "blocks changed to #{@interpreter.block.name}"
@elements.last.at_css(".bright").remove_class("bright")
append( BlockView.new(@interpreter.block) )
remove_first if( @elements.length > 5)
end
def instruction_changed
puts "Should have done something here to redraw (blocks)"
def active_block_name
@children.last.block.name
end
def block_name
@interpreter.block ? @interpreter.block.name : ""
end
def method_name
bl = @interpreter.block
return "" unless bl
@ -38,13 +37,3 @@ class BlocksView < ListView
"#{bl.method.for_class.name}.#{bl.method.name}"
end
end
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

View File

@ -8,7 +8,6 @@ class ObjectView < ElementView
end
def draw
# todo, remove the DOM use
@element = div("ul.nav!")
add( "li" ) << div("span" , class_header(@object_id) )
@element << div("li" , "-------------------------")