Skip to content

Commit

Permalink
prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
LyonSyonII committed Nov 18, 2023
1 parent 8315871 commit 9bc82aa
Show file tree
Hide file tree
Showing 18 changed files with 161 additions and 141 deletions.
28 changes: 0 additions & 28 deletions .github/workflows/ci.yml

This file was deleted.

10 changes: 5 additions & 5 deletions astro.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,15 @@ export default defineConfig({
defaultLocale: "en",
locales: {
en: {
label: "English"
label: "English",
},
es: {
label: "Español"
label: "Español",
},
ca: {
label: "Català"
}
}
label: "Català",
},
},
}),
svelte(),
],
Expand Down
7 changes: 0 additions & 7 deletions lighthouserc.js

This file was deleted.

64 changes: 35 additions & 29 deletions src/components/CodeBlock.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import { writable } from "svelte/store";
import { onThemeChange } from "src/utils/onThemeChange";
import { onDestroy } from "svelte";
/** Code that will be sent to the playground, replaces __VALUE__ with the code in the editor */
export let setup = "__VALUE__";
/** Code visible in the editor */
Expand All @@ -23,27 +23,30 @@
export let showLineNumbers = true;
/** Language used by the editor */
export let lang: keyof typeof langs = "en";
const langs = {
"en": {
en: {
placeholder: "Enter your code here...",
compiling: "Compiling...",
error: "Woops, something went wrong and the code does not compile!\nIf you\'ve mistakenly messed up the code, click the \"Reset\" button to return it back to its original state.\n\nRemember to replace ? with your answer.",
error:
'Woops, something went wrong and the code does not compile!\nIf you\'ve mistakenly messed up the code, click the "Reset" button to return it back to its original state.\n\nRemember to replace ? with your answer.',
},
"ca": {
ca: {
placeholder: "Escriu el teu codi aqui...",
compiling: "Compilant...",
error: "Ups, alguna cosa ha fallat i el codi no compila!\nSi t'has equivocat modificant el codi, fes clic al botó de \"Reset\" per tornar-lo al seu estat original.\n\nRecorda substituïr ? amb la teva resposta."
error:
'Ups, alguna cosa ha fallat i el codi no compila!\nSi t\'has equivocat modificant el codi, fes clic al botó de "Reset" per tornar-lo al seu estat original.\n\nRecorda substituïr ? amb la teva resposta.',
},
"es": {
es: {
placeholder: "Escribe tu código aquí...",
compiling: "Compilando...",
error: "Vaya, ¡algo ha ido mal y el código no compila!\nSi has estropeado el código por error, haz clic en el botón \"Reset\" para devolverlo a su estado original.\n\nRecuerda sustituir ? con tu respuesta.",
}
error:
'Vaya, ¡algo ha ido mal y el código no compila!\nSi has estropeado el código por error, haz clic en el botón "Reset" para devolverlo a su estado original.\n\nRecuerda sustituir ? con tu respuesta.',
},
};
const theme = writable(document.documentElement.dataset.theme);
const observer = onThemeChange(t => theme.set(t));
const observer = onThemeChange((t) => theme.set(t));
onDestroy(() => observer.disconnect());
let value = code;
Expand All @@ -55,14 +58,14 @@
if (!f && !focused) {
return;
}
running = true;
playground_response = langs[lang].compiling;
// Wait for the editor to update `value`
await new Promise((resolve) => setTimeout(resolve, 100));
const params = {
version: "stable",
optimize: "0",
Expand All @@ -78,21 +81,24 @@
mode: "cors",
body: JSON.stringify(params),
})
.then((response) => response.json())
.then((response) => {
console.log({ params, response });
return response;
})
.then((response) => {
if (response.error === null) {
playground_response = response.result;
} else {
playground_response = errorMsg || langs[lang].error || response.error;
}
})
.catch((error) => (playground_response = errorMsg || langs[lang].error || error.message))
.finally(() => (running = false));
.then((response) => response.json())
.then((response) => {
console.log({ params, response });
return response;
})
.then((response) => {
if (response.error === null) {
playground_response = response.result;
} else {
playground_response = errorMsg || langs[lang].error || response.error;
}
})
.catch(
(error) =>
(playground_response =
errorMsg || langs[lang].error || error.message),
)
.finally(() => (running = false));
};
</script>

Expand All @@ -119,7 +125,7 @@
editable={!running}
placeholder={placeholder || langs[lang].placeholder}
/>

