Skip to content

Commit

Permalink
Merge pull request #20 from milafrerichs/add-console
Browse files Browse the repository at this point in the history
Add console
  • Loading branch information
milafrerichs authored Jun 24, 2019
2 parents 445c7aa + fa3f11a commit 1f7cb1c
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
24 changes: 24 additions & 0 deletions src/Console.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<script>
import Viewer from './Viewer.svelte';
import { onMount } from 'svelte';
export let output
let message = '';
$: if(output) {
message = `
document.body.innerHTML = '';
var consoleOutput = '';
var old = console.log;
console.log = function (message) {
if (typeof message == 'object') {
consoleOutput += (JSON && JSON.stringify ? JSON.stringify(message) : message) + '<br />';
} else {
consoleOutput += message + '<br />';
}
};
${output}
document.body.innerHTML = '';
document.body.innerHTML = consoleOutput;
`
}
</script>
<Viewer code={message} />
2 changes: 2 additions & 0 deletions src/Tutorials.svelte
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<script>
import Viewer from './Viewer.svelte';
import Editor from './Editor.svelte';
import Console from './Console.svelte';
let code = '';
let ready = false;
Expand Down Expand Up @@ -92,6 +93,7 @@
{/if}
<div class="{cssStyles.viewer}">
<Viewer bind:ready {code} />
<Console bind:ready output={code} />
</div>
</div>
</div>
2 changes: 1 addition & 1 deletion test/App.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
{
content: 'Test 2',
code: 'document.body.innerHTML = "Test 2";',
solution: 'document.body.innerHTML = "Solution 2";'
solution: 'document.body.innerHTML = "Solution 2";console.log("Test")'
}
]
let cssStyles = {
Expand Down

0 comments on commit 1f7cb1c

Please sign in to comment.