some real models
This commit is contained in:
parent
a2f3daa828
commit
d8a3657365
@ -2,12 +2,14 @@
|
|||||||
require "salama"
|
require "salama"
|
||||||
require_relative "interpreter"
|
require_relative "interpreter"
|
||||||
|
|
||||||
|
|
||||||
module Main
|
module Main
|
||||||
class MainController < Volt::ModelController
|
class MainController < Volt::ModelController
|
||||||
def index
|
def index
|
||||||
init_machine
|
init_machine
|
||||||
init_classes
|
init_classes
|
||||||
init_registers
|
init_registers
|
||||||
|
init_blocks
|
||||||
end
|
end
|
||||||
|
|
||||||
def about
|
def about
|
||||||
@ -26,9 +28,7 @@ module Main
|
|||||||
def init_registers
|
def init_registers
|
||||||
page._registers!.clear
|
page._registers!.clear
|
||||||
@interpreter.registers.each do |reg , val|
|
@interpreter.registers.each do |reg , val|
|
||||||
r = Volt::Model.new :name => reg
|
page._registers << RegisterModel.new( :name => reg , :value => val)
|
||||||
r._value = val
|
|
||||||
page._registers << r
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
def init_classes
|
def init_classes
|
||||||
@ -39,6 +39,11 @@ module Main
|
|||||||
page._classes << c
|
page._classes << c
|
||||||
end
|
end
|
||||||
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
|
# The main template contains a #template binding that shows another
|
||||||
# template. This is the path to that template. It may change based
|
# template. This is the path to that template. It may change based
|
||||||
# on the params._component, params._controller, and params._action values.
|
# on the params._component, params._controller, and params._action values.
|
||||||
|
8
app/main/models/blocks_model.rb
Normal file
8
app/main/models/blocks_model.rb
Normal 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
|
10
app/main/models/register_model.rb
Normal file
10
app/main/models/register_model.rb
Normal 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
|
@ -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
|
|
@ -19,33 +19,32 @@
|
|||||||
<h4> Virtual Machine Instruction </h4>
|
<h4> Virtual Machine Instruction </h4>
|
||||||
page.sources.each do |s|
|
page.sources.each do |s|
|
||||||
<br> s </br>
|
<br> s </br>
|
||||||
end
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="block-view">
|
<div class="block-view">
|
||||||
<div>
|
<div>
|
||||||
<h4> method_name </h4>
|
<h4> {{page._method_name}} </h4>
|
||||||
<h4> Block: #{block_name} </h4>
|
<h4> Block: {{page._block_name}} </h4>
|
||||||
</div>
|
</div>
|
||||||
block.each do |code|
|
{{ page._blocks.each do |b| }}
|
||||||
InstructionView :interpreter => interpreter , :instruction => code
|
<div class="{{b._class_name}}">
|
||||||
end
|
{{b._string}}
|
||||||
|
{{ end }}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="status-view">
|
<div class="status-view">
|
||||||
<div>
|
<div>
|
||||||
button.bright { "next" }.on(:click) { interpreter.tick }
|
button.bright { "next" }.on(:click) { interpreter.tick }
|
||||||
" ".br
|
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<h4> Status </h4>
|
<h4> Status </h4>
|
||||||
<br> state.to_s </br>
|
<br> {{@interpreter.state}} </br>
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<h4> Stdout </h4>
|
<h4> Stdout </h4>
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<br> interpreter.stdout </br>
|
<br> {{@interpreter.stdout}} </br>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@ -53,10 +52,10 @@
|
|||||||
{{ page._registers.each do |reg| }}
|
{{ page._registers.each do |reg| }}
|
||||||
<div class="register-view">
|
<div class="register-view">
|
||||||
<div>
|
<div>
|
||||||
{{ reg._name }}
|
{{ reg.name }}
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
{{ reg._value }}
|
{{ reg.value }}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{{end}}
|
{{end}}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user