Generating documentation using factory

This commit is contained in:
2023-08-25 12:36:37 +02:00
parent 94acee819a
commit 58c0a2cf66
3 changed files with 407 additions and 370 deletions

View File

@ -51,7 +51,7 @@ Array.prototype.in = function <T>(this: T[], value: T): boolean {
return this.includes(value);
};
async function loadSamples() {
export async function loadSamples() {
// const ds = "https://raw.githubusercontent.com/felixroos/dough-samples/main/";
return Promise.all([
initAudioOnFirstClick(),
@ -62,8 +62,6 @@ async function loadSamples() {
]);
}
loadSamples();
export const generateCacheKey = (...args: any[]): string => {
return args.map((arg) => JSON.stringify(arg)).join(",");
};
@ -92,6 +90,10 @@ export class UserAPI {
//this.load = samples("github:tidalcycles/Dirt-Samples/master");
}
_all_samples = (): object => {
return soundMap.get();
};
_reportError = (error: any): void => {
console.log(error);
clearTimeout(this.errorTimeoutID);
@ -236,7 +238,7 @@ export class UserAPI {
}
};
public midi = (value: number|object = 60): NoteEvent => {
public midi = (value: number | object = 60): NoteEvent => {
/**
* Sends a MIDI note to the current MIDI output.
*
@ -323,8 +325,8 @@ export class UserAPI {
this.app.api.patternCache.set(key, player);
}
if ((player && player.notStarted()) || player.played) {
player.callTime = this.epulse();
player.played = false;
player.callTime = this.epulse();
player.played = false;
}
return player;
};
@ -889,7 +891,7 @@ export class UserAPI {
let integral_part = Math.floor(b);
let decimal_part = b - integral_part;
final_pulses.push(
integral_part === this.app.clock.time_position.beat &&
integral_part === this.app.clock.time_position.beat &&
this.app.clock.time_position.pulse ===
decimal_part * this.app.clock.ppqn
);
@ -1235,7 +1237,7 @@ export class UserAPI {
// Trivial functions
// =============================================================
sound = (sound: string|object) => {
sound = (sound: string | object) => {
return new SoundEvent(sound, this.app);
};

File diff suppressed because it is too large Load Diff

View File

@ -14,10 +14,10 @@ import { indentWithTab } from "@codemirror/commands";
import { vim } from "@replit/codemirror-vim";
import { AppSettings, Universe } from "./AppSettings";
import { editorSetup } from "./EditorSetup";
import { documentation } from "./Documentation";
import { documentation_factory } from "./Documentation";
import { EditorView } from "codemirror";
import { Clock } from "./Clock";
import { UserAPI } from "./API";
import { loadSamples, UserAPI } from "./API";
import "./style.css";
import {
Universes,
@ -27,9 +27,6 @@ import {
} from "./AppSettings";
import { tryEvaluate } from "./Evaluator";
type Documentation = { [key: string]: string };
const Docs: Documentation = documentation;
// Importing showdown and setting up the markdown converter
import showdown from "showdown";
showdown.setFlavor("github");
@ -78,6 +75,7 @@ export class Editor {
userPlugins: Extension[] = [];
state: EditorState;
api: UserAPI;
docs: { [key: string]: string } = {};
// Audio stuff
audioContext: AudioContext;
@ -236,6 +234,13 @@ export class Editor {
let dynamicPlugins = new Compartment();
// ================================================================================
// Building the documentation
loadSamples().then(() => {
this.docs = documentation_factory(this);
});
// ================================================================================
// ================================================================================
// Application event listeners
// ================================================================================
@ -662,10 +667,11 @@ export class Editor {
const converter = new showdown.Converter({
emoji: true,
moreStyling: true,
backslashEscapesHTMLTags: true,
extensions: [showdownHighlight({ auto_detection: true }), ...bindings],
});
const converted_markdown = converter.makeHtml(
Docs[this.currentDocumentationPane]
this.docs[this.currentDocumentationPane]
);
function wrapCodeWithPre(inputString: string): string {
let newString = inputString.replace(/<code>/g, "<pre><code>");