Skip to content

Commit 93a9d52

Browse files
committed
feat(brand): Create Sass layer from brand.defaults.bootstrap
1 parent 2bc956a commit 93a9d52

File tree

1 file changed

+60
-2
lines changed

1 file changed

+60
-2
lines changed

src/core/sass/brand.ts

Lines changed: 60 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,43 @@ const brandColorBundle = (
222222
return colorBundle;
223223
};
224224

225+
const brandBootstrapBundle = (
226+
brand: Brand,
227+
key: string
228+
): SassBundleLayers | void => {
229+
const brandBootstrap = (brand?.data?.defaults?.bootstrap as unknown as Record<
230+
string,
231+
Record<string, string | boolean | number | null>
232+
>);
233+
234+
const bsVariables: string[] = [
235+
"/* Bootstrap variables from _brand.yml */",
236+
'// quarto-scss-analysis-annotation { "action": "push", "origin": "_brand.yml defaults.bootstrap" }',
237+
];
238+
for (const bsVar of Object.keys(brandBootstrap)) {
239+
if (bsVar === "version") {
240+
continue;
241+
}
242+
bsVariables.push(
243+
`$${bsVar}: ${brandBootstrap[bsVar]} !default;`,
244+
);
245+
}
246+
// const colorEntries = Object.keys(brand.color);
247+
bsVariables.push('// quarto-scss-analysis-annotation { "action": "pop" }');
248+
const bsBundle: SassBundleLayers = {
249+
key,
250+
// dependency: "bootstrap",
251+
quarto: {
252+
defaults: bsVariables.join("\n"),
253+
uses: "",
254+
functions: "",
255+
mixins: "",
256+
rules: "",
257+
},
258+
};
259+
return bsBundle;
260+
};
261+
225262
const brandTypographyBundle = (
226263
brand: Brand,
227264
key: string,
@@ -446,7 +483,7 @@ const brandTypographyBundle = (
446483
return typographyBundle;
447484
};
448485

449-
export async function brandBootstrapSassBundleLayers(
486+
export async function brandSassBundleLayers(
450487
fileName: string | undefined,
451488
project: ProjectContext,
452489
key: string,
@@ -466,12 +503,33 @@ export async function brandBootstrapSassBundleLayers(
466503
return sassBundles;
467504
}
468505

506+
export async function brandBootstrapSassBundleLayers(
507+
fileName: string | undefined,
508+
project: ProjectContext,
509+
key: string,
510+
nameMap: Record<string, string> = {},
511+
): Promise<SassBundleLayers[]> {
512+
const brand = await project.resolveBrand(fileName);
513+
const sassBundles = await brandSassBundleLayers(fileName, project, key, nameMap);
514+
515+
if (brand?.data?.defaults?.bootstrap) {
516+
const bsBundle = brandBootstrapBundle(brand, key);
517+
if (bsBundle) {
518+
// Add bsBundle to the beginning of the array so that defaults appear
519+
// *after* the rest of the brand variables.
520+
sassBundles.unshift(bsBundle);
521+
}
522+
}
523+
524+
return sassBundles;
525+
}
526+
469527
export async function brandRevealSassBundleLayers(
470528
input: string | undefined,
471529
_format: Format,
472530
project: ProjectContext,
473531
): Promise<SassBundleLayers[]> {
474-
return brandBootstrapSassBundleLayers(
532+
return brandSassBundleLayers(
475533
input,
476534
project,
477535
"reveal-theme",

0 commit comments

Comments
 (0)