Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions content/presentation/directives.md
Original file line number Diff line number Diff line change
Expand Up @@ -260,14 +260,14 @@ Every key of every slide's frontmatter must be one of these nine:
| `author` | string | the theme's, else `markdown-presentation` | **first only** |
| `description` | string | `null` | **first only** |
| `template` | string, or a list of them | none | any |
| `chrome` | string | none | **first only** |
| `templates-file` | string | none | **first only** |

The layout roles are listed with the [themes](/presentation/themes/#layout-roles). Anything else —
including Slidev's own `two-cols` — is refused with the list of what would have worked.

A deck directive on a later slide is refused by name, because it is nearly always a slide that
was meant to be the first one. The deck's own frontmatter **is the first slide's**, so `theme:`,
`author:`, `description:` and `chrome:` belong on the slide that opens the deck.
`author:`, `description:` and `templates-file:` belong on the slide that opens the deck.

{% example %}
````md presentation "The four keys that describe a deck"
Expand Down Expand Up @@ -374,18 +374,18 @@ drawn where the template puts it.
The chrome is drawn **over** what the slide placed itself, so a full-bleed picture is behind the
wordmark and not over it.

### The chrome file
### The templates file

A deck may keep its templates in a file beside it and name it in the deck's frontmatter:

```markdown
---
theme: ./theme.yml
chrome: ./chrome.md
templates-file: ./templates.md
---
```

`chrome.md` is a Markdown file of template definitions in the same syntax as a deck, and it is
`templates.md` is a Markdown file of template definitions in the same syntax as a deck, and it is
resolved against the deck's own directory — so a deck and the furniture it shares travel together.
A file that is not there is a failure, and so is a file outside the directories the render may
read: a path a deck wrote is held to the same scope as a picture in it. A file that holds a slide
Expand Down
11 changes: 6 additions & 5 deletions content/presentation/errors.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@ is about both libraries, is on [Errors in general](/errors/).
| `UnknownMarker` | `::click=0`, backwards, over 500, unclosed, or a stray closer |
| `UnknownLayoutRole` | `layout:` is not one of the layout roles |
| `UnknownTemplate` | a slide names a template the deck does not have — the message names the templates |
| `MalformedChrome` | a template holds ordinary Markdown, or a chrome file holds a slide |
| `ChromeNotFound` | the chrome file a deck names is not there, or is outside the roots |
| `ChromeTooLarge` | the chrome file a deck names is over the ceiling |
| `MalformedChrome` | a template holds ordinary Markdown |
| `MalformedTemplatesFile` | the templates file a deck names holds a slide |
| `TemplatesFileNotFound` | the templates file a deck names is not there, or is outside the roots |
| `TemplatesFileTooLarge` | the templates file a deck names is over the ceiling |
| `UnsupportedColumn` | more `::column` markers than the layout has columns |
| `UnsupportedImageFormat` | not an image, no decoder, or over the ceiling |
| `UnsupportedLink` | `javascript:`, `data:`, `phar://`, `file://`, a UNC share |
Expand Down Expand Up @@ -51,5 +52,5 @@ Five sit beside `InvalidInput` rather than under it: nothing a deck names fixes
be read, a target that cannot be written, a conversion with nothing to convert, or a dependency
that was installed without the fixes the library needs.

The three that carry a template are about the deck rather than about a file on disk: a name
nothing is under, a body that holds the wrong thing, and a file that is not there.
The four that carry a template are the deck author's to fix: a name nothing is under, a body
that holds the wrong thing, a file that holds a slide, and a file that is not there.
2 changes: 1 addition & 1 deletion content/presentation/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ PowerPoint open the deck as `[Repaired]`.
| `MAX_SLIDES` | 1000 |
| `MAX_STEP` | 500 |
| `MAX_PIXELS` | 16,777,216 — 4096 × 4096, enforced on the file header |
| `MAX_BYTES` | 1,048,576 — the size of a chrome file |
| `MAX_BYTES` | 1,048,576 — the size of a templates file |
| `MAX_SHAPES` | 100 — the shapes one slide may carry |
| `MAX_PART_BYTES` | 4,194,304 — one part of a theme's template |

Expand Down
4 changes: 2 additions & 2 deletions content/presentation/themes.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,8 @@ A **template** is not a theme, and it does not live beside one.
A theme's own `template.pptx` is a **third thing** and shares only the name: it is the PowerPoint
file that says where the theme's layouts put their boxes, and it says nothing about the furniture
on a slide. A template that says where the furniture goes is written in Markdown, beside the deck
or in it — `chrome: ./chrome.md` resolves against the deck's own directory, so a deck and the
furniture it shares travel together.
or in it — `templates-file: ./templates.md` resolves against the deck's own directory, so a deck
and the furniture it shares travel together.

The rules a template follows, and the four things that decide what one is, are on
[Presentation directives](/presentation/directives/#slide-templates).
Expand Down
6 changes: 3 additions & 3 deletions src/Reference/Vocabularies.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
use MarkdownPresentation\Render\ImageConverter;
use MarkdownPresentation\Render\PresentationRenderer;
use MarkdownPresentation\Render\TemplateGeometry;
use MarkdownPresentation\Template\ChromeFile;
use MarkdownPresentation\Template\TemplatesFile;
use MarkdownPresentation\Theme\LayoutRole;
use MarkdownPresentation\Theme\StyleMapping;
use MarkdownPresentation\Theme\StyleSlots;
Expand Down Expand Up @@ -79,7 +79,7 @@ public static function all(): array
'presentation.ceilings' => new Vocabulary(
[
'PresentationRenderer::MAX_SLIDES, BlockTranslator::MAX_STEP, ImageConverter::MAX_PIXELS, '
. 'ChromeFile::MAX_BYTES, Furniture::MAX_SHAPES, TemplateGeometry::MAX_PART_BYTES'
. 'TemplatesFile::MAX_BYTES, Furniture::MAX_SHAPES, TemplateGeometry::MAX_PART_BYTES'
=> [
'MAX_SLIDES',
'MAX_STEP',
Expand All @@ -93,7 +93,7 @@ public static function all(): array
'MAX_SLIDES' => PresentationRenderer::MAX_SLIDES,
'MAX_STEP' => BlockTranslator::MAX_STEP,
'MAX_PIXELS' => ImageConverter::MAX_PIXELS,
'MAX_BYTES' => ChromeFile::MAX_BYTES,
'MAX_BYTES' => TemplatesFile::MAX_BYTES,
'MAX_SHAPES' => Furniture::MAX_SHAPES,
'MAX_PART_BYTES' => TemplateGeometry::MAX_PART_BYTES,
],
Expand Down
18 changes: 9 additions & 9 deletions tests/Claims/templates.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

declare(strict_types=1);

use MarkdownOffice\Documentation\Tests\Support\Chrome;
use MarkdownOffice\Documentation\Tests\Support\Deck;
use MarkdownOffice\Documentation\Tests\Support\Site;
use MarkdownOffice\Documentation\Tests\Support\TemplatesFile;

/**
* The claims the pages make about the slide templates.
Expand Down Expand Up @@ -62,24 +62,24 @@
expect(\array_search('circle', $shapes, true))->toBeLessThan(\array_search('rectangle', $shapes, true));
});

it('reads a chrome file from beside the deck', function () {
$shapes = Chrome::shapes(
"---\nchrome: ./chrome.md\n---\n# One\n\n---\nlayout: blank\ntemplate: brand\n---\n\nWords.\n",
it('reads a templates file from beside the deck', function () {
$shapes = TemplatesFile::shapes(
"---\ntemplates-file: ./templates.md\n---\n# One\n\n---\nlayout: blank\ntemplate: brand\n---\n\nWords.\n",
"---\ntemplate: brand\n---\n::rectangle{left=0 top=0 width=10% height=10%}\n",
);

expect($shapes[1])->toContain('rectangle');
});

it('refuses a chrome file that is not there', function () {
$message = Deck::refusal("---\nchrome: ./nowhere.md\n---\n# One\n", \sys_get_temp_dir());
it('refuses a templates file that is not there', function () {
$message = Deck::refusal("---\ntemplates-file: ./nowhere.md\n---\n# One\n", \sys_get_temp_dir());

expect($message)->toContain('There is no chrome file at');
expect($message)->toContain('There is no templates file at');
});

it('lets the deck\'s own template override an imported one of the same name', function () {
$shapes = Chrome::shapes(
"---\nchrome: ./chrome.md\n---\n# One\n\n---\ntemplate: brand\n---\n::circle{left=1% top=1% width=5% height=5%}\n\n---\nlayout: blank\ntemplate: brand\n---\n\nWords.\n",
$shapes = TemplatesFile::shapes(
"---\ntemplates-file: ./templates.md\n---\n# One\n\n---\ntemplate: brand\n---\n::circle{left=1% top=1% width=5% height=5%}\n\n---\nlayout: blank\ntemplate: brand\n---\n\nWords.\n",
"---\ntemplate: brand\n---\n::rectangle{left=0 top=0 width=10% height=10%}\n",
);

Expand Down
20 changes: 10 additions & 10 deletions tests/Support/Chrome.php → tests/Support/TemplatesFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,38 +5,38 @@
namespace MarkdownOffice\Documentation\Tests\Support;

/**
* A deck's own directory, and the chrome file beside it.
* A deck's own directory, and the templates file beside it.
*
* A template may be imported from a file beside the deck, so a claim about one needs a
* deck's directory to put the file in — and the deck has to be rendered from there, or the
* path is resolved against somewhere else.
*/
final class Chrome
final class TemplatesFile
{
/**
* A directory holding a chrome file, and the directory it is in.
* A directory holding a templates file, and the directory it is in.
*/
public static function beside(string $markdown): string
{
$root = Directory::make('chrome');
$root = Directory::make('templates');

\file_put_contents($root . '/chrome.md', $markdown);
\file_put_contents($root . '/templates.md', $markdown);

return $root;
}

/**
* The shapes of a deck drawn against a chrome file.
* The shapes of a deck drawn against a templates file.
*
* The chrome is written beside the deck and taken away again, whatever the deck says:
* a file left behind is a file the next test draws against.
* The templates file is written beside the deck and taken away again, whatever the deck
* says: a file left behind is a file the next test draws against.
*
* @return list<list<string>>
*/
public static function shapes(string $markdown, string $chrome): array
public static function shapes(string $markdown, string $templates): array
{
return Directory::during(
self::beside($chrome),
self::beside($templates),
static fn (string $root): array => Deck::shapes($markdown, $root),
);
}
Expand Down
Loading