Permalink
Browse files

one textarea. Error feedback via iframe and stacktrace

  • Loading branch information...
sorenbs committed May 21, 2012
1 parent 8923219 commit 236ee6d1bd33fdf126139ba85eeaca5a52655cfb
View
@@ -19,17 +19,12 @@
<script type="text/javascript" src="static/app/js/namespace.js"></script>
<script type="text/javascript" src="static/app/js/viewmodels/crafter.model.component.js"></script>
<script type="text/javascript" src="static/app/js/viewmodels/crafter.model.component-list.js"></script>
- <script type="text/javascript" src="static/app/js/viewmodels/crafter.model.crafter.js"></script>\
+ <script type="text/javascript" src="static/app/js/viewmodels/crafter.model.crafter.js"></script>
<script type="text/javascript" src="static/app/js/crafter.js"></script>
+ <script type="text/javascript" src="static/stacktrace-min-0.3.js"></script>
</head_merge>
- <script id="ComponentEditor" type="text/html">
- <textarea data-bind="{value: content, valueUpdate: 'afterkeydown'}" style="height: 100%"></textarea>
- </script>
- <button data-bind="click: playGame">
- Play</button>
- <div data-bind='template:{name: "ComponentEditor", foreach: componentListViewModel.components, afterRender: componentListViewModel.renderCodeMirrors}'
- class="snapContainer">
- </div>
+
+
<div class="codeContainer">
<textarea id="Code">
this
@@ -41,9 +36,45 @@
<div id="cr-stage">
</div>
</div>
+
+ <iframe src="static/gameEvaluator.html">
+
+ </iframe>
<script type="text/javascript">
+
+
+
ko.applyBindings(Crafter.viewModel);
+ var codeArea = document.getElementById('Code');
+ var cm = CodeMirror.fromTextArea(codeArea,
+ {
+ mode: 'javascript',
+ theme: 'ambiance',
+ lineNumbers: true,
+ indentUnit: 4,
+ indentWithTabs: true,
+ extraKeys: { "Ctrl-Space": "autocomplete" },
+ lineWrapping: true,
+ onChange: function () {
+ cm.save();
+
+ with ((window && window.console && window.console._commandLineAPI) || {}) {
+ eval(codeArea.value);
+ };
+
+ return;
+
+
+ try{
+ eval(codeArea.value)
+ } catch(er) {
+ console.log(er.stack)
+ }
+ }
+
+ });
+
</script>
<p>
<span class="lift:helloWorld.howdy">Welcome to your Lift app at <span id="time">Time
@@ -11,7 +11,6 @@
.codeContainer
{
- top: 150px;
width: 50%;
position: relative;
}
@@ -22,7 +21,7 @@
background-color: red;
height: 500px;
position: fixed;
- top: 246px;
+ top: 60px;
right: 0;
}
@@ -0,0 +1,25 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+ <script type="text/javascript" src="stacktrace-min-0.3.js"></script>
+<script type="text/javascript">
+try {
+ var a = 4;
+ var b = a + c;
+} catch (er) {
+ // @http://localhost:8080/static/gameEvaluator.html:8
+ // http://localhost:8080/static/gameEvaluator.html:8:14
+ var trace = printStackTrace({ e: er })[0];
+ var positionPart = trace.split(".html:")[1];
+ var line = col = -1;
+ if (positionPart.indexOf(":") != -1) {
+ line = positionPart.split(':')[0];
+ col = positionPart.split(':')[1];
+ } else {
+ line = positionPart;
+ }
+ console.log(positionPart, line, col);
+}
+</script>
+</head>
+</html>

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.

0 comments on commit 236ee6d

Please sign in to comment.