some real models

This commit is contained in:
Torsten Ruger 2015-07-30 10:09:04 +03:00
parent a2f3daa828
commit d8a3657365
5 changed files with 36 additions and 26 deletions

View File

@ -2,12 +2,14 @@
require "salama"
require_relative "interpreter"
module Main
class MainController < Volt::ModelController
def index
init_machine
init_classes
init_registers
init_blocks
end
def about
@ -26,9 +28,7 @@ module Main
def init_registers
page._registers!.clear
@interpreter.registers.each do |reg , val|
r = Volt::Model.new :name => reg
r._value = val
page._registers << r
page._registers << RegisterModel.new( :name => reg , :value => val)
end
end
def init_classes
@ -39,6 +39,11 @@ module Main
page._classes << c
end
end
def init_blocks
blocks = BlocksModel.new
page._blocks = blocks
@interpreter.register_event(:instruction_changed, blocks)
end
# The main template contains a #template binding that shows another
# template. This is the path to that template. It may change based
# on the params._component, params._controller, and params._action values.

View File

@ -0,0 +1,8 @@
class BlocksModel < Volt::ArrayModel
def instruction_changed old , ins
self.last._class_name = "" if( page._blocks.length > 0)
self << { :name => ins.to_s , :class_name => "active" }
end
end

View File

@ -0,0 +1,10 @@
class RegisterModel < Volt::Model
field :name
field :value
def register_changed reg , old , ins
self.last._class_name = "" if( page._blocks.length > 0)
self << { :name => ins.to_s , :class_name => "active" }
end
end

View File

@ -1,12 +0,0 @@
# By default Volt generates this User model which inherits from Volt::User,
# you can rename this if you want.
class User < Volt::User
# login_field is set to :email by default and can be changed to :username
# in config/app.rb
field login_field
field :name
validate login_field, unique: true, length: 8
validate :email, email: true
end

View File

@ -19,33 +19,32 @@
<h4> Virtual Machine Instruction </h4>
page.sources.each do |s|
<br> s </br>
end
</div>
<div class="block-view">
<div>
<h4> method_name </h4>
<h4> Block: #{block_name} </h4>
<h4> {{page._method_name}} </h4>
<h4> Block: {{page._block_name}} </h4>
</div>
block.each do |code|
InstructionView :interpreter => interpreter , :instruction => code
end
{{ page._blocks.each do |b| }}
<div class="{{b._class_name}}">
{{b._string}}
{{ end }}
</div>
<div class="status-view">
<div>
button.bright { "next" }.on(:click) { interpreter.tick }
" ".br
</div>
<div>
<h4> Status </h4>
<br> state.to_s </br>
<br> {{@interpreter.state}} </br>
</div>
<div>
<h4> Stdout </h4>
</div>
<div>
<br> interpreter.stdout </br>
<br> {{@interpreter.stdout}} </br>
</div>
</div>
@ -53,10 +52,10 @@
{{ page._registers.each do |reg| }}
<div class="register-view">
<div>
{{ reg._name }}
{{ reg.name }}
</div>
<div>
{{ reg._value }}
{{ reg.value }}
</div>
</div>
{{end}}