Skip to content

Commit 53b01e7

Browse files
committed
refactor: add language samples
1 parent 03c33bc commit 53b01e7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+1129
-9
lines changed

projects/dev-app/src/app/home/home.component.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<mat-sidenav-container>
22
<mat-sidenav-content>
33

4-
<mtx-split [style.height]="options.height.value+options.height.unit">
4+
<mtx-split>
55
<mtx-split-pane>
66
<code-editor #editor
77
[style.height]="options.height.value+options.height.unit"
@@ -28,6 +28,6 @@
2828
</mat-sidenav-content>
2929

3030
<mat-sidenav mode="side" position="end" opened>
31-
<gui-form [style.width.px]="300" [config]="config" [model]="options" />
31+
<gui-form [style.width.px]="300" [form]="form" [config]="config" [model]="options" />
3232
</mat-sidenav>
3333
</mat-sidenav-container>

projects/dev-app/src/app/home/home.component.ts

Lines changed: 36 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
import { Component, OnInit } from '@angular/core';
2-
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
1+
import { AfterViewInit, Component, DestroyRef, OnInit, inject } from '@angular/core';
2+
import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
3+
import { FormGroup, FormsModule, ReactiveFormsModule } from '@angular/forms';
34
import { MatSidenavModule } from '@angular/material/sidenav';
45
import { MtxSplitModule } from '@ng-matero/extensions/split';
56

@@ -21,14 +22,20 @@ import { languages } from '@codemirror/language-data';
2122
templateUrl: './home.component.html',
2223
styleUrl: './home.component.scss',
2324
})
24-
export class HomeComponent implements OnInit {
25+
export class HomeComponent implements OnInit, AfterViewInit {
26+
private readonly destroyRef = inject(DestroyRef);
27+
2528
languages = languages;
2629

30+
form = new FormGroup({});
31+
2732
config: GuiFields = {
2833
language: {
2934
type: 'select',
3035
name: 'Language',
31-
options: languages.map(lang => ({ label: lang.name, value: lang.name.toLowerCase() })),
36+
options: languages
37+
.map(lang => ({ label: lang.name, value: lang.name.toLowerCase() }))
38+
.sort((a, b) => a.label.localeCompare(b.label)),
3239
},
3340
theme: {
3441
type: 'buttonToggle',
@@ -108,14 +115,36 @@ export class HomeComponent implements OnInit {
108115
indentUnit: '',
109116
lineWrapping: false,
110117
highlightWhitespace: false,
111-
height: { value: 200, unit: 'px' },
118+
height: { value: 100, unit: '%' },
112119
};
113120

114-
code = 'console.log("Hello world")';
121+
code = '';
115122

116123
log(e: any) {
117124
console.log(e);
118125
}
119126

120-
ngOnInit(): void {}
127+
ngOnInit(): void {
128+
this.getLangSample('javascript');
129+
}
130+
131+
ngAfterViewInit(): void {
132+
this.form
133+
.get('language')
134+
?.valueChanges.pipe(takeUntilDestroyed(this.destroyRef))
135+
.subscribe((lang: string) => {
136+
console.log(lang);
137+
this.getLangSample(lang.replace(' ', '_').replace('#', 'sharp'));
138+
});
139+
}
140+
141+
getLangSample(lang: string) {
142+
fetch(`/assets/lang_samples/${lang}.txt`).then(async response => {
143+
if (response.ok) {
144+
this.code = await response.text();
145+
} else {
146+
this.code = '';
147+
}
148+
});
149+
}
121150
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<h2>Todos</h2>
2+
<input #text />
3+
<button (click)="add(text.value)">Add</button>
4+
5+
@for (todo of todos; track $index) {
6+
<p>
7+
<input type="checkbox" (change)="toggle($index)" />
8+
@if (todo.done) {
9+
<s>{{ todo.text }}</s>
10+
} @else {
11+
<span>{{ todo.text }}</span>
12+
}
13+
</p>
14+
} @empty {
15+
<p>No todos</p>
16+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/bin/bash
2+
3+
###### CONFIG
4+
ACCEPTED_HOSTS="/root/.hag_accepted.conf"
5+
BE_VERBOSE=false
6+
7+
if [ "$UID" -ne 0 ]
8+
then
9+
echo "Superuser rights required"
10+
exit 2
11+
fi
12+
13+
genApacheConf(){
14+
echo -e "# Host ${HOME_DIR}$1/$2 :"
15+
}
16+
17+
echo '"quoted"' | tr -d \" > text.txt
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
class MyClass { // The class
2+
public: // Access specifier
3+
int myNum; // Attribute (int variable)
4+
string myString; // Attribute (string variable)
5+
};
6+
7+
int main() {
8+
MyClass myObj; // Create an object of MyClass
9+
10+
// Access attributes and set values
11+
myObj.myNum = 15;
12+
myObj.myString = "Some text";
13+
14+
// Print attribute values
15+
cout << myObj.myNum << "\n";
16+
cout << myObj.myString;
17+
return 0;
18+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#include <stdio.h>
2+
3+
int main() {
4+
printf("Hello World!");
5+
return 0;
6+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
(def ^:dynamic chunk-size 17)
2+
3+
(defn next-chunk [rdr]
4+
(let [buf (char-array chunk-size)
5+
s (.read rdr buf)]
6+
(when (pos? s)
7+
(java.nio.CharBuffer/wrap buf 0 s))))
8+
9+
(defn chunk-seq [rdr]
10+
(when-let [chunk (next-chunk rdr)]
11+
(cons chunk (lazy-seq (chunk-seq rdr)))))
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
grade = (student, period=(if b? then 7 else 6)) ->
2+
if student.excellentWork
3+
"A+"
4+
else if student.okayStuff
5+
if student.triedHard then "B" else "B-"
6+
else
7+
"C"
8+
9+
class Animal extends Being
10+
constructor: (@name) ->
11+
12+
move: (meters) ->
13+
alert @name + " moved #{meters}m."
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
using System.IO.Compression;
2+
3+
#pragma warning disable 414, 3021
4+
5+
namespace MyApplication
6+
{
7+
[Obsolete("...")]
8+
class Program : IInterface
9+
{
10+
public static List<int> JustDoIt(int count)
11+
{
12+
Span<int> numbers = stackalloc int[length];
13+
Console.WriteLine($"Hello {Name}!");
14+
return new List<int>(new int[] { 1, 2, 3 })
15+
}
16+
}
17+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
body {
2+
background-color: lightblue;
3+
}
4+
5+
h1 {
6+
color: white;
7+
text-align: center;
8+
}
9+
10+
p {
11+
font-family: verdana;
12+
font-size: 20px;
13+
}

0 commit comments

Comments
 (0)