Skip to content

Commit

Permalink
Add precode functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
m7medVision committed Jan 15, 2024
1 parent bef3d3a commit 74f3c00
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 2 deletions.
4 changes: 3 additions & 1 deletion components/EditorSplit.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import Editor from "../islands/Editor.tsx";
import { getPreCode } from "../utils/precode.ts";
import { getTestCase } from "../utils/testcase.ts";

export default function EditorSplit(props: { slug: string }) {
const precode = getPreCode(props.slug);
const testcases = getTestCase(props.slug);
return (
<>
Expand All @@ -22,7 +24,7 @@ export default function EditorSplit(props: { slug: string }) {
</div>
</div>
<Editor
preCode={'console.log("Hello World!")'}
preCode={precode}
testcases={testcases}
slug={props.slug}
/>
Expand Down
3 changes: 2 additions & 1 deletion courses/variables/testcases.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,6 @@
"regex": ".*"
}
}
]
],
"case-sensitivity-in-variables": []
}
8 changes: 8 additions & 0 deletions precodes/variables/case-sensitivity-in-variables.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
var myVar = 5;
var MyVar = 10;
var myVAR = 15;
console.log(myVar, MyVar, myVAR); // 5 10 15
/*
الاتخبار :
تطبع رقم 20 عبر جمع رقمين مختلفين.
*/
17 changes: 17 additions & 0 deletions utils/precode.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { extract } from "https://deno.land/std@0.151.0/encoding/front_matter.ts";
import {existsSync} from "https://deno.land/std@0.212.0/fs/mod.ts";
export function getPreCode(slug: string): string {
console.log(slug);
// TODO: implement this
// open slug file from courses folder .md
// find precode
// return precode
if (!existsSync(`./precodes/${slug}.js`)) {
return `console.log("السلام عليكم, :)");`
}
const text = Deno.readTextFileSync(`./precodes/${slug}.js`);
if (text.length > 0) {
return text;
}
return `console.log("السلام عليكم, :)");`
}

0 comments on commit 74f3c00

Please sign in to comment.