diff --git a/CHANGELOG.md b/CHANGELOG.md index 070aba0..0aad37b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -142,9 +142,9 @@ All notable changes to this project are documented here. The format follows --- ``` - A slide's values are laid over the template's, and the template's over the theme's, and one - value laid over another leaves the rest alone: a slide that names one colour leaves the - other eleven as they were. + A slide's values are laid over the template's, the template's over the deck's and the deck's + over the theme's, and one value laid over another leaves the rest alone: a slide that names + one colour leaves the other eleven as they were. The four roles the theme has — the page, the ink, the subtle ink and the panel — sit on **four different slots**, so overriding a slot moves exactly one of them and `dark:` says @@ -175,6 +175,105 @@ All notable changes to this project are documented here. The format follows settings arrived, and a template defined twice is refused rather than left to win quietly. +- **A deck may name its own settings.** There was no layer for the deck: a deck's frontmatter + is its first slide's, and `theme-variables:` is read per slide, so a deck that named an + accent in its frontmatter painted the first slide in that accent and left every other slide + in the theme's own. + + A deck's frontmatter may now carry `deck-settings:`, and every slide of the deck is drawn + with it: + + ```markdown + --- + theme: corporate-dark + deck-settings: + background: "#101014" + theme-variables: + colors: + accent1: "#123456" + --- + ``` + + The ordinary keys mean the **slide's** own everywhere, so the deck's settings are named as + the deck's, the way a template's are named as the template's. The precedence is + **slide → template → deck → theme**: a slide's own settings are laid over the template's, + the template's over the deck's and the deck's over the theme's, and one value laid over + another leaves the rest alone. + + It belongs in slide 1's front matter, which is the deck's own, and it is refused on any + other slide — the way `theme:` is. + + `examples/markdown/20-deck-settings.md` is the deck that shows it: the deck's page and + ink on every slide of it, and the two slides that name a setting of their own — one that + wins over the deck's, and one that leaves the deck's other settings standing. + +### Changed + +- **A theme is one file.** A theme was a directory of up to five files: `theme.yml` for + the look, `layouts.yml` for the eight layout roles, `text-styles.yml` for the named + text styles, `styles.yml` for the Word half's style slots, and `template.pptx` for the + master. It is now `theme.yml` and the master, with the roles and the named styles as + two sections of the file: + + ```yaml + name: Acme + layouts: + title: Title Slide + content: Title and Content + textStyles: + brand: + color: accent1 + bold: true + ``` + + **What a theme that exists has to do.** Move the contents of `layouts.yml` into a + `layouts:` section of the `theme.yml` beside it, and the contents of `text-styles.yml` + into a `textStyles:` section of it, and delete both files. A `styles.yml` is the Word + half's file and this half does not read it, so it goes. + + The three files are **refused** when they are beside a theme, each with a message + saying what the reader has to do with the file: + + > The theme "acme" has a "layouts.yml" beside it. A theme is one file: move its content into the "layouts:" section of its "theme.yml", and delete the file. + + > The theme "acme" has a "text-styles.yml" beside it. A theme is one file: move its content into the "textStyles:" section of its "theme.yml", and delete the file. + + > The theme "acme" has a "styles.yml" beside it. That file is the Word half's, and this half does not read it: its slots name Word styles, which a deck of slides has no use for. Delete it, and the theme is read again. + + They are refused rather than ignored, because **a file that is quietly not read is a + theme that looks like the one its author wrote and is not**: the author renames a + layout in the file beside the theme, the deck is drawn with the old mapping, and + nothing in the output says so. + +- **The library ships the default layout mapping.** All five themes that ship with the + library carried a byte-identical `layouts.yml` — the same eight Office names — so for + a theme without a master it was a default written out five times. A theme with no + `layouts:` section is drawn with the library's own mapping now: + + | Role | Layout | + | --- | --- | + | `title` | Title Slide | + | `content` | Title and Content | + | `two-column` | Two Content | + | `section` | Section Header | + | `blank` | Blank | + | `image-text` | Picture Left | + | `image-title` | Picture with Caption | + | `image-slide` | Full Bleed Picture | + + A theme **with** a `layouts:` section has the whole mapping: a role the section does + not name is a role the theme does not map, and the deck that asks for one is told which + roles the theme does map. + + The five themes that ship with the library lost their `layouts.yml`, because it was the + library's own mapping written out. + +- **The Word half's style slots are gone from this half.** `Theme\StyleSlots`, + `Exception\UnknownStyleSlot` and `LoadedTheme::styles()` existed for a `styles.yml` + this half loaded and never used: the slots name Word styles, and a deck of slides has + no use for them. A theme that carried one looked like a theme with Word styles in it + and was not one. + ### Fixed - **The anchor of a template's placeholder is read and written.** The renderer read a diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index a31ff1c..9111aa5 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -66,12 +66,12 @@ renders of one deck differ; the parts are what a test reads. | The theme's twelve colours become the colour scheme | `ppt/theme/theme1.xml` | | A dark theme swaps the colour map, and its shapes follow it | `ppt/slideMasters/slideMaster1.xml`, `ppt/slides/slideN.xml` | | The theme's `heading`, `body` and `mono` reach the runs that use them | `` | -| `styles.yml` reaches no shape, because a `.pptx` has no use for a `.docx` style id | — | +| A `styles.yml` beside a theme is refused, because a `.pptx` has no use for a `.docx` style id | — | -The last row is the only one asserted by what is *absent*. `styles.yml` is not read, and -a slot that does not exist still fails when the theme is loaded, so a typo in one is never -rendered as silence — which is a test, but a test of the theme loader rather than of a -rendered file. +The last row is the only one asserted by what is *absent*. A `styles.yml` beside a theme is +refused when the theme is loaded, so a theme that carries one is never read as though it had +said nothing — which is a test, but a test of the theme loader rather than of a rendered +file. Reading has the opposite problem, and it is where the fixtures earn their place. Everything above is checked against files this library wrote, which agree with the reader about every diff --git a/README.md b/README.md index 6e3cce0..43ef442 100644 --- a/README.md +++ b/README.md @@ -604,15 +604,18 @@ drawn in the theme's `hlink`, and a link written in a text style is drawn in the colour instead: the style is the more particular of the two statements. It keeps its underline either way, so it still reads as a link. -The named styles come from the theme's `text-styles.yml`, which is optional: +The named styles come from the theme's own file, under a `textStyles:` section, which is +optional: ```yaml -# themes/resilience-bakery/text-styles.yml -brand: - color: accent1 - bold: true -muted: - color: lt2 +# themes/resilience-bakery/theme.yml +name: Resilience Bakery +textStyles: + brand: + color: accent1 + bold: true + muted: + color: lt2 ``` **A style's name is a word, and a word does not care about case.** A theme that spells a @@ -621,8 +624,8 @@ package folds the names of the directives themselves. The refusal for a name the not have spells the styles it does have the way the theme wrote them, because that is the spelling the author has to change. -Ten mistakes in a `text-styles.yml` are refused when the theme is read rather than -reaching the slide: +Ten mistakes in a theme's `textStyles:` section are refused when the theme is read rather +than reaching the slide: | Refused | Why | | --- | --- | @@ -637,8 +640,8 @@ reaching the slide: | a font that is not a name | a font is a family name | | a flag that is not `true` or `false` | `yes` is a YAML truthy string rather than the flag | -Every one of them names what would have worked instead, so a mistake in a -`text-styles.yml` is never rendered as silence. +Every one of them names what would have worked instead, so a mistake in a theme's +`textStyles:` section is never rendered as silence. A name the theme does not have is refused when the deck is read, and the message names the styles the theme does have: @@ -659,13 +662,13 @@ try { ``` ```text -Slide 1 has the text style ":brand", which is not a style this theme has. The theme has no text styles; a theme names them in its "text-styles.yml". +Slide 1 has the text style ":brand", which is not a style this theme has. The theme has no text styles; a theme names them in its "textStyles:" section. ``` **The label is plain text.** The label of a directive is a string rather than Markdown, so `:brand[**Bakery**]` would be drawn as `**Bakery**` — a deck that renders and shows something the author did not write. It is refused instead, and the message says the two -ways out: give the style the weight — in the theme's own `text-styles.yml` for a named +ways out: give the style the weight — in the theme's own `textStyles:` section for a named style, as an attribute for the raw form — or write the emphasis in the paragraph around it. A bare `*` or `_` is a character and not an intent, so `2 * 3` and `snake_case` are drawn as they are. So is a construct CommonMark does not call emphasis: `__ Bakery__` and @@ -913,7 +916,7 @@ shows a deck's titles and still shows no bullets. ### Templates -A theme may ship a `template.pptx` beside its `layouts.yml`, and a deck written against it is +A theme may ship a `template.pptx` beside its `theme.yml`, and a deck written against it is laid out in *that template's* geometry rather than in this library's. The template is read for the placeholder boxes its own layouts carry, and both the slides and the layout parts this renderer writes are placed at them: @@ -921,7 +924,7 @@ renderer writes are placed at them: ```php use MarkdownPresentation\Render\TemplateGeometry; -// The one theme in this repository that ships a template; see its layouts.yml. +// The one theme in this repository that ships a template; see its theme.yml. $boxes = (new TemplateGeometry((string) getenv('MARKDOWN_PRESENTATION_ROOT') . '/tests/fixtures/themes/templated/template.pptx'))->boxes(); printf( @@ -949,8 +952,9 @@ Three rules decide what a template is allowed to change: - **A template fills in the roles it covers and says nothing about the rest.** A layout it does not have, and a layout it has with no placeholders in it — Office's own *Blank* — leave - that role where `SlideGeometry` puts it. This is the same rule `layouts.yml` follows, where a - theme mapping some of the roles is a theme that works. + that role where `SlideGeometry` puts it. A theme's `layouts:` section is the other rule + entirely: it is the whole mapping, so a role the section does not name is a role the theme + does not map. - **A template places; it does not typeset.** Sizes and alignments stay with `SlideGeometry`, because a template states them in a *master*'s `p:txStyles` — a whole typographic system, not a layout — and adopting one would resize the type of every deck that shipped a template. @@ -970,7 +974,7 @@ part really holds rather than what the archive says it is. #### Using your own deck as the template Any deck will do — it does not have to be a `.potx` or come from PowerPoint's gallery. Copy it -into the theme directory as `template.pptx`, next to the `layouts.yml` that names which of its +into the theme directory as `template.pptx`, next to the `theme.yml` that names which of its layouts each role gets. The deck this library was tested against is carried in the repository, authored and saved by PowerPoint itself, so this is a real file rather than a description of one: @@ -1011,18 +1015,19 @@ The number of placeholders is also the number of columns a role has, whatever th called: map `content` onto *Two Content* and a `::column` on a content slide splits it, because that is how many boxes the layout has. -So the theme directory is the template plus the two files that name it: +So the theme directory is the template plus the one file that names it: ``` themes/harbour/ -├── theme.yml name: Harbour -├── layouts.yml which of your deck's layouts each role gets +├── theme.yml name: Harbour, and which of your deck's layouts each role gets └── template.pptx your deck, copied in ``` ```yaml -# The layout names are your deck's, verbatim — check them in PowerPoint's slide master view. -# A role left out keeps this library's own geometry rather than failing. +# The `layouts:` section of the theme's own file. The layout names are your deck's, +# verbatim — check them in PowerPoint's slide master view. A role the section does not +# name is a role the theme does not map, and a deck that asks for one is told so; a +# layout your template does not have leaves the role where this library puts it. layouts: title: Title Slide content: Title and Content @@ -1595,6 +1600,10 @@ background: accent2 The second slide draws the template and paints its own page over the template's. +The deck's own settings are named as the deck's, under `deck-settings:`, and every slide of +the deck is drawn with them — see [A slide's background, and its own +values](#a-slides-background-and-its-own-values). + A slide may name several templates, and the chrome of each of them is drawn on it: ```markdown @@ -1605,7 +1614,7 @@ template: [brand, page-number] ``` `layout:` and `template:` are independent. `layout:` chooses the geometry — the role the -theme's `layouts.yml` maps onto a box on the page — and `template:` adds furniture on top of +theme's `layouts:` section maps onto a box on the page — and `template:` adds furniture on top of it. `layout: blank` with `template: brand` is therefore a slide with no furniture of its own and the wordmark and the rule drawn where the template puts them. @@ -2097,15 +2106,16 @@ slides. The colour map the master writes says which slot each of `bg1`, `tx1`, ` independently of them — but it is the theme that decides, not the map: a shape's colour is resolved here and written out as hex, and the map is never consulted for it again. -`styles.yml` is **not** read. Its slots are the Word half's vocabulary and the shipped themes -write `.docx` style ids, which a `.pptx` has no use for; mapping them onto shapes would be -inventing a vocabulary nobody wrote down. A slot that does not exist still fails when the -theme is loaded, so a typo in a `styles.yml` is never rendered as silence. +A `styles.yml` beside a theme is **refused**. Its slots are the Word half's vocabulary and +the shipped themes wrote `.docx` style ids, which a `.pptx` has no use for; mapping them onto +shapes would be inventing a vocabulary nobody wrote down. It is refused rather than ignored, +because a file that is quietly not read is a theme that looks like the one its author wrote +and is not — see [The files a theme used to be made of](#the-files-a-theme-used-to-be-made-of). -`text-styles.yml` **is** read, and it is the one file of a theme that says something about -the words inside a box rather than about the box — see [Inline styles](#inline-styles). A -style that sets an attribute nobody reads still fails when the theme is loaded, so a typo in -a `text-styles.yml` is never rendered as silence either. +A theme's `textStyles:` section **is** read, and it is the one part of a theme that says +something about the words inside a box rather than about the box — see +[Inline styles](#inline-styles). A style that sets an attribute nobody reads still fails when +the theme is loaded, so a typo in it is never rendered as silence either. ### Frontmatter @@ -2127,7 +2137,7 @@ try { ``` ```text -The frontmatter of slide 1 names "transition", which is not a directive. The directives are: title, name, level, layout, theme, author, description, template, templates-file, template-settings, background, background-gradient, background-angle, background-radial, theme-variables. +The frontmatter of slide 1 names "transition", which is not a directive. The directives are: title, name, level, layout, theme, author, description, template, templates-file, template-settings, deck-settings, background, background-gradient, background-angle, background-radial, theme-variables. ``` Slidev accepts dozens of directives this library does not read, so a deck written for it will @@ -2138,7 +2148,8 @@ looking for what is missing. `theme`, `author` and `description` describe the deck rather than a slide, so they belong in slide 1's front matter. On any other slide they are a failure that says so, because two slides that both name a theme is a deck that renders one of them and says nothing about the -other. +other. `deck-settings:` is the deck's in the same way, and it belongs in slide 1's front +matter for the same reason. Every slide is checked before anything is built, so a deck whose fourth slide names a directive nobody reads fails before it has written a byte rather than leaving a half-finished @@ -2176,6 +2187,7 @@ theme-variables: | `background-angle` | the angle in degrees | | `background-radial` | the background runs from the middle outwards | | `template-settings` | the settings of the **template** a definition names, under the same keys | +| `deck-settings` | the settings of the **deck**, under the same keys, in slide 1's front matter | The background of a slide is the slide's own: the master keeps the theme's page colour for the slides that name no background. A background is one colour or one gradient, and the two @@ -2184,14 +2196,38 @@ together are refused. A background of a colour has neither an angle nor a radial `theme-variables:` is a **`theme.yml`**: the same keys, the same names, the same spelling, read by the reader that reads the theme's own file — `dark:`, `colors:`, `fonts:` and -`style:`. A slide's values are laid over the template's, and the template's over the -theme's, and one value laid over another leaves the rest alone: a slide that names one -colour leaves the other eleven as they were. +`style:`. A slide's values are laid over the template's, the template's over the deck's and +the deck's over the theme's, and one value laid over another leaves the rest alone: a slide +that names one colour leaves the other eleven as they were. `template-settings:` holds the same keys, for the **template** rather than the slide: a definition carries them, and every slide that draws that template gets them. See [Slide templates](#slide-templates). +`deck-settings:` holds the same keys again, for the **deck** rather than the slide. It is +written in slide 1's front matter — which is the deck's own — and every slide of the deck is +drawn with it: + +```markdown +--- +theme: corporate-dark +deck-settings: + background: "#101014" + theme-variables: + colors: + accent1: "#123456" +--- +``` + +The ordinary keys mean the **slide's** own everywhere, which is what the rule wants: a key +that holds somebody else's settings says whose. So the precedence is **slide → template → +deck → theme** — a slide's own settings are laid over the template's, the template's over +the deck's, and the deck's over the theme's. A slide that names a background of its own is +painted on it, and a slide that names a value of its own is drawn in it. + +`deck-settings:` on any other slide is a failure that says so, like `theme:`: it is the +deck's, and the deck's frontmatter is the first slide's. + The four roles the theme has — the page, the ink, the subtle ink and the panel — sit on **four different slots**, so overriding a slot moves exactly one of them, and `dark:` says which way round they go. There is no `ink:` and no `panel:` to add: the theme's own model @@ -2407,15 +2443,41 @@ instead of the directory holding it. Nothing is compiled and nothing is a PHP cl ``` themes/corporate-dark/ -├── theme.yml required colours, fonts, type scale, metadata -├── styles.yml optional Word style-slot overrides -├── layouts.yml optional semantic role → template layout name -├── text-styles.yml optional named text styles: the words inside a box +├── theme.yml required the look, the layout roles, the named text styles ├── template.pptx optional PowerPoint template: where the layouts put their boxes ├── README.md optional attribution └── LICENSE optional ``` +The theme's own file carries two sections beside its values, and both are optional: + +| Section | What it holds | +| --- | --- | +| `layouts:` | which layout of the theme's master each of the eight roles gets | +| `textStyles:` | the named text styles: the words inside a box | + +A theme with no `layouts:` section is drawn with the library's own mapping — the eight +Office names that every theme shipping with this library carried in a file of its own: + +| Role | Layout | +| --- | --- | +| `title` | Title Slide | +| `content` | Title and Content | +| `two-column` | Two Content | +| `section` | Section Header | +| `blank` | Blank | +| `image-text` | Picture Left | +| `image-title` | Picture with Caption | +| `image-slide` | Full Bleed Picture | + +A theme **with** a `layouts:` section has the whole mapping: a role the section does not +name is a role the theme does not map, and a deck that asks for one is told which roles the +theme does map. + +A theme holds the values a deck is drawn with, and a deck's own settings are laid over +them: a slide's own values, the values of the template it draws, and the deck's — in that +order. See [A slide's background, and its own values](#a-slides-background-and-its-own-values). + The tools that come with the library are in `tools/`: | Tool | What it is | @@ -2468,13 +2530,7 @@ style: leading: 1.32 heading-weight: bold heading-ink: accent -``` - -**One of them brings the named styles.** `corporate-dark` carries a `text-styles.yml` with a -`brand` and a `muted`, so a deck can write `:brand[Bakery]` against a theme that ships with -the library rather than against one of its own: -```yaml path=themes/corporate-dark/text-styles.yml # Named text styles: the words inside a box, written in a deck as `:brand[Bakery]`. # The properties are the same eight the inline style attributes have, and a size is in # points as it is everywhere else. @@ -2482,14 +2538,19 @@ the library rather than against one of its own: # The brand is the theme's own accent, which is what the headings are painted in, and the # muted style is the quiet ink a caption is written in — a step down from the body, which # is what a caption is on a slide rather than in a document. -brand: - color: accent1 - bold: true -muted: - color: lt2 - size: 14 +textStyles: + brand: + color: accent1 + bold: true + muted: + color: lt2 + size: 14 ``` +**One of them brings the named styles.** `corporate-dark` carries a `textStyles:` section +with a `brand` and a `muted`, so a deck can write `:brand[Bakery]` against a theme that +ships with the library rather than against one of its own. + The colours are DrawingML's twelve. The longer spellings an earlier draft of the concept used — `dark1`, `light1`, `dark2`, `light2`, `hyperlink`, `followedHyperlink` — are accepted on input and normalised to DrawingML's own names, @@ -2649,10 +2710,10 @@ Minimal /themes/minimal ``` -Only a `theme.yml` is a manifest, so a `styles.yml` named as the theme is one of a theme's -own files rather than the theme itself. The name the deck wrote is what decides that, not -the name the file carries once it has been resolved — so a `theme.yml` that is a link to a -file of another name is still the manifest, and the roots below still hold the file it +Only a `theme.yml` is a manifest, so a file of another name named as the theme is a file +beside a theme rather than the theme itself. The name the deck wrote is what decides that, +not the name the file carries once it has been resolved — so a `theme.yml` that is a link to +a file of another name is still the manifest, and the roots below still hold the file it reaches. **A theme path has to land inside the deck's own directory, the working directory, the @@ -2670,10 +2731,10 @@ The theme "../secrets" is at "/srv/decks/../secrets" rather than one this render **The files inside a theme are held to the same roots.** A directory that is inside them may hold a `theme.yml` that is a link out of them, and the file the link reaches is read -as readily as one beside it — the `theme.yml`, the `styles.yml`, the `layouts.yml` and the -`template.pptx` are each resolved and held before they are used, and the refusal names the -file it found and the roots it may read. A link that resolves *inside* the roots is a file -like any other, so a theme laid out with links still reads. +as readily as one beside it — the `theme.yml` and the `template.pptx` are each resolved and +held before they are used, and the refusal names the file it found and the roots it may +read. A link that resolves *inside* the roots is a file like any other, so a theme laid out +with links still reads. A shared library of themes beside the project is a real case and is reachable, as a constructor argument — `new ThemeResolver($root, roots: ['/srv/themes'])` — because that is @@ -2799,54 +2860,48 @@ size, it follows a theme's type scale rather than standing still while the type and a heading's air above it follows whatever that theme's `headings` scale says. The two `11-type-scale` decks exist to be looked at side by side for exactly that reason. -### Style slots +### The files a theme used to be made of -`styles.yml` overrides Word style slots. A slot that does not exist is a typo, and a -typo here would otherwise be ignored at render time and produce a document with none -of the styling the theme asked for: +A theme was a directory of up to five files, and three of them have become sections of the +one file that is left. They are **refused** when they are beside a theme, each with a message +saying what the reader has to do with the file: ```php -use MarkdownPresentation\Exception\UnknownStyleSlot; +use MarkdownPresentation\Exception\RetiredThemeFile; use MarkdownPresentation\Files\DiskFinder; use MarkdownPresentation\Theme\ThemeLoader; $root = (string) getenv('MARKDOWN_PRESENTATION_ROOT'); +$finder = new DiskFinder(theme: [$root . '/tests/fixtures/themes']); -try { - (new ThemeLoader())->load( - 'broken', - 'broken', - new DiskFinder(theme: [$root . '/tests/fixtures/themes']), - ); -} catch (UnknownStyleSlot $failure) { - echo $failure->getMessage(), "\n"; +foreach (['with-layouts', 'with-text-styles', 'with-styles'] as $theme) { + try { + (new ThemeLoader())->load($theme, $theme, $finder); + } catch (RetiredThemeFile $failure) { + echo $failure->getMessage(), "\n\n"; + } } ``` ```text -In "/tests/fixtures/themes/broken/styles.yml": "blockquote" is not a style slot. The slots are: heading.1, heading.2, heading.3, heading.4, heading.5, heading.6, paragraph, blockQuote, codeBlock, thematicBreak, htmlFallback, listParagraph, codeFont, linkFont, bulletList, orderedList, table, tableHeaderRow, tableCell. -``` +The theme "with-layouts" has a "layouts.yml" beside it. A theme is one file: move its content into the "layouts:" section of its "theme.yml", and delete the file. -A value is either a styleId from a `.docx` template — `Heading1`, not `Heading 1` — -or an inline style array: +The theme "with-text-styles" has a "text-styles.yml" beside it. A theme is one file: move its content into the "textStyles:" section of its "theme.yml", and delete the file. -```yaml path=themes/corporate-dark/styles.yml -# Word style slots, by the names in a .docx template's styles. A value is either a -# styleId — "Heading1", not "Heading 1" — or an inline style array. -heading.1: Heading1 -heading.2: Heading2 -paragraph: BodyText -blockQuote: PullQuote -codeFont: - name: JetBrains Mono - size: 9 -linkFont: - color: 89B4FA - underline: single +The theme "with-styles" has a "styles.yml" beside it. That file is the Word half's, and this half does not read it: its slots name Word styles, which a deck of slides has no use for. Delete it, and the theme is read again. ``` -References to theme tokens — `{accent1}`, `{fonts.mono}` — are **not** resolved yet, -so a `styles.yml` written with them carries the braces through untouched. +**A file that is quietly not read is a theme that looks like the one its author wrote and +is not.** The author renames a layout in the file beside the theme, the deck is drawn with +the old mapping, and nothing in the output says so — which is why the files are refused +rather than ignored. + +The third of them is the Word half's, and this half loaded it for years without ever using +it. Its slots name Word styles, and a deck of slides has no use for them. **The halves part +at the look**: this half's is `dark:`, `colors:`, `fonts:`, `style:` and `layouts:`, the +Word half's is `styles:`, and a file carrying the other half's look is refused here. So +`styles.yml`, which holds the look in the Word half's vocabulary, is a file this half does +not read. ### Where a deck's files come from diff --git a/examples/README.md b/examples/README.md index 48e94ec..b430692 100644 --- a/examples/README.md +++ b/examples/README.md @@ -36,6 +36,7 @@ quietly. The profile and the scratch script go to the temporary directory, so | `18-bleeding-shapes.md` | `18-bleeding-shapes.pptx` | Shapes that run off the edge of the slide: a circle cut off by the right edge, a panel running under the foot of the page, and the refusal that names `bleed=true` as the way out. The Word half has the same rule for a text box that hangs off the edge of the page | | `17-corporate-template.md` | `17-corporate-template.pptx` | A whole corporate template: a theme of the company's own, a brand mark in two colours — one for a light page and one for a dark one — and the furniture of a deck written once and named by every slide that wants it. Eight slides of the kinds a company deck is made of: a cover, an agenda, a headline, two columns with a chart, a quote, a table, a divider and a closing. The company is invented | | `19-gradient-background.md` | `19-gradient-background.pptx` | A gradient on a shape — two stops, three stops with the middle one at half, a radial one, and an angle of 0° — a background painted with a colour, with a gradient and with a radial gradient, a slide that names the theme's values for itself, and a template that carries settings of its own | +| `20-deck-settings.md` | `20-deck-settings.pptx` | The settings of the deck: a page and an ink every slide of the deck is drawn with, and the two slides that name a setting of their own — one that wins over the deck's, and one that leaves the deck's other settings standing | ## The deck that is not anybody's business @@ -196,3 +197,7 @@ A few of these are here because the render is the only honest evidence: move and the page around them is what the pair is for. - **`09`.** The title is `Ops **runbook**: what *changed*` and is drawn with the emphasis, once, and is not repeated in the body. +- **`20`, the third and fourth slides.** The third names a background of its own and is + painted on it, and the fourth names an ink of its own and is written in it — and is + still painted on the deck's page, because one value laid over another leaves the rest + alone. diff --git a/examples/markdown/04-frontmatter.md b/examples/markdown/04-frontmatter.md index a80ed3a..708d36b 100644 --- a/examples/markdown/04-frontmatter.md +++ b/examples/markdown/04-frontmatter.md @@ -8,10 +8,11 @@ templates-file: ./templates/templates.md # Every frontmatter key -Fifteen keys: `title`, `name`, `level`, `layout`, `theme`, `author`, `description`, -`template`, `templates-file`, `template-settings`, `background`, `background-gradient`, -`background-angle`, `background-radial` and `theme-variables`. A block naming a sixteenth is -a failure that names these fifteen, and this slide carries the first four. +Sixteen keys: `title`, `name`, `level`, `layout`, `theme`, `author`, `description`, +`template`, `templates-file`, `template-settings`, `deck-settings`, `background`, +`background-gradient`, `background-angle`, `background-radial` and `theme-variables`. A block +naming a seventeenth is a failure that names these sixteen, and this slide carries the first +four. --- name: A title that is not a heading diff --git a/examples/markdown/15-inline-styles.md b/examples/markdown/15-inline-styles.md index 625befd..cd18bdc 100644 --- a/examples/markdown/15-inline-styles.md +++ b/examples/markdown/15-inline-styles.md @@ -101,7 +101,7 @@ A style's text is plain text, so `:brand[**Barge**]` is refused. It is not drawn as the asterisks the author wrote: ```text -Slide 5 writes the text style ":brand" around "**Barge**", which is Markdown. A style's text is plain text: give the style the weight in the theme's "text-styles.yml" ("brand: { bold: true }") or write the emphasis in the paragraph around it. +Slide 5 writes the text style ":brand" around "**Barge**", which is Markdown. A style's text is plain text: give the style the weight in the theme's "textStyles:" section ("brand: { bold: true }") or write the emphasis in the paragraph around it. ``` --- diff --git a/examples/markdown/20-deck-settings.md b/examples/markdown/20-deck-settings.md new file mode 100644 index 0000000..4ad6223 --- /dev/null +++ b/examples/markdown/20-deck-settings.md @@ -0,0 +1,55 @@ +--- +title: The deck's own settings +description: The settings of the deck, on every slide of it, and the slides that name one of their own. +theme: default +layout: blank +deck-settings: + background: "#F4F1E9" + theme-variables: + colors: + dk1: "#3A2E22" +--- + +:::content{left=8% top=26% width=84% height=22% font-size=22 align=center vertical-align=middle} +Every slide of this deck is drawn with the deck's own settings. +::: + +:::content{left=8% top=52% width=84% height=26% font-size=14 align=center vertical-align=middle} +`deck-settings:` is written in the front matter above — which is slide 1's, and so the deck's own — and it holds the same keys a slide's own settings are written in. The page behind this slide and the ink it is written in are the deck's. +--- +layout: blank +title: And so is every other slide +--- + +:::content{left=8% top=26% width=84% height=22% font-size=22 align=center vertical-align=middle} +This slide names nothing at all. +::: + +:::content{left=8% top=52% width=84% height=26% font-size=14 align=center vertical-align=middle} +It is drawn with the deck's page and the deck's ink, because the deck's settings are the ones every slide of the deck starts from. +--- +layout: blank +background: "#CFE0F0" +title: And a slide's own wins +--- + +:::content{left=8% top=26% width=84% height=22% font-size=22 align=center vertical-align=middle} +This slide names a background of its own. +::: + +:::content{left=8% top=52% width=84% height=26% font-size=14 align=center vertical-align=middle} +It is painted on it, and not on the deck's. The precedence is slide → template → deck → theme: a slide's own settings are laid over the template's, the template's over the deck's, and the deck's over the theme's. +--- +layout: blank +theme-variables: + colors: + dk1: "#1E3A5F" +title: One value over another leaves the rest alone +--- + +:::content{left=8% top=26% width=84% height=22% font-size=22 align=center vertical-align=middle} +This slide names an ink of its own, and no background. +::: + +:::content{left=8% top=52% width=84% height=26% font-size=14 align=center vertical-align=middle} +So it is painted on the deck's page and written in its own ink: the deck's background is still the one behind it. diff --git a/examples/markdown/corporate/README.md b/examples/markdown/corporate/README.md index c41e0b4..aa6cc98 100644 --- a/examples/markdown/corporate/README.md +++ b/examples/markdown/corporate/README.md @@ -9,9 +9,7 @@ decks have, and every part of it is a file you edit. | | | | --- | --- | -| `theme.yml` | the design — the twelve colour slots, the faces, the type scale and the rhythm | -| `layouts.yml` | which layout each of the eight roles gets | -| `text-styles.yml` | the named text styles a deck writes words in | +| `theme.yml` | the design — the twelve colour slots, the faces, the type scale, the rhythm, the named text styles a deck writes words in, and the layout each role gets | | `templates.md` | the furniture of a deck: the wordmark, the rule, the footer | | `logo.png`, `logo-light.png` | the mark, for a light page and for a dark one | | `make-logo.php` | draws the two marks from the theme's colours | @@ -20,7 +18,7 @@ The deck that uses all of it is `../17-corporate-template.md`. ## Changing it to your company -Three things, and each is one file. +Four things, and each of them is a file or a section of one. **The name.** `templates.md` holds the wordmark, and the name is in it twice — once in the light template and once in the dark one. The dark one is the same named style with the @@ -30,13 +28,24 @@ colour laid over it: :wordmark[Halden Instruments]{color=lt1} ``` -So the name is two edits, and the style behind it is one: `text-styles.yml`. +So the name is two edits, and the style behind it is one: the `textStyles:` section of +`theme.yml`. **The mark.** Drop your own `logo.png` and `logo-light.png` in beside the theme — same names, same 512 × 512 — and nothing else changes. To draw the mark that is here instead, `php make-logo.php` reads the theme's colours and writes both files, so the logo and the theme cannot drift apart. +**The layouts.** `theme.yml` carries a `layouts:` section, and a section is the **whole** +mapping: a role it does not name is a role the theme does not map, and a deck that asks for +one is told which roles the theme does map. This one names every role, in Office's own +names. + +Until a `template.pptx` is dropped in beside the theme the names are labels — the boxes +behind them are the ones the theme computes from its own margins and type scale. That file +is what makes them real: a template's own layout part carries the name the section gives +it, and the theme that carries the template is drawn in the template's geometry. + **The colours.** `theme.yml`, and nothing else. The names are the format's: `lt1` is the page, `dk1` the ink, `lt2` the quiet ink a caption is written in, `dk2` the panel a dark slide is painted with, and `accent1` to `accent6` are yours. `accent1` is the primary — the diff --git a/examples/markdown/corporate/layouts.yml b/examples/markdown/corporate/layouts.yml deleted file mode 100644 index e9d99b1..0000000 --- a/examples/markdown/corporate/layouts.yml +++ /dev/null @@ -1,15 +0,0 @@ -# Which layout each of the eight roles gets. -# -# A theme that ships no `template.pptx` has no layouts of its own, so these names -# are labels: the boxes behind them are the ones the theme computes from its own -# margins and type scale. A company that has a PowerPoint template of its own -# drops the file in beside this one and the names become real. -layouts: - title: Title Slide - content: Title and Content - two-column: Two Content - section: Section Header - blank: Blank - image-text: Picture Left - image-title: Picture with Caption - image-slide: Full Bleed Picture diff --git a/examples/markdown/corporate/text-styles.yml b/examples/markdown/corporate/text-styles.yml deleted file mode 100644 index b002629..0000000 --- a/examples/markdown/corporate/text-styles.yml +++ /dev/null @@ -1,21 +0,0 @@ -# The named text styles: the words inside a box, written in a deck as `:brand[...]`. -# -# The properties are the same eight the inline style attributes have, and a size is -# in points as it is everywhere else. -# -# These are the four a corporate deck uses most. The wordmark is the company's own -# name, the brand is the primary colour, the eyebrow is the small line above a -# title, and the muted style is what a caption is written in. -wordmark: - color: dk1 - bold: true -brand: - color: accent1 - bold: true -eyebrow: - color: accent1 - bold: true - size: 11 -muted: - color: lt2 - size: 12 diff --git a/examples/markdown/corporate/theme.yml b/examples/markdown/corporate/theme.yml index 7ad4779..b067d06 100644 --- a/examples/markdown/corporate/theme.yml +++ b/examples/markdown/corporate/theme.yml @@ -40,3 +40,45 @@ style: leading: 1.4 heading-weight: bold heading-ink: ink + +# The layout name of each role. +# +# A `layouts:` section is the whole mapping: a role it does not name is a role the theme +# does not map, and a deck that asks for one is told which roles the theme does map. This +# one names every role. +# +# The names are Office's own, and they are the names a `template.pptx` dropped in beside +# this file would carry. Until that file is there the names are labels: the boxes behind +# them are the ones this theme computes from its own margins and type scale. +layouts: + title: Title Slide + content: Title and Content + two-column: Two Content + section: Section Header + blank: Blank + image-text: Picture Left + image-title: Picture with Caption + image-slide: Full Bleed Picture + +# The named text styles: the words inside a box, written in a deck as `:brand[...]`. +# +# The properties are the same eight the inline style attributes have, and a size is +# in points as it is everywhere else. +# +# These are the four a corporate deck uses most. The wordmark is the company's own +# name, the brand is the primary colour, the eyebrow is the small line above a +# title, and the muted style is what a caption is written in. +textStyles: + wordmark: + color: dk1 + bold: true + brand: + color: accent1 + bold: true + eyebrow: + color: accent1 + bold: true + size: 11 + muted: + color: lt2 + size: 12 diff --git a/src/Document/Settings.php b/src/Document/Settings.php index cb151b5..58264e1 100644 --- a/src/Document/Settings.php +++ b/src/Document/Settings.php @@ -14,7 +14,8 @@ * @phpstan-type Shape array{background?: array, variables?: array} * * A template definition holds them too, and the two are read the same way, because a - * template's settings are the settings of the slides that draw it. + * template's settings are the settings of the slides that draw it. The deck holds them as + * well, and every slide of the deck is drawn with them. * * The settings are carried as they were written and read where they are drawn, because a * colour is resolved against the theme the slide is drawn in, and a background of one theme @@ -115,17 +116,62 @@ public static function readTemplate(mixed $written): array ); } - foreach (array_keys($written) as $key) { - if (!in_array((string) $key, self::KEYS, true)) { - throw MalformedFrontmatter::unknownSetting( - 'template-settings', - (string) $key, - self::KEYS, - ); + return self::readNamed(null, 'template-settings', $written); + } + + /** + * The settings the deck carries, as its frontmatter named them. + * + * The deck's settings are the deck's, and they are named as the deck's: + * `deck-settings:` holds the same keys a slide's own settings are written in, so that + * the ordinary keys mean the slide's own everywhere. Every slide of the deck is drawn + * with them, and a slide's own settings are laid over them. + * + * @return Shape + * + * @throws MalformedFrontmatter + */ + public static function readDeck(int $slide, mixed $written): array + { + // A list is not a mapping of settings, and an empty one is a key that is there with + // nothing under it: both are mistakes rather than settings. + if (!is_array($written) || $written === [] || array_is_list($written)) { + throw MalformedFrontmatter::wrongType( + $slide, + 'deck-settings', + 'a mapping of the settings the deck carries', + ); + } + + return self::readNamed($slide, 'deck-settings', $written); + } + + /** + * The settings a block of somebody else's names, under the names they are known by. + * + * A name that is not one of the settings is refused rather than left out, so that a + * typo in a deck's or a template's settings is a failure rather than a setting that + * does nothing. + * + * @param array $written + * + * @return Shape + * + * @throws MalformedFrontmatter + */ + private static function readNamed(?int $slide, string $where, array $written): array + { + $settings = []; + + foreach ($written as $key => $value) { + if (!is_string($key) || !in_array($key, self::KEYS, true)) { + throw MalformedFrontmatter::unknownSetting($slide, $where, (string) $key, self::KEYS); } + + $settings[$key] = $value; } - return self::read($written, null); + return self::read($settings, $slide); } /** diff --git a/src/Exception/MalformedFrontmatter.php b/src/Exception/MalformedFrontmatter.php index 36826f2..a176dd5 100644 --- a/src/Exception/MalformedFrontmatter.php +++ b/src/Exception/MalformedFrontmatter.php @@ -71,17 +71,29 @@ public static function duplicateTemplate(string $name): self } /** - * A setting of a template that is not one. + * A setting that is not one. * - * The settings of a template are the definition's, and a definition is not a slide of - * the deck and has no number. + * The slide number is null where the settings are a template definition's: a + * definition is not a slide of the deck and has no number, and naming one would name a + * slide that has nothing to do with it. The deck's settings are the first slide's, and + * that slide has a number. * * @param list $known */ - public static function unknownSetting(string $where, string $key, array $known): self + public static function unknownSetting(?int $slide, string $where, string $key, array $known): self { + if ($slide === null) { + return new self(sprintf( + 'The "%s" of a template definition names "%s", which is not a setting. The settings are: %s.', + $where, + $key, + implode(', ', $known), + )); + } + return new self(sprintf( - 'The "%s" of a template definition names "%s", which is not a setting. The settings are: %s.', + 'The frontmatter of slide %d has a "%s" that names "%s", which is not a setting. The settings are: %s.', + $slide, $where, $key, implode(', ', $known), diff --git a/src/Exception/RetiredThemeFile.php b/src/Exception/RetiredThemeFile.php new file mode 100644 index 0000000..e0fe8b2 --- /dev/null +++ b/src/Exception/RetiredThemeFile.php @@ -0,0 +1,54 @@ + $roles */ @@ -54,7 +54,7 @@ public static function notMapped(string $role, string $theme, array $mapped): se 'The theme "%s" maps no "%s" layout. It maps: %s.', $theme, $role, - $mapped === [] ? '(none — the theme has no layouts.yml)' : implode(', ', $mapped), + $mapped === [] ? '(none — its "layouts" section maps no role)' : implode(', ', $mapped), )); } @@ -63,19 +63,6 @@ public static function notALayoutName(string $file, string $role): self return new self(sprintf('In "%s": the "%s" role is not a layout name.', $file, $role)); } - /** - * @param list $valid - */ - public static function unknownKey(string $file, string $key, array $valid): self - { - return new self(sprintf( - 'In "%s": "%s" is not a key of a layouts file. Valid keys: %s.', - $file, - $key, - implode(', ', $valid), - )); - } - public static function notTheMappings(string $file): self { return new self(sprintf('In "%s": "layouts" is not a mapping of roles to layout names.', $file)); diff --git a/src/Exception/UnknownStyleSlot.php b/src/Exception/UnknownStyleSlot.php deleted file mode 100644 index 0674a67..0000000 --- a/src/Exception/UnknownStyleSlot.php +++ /dev/null @@ -1,29 +0,0 @@ - $slots - */ - public static function named(string $file, string $slot, array $slots): self - { - return new self(sprintf( - 'In "%s": "%s" is not a style slot. The slots are: %s.', - $file, - $slot, - implode(', ', $slots), - )); - } -} diff --git a/src/Exception/UnknownTextStyle.php b/src/Exception/UnknownTextStyle.php index 3f46f9e..b707f06 100644 --- a/src/Exception/UnknownTextStyle.php +++ b/src/Exception/UnknownTextStyle.php @@ -26,7 +26,7 @@ public static function named(int $slide, string $name, array $styles): self $slide, $name, $styles === [] - ? 'The theme has no text styles; a theme names them in its "text-styles.yml".' + ? 'The theme has no text styles; a theme names them in its "textStyles:" section.' : sprintf('The styles are: %s.', implode(', ', $styles)), )); } diff --git a/src/Render/CommonMark/StyleReader.php b/src/Render/CommonMark/StyleReader.php index aa260fa..68c12af 100644 --- a/src/Render/CommonMark/StyleReader.php +++ b/src/Render/CommonMark/StyleReader.php @@ -205,16 +205,16 @@ private function label(DirectiveInline $node, string $name, int $slide): void /** * The way out of a label that holds Markdown. * - * Two, and they are in two different files: a named style is given its weight in the - * theme's own `text-styles.yml`, and the raw form carries it as an attribute — the raw - * form has no theme file, because `style` is the one name a theme may not give a style - * of its own. + * Two, and they are in two different places: a named style is given its weight in the + * theme's own `textStyles:` section, and the raw form carries it as an attribute — the + * raw form has no theme to ask, because `style` is the one name a theme may not give a + * style of its own. */ private static function wayOut(string $name): string { return TextStyle::isReserved($name) ? 'give the style the weight as an attribute ("bold=true")' - : sprintf('give the style the weight in the theme\'s "text-styles.yml" ("%s: { bold: true }")', $name); + : sprintf('give the style the weight in the theme\'s "textStyles:" section ("%s: { bold: true }")', $name); } /** diff --git a/src/Render/DeckFaces.php b/src/Render/DeckFaces.php index 5aff3ce..6419aa0 100644 --- a/src/Render/DeckFaces.php +++ b/src/Render/DeckFaces.php @@ -42,8 +42,9 @@ public function __construct( * where to change it. * * The faces the theme's text styles name are asked about here too, because - * `text-styles.yml` is a file of the theme and a style in it is a face the theme - * names — a face a word written in that style is drawn in, and therefore measured in. + * a theme's `textStyles:` section is a part of the theme and a style in it is a face + * the theme names — a face a word written in that style is drawn in, and therefore + * measured in. * A style that names one of the theme's own slots is that slot's face and is not a * finding: the theme has already said it. */ diff --git a/src/Render/DeckTheme.php b/src/Render/DeckTheme.php index 19983fa..06862bc 100644 --- a/src/Render/DeckTheme.php +++ b/src/Render/DeckTheme.php @@ -157,7 +157,9 @@ public function usedRoles(array $roles): array * A theme ships one or ships none, and this is where that decides anything: the roles a * template covers are drawn in the template's geometry and the rest keep * {@see SlideGeometry}'s, which is the precedence — a template fills in what it has and - * says nothing about what it does not, the same rule `layouts.yml` follows. Read before + * says nothing about what it does not. A theme's `layouts:` section is the other rule + * entirely: it is the whole mapping, so a role it does not name is a role the theme does + * not map. Read before * anything is built, so a template that cannot be read fails while there is still no file * on disk to clean up. * diff --git a/src/Render/PresentationRenderer.php b/src/Render/PresentationRenderer.php index dee08ab..b813efb 100644 --- a/src/Render/PresentationRenderer.php +++ b/src/Render/PresentationRenderer.php @@ -64,11 +64,11 @@ * - A deck that names no theme gets the built-in `default`. That is the absence of a * directive, not a fallback from a directive that failed — a named theme that does not * resolve is still {@see ThemeNotFound}. - * - `styles.yml` is not read. {@see \MarkdownPresentation\Theme\StyleSlots} is the Word - * half's vocabulary and the shipped themes write `.docx` style ids, which a `.pptx` has - * no use for; mapping them onto shapes would be inventing a vocabulary nobody wrote down. - * A slot that does not exist still fails at {@see \MarkdownPresentation\Theme\ThemeLoader} - * time, so a typo in a `styles.yml` is never rendered as silence. + * - A `styles.yml` beside a theme is refused rather than read. Its slots are the Word + * half's vocabulary — a slot names a Word style — and a `.pptx` has no use for them; + * mapping them onto shapes would be inventing a vocabulary nobody wrote down. The + * refusal is at {@see \MarkdownPresentation\Theme\ThemeLoader} time, so a theme that + * carries one is never rendered as though it had said nothing. * * And one it does: a directive in the body of a slide it cannot draw — a `v-*` element, a * `:::` fence, an HTML comment, an unclosed `::note` — is a @@ -104,12 +104,12 @@ final class PresentationRenderer */ public const DIRECTIVES = [ 'title', 'name', 'level', 'layout', 'theme', 'author', 'description', 'template', 'templates-file', - 'template-settings', + 'template-settings', 'deck-settings', ...Settings::KEYS, ]; /** The keys that describe the deck rather than a slide, and so belong to slide 1's block. */ - public const DECK_DIRECTIVES = ['theme', 'author', 'description', 'templates-file']; + public const DECK_DIRECTIVES = ['theme', 'author', 'description', 'templates-file', 'deck-settings']; /** The theme a deck that names none gets. */ public const DEFAULT_THEME = DeckTheme::DEFAULT_THEME; @@ -301,8 +301,8 @@ public function __construct( * @throws \MarkdownPresentation\Exception\MalformedTheme When the theme's own files do * not describe a theme. * @throws UnknownLayoutRole When the theme names a layout role that does not exist. - * @throws \MarkdownPresentation\Exception\UnknownStyleSlot When the theme names a - * style slot that does not exist. + * @throws \MarkdownPresentation\Exception\RetiredThemeFile When a file of the old + * format is beside the theme. * @throws \MarkdownPresentation\Exception\UnservedTemplate When the theme carries a * master the source of the theme cannot serve. * @throws \MarkdownPresentation\Exception\Exception When one of the theme's files @@ -657,9 +657,10 @@ private function pageOf(Theme $theme): ?Background /** * How each slide is drawn. * - * The deck's theme with the values the slide names laid over it — the values of the - * templates it names first, and its own over them — and the background the slide names - * or the template it names gave it. + * The deck's theme with the values laid over it: the deck's own first, the template's + * over them and the slide's over both. The background is the last of the three that + * names one: a slide's own background is painted over the template's, and the template's + * over the deck's. * * The background's colour is resolved against the slide's own theme, so a background * that names a slot is painted in the colour that slot has on that slide. @@ -685,10 +686,11 @@ private function appearance( array $boxes, ): array { $appearance = []; + $deckSettings = $this->deckSettings($deck); foreach ($deck->slides() as $slide) { $settings = Settings::merge( - $this->furniture->settings($this->templates, $slide), + Settings::merge($deckSettings, $this->furniture->settings($this->templates, $slide)), Settings::read($slide->frontmatter(), $slide->index() + 1), ); @@ -717,6 +719,27 @@ private function appearance( return $appearance; } + /** + * The settings the deck carries, or none where it names none. + * + * The deck's frontmatter is its first slide's, so the settings are read from there and + * the slide they are named in is slide 1 — which is where a deck directive belongs. + * + * @return array{background?: array, variables?: array} + * + * @throws MalformedFrontmatter + */ + private function deckSettings(Deck $deck): array + { + $frontmatter = $deck->frontmatter(); + + if (!array_key_exists('deck-settings', $frontmatter)) { + return []; + } + + return Settings::readDeck(1, $frontmatter['deck-settings']); + } + /** * Every frontmatter key of every slide, checked before anything is built. * diff --git a/src/Render/SlideGeometry.php b/src/Render/SlideGeometry.php index bdca246..1c13d94 100644 --- a/src/Render/SlideGeometry.php +++ b/src/Render/SlideGeometry.php @@ -238,8 +238,9 @@ public function __construct( * A copy whose named roles take their boxes from a template. * * Merged rather than replacing what this already knows, so a template that covers only some - * of the roles leaves the rest where this class puts them — the same rule - * `layouts.yml` follows, where a theme that maps two of them is a theme that works. + * of the roles leaves the rest where this class puts them. A theme's `layouts:` section is + * the other rule entirely: it is the whole mapping, so a role it does not name is a role + * the theme does not map. * * @param array}> $boxes */ diff --git a/src/Render/TemplateGeometry.php b/src/Render/TemplateGeometry.php index b88e988..38a45af 100644 --- a/src/Render/TemplateGeometry.php +++ b/src/Render/TemplateGeometry.php @@ -104,14 +104,14 @@ public function __construct( * A layout with nothing this library can draw in it contributes nothing: Office's own * *Blank* has no placeholders at all, and a role that maps to one keeps the geometry * {@see SlideGeometry} puts it at. That is the precedence — a template fills in the roles - * it covers and says nothing about the rest — and it is the rule `layouts.yml` already - * follows, where a theme that maps two roles is a theme that works rather - * than one that fails on the three. + * it covers and says nothing about the rest. A theme's `layouts:` section is the other + * rule entirely: it is the whole mapping, so a role it does not name is a role the theme + * does not map, and a deck that asks for one is told which roles the theme does map. * * Two layouts with the same name would collide; the last one in the archive wins, which * is what a reader of the file would see too. A layout that carries no name is filed * under the empty string, which no theme can ask for: `ThemeLoader` refuses an empty - * layout name in a `layouts.yml`. + * layout name in a theme's own file. * * @return array}> * diff --git a/src/Theme/LayoutRole.php b/src/Theme/LayoutRole.php index 14f8d3e..8e8df7a 100644 --- a/src/Theme/LayoutRole.php +++ b/src/Theme/LayoutRole.php @@ -35,6 +35,33 @@ public static function names(): array return array_map(static fn (self $role): string => $role->value, self::cases()); } + /** + * The layout names the library's own mapping gives each role. + * + * The eight Office names that every theme shipping with this library carried in a + * `layouts.yml` of its own, byte for byte: a theme with no `layouts:` section is + * drawn with these. + * + * The names and the roles have to stay in step — a role here without a name is a role + * the library cannot draw, and a name here for a role that does not exist is a layout + * no deck asks for. + * + * @return array + */ + public static function defaults(): array + { + return [ + self::Title->value => 'Title Slide', + self::Content->value => 'Title and Content', + self::TwoColumn->value => 'Two Content', + self::Section->value => 'Section Header', + self::Blank->value => 'Blank', + self::ImageText->value => 'Picture Left', + self::ImageTitle->value => 'Picture with Caption', + self::ImageSlide->value => 'Full Bleed Picture', + ]; + } + /** * Whether a slide on this role has a title box of its own. * diff --git a/src/Theme/LoadedTheme.php b/src/Theme/LoadedTheme.php index 21b19a5..be5ae2f 100644 --- a/src/Theme/LoadedTheme.php +++ b/src/Theme/LoadedTheme.php @@ -7,25 +7,23 @@ use MarkdownPresentation\Exception\UnknownLayoutRole; /** - * A theme directory, read: the colours and fonts, the Word style slots it - * overrides, the layout roles it maps, and the template that goes with it. + * A theme read: the colours and fonts, the layout roles it maps, and the template that + * goes with it. * - * A theme is a directory, and only `theme.yml` is required. The rest are read when - * they are there and are absent when they are not — except a `styles.yml` that - * names a slot which does not exist and a `layouts.yml` that maps a role which is - * not one, which are mistakes rather than absences and are refused. + * A theme is one file, and only `theme.yml` is required. The master beside it is read + * when it is there and is absent when it is not, and a `layouts:` section that names a + * role which is not one is refused when the theme is read, while a role the section does + * not map is refused when a deck asks for it. */ final class LoadedTheme { /** * @param array $layouts Role name to the template's own layout name. - * @param array $styles Word style slot to styleId or inline style array. */ public function __construct( private readonly string $name, private readonly string $directory, private readonly Theme $theme, - private readonly array $styles, private readonly array $layouts, private readonly ?Master $template, ) { @@ -57,16 +55,6 @@ public function theme(): Theme return $this->theme; } - /** - * The theme's Word style slot overrides, in the order the file listed them. - * - * @return array - */ - public function styles(): array - { - return $this->styles; - } - /** * The roles this theme maps, to the layout names of its template. * diff --git a/src/Theme/StyleSlots.php b/src/Theme/StyleSlots.php deleted file mode 100644 index 12c4b80..0000000 --- a/src/Theme/StyleSlots.php +++ /dev/null @@ -1,71 +0,0 @@ - - */ - public static function names(): array - { - return [ - self::HEADING_1, - self::HEADING_2, - self::HEADING_3, - self::HEADING_4, - self::HEADING_5, - self::HEADING_6, - self::PARAGRAPH, - self::BLOCK_QUOTE, - self::CODE_BLOCK, - self::THEMATIC_BREAK, - self::HTML_FALLBACK, - self::LIST_PARAGRAPH, - self::CODE_FONT, - self::LINK_FONT, - self::BULLET_LIST, - self::ORDERED_LIST, - self::TABLE, - self::TABLE_HEADER_ROW, - self::TABLE_CELL, - ]; - } -} diff --git a/src/Theme/TextStyle.php b/src/Theme/TextStyle.php index 6f022d9..f6e4f43 100644 --- a/src/Theme/TextStyle.php +++ b/src/Theme/TextStyle.php @@ -5,7 +5,7 @@ namespace MarkdownPresentation\Theme; /** - * One named style's properties, as a theme's `text-styles.yml` writes them. + * One named style's properties, as a theme's `textStyles:` section writes them. * * A property that is null is one the style does not set, and a run it is applied to * inherits that property from the block it is in — a colour from the `:::content` box, a @@ -14,7 +14,7 @@ * * The colours are as they were written rather than as they resolve, because a role and a * theme slot are only a colour once the theme they belong to is known — and the theme - * that reads this file is the one that resolves them. + * that reads this style is the one that resolves them. */ final class TextStyle { diff --git a/src/Theme/TextStyles.php b/src/Theme/TextStyles.php index bcdda9d..ca7168b 100644 --- a/src/Theme/TextStyles.php +++ b/src/Theme/TextStyles.php @@ -9,9 +9,9 @@ /** * The named styles a theme carries. * - * A theme without a `text-styles.yml` has none, and every named form is then a name this - * theme does not have — which is a refusal naming the styles that exist, and there are - * none. + * A theme without a `textStyles:` section has none, and every named form is then a name + * this theme does not have — which is a refusal naming the styles that exist, and there + * are none. * * The names are folded, because a style's name is a word to a reader: `:Brand[Bakery]` and * `:brand[Bakery]` are the same word written twice. The theme's own spelling is kept diff --git a/src/Theme/Theme.php b/src/Theme/Theme.php index cbe00a9..ec4d5fc 100644 --- a/src/Theme/Theme.php +++ b/src/Theme/Theme.php @@ -349,7 +349,7 @@ public function style(): Style /** * The named text styles this theme carries. * - * Empty for a theme without a `text-styles.yml`, which is most of them: a style is + * Empty for a theme without a `textStyles:` section, which is most of them: a style is * something a deck names, and a deck that names none has said nothing about the words * it draws. */ diff --git a/src/Theme/ThemeLoader.php b/src/Theme/ThemeLoader.php index 77c2dcb..06e28cd 100644 --- a/src/Theme/ThemeLoader.php +++ b/src/Theme/ThemeLoader.php @@ -6,9 +6,9 @@ use MarkdownPresentation\Exception\Exception; use MarkdownPresentation\Exception\MalformedTheme; +use MarkdownPresentation\Exception\RetiredThemeFile; use MarkdownPresentation\Exception\ThemeNotFound; use MarkdownPresentation\Exception\UnknownLayoutRole; -use MarkdownPresentation\Exception\UnknownStyleSlot; use MarkdownPresentation\Exception\UnservedTemplate; use MarkdownPresentation\Files\FileFinder; use MarkdownPresentation\Filesystem\PathScope; @@ -18,19 +18,24 @@ /** * Reads a theme out of a finder: the `theme.yml` and the files beside it. * - * Only `theme.yml` is required. `styles.yml`, `layouts.yml` and `text-styles.yml` are - * read when they are there, and `template.pptx` is the theme's master: it is opened as a - * file, so a source that holds only its bytes has them staged into one, and nothing here - * reads what is inside it — a theme's master belongs to whoever renders the deck rather - * than to the loader that found it. + * A theme is one file. `theme.yml` carries the look, the roles the theme maps and the + * named styles a deck may write in, and `template.pptx` beside it is the theme's master: + * it is opened as a file, so a source that holds only its bytes has them staged into one, + * and nothing here reads what is inside it — a theme's master belongs to whoever renders + * the deck rather than to the loader that found it. * - * The finder is asked by name — `house/theme.yml`, `house/styles.yml` — because the + * The files a theme used to be made of — `styles.yml`, `layouts.yml` and + * `text-styles.yml` — are refused when they are beside it, each with a message saying + * what the reader has to do: move the content into the section it became and delete the + * file, or delete the file that belongs to the other half. + * + * The finder is asked by name — `house/theme.yml`, `house/template.pptx` — because the * library composes names and a finder answers them. A theme that never had a directory * is read the same way as one that did. * * Each of the theme's own files is resolved and held to the scope the loader was given * before it is read, and the scope is asked of the file rather than of the directory it - * was found in: a `styles.yml` that is a symlink pointing out of the scope is read just + * was found in: a file that is a symlink pointing out of the scope is read just * as readily as one inside it, and the `author:` the manifest carries is copied into * `docProps/core.xml` of the deck — a way to get the contents of a file out through a * download. @@ -43,8 +48,28 @@ final class ThemeLoader public const TEXT_STYLES_FILE = 'text-styles.yml'; public const TEMPLATE_FILE = 'template.pptx'; - /** The only key a layouts file may put around its mappings. */ - private const LAYOUTS_KEY = 'layouts'; + /** + * The sections a theme's file may carry beside the theme's own values. + * + * The theme's own keys are {@see ThemeMapping::KEYS}, and a key that is neither one + * nor a section is refused: the typo-catching is the point of a closed vocabulary. + * + * Public because the refusal already names it — {@see MalformedTheme::unknownKey()} + * offers the whole vocabulary — so a reader of the format is given the list and then + * asked to find it somewhere else. + */ + public const SECTIONS = ['layouts', 'textStyles']; + + /** + * The files whose content has become a section of the theme's own file. + * + * The `styles.yml` is not among them: it is the Word half's, and this half has no + * section for it. + */ + private const MOVED = [ + self::LAYOUTS_FILE => 'layouts', + self::TEXT_STYLES_FILE => 'textStyles', + ]; /** The smallest a size of type may be, in points. */ private const MINIMUM_POINTS = 0.5; @@ -67,8 +92,8 @@ public function __construct(private readonly ?PathScope $scope = null) * * @throws ThemeNotFound when the theme has no `theme.yml`, so it is not a theme * @throws MalformedTheme when a file in it does not describe a theme - * @throws UnknownStyleSlot when `styles.yml` names a slot that does not exist - * @throws UnknownLayoutRole when `layouts.yml` names a role that does not exist + * @throws RetiredThemeFile when a file of the old format is beside the theme + * @throws UnknownLayoutRole when the `layouts:` section names a role that does not exist * @throws UnservedTemplate when the theme carries a master the source cannot serve * @throws Exception when a file in it cannot be read or parsed, or resolves out * of the scope @@ -91,7 +116,7 @@ public function load(string $name, ?string $written = null, ?FileFinder $files = * the manifest. * * The name the deck wrote is what makes the file the manifest rather than one of the - * theme's other files: a `styles.yml` named as the theme is a file the theme's own + * theme's other files: a `theme.yml` named as the theme is the file the theme's own * directory holds, not the theme. * * The Word half's loader asks the same question the same way, and the two have to @@ -104,8 +129,8 @@ public function load(string $name, ?string $written = null, ?FileFinder $files = * @throws ThemeNotFound when the file is not there, or is not a `theme.yml` and so * is not a manifest * @throws MalformedTheme when the file does not describe a theme - * @throws UnknownStyleSlot when `styles.yml` names a slot that does not exist - * @throws UnknownLayoutRole when `layouts.yml` names a role that does not exist + * @throws RetiredThemeFile when a file of the old format is beside the theme + * @throws UnknownLayoutRole when the `layouts:` section names a role that does not exist * @throws UnservedTemplate when the theme carries a master the source cannot serve * @throws Exception when a file in it cannot be read or parsed, or resolves out * of the scope @@ -130,30 +155,91 @@ public function loadManifest(string $name, ?string $written = null, ?FileFinder /** * The theme a manifest describes, with the rest of it read from beside the manifest. * + * The files the old format had beside the manifest are refused first: a theme that + * carries one is a theme whose shape is wrong whatever its manifest says. + * * @param array{contents: string, path: string} $manifest * * @throws MalformedTheme * @throws ThemeNotFound * @throws UnknownLayoutRole - * @throws UnknownStyleSlot + * @throws RetiredThemeFile * @throws Exception */ private function read(array $manifest, string $name, string $written, ?FileFinder $files): LoadedTheme { + $this->refuseRetired($name, $written, $files); + + $data = $this->mapping($manifest, 'a theme'); + $file = $manifest['path']; + return new LoadedTheme( $name, - dirname($manifest['path']), + dirname($file), Theme::fromArray( - $this->mapping($manifest, 'a theme'), - $manifest['path'], - $this->textStyles($name, $written, $files), + $this->values($data, $file), + $file, + $this->textStyles($data, $file), ), - $this->styles($name, $written, $files), - $this->layouts($name, $written, $files), + $this->layouts($data, $file), $this->template($name, $written, $files), ); } + /** + * The files of the old format, refused when they are beside the theme. + * + * Each is asked of the finder and held to the scope like every other file of the + * theme, so that a file resolving out of the roots is refused for that before it is + * refused for what it is. + * + * @throws RetiredThemeFile + * @throws ThemeNotFound + * @throws Exception + */ + private function refuseRetired(string $name, string $written, ?FileFinder $files): void + { + foreach (self::MOVED as $file => $section) { + if ($this->file($files, $name, $file, $written) !== null) { + throw RetiredThemeFile::moved($written, $file, $section); + } + } + + if ($this->file($files, $name, self::STYLES_FILE, $written) !== null) { + throw RetiredThemeFile::otherHalf($written, self::STYLES_FILE); + } + } + + /** + * The theme's own values, and the refusal of a key that is neither one nor a section. + * + * @param array $data + * + * @return array + * + * @throws MalformedTheme + */ + private function values(array $data, string $file): array + { + $values = []; + + foreach ($data as $key => $value) { + $key = (string) $key; + + if (in_array($key, self::SECTIONS, true)) { + continue; + } + + if (!in_array($key, ThemeMapping::KEYS, true)) { + throw MalformedTheme::unknownKey($file, $key, [...ThemeMapping::KEYS, ...self::SECTIONS]); + } + + $values[$key] = $value; + } + + return $values; + } + /** * One of the theme's own files, resolved and held to the scope. * @@ -306,69 +392,29 @@ private static function describe(mixed $parsed): string } /** - * The Word style slot overrides, every slot checked against the slots the Word - * half really has. + * The role mappings the theme's file carries, or the library's own. * - * @return array + * A theme with a `layouts:` section has the whole mapping: a role the section does + * not name is a role the theme does not map, and the failure names the roles it does + * map. A theme with no section is drawn with the library's own mapping, which is the + * one every theme shipping with this library carried in a file of its own. * - * @throws ThemeNotFound - * @throws Exception - */ - private function styles(string $name, string $written, ?FileFinder $files): array - { - $file = $this->file($files, $name, self::STYLES_FILE, $written); - - if ($file === null) { - return []; - } - - $styles = []; - - foreach ($this->mapping($file, 'a mapping of style slots to styles') as $slot => $style) { - $slot = (string) $slot; - - if (!in_array($slot, StyleSlots::names(), true)) { - throw UnknownStyleSlot::named($file['path'], $slot, StyleSlots::names()); - } - - $styles[$slot] = $style; - } - - return $styles; - } - - /** - * The role mappings, every role checked against the portable roles. The mappings may - * stand on their own or under a `layouts:` key, because the concept draft writes the - * second and a bare mapping is what a person types. + * @param array $data * * @return array * - * @throws ThemeNotFound - * @throws Exception + * @throws UnknownLayoutRole */ - private function layouts(string $name, string $written, ?FileFinder $files): array + private function layouts(array $data, string $file): array { - $file = $this->file($files, $name, self::LAYOUTS_FILE, $written); - - if ($file === null) { - return []; + if (!array_key_exists('layouts', $data)) { + return LayoutRole::defaults(); } - $mapping = $this->mapping($file, 'a mapping of layout roles to layout names'); + $mapping = $data['layouts']; - if (isset($mapping[self::LAYOUTS_KEY])) { - foreach (array_keys($mapping) as $key) { - if ((string) $key !== self::LAYOUTS_KEY) { - throw UnknownLayoutRole::unknownKey($file['path'], (string) $key, [self::LAYOUTS_KEY]); - } - } - - $mapping = $mapping[self::LAYOUTS_KEY]; - } - - if (!is_array($mapping)) { - throw UnknownLayoutRole::notTheMappings($file['path']); + if (!is_array($mapping) || ($mapping !== [] && array_is_list($mapping))) { + throw UnknownLayoutRole::notTheMappings($file); } $layouts = []; @@ -381,7 +427,7 @@ private function layouts(string $name, string $written, ?FileFinder $files): arr } if (!is_string($layout) || trim($layout) === '') { - throw UnknownLayoutRole::notALayoutName($file['path'], $role); + throw UnknownLayoutRole::notALayoutName($file, $role); } $layouts[$role] = trim($layout); @@ -391,48 +437,51 @@ private function layouts(string $name, string $written, ?FileFinder $files): arr } /** - * The named text styles a theme carries, read from its `text-styles.yml`. + * The named text styles the theme's file carries. * - * The file is optional: a theme without one has no named styles, and every named form - * in a deck drawn with it is then a name the theme does not have. It is held to the - * scope like every other file of the theme, because it is one of them. + * A theme without a `textStyles:` section has none, and every named form in a deck + * drawn with it is then a name the theme does not have. * * A style named twice is refused by {@see TextStyles} itself rather than here, because * the styles may also be built in code and the rule belongs to them. * - * @throws ThemeNotFound - * @throws Exception + * @param array $data + * * @throws MalformedTheme */ - private function textStyles(string $name, string $written, ?FileFinder $files): TextStyles + private function textStyles(array $data, string $file): TextStyles { - $file = $this->file($files, $name, self::TEXT_STYLES_FILE, $written); - - if ($file === null) { + if (!array_key_exists('textStyles', $data)) { return new TextStyles(); } - $styles = []; + $styles = $data['textStyles']; + + if (!is_array($styles) || ($styles !== [] && array_is_list($styles))) { + throw MalformedTheme::wrongType($file, 'textStyles', 'a mapping of style names to text styles'); + } + + $read = []; - foreach ($this->mapping($file, 'a mapping of style names to text styles') as $style => $properties) { + foreach ($styles as $style => $properties) { $style = (string) $style; if (TextStyle::isReserved($style)) { - throw MalformedTheme::reservedStyle($file['path'], $style); + throw MalformedTheme::reservedStyle($file, $style); } if (!is_array($properties) || ($properties !== [] && array_is_list($properties))) { - throw MalformedTheme::wrongType($file['path'], $style, 'a mapping of attributes to values'); + throw MalformedTheme::wrongType($file, $style, 'a mapping of attributes to values'); } if ($properties === []) { - throw MalformedTheme::emptyStyle($file['path'], $style); + throw MalformedTheme::emptyStyle($file, $style); } - $styles[$style] = $this->textStyle($file['path'], $style, $properties); + $read[$style] = $this->textStyle($file, $style, $properties); } - return new TextStyles($styles, $file['path']); + return new TextStyles($read, $file); } /** diff --git a/src/Theme/ThemeMapping.php b/src/Theme/ThemeMapping.php index 6a273ab..9f494f5 100644 --- a/src/Theme/ThemeMapping.php +++ b/src/Theme/ThemeMapping.php @@ -17,7 +17,13 @@ */ final class ThemeMapping { - /** The keys a `theme.yml` may have. */ + /** + * The keys a theme's own values may have. + * + * The theme's own, and not the file's: the two sections a theme's file may carry + * beside them are read by {@see \MarkdownPresentation\Theme\ThemeLoader}, which is + * what tells the two apart and refuses a key that is neither. + */ public const KEYS = ['name', 'description', 'author', 'dark', 'colors', 'fonts', 'style']; /** @@ -79,10 +85,12 @@ public static function read(array $data, string $file = 'theme.yml', ?TextStyles } /** - * The theme's `theme.yml` as an array, in DrawingML's spellings. + * The theme's own values as an array, in DrawingML's spellings. * - * The named text styles are not in here: they are read from a file of their own, and a - * `theme.yml` that carried them would be a theme with two places to say the same thing. + * The named text styles are not in here: they are not values a slide may lay over, + * and a theme's file carries them beside these rather than among them. They travel + * beside the round trip instead — {@see \MarkdownPresentation\Theme\ThemeVariables::apply()} + * hands the theme's own styles back to the reader. * * @return array{name: string, description: ?string, author: ?string, dark: bool, colors: array, fonts: array, style: array} */ diff --git a/src/Theme/ThemeVariables.php b/src/Theme/ThemeVariables.php index 422a519..a2f7501 100644 --- a/src/Theme/ThemeVariables.php +++ b/src/Theme/ThemeVariables.php @@ -13,8 +13,9 @@ * the reader that reads the theme's own file. A slide writes `colors: {accent1: "#FF0000"}` * and a theme's file writes the same, and there is one vocabulary rather than two. * - * What a slide may name is the theme's *values* and not its identity: `name`, `description` - * and `author` are the theme's, and a slide has none of them. + * What a slide may name is the theme's *values* and not the rest of it: `name`, + * `description` and `author` are the theme's identity, and `layouts` and `textStyles` are + * its own shape rather than anything a slide may lay over it. * * The values are merged as the mappings they are and read once, rather than merged as the * objects they become. That is what makes an override of one value leave the others alone: diff --git a/tests/Pest.php b/tests/Pest.php index 7890200..c1c66c1 100644 --- a/tests/Pest.php +++ b/tests/Pest.php @@ -4,6 +4,7 @@ use MarkdownPresentation\Filesystem\PathScope; use MarkdownPresentation\Tests\Support\Doctest; +use MarkdownPresentation\Tests\Support\Pptx; use MarkdownPresentation\Tests\Support\Scratch; pest()->afterEach(function (): void { @@ -38,7 +39,7 @@ function deckScope(string $directory, array $roots = []): PathScope /** * The part every test about the first slide's contents reads, the deck two of them - * convert, and the layout a `layouts.yml` maps a content slide to. + * convert, and the layout a theme's `layouts:` section maps a content slide to. * * `TWO_SLIDES` is the smallest deck there is two slides of. Every test about where a split * falls needs one where falling it somewhere else is visible, and the two titles are the @@ -54,6 +55,31 @@ function deckScope(string $directory, array $roots = []): PathScope const TITLE_AND_CONTENT = 'Title and Content'; +/** + * The colours the words of a slide are drawn in, in the order the file lists them. + */ +function inkOf(Pptx $pptx, int $slide = 1): array +{ + $xml = $pptx->part(sprintf('ppt/slides/slide%d.xml', $slide)); + preg_match_all('#]*>\s*\s*part(sprintf('ppt/slides/slide%d.xml', $slide)); + + if (preg_match('#.*?toBe('F4F1E9') + ->and(pageOf($pptx, 2))->toBe('F4F1E9') + ->and(pageOf($pptx, 3))->toBe('CFE0F0') + ->and(pageOf($pptx, 4))->toBe('F4F1E9') + ->and(inkOf($pptx, 1))->toContain('3A2E22') + ->and(inkOf($pptx, 2))->toContain('3A2E22') + ->and(inkOf($pptx, 3))->toContain('3A2E22') + ->and(inkOf($pptx, 4))->toContain('1E3A5F') + ->and(inkOf($pptx, 4))->not->toContain('3A2E22'); +}); + it('gives every slide that draws a template the settings of that template', function () { // The deck's last two slides draw a template that carries settings of its own, and // neither slide names a background or a theme of its own: what they are painted with is @@ -299,7 +318,8 @@ function runsOfShape(Pptx $pptx, string $name, int $slide = 1, int $index = 0): [$pptx] = builtDeck(PICTURE_DECK); // A role is portable and the layout part is not: the deck wrote `image-text` and the - // file carries a part called `Picture Left`, which is what `layouts.yml` is for. + // file carries a part called `Picture Left`, which is what a theme's `layouts:` section + // is for. expect($pptx->layoutNames())->toContain('Picture Left', 'Picture with Caption', FULL_BLEED_LAYOUT); }); diff --git a/tests/Support/ThemeDirectory.php b/tests/Support/ThemeDirectory.php index 7e91598..3215b88 100644 --- a/tests/Support/ThemeDirectory.php +++ b/tests/Support/ThemeDirectory.php @@ -100,6 +100,19 @@ public static function acme(array $beside = [], string $prefix = 'theme'): strin return self::create(['theme.yml' => self::ACME] + $beside, $prefix); } + /** + * A theme directory whose own manifest says what the test needs it to say. + * + * The manifest is the one file of a theme that says what the theme is, so a test about + * anything else in it writes the manifest itself. + * + * @param array $beside Files beside `theme.yml`, keyed by name. + */ + public static function withManifest(string $manifest, array $beside = [], string $prefix = 'theme'): string + { + return self::create(['theme.yml' => $manifest] + $beside, $prefix); + } + /** * A theme read out of a directory, the way the loader reads one. * diff --git a/tests/Unit/dead-code.php b/tests/Unit/dead-code.php index 5acfc25..5ba6eb5 100644 --- a/tests/Unit/dead-code.php +++ b/tests/Unit/dead-code.php @@ -414,6 +414,11 @@ function pagesWithClaim(string $claim): array // background of a slide was the master's. A slide may name its own background now, so // the phrase below is the old rule's own wording, and no comment or page may say it. 'a slide wanting its own colour carries the colour as a shape' => 'so a slide wanting its own colour carries the colour as a shape', + // The deck's settings are between the template's and the theme's, so a sentence that put + // the template's straight over the theme's left a layer out. The phrase below is what + // the changelog and the tests said while the deck had no settings of its own, and no + // page or comment may say it now. + 'the template\'s settings are laid over the theme\'s' => 'the template\'s over the theme\'s', // A manifest was named by the file the path resolved to rather than by the name the deck // wrote, so a `theme.yml` that was a link to a file of another name was refused for the @@ -546,6 +551,63 @@ function pagesWithClaim(string $claim): array // The placement table names eight attributes, and a count of them in prose is wrong the // moment one is added. The phrase is the heading the page carried when it was one short. 'the placement table names seven attributes' => 'Seven attributes, on every name', + + // A theme is one file now, and the three files beside it that this format no longer has + // are refused rather than ignored. The phrases are the claims the pages and the comments + // made about them; the changelog has to be able to name what a theme used to be made + // of, so the phrases are the claims rather than the file names. + 'a theme reads the named styles from a file of their own' => 'read from a file of their own', + 'a theme without a layouts file maps no role at all' => 'maps no role at all', + 'a theme without a layouts file says so in the failure' => 'the theme has no layouts.yml', + 'a styles file beside a theme is read and not used' => '`styles.yml` is not read', + 'a styles file beside a theme is read and not used, in a page' => '`styles.yml` is **not** read', + // The refusal for a file of the old format named one step where the reader has to take + // two: the content goes into a section and the file goes with it, because the refusal + // is about the file being there rather than about what is in it. A reader who followed + // the message as it was moved the content and left the file beside the theme, and the + // next render failed the same way. The phrase is the end of that message, so it cannot + // come back. + 'a retired theme file only has to have its content moved' => 'of its "theme.yml".', + // The sentence about a role the mapping leaves out was about the template and read as + // being about the theme, and the two are different: a theme's `layouts:` section is the + // whole mapping, while a template that has no layout for a role leaves the role where + // the library puts it. + 'a role the mapping leaves out keeps the library geometry' => 'A role left out keeps this library\'s own geometry rather than failing', + + // The background of a slide is the last of the settings to say one and not the first: + // the slide's own is painted over the template's, and the template's over the deck's. + // The phrase is the sentence the docblock gave, and it said the opposite of what the + // merge does — and of what the next clause of the same paragraph said. + 'a background is the first of the three that names one' => 'The background is the first of the three that', + + // A `styles.yml` beside a theme is refused, and the reason was given in terms of the + // themes that used to ship one. None of them does now, and none can: the file is + // refused at loader time, so a theme this library ships cannot carry one. The phrase + // is the claim as it was made — the history in `CHANGELOG.md` names the same thing + // across a line break, so it is not caught by it. + 'the shipped themes write the docx style ids' => 'the shipped themes write `.docx` style ids', + + // A template and a theme's `layouts:` section are two different rules, and five + // sentences said they were the same one: a template fills in the roles it covers and + // leaves the rest where the library puts them, while a `layouts:` section is the whole + // mapping — a role it does not name is a role the theme does not map. The phrases are + // the words the sentences used, one line of each. + 'a template\'s rule is the rule a theme\'s `layouts:` section follows' => 'rule a theme\'s `layouts:`', + 'a theme\'s `layouts:` section follows a template\'s rule' => 'a theme\'s `layouts:` section follows', + // The other half of the same wrong claim, in three spellings: a theme that maps some + // of the roles is a theme that works. It is a template that fills in the roles it + // covers; a theme's section is all or nothing. + 'a theme that maps two of them is a theme that works' => 'a theme that maps two of them is a theme', + 'a theme that maps two roles is a theme that works' => 'a theme that maps two roles is a theme that works', + 'a theme mapping some of the roles is a theme that works' => 'a theme mapping some of the roles is a theme that works', + + // A theme directory was said to serve one half, which is not so: the two halves share + // `name`, `description`, `author` and `textStyles`, and part at the look — this half's is + // `dark:`, `colors:`, `fonts:`, `style:` and `layouts:`, the Word half's is `styles:`. A + // file carrying the other half's look is refused, which is what the refusal of a + // `styles.yml` is about. The phrase is the old claim, and the README has to be able to + // say what the halves part at without saying it. + 'a theme directory serves one half' => 'a theme directory serves one half', ]); it('has no decorative dividers in it', function () { diff --git a/tests/Unit/deck-settings.php b/tests/Unit/deck-settings.php new file mode 100644 index 0000000..cd5b708 --- /dev/null +++ b/tests/Unit/deck-settings.php @@ -0,0 +1,180 @@ +render((new DeckParser())->parse($markdown), $path); + + return Pptx::open($path); +} + +/** + * A deck built by hand rather than parsed, and the file it was written to. + * + * @param list $slides + */ +function deckSettingsHandBuilt(array $slides): string +{ + $path = Scratch::file('deck-settings.pptx', ''); + + (new PresentationRenderer(directory: Scratch::directory())) + ->render(new Deck('', $slides), $path); + + return $path; +} + +it('draws every slide of the deck in the values the deck names', function () { + // The gap this closes: the deck's own frontmatter reached the first slide and no + // other, so a deck that named an accent in it had one slide in that accent and the + // rest in the theme's. + $pptx = deckSettingsDeck( + "---\ndeck-settings:\n theme-variables:\n colors:\n dk1: \"#123456\"\n---\n\n# One\n\n---\n\n# Two\n", + ); + + expect(inkOf($pptx, 1))->toContain('123456') + ->and(inkOf($pptx, 2))->toContain('123456'); +}); + +it('lays a slide\'s own values over the deck\'s', function () { + // The precedence is slide → template → deck → theme, so a slide that names a value of + // its own is drawn in that value and not in the deck's. + $pptx = deckSettingsDeck( + "---\ndeck-settings:\n theme-variables:\n colors:\n dk1: \"#123456\"\n---\n\n# One\n\n" + . "---\ntheme-variables:\n colors:\n dk1: \"#654321\"\n---\n\n# Two\n", + ); + + expect(inkOf($pptx, 1))->toContain('123456') + ->and(inkOf($pptx, 2))->toContain('654321') + ->and(inkOf($pptx, 2))->not->toContain('123456'); +}); + +it('lays a template\'s values over the deck\'s', function () { + // A template's settings are the template's, and the template is above the deck: the + // slides that draw it are drawn in the template's values and not in the deck's. + $pptx = deckSettingsDeck( + "---\ndeck-settings:\n theme-variables:\n colors:\n dk1: \"#123456\"\n---\n\n# One\n\n" + . "---\ntemplate: brand\ntemplate-settings:\n theme-variables:\n colors:\n dk1: \"#654321\"\n" + . "---\n::line{}\n\n" + . "---\nlayout: content\ntemplate: brand\n---\n\nWords.\n", + ); + + expect(inkOf($pptx, 1))->toContain('123456') + ->and(inkOf($pptx, 2))->toContain('654321'); +}); + +it('paints every slide of the deck with the background the deck names', function () { + $pptx = deckSettingsDeck( + "---\ndeck-settings:\n background: \"#123456\"\n---\n\n# One\n\n---\n\n# Two\n", + ); + + expect(pageOf($pptx, 1))->toBe('123456') + ->and(pageOf($pptx, 2))->toBe('123456'); +}); + +it('lays a slide\'s own background over the deck\'s', function () { + $pptx = deckSettingsDeck( + "---\ndeck-settings:\n background: \"#123456\"\n---\n\n# One\n\n" + . "---\nbackground: \"#654321\"\n---\n\n# Two\n", + ); + + expect(pageOf($pptx, 1))->toBe('123456') + ->and(pageOf($pptx, 2))->toBe('654321'); +}); + +it('refuses the settings of the deck on a later slide, and says where they belong', function () { + // The deck's settings are the deck's, and the deck's frontmatter is the first slide's. + // A later slide naming them is a mistake, and it is refused rather than left to be read + // as nothing at all. + expect(fn () => deckSettingsDeck("# One\n\n---\ndeck-settings:\n background: accent1\n---\n\n# Two\n")) + ->toThrow( + UnknownDirective::class, + 'The frontmatter of slide 2 names "deck-settings", which is a deck directive and belongs in ' + . 'the frontmatter of slide 1.', + ); +}); + +it('refuses a setting of the deck that is not a setting', function () { + expect(fn () => deckSettingsDeck("---\ndeck-settings:\n backgroun: accent1\n---\n\n# One\n")) + ->toThrow( + MalformedFrontmatter::class, + 'The frontmatter of slide 1 has a "deck-settings" that names "backgroun", which is not a setting.', + ) + ->toThrow( + MalformedFrontmatter::class, + 'The settings are: background, background-gradient, background-angle, background-radial, theme-variables.', + ); +}); + +it('refuses the settings of the deck that are not a mapping', function () { + expect(fn () => deckSettingsDeck("---\ndeck-settings: accent1\n---\n\n# One\n")) + ->toThrow( + MalformedFrontmatter::class, + 'The frontmatter of slide 1 has a "deck-settings" that is not a mapping of the settings the deck carries.', + ); +}); + +it('refuses the settings of the deck that are not there', function () { + // A key that is there with nothing under it is a mistake rather than the absence of + // one: the deck's settings are the ones every slide is drawn with, and a block that + // says nothing under the key says nothing. + expect(fn () => deckSettingsDeck("---\ndeck-settings:\n---\n\n# One\n")) + ->toThrow(MalformedFrontmatter::class, 'has a "deck-settings" that is not a mapping'); +}); + +it('refuses the settings of the deck when the mapping holds nothing', function () { + expect(fn () => deckSettingsDeck("---\ndeck-settings: {}\n---\n\n# One\n")) + ->toThrow(MalformedFrontmatter::class, 'has a "deck-settings" that is not a mapping'); +}); + +it('draws a deck built by hand with the settings of the deck', function () { + // A deck a caller built without the parser carries the same frontmatter, and the + // deck's settings are read out of it as they are out of a parsed deck's. + $path = deckSettingsHandBuilt([ + new Slide(0, '# One', '# One', ['deck-settings' => ['background' => '#123456']], 'One', 1, null, 0, 1), + ]); + + expect(pageOf(Pptx::open($path)))->toBe('123456'); +}); + +it('refuses the settings of the deck on a later slide of a deck built by hand', function () { + // The line behind the parser's own refusal, for a deck a caller built without it. + $slides = [ + new Slide(0, '# One', '# One', [], 'One', 1, null, 0, 1), + new Slide(1, '# Two', '# Two', ['deck-settings' => ['background' => '#123456']], 'Two', 1, null, 1, 2), + ]; + + expect(fn () => deckSettingsHandBuilt($slides)) + ->toThrow( + UnknownDirective::class, + 'The frontmatter of slide 2 names "deck-settings", which is a deck directive and belongs in ' + . 'the frontmatter of slide 1.', + ); +}); diff --git a/tests/Unit/exceptions.php b/tests/Unit/exceptions.php index 76628bf..1bd7feb 100644 --- a/tests/Unit/exceptions.php +++ b/tests/Unit/exceptions.php @@ -27,7 +27,7 @@ use MarkdownPresentation\Exception\UnknownFont; use MarkdownPresentation\Exception\UnknownLayoutRole; use MarkdownPresentation\Exception\UnknownMarker; -use MarkdownPresentation\Exception\UnknownStyleSlot; +use MarkdownPresentation\Exception\RetiredThemeFile; use MarkdownPresentation\Exception\UnknownTemplate; use MarkdownPresentation\Exception\UnknownTextStyle; use MarkdownPresentation\Exception\UnreadableDeck; @@ -110,6 +110,7 @@ function reportedExceptions(): array MalformedTemplatesFile::class, MalformedTextStyle::class, MalformedTheme::class, + RetiredThemeFile::class, TemplatesFileNotFound::class, TemplatesFileTooLarge::class, ThemeNotFound::class, @@ -119,7 +120,6 @@ function reportedExceptions(): array UnknownFont::class, UnknownLayoutRole::class, UnknownMarker::class, - UnknownStyleSlot::class, UnknownTemplate::class, UnknownTextStyle::class, UnsupportedColumn::class, diff --git a/tests/Unit/layouts-and-steps.php b/tests/Unit/layouts-and-steps.php index 73c7008..8c20f6d 100644 --- a/tests/Unit/layouts-and-steps.php +++ b/tests/Unit/layouts-and-steps.php @@ -88,8 +88,7 @@ function slideDeck(string $markdown): Pptx it('refuses a layout the theme does not map, and names the ones it maps', function () { // A role the theme does not map is the theme's to fix, and its message already says so. $themes = ThemeDirectory::create([ - 'theme.yml' => "name: Sparse\n", - 'layouts.yml' => "layouts:\n title: Title Slide\n content: Title and Content\n", + 'theme.yml' => "name: Sparse\nlayouts:\n title: Title Slide\n content: Title and Content\n", ]); $path = Scratch::file('deck.pptx', ''); @@ -151,7 +150,9 @@ function slideDeck(string $markdown): Pptx it('leaves the roles a template says nothing about where the library puts them', function () { // A template that maps only some layouts is a theme that works, not one that fails on - // the three its deck never asked for — the rule `layouts.yml` already follows. + // the three its deck never asked for. A theme's `layouts:` section is the other rule + // entirely: it is the whole mapping, so a role it does not name is a role the theme + // does not map. $geometry = (new SlideGeometry())->with(['content' => ['body' => [new Box(0, 0, 10, 10)]]]); expect($geometry->body(LayoutRole::TwoColumn))->toHaveCount(2) diff --git a/tests/Unit/master-finder.php b/tests/Unit/master-finder.php index f43a839..e9a2310 100644 --- a/tests/Unit/master-finder.php +++ b/tests/Unit/master-finder.php @@ -85,7 +85,7 @@ public function themes(): array public function files(string $theme): array { - return ['layouts.yml', 'template.pptx', 'theme.yml']; + return ['template.pptx', 'theme.yml']; } } @@ -122,7 +122,7 @@ public function themes(): array public function files(string $theme): array { - return ['layouts.yml', 'template.pptx', 'theme.yml']; + return ['template.pptx', 'theme.yml']; } } @@ -139,7 +139,6 @@ function unmountedTheme(string $prefix = 'mounted'): string mkdir($directory . '/house'); file_put_contents($directory . '/house/theme.yml', (string) file_get_contents(masterTheme() . '/theme.yml')); - file_put_contents($directory . '/house/layouts.yml', (string) file_get_contents(masterTheme() . '/layouts.yml')); return $directory; } @@ -165,7 +164,6 @@ function unmountedTheme(string $prefix = 'mounted'): string // staged into one — and the deck is drawn in the same geometry all the same. $finder = new MemoryFinder([ 'house/theme.yml' => (string) file_get_contents(masterTheme() . '/theme.yml'), - 'house/layouts.yml' => (string) file_get_contents(masterTheme() . '/layouts.yml'), 'house/template.pptx' => (string) file_get_contents(masterTheme() . '/template.pptx'), ]); @@ -188,7 +186,6 @@ function unmountedTheme(string $prefix = 'mounted'): string $finder = new MemoryFinder([ 'house/theme.yml' => (string) file_get_contents(masterTheme() . '/theme.yml'), - 'house/layouts.yml' => (string) file_get_contents(masterTheme() . '/layouts.yml'), 'house/template.pptx' => (string) file_get_contents(masterTheme() . '/template.pptx'), ]); @@ -209,7 +206,6 @@ function unmountedTheme(string $prefix = 'mounted'): string $finder = new MemoryFinder([ 'house/theme.yml' => (string) file_get_contents(masterTheme() . '/theme.yml'), - 'house/layouts.yml' => (string) file_get_contents(masterTheme() . '/layouts.yml'), 'house/template.pptx' => (string) file_get_contents(masterTheme() . '/template.pptx'), ]); @@ -230,7 +226,6 @@ function unmountedTheme(string $prefix = 'mounted'): string // refused — and the deck is not drawn at all. $finder = new MasterlessSource([ 'house/theme.yml' => (string) file_get_contents(masterTheme() . '/theme.yml'), - 'house/layouts.yml' => (string) file_get_contents(masterTheme() . '/layouts.yml'), ]); $path = Scratch::file('master-unserved.pptx', ''); @@ -285,7 +280,6 @@ function unmountedTheme(string $prefix = 'mounted'): string // this library puts it at, and nothing is said about a master that was never there. $finder = new MemoryFinder([ 'house/theme.yml' => (string) file_get_contents(masterTheme() . '/theme.yml'), - 'house/layouts.yml' => (string) file_get_contents(masterTheme() . '/layouts.yml'), ]); $path = Scratch::file('no-master.pptx', ''); @@ -305,7 +299,6 @@ function unmountedTheme(string $prefix = 'mounted'): string // it is given back at the end of the render, and the render after that writes it again. $finder = new MemoryFinder([ 'house/theme.yml' => (string) file_get_contents(masterTheme() . '/theme.yml'), - 'house/layouts.yml' => (string) file_get_contents(masterTheme() . '/layouts.yml'), 'house/template.pptx' => (string) file_get_contents(masterTheme() . '/template.pptx'), ]); diff --git a/tests/Unit/metric.php b/tests/Unit/metric.php index e2e2b73..ad7ef95 100644 --- a/tests/Unit/metric.php +++ b/tests/Unit/metric.php @@ -70,8 +70,10 @@ function measuredIn(string $theme, string $markdown): Pptx function themeNamingMono(string $face): string { return ThemeDirectory::create([ - 'theme.yml' => sprintf("name: Mono\nfonts:\n mono: \"%s\"\n", $face), - 'layouts.yml' => "layouts:\n title: Title Slide\n content: Title and Content\n", + 'theme.yml' => sprintf( + "name: Mono\nfonts:\n mono: \"%s\"\nlayouts:\n title: Title Slide\n content: Title and Content\n", + $face, + ), ]); } @@ -464,8 +466,8 @@ function renderedIn(string $theme, bool $strict = false): PresentationRenderer function themeWithAnUnknownFace(): string { return ThemeDirectory::create([ - 'theme.yml' => "name: Odd\nfonts:\n heading: \"Comic Sans MS\"\n body: \"Comic Sans MS\"\n", - 'layouts.yml' => "layouts:\n title: Title Slide\n content: Title and Content\n", + 'theme.yml' => "name: Odd\nfonts:\n heading: \"Comic Sans MS\"\n body: \"Comic Sans MS\"\n" + . "layouts:\n title: Title Slide\n content: Title and Content\n", ]); } diff --git a/tests/Unit/powerpoint-fixtures.php b/tests/Unit/powerpoint-fixtures.php index 7abd4ee..0285ab4 100644 --- a/tests/Unit/powerpoint-fixtures.php +++ b/tests/Unit/powerpoint-fixtures.php @@ -36,9 +36,10 @@ function powerpointFixtures(): string /* * The layout names both decks carry, as PowerPoint spells them. * - * A `layouts.yml` matches a template by the name its layout part carries, so these two strings - * are the whole interface between the two, and a theme that spells one differently stops matching - * with nothing to say so. Spelled once here rather than at every place a test happens to need one. + * A theme's `layouts:` section matches a template by the name its layout part carries, so these + * two strings are the whole interface between the two, and a theme that spells one differently + * stops matching with nothing to say so. Spelled once here rather than at every place a test + * happens to need one. */ const PICTURE_WITH_CAPTION = 'Picture with Caption'; @@ -169,8 +170,7 @@ function workshopNotes(): string // not write: the layout part the deck is given and the slide on it agree, so *Reset* // restores what the slide already has. $theme = ThemeDirectory::create([ - 'theme.yml' => HARBOUR_THEME, - 'layouts.yml' => "layouts:\n content: Title and Content\n", + 'theme.yml' => HARBOUR_THEME . "layouts:\n content: Title and Content\n", 'template.pptx' => file_get_contents(harbourLights()), ]); @@ -193,8 +193,7 @@ function workshopNotes(): string // all and one whose theme is this deck are visibly different files, which is the point of // carrying it. $theme = ThemeDirectory::create([ - 'theme.yml' => "name: Workshop\n", - 'layouts.yml' => "layouts:\n content: Title and Content\n", + 'theme.yml' => "name: Workshop\nlayouts:\n content: Title and Content\n", 'template.pptx' => file_get_contents(workshopNotes()), ]); @@ -213,8 +212,7 @@ function workshopNotes(): string it('draws both columns of a two-content slide where a real deck puts them', function () { $theme = ThemeDirectory::create([ - 'theme.yml' => HARBOUR_THEME, - 'layouts.yml' => "layouts:\n two-column: Two Content\n", + 'theme.yml' => HARBOUR_THEME . "layouts:\n two-column: Two Content\n", 'template.pptx' => file_get_contents(harbourLights()), ]); @@ -234,14 +232,13 @@ function workshopNotes(): string it('leaves a role whose layout the deck does not have where the library puts it', function () { // The precedence is the same as it is for a written template: a template fills in the roles - // it covers and says nothing about the rest. A `layouts.yml` naming a layout the deck does - // not have is therefore not an error — it is a role kept where the library puts it, which is - // the only thing a half-matched theme can mean. + // it covers and says nothing about the rest. A `layouts:` section naming a layout the deck + // does not have is therefore not an error — it is a role kept where the library puts it, + // which is the only thing a half-matched theme can mean. $theme = ThemeDirectory::create([ - 'theme.yml' => HARBOUR_THEME, // A section mapped to a layout neither deck has, which is the ordinary way a theme is // written and then used against a deck nobody checked it against. - 'layouts.yml' => "layouts:\n content: Title and Content\n section: Section Divider\n", + 'theme.yml' => HARBOUR_THEME . "layouts:\n content: Title and Content\n section: Section Divider\n", 'template.pptx' => file_get_contents(harbourLights()), ]); @@ -258,7 +255,8 @@ function workshopNotes(): string }); it('names nothing in either deck that PowerPoint did not write', function () { - // A `layouts.yml` matches a template by the name its layout part carries, so the names are + // A theme's `layouts:` section matches a template by the name its layout part carries, so + // the names are // the whole interface. They are checked here as a list because a rename in PowerPoint would // otherwise show up as a theme that silently stops matching: no error, and a deck drawn in // the library's geometry rather than the deck's. diff --git a/tests/Unit/rendering.php b/tests/Unit/rendering.php index fe177d6..16fc714 100644 --- a/tests/Unit/rendering.php +++ b/tests/Unit/rendering.php @@ -334,8 +334,7 @@ function ico(): string // The theme of a deck is in the deck's own directory, and the process rendering the // deck is somewhere else: a deck rendered by its path finds its theme either way. $directory = ThemeDirectory::create([ - 'themes/bakery/theme.yml' => "name: Bakery\n", - 'themes/bakery/layouts.yml' => "layouts:\n content: Title and Content\n", + 'themes/bakery/theme.yml' => "name: Bakery\nlayouts:\n content: Title and Content\n", ], 'deck'); $pptx = renderDeck("---\ntheme: bakery\n---\n\n# One\n", $directory); @@ -349,8 +348,7 @@ function ico(): string // path is: `theme: ./theme.yml` names the manifest next to the deck, and a build // script that renders a deck by its path must not have to change directory first. $directory = ThemeDirectory::create([ - 'theme.yml' => "name: Beside\n", - 'layouts.yml' => "layouts:\n content: Title and Content\n", + 'theme.yml' => "name: Beside\nlayouts:\n content: Title and Content\n", ], 'deck'); $pptx = renderDeck("---\ntheme: ./theme.yml\n---\n\n# One\n", $directory); @@ -1909,7 +1907,7 @@ function ico(): string UnknownDirective::class, 'The frontmatter of slide 1 names "transition", which is not a directive. ' . 'The directives are: title, name, level, layout, theme, author, description, template, templates-file, ' - . 'template-settings, background, background-gradient, background-angle, background-radial, theme-variables.', + . 'template-settings, deck-settings, background, background-gradient, background-angle, background-radial, theme-variables.', ); }); diff --git a/tests/Unit/template.php b/tests/Unit/template.php index 70e2fa0..9220b40 100644 --- a/tests/Unit/template.php +++ b/tests/Unit/template.php @@ -29,10 +29,10 @@ const TEMPLATED_PPTX = '/template.pptx'; /** - * The layouts mapping a theme built for these tests writes, and the layout name it maps to. + * The `layouts:` section a theme built for these tests writes. * - * Both are constants rather than literals because every test below that builds a theme maps - * the same role onto the same layout: a test that mapped `content` somewhere else would be + * A constant rather than a literal because every test below that builds a theme maps the + * same role onto the same layout: a test that mapped `content` somewhere else would be * testing something else, and spelling it out each time is how that happens quietly. */ const CONTENT_LAYOUT = "layouts:\n content: Title and Content\n"; @@ -247,8 +247,7 @@ function templateThatLiesAboutItsPart(): string // used to get wrong too — it asked the constructor's default geometry rather than the // merged one, so the second box was laid out and left empty with nothing saying so. $theme = ThemeDirectory::create([ - 'theme.yml' => "name: Two Columns\n", - 'layouts.yml' => "layouts:\n content: Two Content\n", + 'theme.yml' => "name: Two Columns\nlayouts:\n content: Two Content\n", 'template.pptx' => file_get_contents(templatedTheme() . TEMPLATED_PPTX), ]); @@ -342,8 +341,7 @@ function templateThatLiesAboutItsPart(): string // Every box in a template is a fraction of its page, so one that does not state a page // cannot place anything. `p:sldSz` is optional in the schema and this is what that costs. $theme = ThemeDirectory::create([ - 'theme.yml' => "name: Sizeless\n", - 'layouts.yml' => CONTENT_LAYOUT, + 'theme.yml' => "name: Sizeless\n" . CONTENT_LAYOUT, // The contents, not the path: this copies a file into a theme directory rather than // naming one. 'template.pptx' => file_get_contents(builtTemplate(page: ['cx' => 0, 'cy' => 0])), @@ -387,8 +385,7 @@ function templateThatLiesAboutItsPart(): string it('refuses a template with a part it cannot read', function () { $theme = ThemeDirectory::create([ - 'theme.yml' => "name: Broken\n", - 'layouts.yml' => CONTENT_LAYOUT, + 'theme.yml' => "name: Broken\n" . CONTENT_LAYOUT, ]); $zip = new ZipArchive(); @@ -459,8 +456,7 @@ function templateThatLiesAboutItsPart(): string // The refusal has to reach the caller of the library and not only the reader, or a render ends // in a fatal error that names neither the theme nor the part. $theme = ThemeDirectory::create([ - 'theme.yml' => "name: Oversized\n", - 'layouts.yml' => CONTENT_LAYOUT, + 'theme.yml' => "name: Oversized\n" . CONTENT_LAYOUT, 'template.pptx' => (string) file_get_contents(templateWithPartOf(TemplateGeometry::MAX_PART_BYTES + 1)), ]); @@ -475,8 +471,7 @@ function templateThatLiesAboutItsPart(): string // inherit, so its placeholders have nowhere to come from and the role keeps the geometry // the library puts it at — rather than this reading a master it was never told about. $theme = ThemeDirectory::create([ - 'theme.yml' => "name: Orphaned\n", - 'layouts.yml' => CONTENT_LAYOUT, + 'theme.yml' => "name: Orphaned\n" . CONTENT_LAYOUT, 'template.pptx' => file_get_contents(builtTemplate( [['name' => TITLE_AND_CONTENT, 'shapes' => [['type' => 'title']]]], layoutHasMaster: false, diff --git a/tests/Unit/text-styles.php b/tests/Unit/text-styles.php index 362935b..d3c6d84 100644 --- a/tests/Unit/text-styles.php +++ b/tests/Unit/text-styles.php @@ -25,12 +25,6 @@ */ const TEXT_STYLE_THEME = "name: Acme\ncolors:\n accent1: \"#00B4D8\"\n"; -/** - * The layouts the theme needs, because a theme that maps no `content` role cannot draw a - * slide at all. - */ -const TEXT_STYLE_LAYOUTS = "layouts:\n content: Title and Content\n blank: Blank\n"; - /** * The box the wordmark is drawn in, which has a colour of its own. * @@ -41,20 +35,17 @@ const WORDMARK_BOX = 'left=4.5% top=3.913% width=29.996% height=4.969% fill=none padding=0 color=FFFFFF font-size=11'; /** - * A theme directory with the named styles beside it, or without the file at all. + * A theme directory whose own file carries the named styles, or carries none at all. */ function textStyleTheme(?string $styles): string { - $files = [ - 'theme.yml' => TEXT_STYLE_THEME, - 'layouts.yml' => TEXT_STYLE_LAYOUTS, - ]; + $theme = TEXT_STYLE_THEME; if ($styles !== null) { - $files['text-styles.yml'] = $styles; + $theme .= "textStyles:\n" . preg_replace('/^/m', ' ', rtrim($styles, "\n")) . "\n"; } - return ThemeDirectory::create($files, 'text-style'); + return ThemeDirectory::create(['theme.yml' => $theme], 'text-style'); } /** @@ -193,6 +184,25 @@ function wordmarkIn(string $face): string ]); }); +it('draws a named style on a slide that lays values over the theme', function () { + // The named styles are the theme's own and not among the values a slide may lay over + // it, so a slide that lays values over the theme keeps them: they travel beside the + // round trip rather than among the values it carries. The colour the style names is + // resolved against the slide's own theme, so the accent the slide moved is the accent + // the word is drawn in. + $directory = textStyleTheme("brand:\n color: accent1\n"); + + $deck = sprintf( + "---\ntheme: ./theme.yml\ntheme-variables:\n colors:\n accent1: \"#123456\"\n---\n\n:::content{%s}\nResilience :brand[Bakery]\n:::\n", + WORDMARK_BOX, + ); + + expect(runColours(styledDeck($deck, $directory)))->toBe([ + 'Resilience ' => ['colour' => 'FFFFFF', 'size' => 11], + 'Bakery' => ['colour' => '123456', 'size' => 11], + ]); +}); + it('sets the weight a style names, and leaves the rest of the run to the box', function () { [$deck, $directory] = wordmark("brand:\n color: accent1\n bold: true\n", ':brand[Bakery]'); @@ -311,7 +321,7 @@ function wordmarkIn(string $face): string [$raw, $rawDirectory] = wordmark("brand:\n color: accent1\n", ':style[**Bakery**]{bold=true}'); expect(fn () => styledDeck($named, $namedDirectory)) - ->toThrow(MalformedTextStyle::class, 'give the style the weight in the theme\'s "text-styles.yml" ("brand: { bold: true }")') + ->toThrow(MalformedTextStyle::class, 'give the style the weight in the theme\'s "textStyles:" section ("brand: { bold: true }")') ->and(fn () => styledDeck($raw, $rawDirectory)) ->toThrow(MalformedTextStyle::class, 'give the style the weight as an attribute ("bold=true")'); }); diff --git a/tests/Unit/theme-finder.php b/tests/Unit/theme-finder.php index 5c57147..f37ed3b 100644 --- a/tests/Unit/theme-finder.php +++ b/tests/Unit/theme-finder.php @@ -48,26 +48,23 @@ function finderResolver(?FileFinder $files = null, array $roots = []): ThemeReso // and never had a directory to hand over. The theme comes back the same way it // would from a directory. $finder = new MemoryFinder([ - 'house/theme.yml' => "name: House\n", - 'house/styles.yml' => "heading.1: ReportTitle\n", - 'house/layouts.yml' => "layouts:\n content: Title and Content\n", + 'house/theme.yml' => "name: House\nlayouts:\n content: Title and Content\n", ]); $theme = (new ThemeLoader())->load('house', 'house', $finder); expect($theme->theme()->name())->toBe('House') - ->and($theme->styles())->toBe(['heading.1' => 'ReportTitle']) ->and($theme->layouts())->toBe(['content' => 'Title and Content']) // A finder with no path has no directory, and the theme's name stands in. ->and($theme->directory())->toBe('house'); }); it('asks the finder for the theme\'s files by name', function () { - // The names are the library's own: a theme's manifest is `/theme.yml` and - // the files beside it are `/styles.yml` and the rest. + // The names are the library's own: a theme's manifest is `/theme.yml`, the + // master beside it is `/template.pptx`, and the files of the old format are + // asked for as well — the loader has to find out whether a theme carries one. $finder = new MemoryFinder([ 'house/theme.yml' => "name: House\n", - 'house/styles.yml' => "heading.1: ReportTitle\n", ]); (new ThemeLoader())->load('house', 'house', $finder); @@ -88,13 +85,11 @@ function finderResolver(?FileFinder $files = null, array $roots = []): ThemeReso it('resolves a theme the source holds and no directory has', function () { $finder = new MemoryFinder([ 'house/theme.yml' => "name: House\n", - 'house/styles.yml' => "heading.1: ReportTitle\n", ]); $theme = finderResolver($finder)->resolve('house'); - expect($theme->theme()->name())->toBe('House') - ->and($theme->styles())->toBe(['heading.1' => 'ReportTitle']); + expect($theme->theme()->name())->toBe('House'); }); it('refuses a theme file that resolves outside the scope, in the library\'s words', function () { @@ -216,7 +211,6 @@ public function files(string $theme): array // not once for the name and once for the deck. $finder = new MemoryFinder([ 'house/theme.yml' => "name: House\n", - 'house/layouts.yml' => "layouts:\n content: Title and Content\n", ]); $renderer = (new PresentationRenderer(themes: finderResolver($finder)))->withTheme('house'); diff --git a/tests/Unit/theme-loader.php b/tests/Unit/theme-loader.php index 45f4e98..cca45f2 100644 --- a/tests/Unit/theme-loader.php +++ b/tests/Unit/theme-loader.php @@ -2,12 +2,15 @@ declare(strict_types=1); +use MarkdownPresentation\Document\DeckParser; use MarkdownPresentation\Exception\Exception; use MarkdownPresentation\Exception\MalformedTheme; +use MarkdownPresentation\Exception\RetiredThemeFile; use MarkdownPresentation\Exception\ThemeNotFound; use MarkdownPresentation\Exception\UnknownLayoutRole; -use MarkdownPresentation\Exception\UnknownStyleSlot; use MarkdownPresentation\Filesystem\PathScope; +use MarkdownPresentation\Render\PresentationRenderer; +use MarkdownPresentation\Tests\Support\Pptx; use MarkdownPresentation\Tests\Support\Scratch; use MarkdownPresentation\Tests\Support\ThemeDirectory; use MarkdownPresentation\Theme\ThemeLoader; @@ -17,44 +20,156 @@ expect($loaded->theme()->name())->toBe('acme') ->and($loaded->directory())->toEndWith('/' . basename($loaded->directory())) - ->and($loaded->styles())->toBe([]) - ->and($loaded->layouts())->toBe([]) ->and($loaded->template())->toBeNull(); }); -it('reads the style slots and the layout roles beside a theme.yml', function () { - $loaded = ThemeDirectory::load(ThemeDirectory::acme([ - 'styles.yml' => "heading.1: ReportTitle\nparagraph: BodyText\ncodeFont:\n name: Fira Code\n size: 10\n", - 'layouts.yml' => "layouts:\n title: Title Slide\n two-column: Two Content\n", - ])); +it('maps every role the library maps when the theme names no layouts', function () { + // A theme with no `layouts:` section is drawn with the library's own mapping, which is + // the one every theme shipping with this library carried in a file of its own. + $loaded = ThemeDirectory::load(ThemeDirectory::minimal('acme')); + + expect($loaded->layouts())->toBe([ + 'title' => 'Title Slide', + 'content' => 'Title and Content', + 'two-column' => 'Two Content', + 'section' => 'Section Header', + 'blank' => 'Blank', + 'image-text' => 'Picture Left', + 'image-title' => 'Picture with Caption', + 'image-slide' => 'Full Bleed Picture', + ]) + ->and($loaded->roles())->toBe([ + 'title', 'content', 'two-column', 'section', 'blank', 'image-text', 'image-title', 'image-slide', + ]); +}); + +it('reads the layout roles a theme\'s own file carries', function () { + $loaded = ThemeDirectory::load(ThemeDirectory::withManifest( + "name: Acme\nlayouts:\n title: Deck Title\n content: Body Text\n", + )); + + expect($loaded->layouts())->toBe(['title' => 'Deck Title', 'content' => 'Body Text']) + ->and($loaded->roles())->toBe(['title', 'content']); +}); + +it('reads the named styles a theme\'s own file carries', function () { + $loaded = ThemeDirectory::load(ThemeDirectory::withManifest( + "name: Acme\ntextStyles:\n brand:\n color: accent1\n bold: true\n", + )); + + expect($loaded->theme()->textStyles()->names())->toBe(['brand']) + ->and($loaded->theme()->textStyles()->get('brand')?->colour)->toBe('accent1') + ->and($loaded->theme()->textStyles()->get('brand')?->bold)->toBeTrue(); +}); + +it('draws a deck with the roles and the named styles a theme\'s own file carries', function () { + // The two sections are read out of the theme's own file and reach the deck: the layout + // part is named by the theme's mapping, and a word written in a named style is drawn + // in it. + $directory = ThemeDirectory::withManifest( + "name: Acme\nlayouts:\n content: Body Text\ntextStyles:\n brand:\n color: \"#00B4D8\"\n", + ); - expect($loaded->styles())->toBe([ - 'heading.1' => 'ReportTitle', - 'paragraph' => 'BodyText', - 'codeFont' => ['name' => 'Fira Code', 'size' => 10], - ])->and($loaded->layouts())->toBe(['title' => 'Title Slide', 'two-column' => 'Two Content']) - ->and($loaded->roles())->toBe(['title', 'two-column']); + $deck = (new DeckParser())->parse(sprintf( + "---\ntheme: %s\n---\n\n:::content{color=FFFFFF}\nA :brand[word]\n:::\n", + $directory, + )); + + $path = Scratch::file('deck.pptx', ''); + + (new PresentationRenderer())->render($deck, $path); + + $pptx = Pptx::open($path); + + expect($pptx->layoutNames())->toBe([1 => 'Body Text']) + ->and($pptx->part('ppt/slides/slide1.xml'))->toContain(''); }); -it('reads a layouts file whose mappings stand on their own', function () { - $loaded = ThemeDirectory::load(ThemeDirectory::acme([ - 'layouts.yml' => "title: Title Slide\nblank: Blank\n", +it('refuses a layouts section that names a role which is not one', function () { + ThemeDirectory::load(ThemeDirectory::withManifest("name: Acme\nlayouts:\n two-columns: Two Content\n")); +})->throws(UnknownLayoutRole::class, '"two-columns" is not a layout role. The roles are: title, content, two-column, section, blank, image-text, image-title, image-slide'); + +it('refuses a layouts section that does not hold the mappings', function () { + ThemeDirectory::load(ThemeDirectory::withManifest("name: Acme\nlayouts: Two Content\n")); +})->throws(UnknownLayoutRole::class, '"layouts" is not a mapping of roles to layout names'); + +it('refuses a role mapped to nothing', function () { + ThemeDirectory::load(ThemeDirectory::withManifest("name: Acme\nlayouts:\n title:\n")); +})->throws(UnknownLayoutRole::class, 'the "title" role is not a layout name'); + +it('names the roles a theme does have when the one asked for is not one of them', function () { + // The section is the whole mapping rather than a layer over the library's own, so a + // role it leaves out is a role the theme does not map — and the failure names the ones + // it does, because the fix is in the message. + $loaded = ThemeDirectory::load(ThemeDirectory::withManifest( + "name: Acme\nlayouts:\n title: Title Slide\n blank: Blank\n", + )); + + $loaded->layout('section'); +})->throws(UnknownLayoutRole::class, 'The theme "Acme" maps no "section" layout. It maps: title, blank'); + +it('says a theme whose layouts section names no role maps none', function () { + $loaded = ThemeDirectory::load(ThemeDirectory::withManifest("name: Acme\nlayouts: {}\n")); + + $loaded->layout('content'); +})->throws(UnknownLayoutRole::class, 'The theme "Acme" maps no "content" layout. It maps: (none — its "layouts" section maps no role)'); + +it('refuses a layouts.yml beside a theme, and names the section to move it into', function () { + ThemeDirectory::load(ThemeDirectory::acme([ + 'layouts.yml' => "layouts:\n title: Title Slide\n", + ])); +})->throws(RetiredThemeFile::class, 'has a "layouts.yml" beside it. A theme is one file: move its content into the "layouts:" section of its "theme.yml", and delete the file.'); + +it('refuses a text-styles.yml beside a theme, and names the section to move it into', function () { + ThemeDirectory::load(ThemeDirectory::acme([ + 'text-styles.yml' => "brand:\n color: accent1\n", ])); +})->throws(RetiredThemeFile::class, 'has a "text-styles.yml" beside it. A theme is one file: move its content into the "textStyles:" section of its "theme.yml", and delete the file.'); + +it('refuses the file beside a theme, not the content it holds', function () { + // The message asks for two things — the content moved and the file deleted — because + // the refusal is about the file being there: a theme that already carries the section + // is read, and the same theme with the file beside it is refused as well. + $manifest = "name: Acme\nlayouts:\n title: Title Slide\n"; + + $read = ThemeDirectory::load(ThemeDirectory::withManifest($manifest)); - expect($loaded->layout('blank'))->toBe('Blank'); + expect($read->layouts())->toBe(['title' => 'Title Slide']); + + expect(fn () => ThemeDirectory::load(ThemeDirectory::withManifest($manifest, [ + 'layouts.yml' => "layouts:\n title: Title Slide\n", + ])))->toThrow(RetiredThemeFile::class, 'has a "layouts.yml" beside it.'); }); +it('refuses a styles.yml beside a theme, and says which half the file belongs to', function () { + // The file is the Word half's, and this half has never drawn a slide with it: the + // slots name Word styles, and a deck of slides has no use for them. + ThemeDirectory::load(ThemeDirectory::acme([ + 'styles.yml' => "heading.1: Heading1\n", + ])); +})->throws(RetiredThemeFile::class, 'has a "styles.yml" beside it. That file is the Word half\'s, and this half does not read it'); + +it('refuses a key in the theme\'s own file that is neither a value nor a section', function () { + ThemeDirectory::load(ThemeDirectory::withManifest("name: Acme\ncolourz:\n accent1: \"#123456\"\n")); +})->throws(MalformedTheme::class, '"colourz" is not a key of a theme. Valid keys: name, description, author, dark, colors, fonts, style, layouts, textStyles.'); + +it('refuses the Word half\'s styles section, which this half does not know', function () { + ThemeDirectory::load(ThemeDirectory::withManifest("name: Acme\nstyles:\n heading.1: Heading1\n")); +})->throws(MalformedTheme::class, '"styles" is not a key of a theme. Valid keys: name, description, author, dark, colors, fonts, style, layouts, textStyles.'); + +it('refuses a textStyles section that is not a mapping of styles', function () { + ThemeDirectory::load(ThemeDirectory::withManifest("name: Acme\ntextStyles:\n - brand\n")); +})->throws(MalformedTheme::class, '"textStyles" is not a mapping of style names to text styles'); + it('says a directory with no theme.yml is not a theme', function () { - ThemeDirectory::load(ThemeDirectory::create(['layouts.yml' => "title: Title Slide\n"], 'not-a-theme')); + ThemeDirectory::load(ThemeDirectory::create(['notes.txt' => 'not a theme'], 'not-a-theme')); })->throws(ThemeNotFound::class, 'is not a theme: it has no theme.yml'); it('reads a theme from the manifest file that describes it', function () { // The manifest is the theme, and the rest of the theme is read from beside it: a // theme is a directory, and the manifest is the one file that directory cannot do // without. - $directory = ThemeDirectory::acme([ - 'layouts.yml' => "layouts:\n content: Title and Content\n", - ]); + $directory = ThemeDirectory::withManifest("name: Acme\nlayouts:\n content: Title and Content\n"); $loaded = ThemeDirectory::loadManifest($directory); @@ -75,67 +190,10 @@ ThemeDirectory::loadManifest($directory); })->throws(ThemeNotFound::class, 'is not a theme: it has no theme.yml'); -it('hands a style value back as it was written, tokens and all', function () { - // A `styles.yml` may already reference a theme token. Resolving them is not - // written yet, so the value passes through exactly as the file has it rather - // than losing the reference. - $loaded = ThemeDirectory::load(ThemeDirectory::acme([ - 'styles.yml' => "linkFont:\n color: \"{accent1}\"\n name: \"{fonts.mono}\"\n", - ])); - - expect($loaded->styles())->toBe(['linkFont' => ['color' => '{accent1}', 'name' => '{fonts.mono}']]); -}); - -it('refuses a styles.yml slot that is not a style slot, and names the slots that are', function () { - // The shipped fixture, so the README can show the same failure from the same - // file rather than a directory built for the occasion. - $directory = dirname(__DIR__) . '/fixtures/themes/broken'; - - ThemeDirectory::load($directory); -})->throws(UnknownStyleSlot::class, '"blockquote" is not a style slot. The slots are: heading.1, heading.2'); - -it('refuses a layouts.yml role that is not a role, and names the roles that are', function () { - ThemeDirectory::load(ThemeDirectory::acme([ - 'layouts.yml' => "layouts:\n two-columns: Two Content\n", - ])); -})->throws(UnknownLayoutRole::class, '"two-columns" is not a layout role. The roles are: title, content, two-column, section, blank, image-text, image-title, image-slide'); - -it('refuses a key beside the mappings that is not one', function () { - ThemeDirectory::load(ThemeDirectory::acme([ - 'layouts.yml' => "layouts:\n title: Title Slide\nlayout: Two Content\n", - ])); -})->throws(UnknownLayoutRole::class, '"layout" is not a key of a layouts file. Valid keys: layouts'); - -it('refuses a layouts key that does not hold the mappings', function () { - ThemeDirectory::load(ThemeDirectory::acme([ - 'layouts.yml' => "layouts: Two Content\n", - ])); -})->throws(UnknownLayoutRole::class, '"layouts" is not a mapping of roles to layout names'); - -it('refuses a role mapped to nothing', function () { - ThemeDirectory::load(ThemeDirectory::acme([ - 'layouts.yml' => "layouts:\n title:\n", - ])); -})->throws(UnknownLayoutRole::class, 'the "title" role is not a layout name'); - -it('refuses a styles file that is not YAML', function () { - ThemeDirectory::load(ThemeDirectory::acme([ - 'styles.yml' => "heading.1: \"unclosed\n", - ])); +it('refuses a theme.yml that is not YAML', function () { + ThemeDirectory::load(ThemeDirectory::create(['theme.yml' => "heading.1: \"unclosed\n"])); })->throws(Exception::class, 'is not valid YAML'); -it('refuses a styles file that is not a mapping of slots', function () { - ThemeDirectory::load(ThemeDirectory::acme([ - 'styles.yml' => "- heading.1\n", - ])); -})->throws(MalformedTheme::class, 'The file does not contain a mapping of style slots to styles'); - -it('refuses a layouts file that is not a mapping of roles', function () { - ThemeDirectory::load(ThemeDirectory::acme([ - 'layouts.yml' => "- title\n", - ])); -})->throws(MalformedTheme::class, 'The file does not contain a mapping of layout roles to layout names'); - it('says a file it cannot read is a file it cannot read', function () { skipWithoutPermissions('The unreadable file'); @@ -154,29 +212,17 @@ ThemeDirectory::load(ThemeDirectory::create(['theme.yml' => "Corporate Dark\n"])); })->throws(MalformedTheme::class, 'The file does not contain a theme — it is a string'); -it('reads a file with nothing in it as a file with nothing in it', function () { - // An empty styles file is a theme that overrides nothing, which is a fact about - // the theme rather than a mistake in it. - $loaded = ThemeDirectory::load(ThemeDirectory::acme([ - 'styles.yml' => '', - ])); - - expect($loaded->styles())->toBe([]); -}); - -it('names a theme that has no layouts.yml when a role cannot be resolved', function () { - $loaded = ThemeDirectory::load(ThemeDirectory::minimal('acme')); - - $loaded->layout('content'); -})->throws(UnknownLayoutRole::class, 'The theme "acme" maps no "content" layout. It maps: (none — the theme has no layouts.yml)'); +it('refuses a theme.yml with nothing in it, because a theme has a name', function () { + ThemeDirectory::load(ThemeDirectory::create(['theme.yml' => ''], 'empty-theme')); +})->throws(MalformedTheme::class, 'A theme needs a "name".'); -it('names the roles a theme does have when the one asked for is not one of them', function () { - $loaded = ThemeDirectory::load(ThemeDirectory::acme([ - 'layouts.yml' => "layouts:\n title: Title Slide\n blank: Blank\n", - ])); +it('reads a theme whose own file names no text styles as a theme with none', function () { + // An empty section is a theme that names no styles, which is a fact about the theme + // rather than a mistake in it. + $loaded = ThemeDirectory::load(ThemeDirectory::withManifest("name: Acme\ntextStyles: {}\n")); - $loaded->layout('section'); -})->throws(UnknownLayoutRole::class, 'The theme "Acme" maps no "section" layout. It maps: title, blank'); + expect($loaded->theme()->textStyles()->names())->toBe([]); +}); it('refuses a layout name that is not a role at all', function () { $loaded = ThemeDirectory::load(ThemeDirectory::minimal('acme')); @@ -185,10 +231,10 @@ })->throws(UnknownLayoutRole::class, '"Two Content" is not a layout role. The roles are: title, content, two-column, section, blank, image-text, image-title, image-slide'); it('turns a role into the layout name of the theme\'s own template', function () { - $loaded = ThemeDirectory::load(ThemeDirectory::acme([ - 'layouts.yml' => "layouts:\n two-column: Two Content\n", - 'template.pptx' => 'not really a template', - ])); + $loaded = ThemeDirectory::load(ThemeDirectory::withManifest( + "name: Acme\nlayouts:\n two-column: Two Content\n", + ['template.pptx' => 'not really a template'], + )); expect($loaded->layout('two-column'))->toBe('Two Content') ->and($loaded->template()?->path())->toBe($loaded->directory() . '/template.pptx'); @@ -227,18 +273,18 @@ // The scope is what makes the check; without one the loader reads what it is // given, which is what a theme this library ships is and what a caller naming a // directory of its own is asking for. - $outside = ThemeDirectory::create(['styles.yml' => "heading.1: ReportTitle\n"], 'outside'); + $outside = ThemeDirectory::create(['theme.yml' => "name: Linked\n"], 'outside'); $directory = ThemeDirectory::acme(); - ThemeDirectory::link($directory . '/styles.yml', $outside . '/styles.yml'); + ThemeDirectory::link($directory . '/theme.yml', $outside . '/theme.yml'); - expect(ThemeDirectory::load($directory)->styles())->toBe(['heading.1' => 'ReportTitle']); + expect(ThemeDirectory::load($directory)->theme()->name())->toBe('Linked'); }); it('reads a manifest the deck named, whatever the file it reached is called', function () { // The resolver resolves a path before it hands it over, so the loader is given the // file the path reached, whose name is the target's rather than the one the deck - // wrote. The name the deck wrote is what makes a file the manifest of a theme, so - // the file is read rather than refused for the name it happens to have. + // wrote. The name the deck wrote is what makes a file the manifest of a theme, so the + // file is read rather than refused for the name it happens to have. $directory = ThemeDirectory::create(['other.yml' => "name: Linked\n"], 'manifest'); ThemeDirectory::link($directory . '/theme.yml', $directory . '/other.yml'); diff --git a/tests/Unit/theme-resolver.php b/tests/Unit/theme-resolver.php index 38cd0be..3ab00a9 100644 --- a/tests/Unit/theme-resolver.php +++ b/tests/Unit/theme-resolver.php @@ -66,8 +66,7 @@ function resolverIn(string $workingDirectory): ThemeResolver // `theme: ./theme.yml` is the manifest rather than the directory holding it, and the // rest of the theme — the layouts, the styles, the template — is read from beside it. $directory = ThemeDirectory::create([ - 'theme.yml' => "name: Manifest\n", - 'layouts.yml' => "layouts:\n content: Title and Content\n", + 'theme.yml' => "name: Manifest\nlayouts:\n content: Title and Content\n", ], 'manifest'); $resolver = resolverIn($directory); @@ -94,8 +93,7 @@ function resolverIn(string $workingDirectory): ThemeResolver // rest of the theme is read from beside the file it reached. $deck = ThemeDirectory::create([ 'theme.yml' => "name: Manifest\n", - 'other.yml' => "name: Linked\n", - 'layouts.yml' => "layouts:\n content: Title and Content\n", + 'other.yml' => "name: Linked\nlayouts:\n content: Title and Content\n", ], 'manifest'); ThemeDirectory::link($deck . '/theme.yml', $deck . '/other.yml'); $resolver = resolverIn(ThemeDirectory::create([], 'working'))->beside($deck); @@ -264,8 +262,8 @@ function resolverIn(string $workingDirectory): ThemeResolver // author does reach the file. Without this the test above would also pass if the author // were never copied at all. $library = ThemeDirectory::create([ - 'theme.yml' => "name: Shared\nauthor: Somebody\n", - 'layouts.yml' => "layouts:\n title: Title Slide\n content: Title and Content\n", + 'theme.yml' => "name: Shared\nauthor: Somebody\n" + . "layouts:\n title: Title Slide\n content: Title and Content\n", ], 'library'); $working = ThemeDirectory::create([], 'working'); $builtin = ThemeDirectory::create([], 'builtin'); @@ -409,20 +407,17 @@ function resolverIn(string $workingDirectory): ThemeResolver ); }); -it('reads a theme whose files are all inside the roots', function () { +it('reads a theme whose own files are all inside the roots', function () { // The other half of the refusals above: a theme whose own files are where it says // they are is a theme that reads. $deck = ThemeDirectory::create([ - 'themes/acme/theme.yml' => "name: Acme\n", - 'themes/acme/styles.yml' => "heading.1: ReportTitle\n", - 'themes/acme/layouts.yml' => "layouts:\n content: Title and Content\n", + 'themes/acme/theme.yml' => "name: Acme\nlayouts:\n content: Title and Content\n", ], 'deck'); $resolver = resolverIn(ThemeDirectory::create([], 'working'))->beside($deck); $theme = $resolver->resolve('acme'); expect($theme->theme()->name())->toBe('Acme') - ->and($theme->styles())->toBe(['heading.1' => 'ReportTitle']) ->and($theme->layouts())->toBe(['content' => 'Title and Content']); }); @@ -430,14 +425,14 @@ function resolverIn(string $workingDirectory): ThemeResolver // A link is not a threat; where it points is. A theme laid out with links — one // file shared by two themes — is a theme that works. $deck = ThemeDirectory::create([ - 'themes/shared/styles.yml' => "heading.1: ReportTitle\n", + 'themes/shared/theme.yml' => "name: Shared\n", 'themes/acme/theme.yml' => "name: Acme\n", ], 'deck'); - ThemeDirectory::link($deck . '/themes/acme/styles.yml', $deck . '/themes/shared/styles.yml'); + ThemeDirectory::link($deck . '/themes/acme/theme.yml', $deck . '/themes/shared/theme.yml'); $resolver = resolverIn(ThemeDirectory::create([], 'working'))->beside($deck); - expect($resolver->resolve('acme')->styles())->toBe(['heading.1' => 'ReportTitle']); + expect($resolver->resolve('acme')->theme()->name())->toBe('Shared'); }); it('does not open a template outside the roots', function () { @@ -447,8 +442,7 @@ function resolverIn(string $workingDirectory): ThemeResolver // scope before it is handed over. $outside = ThemeDirectory::create(['template.pptx' => 'not really a template'], 'outside'); $deck = ThemeDirectory::create([ - 'themes/acme/theme.yml' => "name: Acme\n", - 'themes/acme/layouts.yml' => "layouts:\n content: Title and Content\n", + 'themes/acme/theme.yml' => "name: Acme\nlayouts:\n content: Title and Content\n", ], 'deck'); ThemeDirectory::link($deck . '/themes/acme/template.pptx', $outside . '/template.pptx'); $working = ThemeDirectory::create([], 'working'); diff --git a/tests/Unit/theme-style.php b/tests/Unit/theme-style.php index 6d01dd6..b79db99 100644 --- a/tests/Unit/theme-style.php +++ b/tests/Unit/theme-style.php @@ -11,7 +11,6 @@ use MarkdownPresentation\Theme\Theme; use MarkdownPresentation\Theme\ThemeMapping; use MarkdownPresentation\Theme\ThemeResolver; -use MarkdownPresentation\Theme\LayoutRole; use MarkdownPresentation\Tests\Support\Pptx; use MarkdownPresentation\Tests\Support\Scratch; @@ -50,17 +49,10 @@ function styledTheme(array $style, array $colors = []): Theme function themedDeck(Theme $theme, string $markdown = "---\ntheme: %s\n---\n\n# T\n\n## Sub\n\nBody.\n\n***\n"): Pptx { $directory = Scratch::directoryPath('theme'); - file_put_contents($directory . '/theme.yml', (string) json_encode(ThemeMapping::write($theme))); - // A theme with no `layouts.yml` maps no role at all, and a deck is written in the - // `content` role whether it says so or not — so the mappings a deck needs are the ones - // every shipped theme carries, and naming them here keeps what is under test the style. - file_put_contents($directory . '/layouts.yml', (string) json_encode([ - 'layouts' => array_combine( - LayoutRole::names(), - array_map(static fn (LayoutRole $role): string => ucwords(str_replace('-', ' ', $role->value)), LayoutRole::cases()), - ), - ])); + // A theme with no `layouts:` section is drawn with the library's own mapping, which + // covers every role, so what is under test here is the style and nothing else. + file_put_contents($directory . '/theme.yml', (string) json_encode(ThemeMapping::write($theme))); $path = Scratch::file('style.pptx', ''); diff --git a/tests/Unit/theme-text-styles.php b/tests/Unit/theme-text-styles.php index b268cbe..8ff768b 100644 --- a/tests/Unit/theme-text-styles.php +++ b/tests/Unit/theme-text-styles.php @@ -9,22 +9,24 @@ use MarkdownPresentation\Theme\Theme; /** - * The theme's named text styles: what a `text-styles.yml` says, and what the loader makes - * of it. + * The theme's named text styles: what a `textStyles:` section says, and what the loader + * makes of it. * * The styles are a theme's own vocabulary, and the loader is where a mistake in one is * caught: a theme that names an attribute nobody reads is a theme nobody wanted. */ /** - * A theme directory with the named text styles beside the manifest. + * A theme directory whose own file carries the named text styles. * * The manifest is the library's own, because the styles are what these tests are about and * a theme that shipped with one would put a second claim into every assertion. */ function themeWithTextStyles(string $styles): string { - return ThemeDirectory::acme(['text-styles.yml' => $styles], 'text-style'); + return ThemeDirectory::create([ + 'theme.yml' => "name: Acme\ntextStyles:\n" . preg_replace('/^/m', ' ', rtrim($styles, "\n")) . "\n", + ], 'text-style'); } it('reads the named styles a theme carries', function () { diff --git a/tests/Unit/theme-variables.php b/tests/Unit/theme-variables.php index 62cb3e4..a02ac68 100644 --- a/tests/Unit/theme-variables.php +++ b/tests/Unit/theme-variables.php @@ -14,7 +14,7 @@ * * The values are a `theme.yml`, so the vocabulary is the theme's own and the reader is the * theme's own. What is checked here is the merge: the slide's over the template's, the - * template's over the theme's, and one value over another leaving the rest alone. + * template's over the deck's, and one value over another leaving the rest alone. */ function variablesDeck(string $markdown): Pptx { @@ -26,27 +26,6 @@ function variablesDeck(string $markdown): Pptx return Pptx::open($path); } -/** The colours the words of a slide are drawn in, in the order the file lists them. */ -function inkOf(Pptx $pptx, int $slide = 1): array -{ - $xml = $pptx->part(sprintf('ppt/slides/slide%d.xml', $slide)); - preg_match_all('#]*>\s*\s*part(sprintf('ppt/slides/slide%d.xml', $slide)); - - if (preg_match('#.*?toThrow(MalformedTheme::class, '"name" is not a value a theme holds'); }); +it('refuses the sections of a theme\'s own file in a slide\'s values', function () { + // The values are the values: the layout roles and the named styles are the theme's own + // shape, and a slide has none of them to lay over it. + expect(fn () => variablesDeck("---\ntheme-variables:\n layouts:\n content: Body Text\n---\n\n# One\n")) + ->toThrow(MalformedTheme::class, '"layouts" is not a value a theme holds') + ->and(fn () => variablesDeck("---\ntheme-variables:\n textStyles:\n brand:\n color: accent1\n---\n\n# One\n")) + ->toThrow(MalformedTheme::class, '"textStyles" is not a value a theme holds'); +}); + it('refuses a colour that is not a colour', function () { expect(fn () => variablesDeck("---\ntheme-variables:\n colors:\n accent1: red\n---\n\n# One\n")) ->toThrow(MalformedTheme::class, 'which is not a colour'); diff --git a/tests/Unit/theme.php b/tests/Unit/theme.php index 127942d..d2cd8cb 100644 --- a/tests/Unit/theme.php +++ b/tests/Unit/theme.php @@ -7,7 +7,6 @@ use MarkdownPresentation\Theme\Fonts; use MarkdownPresentation\Theme\LayoutRole; use MarkdownPresentation\Theme\Style; -use MarkdownPresentation\Theme\StyleSlots; use MarkdownPresentation\Theme\Theme; use MarkdownPresentation\Theme\ThemeMapping; @@ -131,6 +130,17 @@ ->and(Theme::fromArray(ThemeMapping::write($night))->isDark())->toBeTrue(); }); +it('writes the theme\'s own values and not the sections beside them', function () { + // The round trip a slide's own values make writes the theme out and reads it back, and + // the sections are not among the values: a section written here would be a key the + // reader does not know, and every slide that laid values over a theme would fail. + $written = ThemeMapping::write(Theme::fromArray(['name' => 'Round', 'style' => ['margin' => 48]])); + + expect($written)->not->toHaveKey('layouts') + ->and($written)->not->toHaveKey('textStyles') + ->and($written)->toHaveKey('style'); +}); + it('refuses a theme with no name', function () { Theme::fromArray(['colors' => []]); })->throws(MalformedTheme::class, 'A theme needs a "name"'); @@ -249,11 +259,6 @@ ->and(LayoutRole::tryFrom('Two Content'))->toBeNull(); }); -it('lists the style slots a theme may name', function () { - expect(StyleSlots::names())->toContain('heading.1', 'paragraph', 'codeFont', 'tableCell') - ->and(StyleSlots::names())->not->toContain('blockquote'); -}); - it('loads every theme that ships with the library', function () { $loader = new MarkdownPresentation\Theme\ThemeLoader(); $finder = new MarkdownPresentation\Files\DiskFinder(theme: [dirname(__DIR__, 2) . THEMES]); diff --git a/tests/Unit/to-string.php b/tests/Unit/to-string.php index 3269dcf..f868bc3 100644 --- a/tests/Unit/to-string.php +++ b/tests/Unit/to-string.php @@ -79,7 +79,6 @@ function stagedFiles(): array $finder = new MemoryFinder([ 'house/theme.yml' => (string) file_get_contents(masterTheme() . '/theme.yml'), - 'house/layouts.yml' => (string) file_get_contents(masterTheme() . '/layouts.yml'), 'house/template.pptx' => (string) file_get_contents(masterTheme() . '/template.pptx'), ]); diff --git a/tests/fixtures/themes/anchored/layouts.yml b/tests/fixtures/themes/anchored/layouts.yml deleted file mode 100644 index 43409f3..0000000 --- a/tests/fixtures/themes/anchored/layouts.yml +++ /dev/null @@ -1,7 +0,0 @@ -# The layout names this theme's own `template.pptx` gives each role. -# -# One role is mapped, because the template carries one layout: a theme that covers part of the -# vocabulary is a theme that works, and the roles it says nothing about keep the geometry the -# library puts them at. -layouts: - content: Title and Content diff --git a/tests/fixtures/themes/anchored/theme.yml b/tests/fixtures/themes/anchored/theme.yml index 20fc136..20d3f68 100644 --- a/tests/fixtures/themes/anchored/theme.yml +++ b/tests/fixtures/themes/anchored/theme.yml @@ -24,3 +24,11 @@ fonts: heading: Source Sans Pro body: Source Sans Pro mono: Fira Code + +# The layout names this theme's own `template.pptx` gives each role. +# +# One role is mapped, because the template carries one layout. A role the section does +# not name is a role the theme does not map, and a deck that asks for one is told which +# roles this theme does have. +layouts: + content: Title and Content diff --git a/tests/fixtures/themes/broken/styles.yml b/tests/fixtures/themes/broken/styles.yml deleted file mode 100644 index 573810f..0000000 --- a/tests/fixtures/themes/broken/styles.yml +++ /dev/null @@ -1,4 +0,0 @@ -# The slot is `blockQuote` and this is `blockquote`. A style slot that does not -# exist would be ignored at render time and the deck would come out with none of the -# styling the theme asked for, so the theme is refused instead. -blockquote: PullQuote diff --git a/tests/fixtures/themes/broken/theme.yml b/tests/fixtures/themes/broken/theme.yml deleted file mode 100644 index 51c2729..0000000 --- a/tests/fixtures/themes/broken/theme.yml +++ /dev/null @@ -1,3 +0,0 @@ -name: Broken -description: A theme whose styles.yml names a slot that does not exist, for the failure it produces. -author: markdown-office diff --git a/tests/fixtures/themes/sparse/layouts.yml b/tests/fixtures/themes/sparse/layouts.yml deleted file mode 100644 index 5ba21eb..0000000 --- a/tests/fixtures/themes/sparse/layouts.yml +++ /dev/null @@ -1,5 +0,0 @@ -# Two of the five roles. The other three are not mapped, and a deck that asks for -# one of them is told which roles this theme does have. -layouts: - title: Deck Title - content: Body Text diff --git a/tests/fixtures/themes/sparse/theme.yml b/tests/fixtures/themes/sparse/theme.yml index bb21f49..264abfd 100644 --- a/tests/fixtures/themes/sparse/theme.yml +++ b/tests/fixtures/themes/sparse/theme.yml @@ -1,3 +1,9 @@ name: Sparse description: A theme whose template has fewer layouts than there are roles, for the failure it produces. author: markdown-office + +# Two of the five roles. The other three are not mapped, and a deck that asks for +# one of them is told which roles this theme does have. +layouts: + title: Deck Title + content: Body Text diff --git a/tests/fixtures/themes/templated/layouts.yml b/tests/fixtures/themes/templated/layouts.yml deleted file mode 100644 index caf7438..0000000 --- a/tests/fixtures/themes/templated/layouts.yml +++ /dev/null @@ -1,14 +0,0 @@ -# The layout names this theme's own `template.pptx` gives each role. -# -# `section` is mapped to a layout the template does not have, and `blank` to one it has with -# nothing in it. Both are deliberate: a template that covers part of the vocabulary is a theme -# that works, and the roles it says nothing about keep the geometry the library puts them at. -layouts: - title: Title Slide - content: Title and Content - two-column: Two Content - section: Section Header - blank: Blank - image-text: Picture Left - image-title: Picture with Caption - image-slide: Full Bleed Picture diff --git a/tests/fixtures/themes/templated/theme.yml b/tests/fixtures/themes/templated/theme.yml index 6d586f0..3facd0c 100644 --- a/tests/fixtures/themes/templated/theme.yml +++ b/tests/fixtures/themes/templated/theme.yml @@ -1,8 +1,8 @@ # A theme that ships a template of its own, which is what `templates.pptx` is for. # -# The layouts below name the ones `template.pptx` carries. Only three of the five roles are -# mapped, and that is deliberate: a template that covers part of the vocabulary is a theme -# that works, not one that fails on the roles its deck never asked for. +# The layouts below name the ones `template.pptx` carries, and they name every role: a +# `layouts:` section is the whole mapping, so a role it leaves out is a role the theme does +# not map and a deck that asks for one is refused. name: Templated description: A theme whose geometry comes from its own PowerPoint template. author: markdown-office @@ -24,3 +24,19 @@ fonts: heading: Source Sans Pro body: Source Sans Pro mono: Fira Code + +# The layout names this theme's own `template.pptx` gives each role. +# +# `section` is mapped to a layout the template does not have, and `blank` to one it has with +# nothing in it. Both are deliberate: a template fills in the roles it covers and leaves the +# rest where the library puts them, so the two roles keep the geometry the library gives +# them rather than the template's. +layouts: + title: Title Slide + content: Title and Content + two-column: Two Content + section: Section Header + blank: Blank + image-text: Picture Left + image-title: Picture with Caption + image-slide: Full Bleed Picture diff --git a/tests/fixtures/themes/with-layouts/layouts.yml b/tests/fixtures/themes/with-layouts/layouts.yml new file mode 100644 index 0000000..c97c83d --- /dev/null +++ b/tests/fixtures/themes/with-layouts/layouts.yml @@ -0,0 +1,6 @@ +# Which of the eight layout roles gets which layout. This file is beside the theme and is +# no longer part of the format: its content belongs in the "layouts:" section of the +# theme's own file. +layouts: + title: Title Slide + content: Title and Content diff --git a/tests/fixtures/themes/with-layouts/theme.yml b/tests/fixtures/themes/with-layouts/theme.yml new file mode 100644 index 0000000..af7312c --- /dev/null +++ b/tests/fixtures/themes/with-layouts/theme.yml @@ -0,0 +1,3 @@ +name: With Layouts +description: A theme that carries a layouts.yml beside it, for the refusal it produces. +author: markdown-office diff --git a/tests/fixtures/themes/with-styles/styles.yml b/tests/fixtures/themes/with-styles/styles.yml new file mode 100644 index 0000000..47eb335 --- /dev/null +++ b/tests/fixtures/themes/with-styles/styles.yml @@ -0,0 +1,5 @@ +# Word style slots, by the names in a .docx template's styles. This file belongs to the +# Word half, and this half does not read it: the slots name Word styles, which a deck of +# slides has no use for. +heading.1: Heading1 +paragraph: BodyText diff --git a/tests/fixtures/themes/with-styles/theme.yml b/tests/fixtures/themes/with-styles/theme.yml new file mode 100644 index 0000000..6fbeb2c --- /dev/null +++ b/tests/fixtures/themes/with-styles/theme.yml @@ -0,0 +1,3 @@ +name: With Styles +description: A theme that carries a styles.yml beside it, for the refusal it produces. +author: markdown-office diff --git a/tests/fixtures/themes/with-text-styles/text-styles.yml b/tests/fixtures/themes/with-text-styles/text-styles.yml new file mode 100644 index 0000000..179f453 --- /dev/null +++ b/tests/fixtures/themes/with-text-styles/text-styles.yml @@ -0,0 +1,5 @@ +# The named text styles, in a file beside the theme. This file is no longer part of the +# format: its content belongs in the "textStyles:" section of the theme's own file. +brand: + color: accent1 + bold: true diff --git a/tests/fixtures/themes/with-text-styles/theme.yml b/tests/fixtures/themes/with-text-styles/theme.yml new file mode 100644 index 0000000..bea647e --- /dev/null +++ b/tests/fixtures/themes/with-text-styles/theme.yml @@ -0,0 +1,3 @@ +name: With Text Styles +description: A theme that carries a text-styles.yml beside it, for the refusal it produces. +author: markdown-office diff --git a/themes/corporate-dark/layouts.yml b/themes/corporate-dark/layouts.yml deleted file mode 100644 index 03efa62..0000000 --- a/themes/corporate-dark/layouts.yml +++ /dev/null @@ -1,9 +0,0 @@ -layouts: - title: Title Slide - content: Title and Content - two-column: Two Content - section: Section Header - blank: Blank - image-text: Picture Left - image-title: Picture with Caption - image-slide: Full Bleed Picture diff --git a/themes/corporate-dark/styles.yml b/themes/corporate-dark/styles.yml deleted file mode 100644 index 4cba213..0000000 --- a/themes/corporate-dark/styles.yml +++ /dev/null @@ -1,12 +0,0 @@ -# Word style slots, by the names in a .docx template's styles. A value is either a -# styleId — "Heading1", not "Heading 1" — or an inline style array. -heading.1: Heading1 -heading.2: Heading2 -paragraph: BodyText -blockQuote: PullQuote -codeFont: - name: JetBrains Mono - size: 9 -linkFont: - color: 89B4FA - underline: single diff --git a/themes/corporate-dark/text-styles.yml b/themes/corporate-dark/text-styles.yml deleted file mode 100644 index c7122a7..0000000 --- a/themes/corporate-dark/text-styles.yml +++ /dev/null @@ -1,13 +0,0 @@ -# Named text styles: the words inside a box, written in a deck as `:brand[Bakery]`. -# The properties are the same eight the inline style attributes have, and a size is in -# points as it is everywhere else. -# -# The brand is the theme's own accent, which is what the headings are painted in, and the -# muted style is the quiet ink a caption is written in — a step down from the body, which -# is what a caption is on a slide rather than in a document. -brand: - color: accent1 - bold: true -muted: - color: lt2 - size: 14 diff --git a/themes/corporate-dark/theme.yml b/themes/corporate-dark/theme.yml index 89ec511..1204cd6 100644 --- a/themes/corporate-dark/theme.yml +++ b/themes/corporate-dark/theme.yml @@ -36,3 +36,18 @@ style: leading: 1.32 heading-weight: bold heading-ink: accent + +# Named text styles: the words inside a box, written in a deck as `:brand[Bakery]`. +# The properties are the same eight the inline style attributes have, and a size is in +# points as it is everywhere else. +# +# The brand is the theme's own accent, which is what the headings are painted in, and the +# muted style is the quiet ink a caption is written in — a step down from the body, which +# is what a caption is on a slide rather than in a document. +textStyles: + brand: + color: accent1 + bold: true + muted: + color: lt2 + size: 14 diff --git a/themes/default/layouts.yml b/themes/default/layouts.yml deleted file mode 100644 index 03efa62..0000000 --- a/themes/default/layouts.yml +++ /dev/null @@ -1,9 +0,0 @@ -layouts: - title: Title Slide - content: Title and Content - two-column: Two Content - section: Section Header - blank: Blank - image-text: Picture Left - image-title: Picture with Caption - image-slide: Full Bleed Picture diff --git a/themes/dense/layouts.yml b/themes/dense/layouts.yml deleted file mode 100644 index 03efa62..0000000 --- a/themes/dense/layouts.yml +++ /dev/null @@ -1,9 +0,0 @@ -layouts: - title: Title Slide - content: Title and Content - two-column: Two Content - section: Section Header - blank: Blank - image-text: Picture Left - image-title: Picture with Caption - image-slide: Full Bleed Picture diff --git a/themes/minimal/layouts.yml b/themes/minimal/layouts.yml deleted file mode 100644 index 03efa62..0000000 --- a/themes/minimal/layouts.yml +++ /dev/null @@ -1,9 +0,0 @@ -layouts: - title: Title Slide - content: Title and Content - two-column: Two Content - section: Section Header - blank: Blank - image-text: Picture Left - image-title: Picture with Caption - image-slide: Full Bleed Picture diff --git a/themes/minimal/styles.yml b/themes/minimal/styles.yml deleted file mode 100644 index 318c07b..0000000 --- a/themes/minimal/styles.yml +++ /dev/null @@ -1,2 +0,0 @@ -paragraph: BodyText -listParagraph: ListParagraph diff --git a/themes/pitch/layouts.yml b/themes/pitch/layouts.yml deleted file mode 100644 index 03efa62..0000000 --- a/themes/pitch/layouts.yml +++ /dev/null @@ -1,9 +0,0 @@ -layouts: - title: Title Slide - content: Title and Content - two-column: Two Content - section: Section Header - blank: Blank - image-text: Picture Left - image-title: Picture with Caption - image-slide: Full Bleed Picture diff --git a/tools/build-powerpoint-fixtures.sh b/tools/build-powerpoint-fixtures.sh index 1b436bd..0341234 100755 --- a/tools/build-powerpoint-fixtures.sh +++ b/tools/build-powerpoint-fixtures.sh @@ -60,8 +60,8 @@ mkdir -p "$WORK" "$CONTAINER" cp -f "$PICTURE" "$CONTAINER/logo.png" # The English names are the ones PowerPoint writes on an English installation, and the layout -# name is what a `layouts.yml` has to match. This machine's PowerPoint is otherwise German, -# which it would otherwise be for the whole run. +# name is what a theme's `layouts:` section has to match. This machine's PowerPoint is +# otherwise German, which it would otherwise be for the whole run. LANGUAGE=(--args -AppleLanguages "(en)") author () {