Skip to content

Commit

Permalink
Merge pull request #9997 from quarto-dev/fix/extensions/format-resour…
Browse files Browse the repository at this point in the history
…ces-globs
  • Loading branch information
cderv authored Jun 17, 2024
2 parents 66ffcaa + 50b4cf1 commit 68cc8cb
Show file tree
Hide file tree
Showing 11 changed files with 78 additions and 0 deletions.
1 change: 1 addition & 0 deletions news/changelog-1.5.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ All changes included in 1.5:

- ([#8385](https://github.com/quarto-dev/quarto-cli/issues/8385)): Properly copy project resources when extensions are installed at project level.
- ([#8547](https://github.com/quarto-dev/quarto-cli/issues/8547)): Support installing extensions from github branch with forward slash in the name.
- ([#9918](https://github.com/quarto-dev/quarto-cli/issues/9918)): `format-resources` can use explicit [Quarto glob syntax](https://quarto.org/docs/reference/globs.html), e.g. `format-resources: dir/**/*` to copy all files in `dir` and its subdirectories to input root, but use `format-resources: dir` to copy `dir` and its contents to input root.
- ([#9948](https://github.com/quarto-dev/quarto-cli/issues/9948)): New extension type: `metadata`. Example use case: support `pre-render` and `post-render` script lists in `project` metadata.

## Shortcodes
Expand Down
1 change: 1 addition & 0 deletions src/extension/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -730,6 +730,7 @@ async function readExtension(
extensionDir,
formatMeta[kFormatResources] as string[],
[],
{ mode: "strict" },
);
if (resolved.include.length > 0) {
formatMeta[kFormatResources] = resolved.include.map((include) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
title: Test
author: Christophe Dervieux
version: 1.0.0
quarto-required: ">=1.3"
contributes:
formats:
html:
format-resources:
- folder-to-root
- files-to-root/**/*
- dummy-4.txt
gfm:
format-resources: folder-to-root
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This file should be copied to root project for rendering as it is included as a format-resources
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This file should be copied to root project for rendering as it is included as a format-resources
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This file should be copied to root project for rendering as it is included as a format-resources
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This file should be copied to root project for rendering as it is included as a format-resources
9 changes: 9 additions & 0 deletions tests/docs/extensions/format-resources/9918/index.qmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
title: Untitled
format:
test-html: default
test-gfm: default
---

This document uses a test extension that should include nested resources

33 changes: 33 additions & 0 deletions tests/smoke/extensions/extension-render-format-resources.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* extension-render-doc.test.ts
*
* Copyright (C) 2020-2022 Posit Software, PBC
*
*/

import { safeRemoveSync } from "../../../src/core/path.ts";
import { dirname, join } from "../../../src/deno_ral/path.ts";
import { fileLoader } from "../../utils.ts";
import { fileExists, folderExists, pathDoNotExists } from "../../verify.ts";
import { testRender } from "../render/render.ts";

// This file uses custom formats 'test-html' provided by test extension
const input = fileLoader("extensions/format-resources/9918")("index.qmd", "test-html");
const rootDir = dirname(input.input)
const resourcesFile = [
join('folder-to-root', 'dummy.txt'),
'dummy-2.txt', 'dummy-3.txt', 'dummy-4.txt',
].map((x) => join(rootDir, x))
testRender(input.input, "test-html", false,
[
folderExists(join(rootDir, "folder-to-root")),
...resourcesFile.map(fileExists),
pathDoNotExists(join(rootDir, "dummy.txt")),
],
{
teardown: () => {
resourcesFile.forEach((x) => safeRemoveSync(x));
return Promise.resolve();
},
}
);
7 changes: 7 additions & 0 deletions tests/smoke/render/render.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
} from "../../verify.ts";
import { safeRemoveSync } from "../../../src/core/path.ts";
import { safeExistsSync } from "../../../src/core/path.ts";
import { assert } from "../../../src/vendor/deno.land/[email protected]/assert/assert.ts";

export function testSimpleIsolatedRender(
file: string,
Expand Down Expand Up @@ -66,6 +67,12 @@ export function testRender(
verify,
{
...context,
setup: async () => {
if (context?.setup) {
await context?.setup();
}
assert(safeExistsSync(input), `Input file ${input} does not exist. Test could not be ran.`);
},
teardown: async () => {
if (context?.teardown) {
await context?.teardown();
Expand Down
10 changes: 10 additions & 0 deletions tests/verify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,16 @@ export const fileExists = (file: string): Verify => {
};
};

export const pathDoNotExists = (path: string): Verify => {
return {
name: `path ${path} exists`,
verify: (_output: ExecuteOutput[]) => {
verifyNoPath(path);
return Promise.resolve();
},
};
};

export const directoryContainsOnlyAllowedPaths = (dir: string, paths: string[]): Verify => {
return {
name: `Ensure only has ${paths.length} paths in folder`,
Expand Down

0 comments on commit 68cc8cb

Please sign in to comment.