<button
class="not-content"
title="Run (Shift+Enter)"
Expand Down
2 changes: 1 addition & 1 deletion src/components/QuestionCard.astro
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ const { question } = Astro.props;
gap: clamp(0.5rem, calc(0.125rem + 1vw), 1rem);
overflow: auto;
}
</style>
</style>
10 changes: 8 additions & 2 deletions src/content/docs/ca/first-steps/1-introduction.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,13 @@ Cada missió et proporcionarà una lliçó de programació, i inclou un fragment
Intenta executar el següent fragment de codi (fes clic al botó d'"Executar" de la dreta o `⇧ + ↵` al teclat mentre estiguis editant):

<QuestionCard>
<CodeBlock client:only code={'println!("Hola, Món!")'} showLineNumbers={false} lang="ca" errorMsg={`Ups, alguna cosa ha fallat i el codi no compila!\nSi t'has equivocat modificant el codi, fes clic al botó de "Reset" per tornar-lo al seu estat original.`} />
<CodeBlock
client:only
code={'println!("Hola, Món!")'}
showLineNumbers={false}
lang="ca"
errorMsg={`Ups, alguna cosa ha fallat i el codi no compila!\nSi t'has equivocat modificant el codi, fes clic al botó de "Reset" per tornar-lo al seu estat original.`}
/>
</QuestionCard>

:::tip[Exercici]
Expand All @@ -32,4 +38,4 @@ Per exemple: `"Hola, Liam!"`.
:::

Ara l'ordinador et parla, que simpàtic!
Si estàs llest, fes clic a la fletxa de sota per començar la teva aventura!
Si estàs llest, fes clic a la fletxa de sota per començar la teva aventura!
22 changes: 16 additions & 6 deletions src/content/docs/ca/first-steps/2-the-adventurers-guild.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ description: L'heroi es registra en el Gremi d'Aventurers.

import QuestionCard from "@components/QuestionCard.astro";
import CodeBlock from "@components/CodeBlock.svelte";
import lang from "@i18n/ca.json";

export function SimpleQuestion({
question,
Expand All @@ -30,10 +29,16 @@ export function SimpleQuestion({
_ => println!("${wrong}"),
}
`.replaceAll("\n", "");

return (
<QuestionCard question={question}>
<CodeBlock client:only code={code} setup={setup} showLineNumbers={false} lang="ca" />
<CodeBlock
client:only
code={code}
setup={setup}
showLineNumbers={false}
lang="ca"
/>
</QuestionCard>
);
}
Expand All @@ -47,7 +52,13 @@ export function FreeQuestion({ question, code = "", correct }) {
`.replaceAll("\n", "");
return (
<QuestionCard question={question}>
<CodeBlock client:only code={code} setup={setup} showLineNumbers={false} lang="ca"/>
<CodeBlock
client:only
code={code}
setup={setup}
showLineNumbers={false}
lang="ca"
/>
</QuestionCard>
);
}
Expand Down Expand Up @@ -127,7 +138,7 @@ Ara farem algunes comparacions, res difícil.
Veus el que estem fent?
Intenta reescriure el codi dels exercicis que hem fet, exactament com es formula la pregunta.

Per exemple, per la primera pregunta, en comptes de dir `200 és més petit que ?`, digues `? és més gran que 200`.
Per exemple, per la primera pregunta, en comptes de dir `200 és més petit que ?`, digues `? és més gran que 200`.

**Recorda substituïr `?` en la solució final.**

Expand Down Expand Up @@ -165,4 +176,3 @@ Ara si us plau signa aquí, i estaràs llest per fer la teva primera missió.
lang="ca"
/>
</QuestionCard>

9 changes: 7 additions & 2 deletions src/content/docs/en/first-steps/1-introduction.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ This book is designed for people with zero experience in Rust or programming in
Usually, Rust is seen as a difficult language to learn, and is not recommended as a first language.
Well, my goal is to prove otherwise!

I believe Rust is a very strict but thorough teacher, that makes sure you understand your code before letting you run it.
I believe Rust is a very strict but thorough teacher, that makes sure you understand your code before letting you run it.
Some may find this unappealing at first: "Let me run my program!"
However, this strictness will make you a better programmer, one that writes code that "works the first time".

Expand All @@ -22,7 +22,12 @@ Each quest provides a programming lesson and includes a snippet of code that you
Try running the following snippet (click the "Run" button on the right or press `⇧ + ↵` on your keyboard while editing):

<QuestionCard>
<CodeBlock client:only code={'println!("Hello World!")'} showLineNumbers={false} errorMsg={`Woops, something went wrong and the code does not compile!\nIf you've mistakenly messed up the code, click the "Reset" button to return it back to its original state.`} />
<CodeBlock
client:only
code={'println!("Hello World!")'}
showLineNumbers={false}
errorMsg={`Woops, something went wrong and the code does not compile!\nIf you've mistakenly messed up the code, click the "Reset" button to return it back to its original state.`}
/>
</QuestionCard>

:::tip[Exercise]
Expand Down
15 changes: 12 additions & 3 deletions src/content/docs/en/first-steps/2-the-adventurers-guild.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,12 @@ export function SimpleQuestion({
`.replaceAll("\n", "");
return (
<QuestionCard question={question}>
<CodeBlock client:only code={code} setup={setup} showLineNumbers={false} />
<CodeBlock
client:only
code={code}
setup={setup}
showLineNumbers={false}
/>
</QuestionCard>
);
}
Expand All @@ -45,7 +50,12 @@ export function FreeQuestion({ question, code = "", correct }) {
`.replaceAll("\n", "");
return (
<QuestionCard question={question}>
<CodeBlock client:only code={code} setup={setup} showLineNumbers={false} />
<CodeBlock
client:only
code={code}
setup={setup}
showLineNumbers={false}
/>
</QuestionCard>
);
}
Expand Down Expand Up @@ -161,4 +171,3 @@ Now please sign here, and you'll be ready to take your first quest.
}
/>
</QuestionCard>

2 changes: 1 addition & 1 deletion src/content/docs/en/first-steps/3-the-first-quest.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ title: The First Quest
description: Finally, your first quest! What will it be...
---

Work in progress
Work in progress
10 changes: 8 additions & 2 deletions src/content/docs/es/first-steps/1-introduction.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Este libro está pensado para gente con cero experiencia en Rust o programación
Usualmente, Rust es visto como un lenguaje difícil de aprender, y no es recomendado como primer lenguaje.
Pues bien, ¡mi objetivo es demostrar lo contrario!

Creo que Rust es un profesor muy estricto pero minucioso, que se asegura de que entiendes tu código antes de dejarte ejecutarlo.
Creo que Rust es un profesor muy estricto pero minucioso, que se asegura de que entiendes tu código antes de dejarte ejecutarlo.
Algunos pueden encontrar esto poco atractivo al principio: "¡Déjame ejecutar mi programa!".
Sin embargo, esta rigurosidad te convertirá en un mejor programador, uno que escribe código que "funciona a la primera".

Expand All @@ -22,7 +22,13 @@ Cada misión te proporcionará una lección de programación, e incluye un fragm
Prueba a ejecutar el siguiente fragmento de código (haz clic en el botón "Ejecutar" de la derecha o pulsa `⇧ + ↵` en el teclado mientras editas):

<QuestionCard>
<CodeBlock client:only code={'println!("¡Hola, Mundo!")'} showLineNumbers={false} lang="es" errorMsg={`Ups, ¡algo ha ido mal y el código no compila!\nSi has estropeado el código por error, haz clic en el botón "Reset" para devolverlo a su estado original.`} />
<CodeBlock
client:only
code={'println!("¡Hola, Mundo!")'}
showLineNumbers={false}
lang="es"
errorMsg={`Ups, ¡algo ha ido mal y el código no compila!\nSi has estropeado el código por error, haz clic en el botón "Reset" para devolverlo a su estado original.`}
/>
</QuestionCard>

:::tip[Ejercicio]
Expand Down
19 changes: 15 additions & 4 deletions src/content/docs/es/first-steps/2-the-adventurers-guild.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,13 @@ export function SimpleQuestion({
`.replaceAll("\n", "");
return (
<QuestionCard question={question}>
<CodeBlock client:only code={code} setup={setup} showLineNumbers={false} lang="es" />
<CodeBlock
client:only
code={code}
setup={setup}
showLineNumbers={false}
lang="es"
/>
</QuestionCard>
);
}
Expand All @@ -45,7 +51,13 @@ export function FreeQuestion({ question, code = "", correct }) {
`.replaceAll("\n", "");
return (
<QuestionCard question={question}>
<CodeBlock client:only code={code} setup={setup} showLineNumbers={false} lang="es" />
<CodeBlock
client:only
code={code}
setup={setup}
showLineNumbers={false}
lang="es"
/>
</QuestionCard>
);
}
Expand Down Expand Up @@ -125,7 +137,7 @@ Ahora haremos algunas comparaciones, cosas sencillas.
¿Ves lo que estamos haciendo?
Intenta reescribir el código de los ejercicios anteriores, exactamente como está formulada la pregunta.

Por ejemplo, para la primera pregunta, en lugar de decir `200 es menor que ?`, di `? es mayor que 200`.
Por ejemplo, para la primera pregunta, en lugar de decir `200 es menor que ?`, di `? es mayor que 200`.

**Acuérdate de rellenar el `?` en tu respuesta final.**

Expand Down Expand Up @@ -163,4 +175,3 @@ Ahora por favor firma aquí, y estarás listo para tu primera misión.
lang="es"
/>
</QuestionCard>

2 changes: 1 addition & 1 deletion src/content/docs/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ hero:
head:
- tag: title
content: "Rust Quest"
---
---
Loading

0 comments on commit 9bc82aa

Please sign in to comment.