Skip to content

Commit 49b6d59

Browse files
committed
merging main
2 parents 5818cbb + f508773 commit 49b6d59

File tree

7 files changed

+44
-22
lines changed

7 files changed

+44
-22
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ A plugin for [Eleventy](https://www.11ty.dev) to showcase your SCAD files.
66

77
Use Eleventy to generate a site to showcase your OpenSCAD models. This plugin adds `.scad` as a template and will use your OpenSCAD to render the file into an `.stl`. Along with the model, a Three.js model view page is gererated as well.
88

9+
Check out [a demo site](https://kevinkhill.github.io/eleventy-scad-plugin-demo/) generated from the examples that come with OpenSCAD
10+
911
## Install into Project
1012

1113
```bash

dist/assets/scad.collection.njk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<html lang="en">
33
<head>
44
<title>OpenSCAD Files</title>
5-
{% w3_theme_css %}
5+
{% w3_theme_css theme %}
66
<script>
77
console.log({{ page | dump | safe }});
88
</script>

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "eleventy-plugin-scad",
3-
"version": "0.7.4",
3+
"version": "0.8.1",
44
"description": "Eleventy plugin to use SCAD files as templates to rendering STLs and HTML",
55
"keywords": [
66
"eleventy",

src/assets/scad.collection.njk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<html lang="en">
33
<head>
44
<title>OpenSCAD Files</title>
5-
{% w3_theme_css %}
5+
{% w3_theme_css theme %}
66
<script>
77
console.log({{ page | dump | safe }});
88
</script>

src/core/templates.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Debug, getAssetFileContent } from "../lib";
22
import { DEFAULT_COLLECTION_LAYOUT, DEFAULT_SCAD_LAYOUT } from "./const";
3-
import type { EleventyConfig } from "../types";
3+
import type { EleventyConfig, ModelViewerTheme } from "../types";
44

55
const log = Debug.extend("templates");
66

@@ -17,6 +17,7 @@ export function addBuiltinScadLayoutVirtualTemplate(
1717

1818
export function addScadCollectionVirtualTemplate(
1919
eleventyConfig: EleventyConfig,
20+
pageTheme: ModelViewerTheme,
2021
) {
2122
log(`(virtual) adding "%o"`, DEFAULT_COLLECTION_LAYOUT);
2223
eleventyConfig.addTemplate(
@@ -33,7 +34,10 @@ export function addScadCollectionVirtualTemplate(
3334
<li><a href="{{ item.data.page.url | url }}">{{ item.data.title }}</a></li>
3435
{% endfor %}
3536
</ul>`,
36-
{ layout: DEFAULT_COLLECTION_LAYOUT },
37+
{
38+
layout: DEFAULT_COLLECTION_LAYOUT,
39+
theme: pageTheme,
40+
},
3741
);
3842
log(`(virtual) added "%o"`, DEFAULT_COLLECTION_TEMPLATE);
3943
}

src/plugin.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ export function EleventyPluginOpenSCAD(
111111

112112
// Add template file that lists all the collected `.scad` files
113113
if (collectionPage) {
114-
addScadCollectionVirtualTemplate(eleventyConfig);
114+
addScadCollectionVirtualTemplate(eleventyConfig, theme);
115115
}
116116

117117
/**

test/e2e/Themes.test.ts

Lines changed: 32 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,46 @@
1-
import { expect, test } from "vitest";
2-
import { SCAD_EXT, THEMES } from "../../src/core";
1+
import path from "node:path";
2+
import { describe, expect, test } from "vitest";
33
import { createTestInstance } from "../_setup/eleventy";
4+
import type { EleventyDirs, ModelViewerTheme } from "../../src";
45

5-
const CASES = THEMES.map((t) => [t]);
6+
const CASES: ModelViewerTheme[][] = [
7+
["Traditional"],
8+
["Modernist"],
9+
["Midnight"],
10+
["Chocolate"],
11+
["Oldstyle"],
12+
["Steely"],
13+
["Swiss"],
14+
["Ultramarine"],
15+
];
616

7-
test("invalid theme throws an error", async () => {
8-
await expect(async () => {
9-
// @ts-expect-error
10-
const eleventy = createTestInstance({ theme: "TacoBell#324" });
11-
await eleventy.toJSON();
12-
}).rejects.toThrow("Error processing the `EleventyPluginOpenSCAD` plugin");
13-
});
14-
15-
test.each(CASES)("%s", async (theme) => {
17+
describe.for(CASES)("Theme: %s", async ([theme]) => {
1618
const eleventy = createTestInstance({
1719
launchPath: "docker",
1820
resolveLaunchPath: false,
1921
theme: theme,
2022
silent: true,
2123
noSTL: true,
2224
});
25+
2326
const pages = await eleventy.toJSON();
24-
const scadPages = pages.filter((p) => p.inputPath.endsWith(SCAD_EXT));
2527

26-
for (const page of scadPages) {
27-
const themeURL = `https://www.w3.org/StyleSheets/Core/${theme}`;
28-
expect(page.content).includes(themeURL);
28+
for (const page of pages) {
29+
const relativeSTL = path.relative(
30+
(eleventy.directories as EleventyDirs).output,
31+
page.outputPath,
32+
);
33+
test(`CSS: ${relativeSTL}`, () => {
34+
const themeURL = `https://www.w3.org/StyleSheets/Core/${theme}`;
35+
expect(page.content).includes(themeURL);
36+
});
2937
}
3038
});
39+
40+
test("invalid theme throws an error", async () => {
41+
await expect(async () => {
42+
// @ts-expect-error
43+
const eleventy = createTestInstance({ theme: "TacoBell#324" });
44+
await eleventy.toJSON();
45+
}).rejects.toThrow("Error processing the `EleventyPluginOpenSCAD` plugin");
46+
});

0 commit comments

Comments
 (0)