Skip to content

Commit

Permalink
Update reference to show p5.sound
Browse files Browse the repository at this point in the history
  • Loading branch information
davepagurek committed Oct 7, 2024
1 parent 8b04e14 commit 53b88c1
Show file tree
Hide file tree
Showing 9 changed files with 38 additions and 17 deletions.
4 changes: 4 additions & 0 deletions src/components/CodeEmbed/frame.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ interface CodeBundle {
htmlBody?: string;
js?: string;
base?: string;
scripts?: string[];
}

/*
Expand Down Expand Up @@ -41,6 +42,7 @@ canvas {
}
${code.css || ""}
</style>
${(code.scripts || []).map((src) => `<script type="text/javascript" src="${src}"></script>`).join('\n')}
<body>${code.htmlBody || ""}</body>
<script id="code" type="text/javascript">${wrapSketch(code.js) || ""}</script>
<script type="text/javascript">
Expand All @@ -67,6 +69,7 @@ export interface CodeFrameProps {
width?: number | string;
base?: string;
lazyLoad?: boolean;
scripts?: string[];
}

/*
Expand Down Expand Up @@ -155,6 +158,7 @@ export const CodeFrame = (props: CodeFrameProps) => {
css: props.cssCode,
htmlBody: props.htmlBodyCode,
base: props.base,
scripts: props.scripts,
})}
sandbox="allow-scripts allow-popups allow-modals allow-forms allow-same-origin"
aria-label="Code Preview"
Expand Down
4 changes: 3 additions & 1 deletion src/components/CodeEmbed/index.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useState, useEffect, useRef } from "preact/hooks";
import CodeMirror, { EditorView } from "@uiw/react-codemirror";
import { javascript } from "@codemirror/lang-javascript";
import { cdnLibraryUrl } from "@/src/globals/globals";
import { cdnLibraryUrl, cdnSoundUrl } from "@/src/globals/globals";

import { CodeFrame } from "./frame";
import { CopyCodeButton } from "../CopyCodeButton";
Expand All @@ -21,6 +21,7 @@ import { Icon } from "../Icon";
* TODO: refactor this prop behavior
* allowSideBySide?: boolean
* fullWidth?: boolean
* includeSound?: boolean
* }
*/
export const CodeEmbed = (props) => {
Expand Down Expand Up @@ -90,6 +91,7 @@ export const CodeEmbed = (props) => {
base={props.base}
frameRef={codeFrameRef}
lazyLoad={props.lazyLoad}
scripts={props.includeSound ? [cdnSoundUrl] : []}
/>
</div>
<div className={`flex gap-2.5 ${largeSketch ? "flex-row" : "md:flex-row lg:flex-col"}`}>
Expand Down
8 changes: 4 additions & 4 deletions src/components/ReferenceDirectoryWithFilter/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,11 @@ export const ReferenceDirectoryWithFilter = ({
subcat: { name: string },
category: { name: string },
) => {
return !(!subcat.name || !category.name || subcat.name === "p5.sound");
return !(!subcat.name || !category.name);
}

const getSubcatHeading = (
subcat: { name: string },
subcat: { name: string; entry?: any },
category: { name: string },
) => {
if (!subcatShouldHaveHeading(subcat, category)) {
Expand All @@ -129,10 +129,10 @@ export const ReferenceDirectoryWithFilter = ({

return (
<>
{subcat.name.includes("p5.") ? (
{subcat.entry ? (
<a
id={subcat.name}
href={`/reference/${category.name === "p5.sound" ? "p5.sound" : "p5"}/${subcat.name}`}
href={`/reference/${category.name === "p5.sound" ? "p5.sound" : "p5"}/${subcat.name}/`}
>
<h3 className="m-0 py-gutter-md">{subcat.name}</h3>
</a>
Expand Down
3 changes: 2 additions & 1 deletion src/content/reference/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export const categories = [
"Structure", // TODO: move to top once revised
"Constants",
"Foundation",
"p5.sound",
] as const;

const paramSchema = z.object({
Expand All @@ -32,7 +33,7 @@ const paramSchema = z.object({

const returnSchema = z.object({
description: z.string(),
type: z.string(),
type: z.string().optional(),
});

const exampleSchema = z.string();
Expand Down
2 changes: 2 additions & 0 deletions src/globals/globals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,5 @@ export const libraryDownloadUrl =
`https://github.com/processing/p5.js/releases/download/v${p5Version}/p5.js` as const;
export const minifiedLibraryDownloadUrl =
`https://github.com/processing/p5.js/releases/download/v${p5Version}/p5.min.js` as const;
export const cdnSoundUrl =
`https://cdn.jsdelivr.net/npm/p5@${p5Version}/lib/addons/p5.sound.js` as const;
1 change: 1 addition & 0 deletions src/layouts/ReferenceItemLayout.astro
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ const seenParams: Record<string, true> = {};
editable
lazyLoad={false}
allowSideBySide={true}
includeSound={entry.data.module === 'p5.sound'}
/>
);
})}
Expand Down
2 changes: 1 addition & 1 deletion src/layouts/ReferenceLayout.astro
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ const categoryData = categories.map((category) => {
...new Set(
directEntries
// Ignore classes here, they will be added later
.filter((e) => e.data.submodule && !e.data.isConstructor)
.filter((e) => e.data.submodule && !e.data.isConstructor && (!e.data.class || e.data.class === 'p5'))
.map((e) => e.data.submodule)
).values(),
].sort();
Expand Down
25 changes: 20 additions & 5 deletions src/scripts/parsers/reference.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,20 @@ export const parseLibraryReference =
async (): Promise<ParsedLibraryReference | null> => {
// Clone p5.js
await cloneLibraryRepo(localPath);
await saveYuidocOutput('p5.js', 'data-p5');
// TODO(dave): let this happen via `npm run docs` in the p5 repo once we
// merge the 2.0 branch
await saveYuidocOutput('p5.js', 'data-p5', {
flags: `--config ${path.join(__dirname, '../../../yuidoc.json')}`,
inputPath: './src',
});
const p5Data = await getYuidocOutput('data-p5');
if (!p5Data) throw new Error('Error generating p5 reference data!');

// Clone p5.sound.js
await cloneLibraryRepo(
localSoundPath,
'https://github.com/processing/p5.sound.js.git',
'moduleref', // 'main',
'https://github.com/davepagurek/p5.sound.js-pre-release.git', // 'https://github.com/processing/p5.sound.js.git',
'moduleref-doc-comments', // 'main',
{ shouldFixAbsolutePathInPreprocessor: false }
);
await saveYuidocOutput('p5.sound.js', 'data-sound');
Expand Down Expand Up @@ -76,15 +81,25 @@ const getYuidocOutput = async (outDirName: string): Promise<ParsedLibraryReferen
/**
* Parses the p5.js library using YUIDoc and captures the output
*/
export const saveYuidocOutput = async (inDirName: string, outDirName: string) => {
export const saveYuidocOutput = async (
inDirName: string,
outDirName: string,
{
flags = '',
inputPath = '.',
}: {
flags?: string
inputPath?: string
} = {}
) => {
console.log("Running YUIDoc command and capturing output...");
const outputFilePath = path.join(yuidocOutputPath, outDirName);
try {
await fs.mkdir(yuidocOutputPath, { recursive: true });
const inPath = path.join(__dirname, "in", inDirName);
console.log(inPath)
await new Promise((resolve, reject) => {
exec(`yuidoc -p --outdir ${outputFilePath} .`, { cwd: inPath }, (error, stdout) => {
exec(`yuidoc -p --outdir ${outputFilePath} ${flags} ${inputPath}`, { cwd: inPath }, (error, stdout) => {
if (error) {
console.error(`Error running YUIDoc command: ${error}`);
reject(error);
Expand Down
6 changes: 1 addition & 5 deletions yuidoc.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@
"description": "",
"url": "",
"options": {
"preprocessor": "./src/scripts/parsers/in/p5.js/docs/preprocessor.js",
"paths": [
"./src/scripts/parsers/in/p5.js/src/",
"./src/scripts/parsers/in/p5.js/lib/addons/"
]
"preprocessor": "./docs/preprocessor.js"
}
}

0 comments on commit 53b88c1

Please sign in to comment.