create separate main

figuring load order
This commit is contained in:
Torsten Ruger 2015-07-23 14:59:29 +03:00
parent 736bff02a5
commit 03c0041255
4 changed files with 53 additions and 33 deletions

View File

@ -1,37 +1,16 @@
require 'opal'
require 'opal-jquery'
require "opal/parser"
require "json"
require 'opal-react'
require "salama"
require "class_view"
require "register_view"
require "source_view"
require "block_view"
require "interpreter"
Virtual.machine.boot
Document.ready? do # Document.ready? is a opal-jquery method.
React.render( React.create_element( Debugger), Element['#content'] )
end
class Debugger class Debugger
include React::Component include React::Component
# required_param :url # required_param :machine
# define_state sources: JSON.from_object(`window.initial_sources`) define_state :machine => Virtual.machine.boot
before_mount do
code = Ast::ExpressionList.new [Ast::CallSiteExpression.new( "putstring", [], Ast::StringExpression.new("Hello again"))]
Virtual::Compiler.compile( code , machine.space.get_main )
machine.run_before "Register::CallImplementation"
end
# before_mount do
# HTTP.get(url) do |response|
# if response.ok?
# sources! JSON.parse(response.body)
# else
# puts "failed with status #{response.status_code}"
# end
# end
# end
def initialize def initialize
@interpreter = Interpreter.new @interpreter = Interpreter.new
end end
@ -40,7 +19,7 @@ class Debugger
div.container do div.container do
div.row do div.row do
div.col_md_1 do div.col_md_1 do
ClassView classes: Virtual.machine.space.classes ClassView classes: machine.space.classes
end end
div.col_md_11 do div.col_md_11 do
div.row do div.row do

17
app/main.rb Normal file
View File

@ -0,0 +1,17 @@
require 'opal'
require "opal/parser"
require 'opal-jquery'
require "json"
require 'opal-react'
require "salama"
require "class_view"
require "register_view"
require "source_view"
require "block_view"
require "interpreter"
require "debugger"
Document.ready? do # Document.ready? is a opal-jquery method.
React.render( React.create_element( Debugger ), Element['#content'] )
end

View File

@ -1,17 +1,41 @@
# config.ru # config.ru
require 'bundler' require 'bundler'
Bundler.require Bundler.require
require "opal/parser"
Opal.use_gem "salama" Opal.use_gem "salama"
Opal.use_gem "salama-arm" Opal.use_gem "salama-arm"
require "tilt/erb"
require "json"
require "react/source" require "react/source"
class DebugServer < Opal::Server
run Opal::Server.new {|s| def parse(num)
string_input = '"Hello again".putstring()'
parser = Parser::Salama.new
out = parser.parse(string_input)
parts = Parser::Transform.new.apply(out)
parts.to_basic
end
def call(env)
if env['PATH_INFO'].include? "/parse.json"
parse_out = parse(1).to_s
[200, { 'Content-Type' => 'text/json' }, [parse_out]]
else
super
end
end
end
run DebugServer.new {|s|
s.append_path 'app' s.append_path 'app'
s.append_path 'lib' s.append_path 'lib'
s.append_path File.dirname(::React::Source.bundled_path_for("react-with-addons.js")) s.append_path File.dirname(::React::Source.bundled_path_for("react-with-addons.js"))
s.main = 'debugger' s.main = 'main'
s.debug = true s.debug = true
s.source_map = true s.source_map = true
s.index_path = "index.html.erb" s.index_path = "index.html.erb"

View File

@ -4,7 +4,7 @@
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css"> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
<script src="https://code.jquery.com/jquery-2.1.3.min.js"></script> <script src="https://code.jquery.com/jquery-2.1.3.min.js"></script>
<script src="/assets/react-with-addons.js"></script> <script src="/assets/react-with-addons.js"></script>
<%= javascript_include_tag 'debugger' %> <%= javascript_include_tag 'main' %>
</head> </head>
<body> <body>
<div id="content"></div> <div id="content"></div>