Skip to content

Commit 6809f27

Browse files
committed
docs(feat): add welcome playground example with solution display
1 parent 1562734 commit 6809f27

1 file changed

Lines changed: 13 additions & 8 deletions

File tree

docs/.vitepress/theme/components/PlayGround.vue

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const copied = ref(false);
1010
1111
function runScript() {
1212
try {
13-
output.value = JSON.stringify(evaluate(code.value), null, 2);
13+
output.value = evaluate(code.value);
1414
} catch (error) {
1515
output.value = '' + error;
1616
}
@@ -45,17 +45,16 @@ onMounted(() => {
4545
const params = new URLSearchParams(window.location.search);
4646
if (params.has('s')) {
4747
code.value = decodeURIComponent(params.get('s'));
48+
} else {
49+
code.value = '# Hello World!\n# This is a comment\nx = 1\ny = 2\n\n# return sum of x and y\nx + y\n\n# now hit run to view the solution';
4850
}
4951
});
5052
</script>
5153

5254
<template>
5355
<div class="box">
5456
<div>
55-
<label for="code">Code</label>
56-
<br />
57-
<textarea ref="input" v-model.trim="code" @input="reset" name="code" id="code" spellcheck="false"
58-
autocomplete="off"></textarea>
57+
<textarea ref="input" v-model.trim="code" @input="reset" spellcheck="false" autocomplete="off"></textarea>
5958
</div>
6059
<div>
6160
<button @click="runScript">Run</button>
@@ -68,9 +67,15 @@ onMounted(() => {
6867
<span @click="copyURL">{{ copied ? 'Copied' : 'Copy' }}</span>
6968
</div>
7069
</div>
71-
<div v-show="output.length">
70+
<div v-show="(typeof output !== 'string')">
71+
<div v-if="output.solution">
72+
<b>Solution:</b>
73+
<div v-for="n in output.solution" :key="n">= {{ n }}</div>
74+
</div>
75+
</div>
76+
<div v-show="(typeof output !== 'string')">
7277
<b>Output:</b>
73-
<p>{{ output }}</p>
78+
<p>{{ JSON.stringify(output, null, 2) }}</p>
7479
</div>
7580
</div>
7681
</template>
@@ -84,7 +89,7 @@ onMounted(() => {
8489
}
8590
8691
.box>div {
87-
margin-bottom: 1rem;
92+
margin-bottom: 1.5rem;
8893
}
8994
9095
button {

0 commit comments

Comments
 (0)