Skip Navigation
StructureStructure

ThemeCodeGenerator

Generates Swift code from theme bundles and stylesheets.

struct ThemeCodeGenerator

Overview

This type converts parsed theme bundles and the base stylesheet into Swift source code that is compiled directly into the binary, eliminating the need for runtime file loading. The generated file defines the ThemeSettings.BuiltInTheme enumeration, so adding a theme bundle to the Themes directory is all it takes to add a built-in theme. The output depends only on its input, so repeated builds produce identical files.

Example

let generator = ThemeCodeGenerator()
let bundles = try ThemeBundleSource.loadAll(in: themesDirectory)
let base = try ThemeBundleLayout.stylesheets(in: stylesheetsDirectory)
let swiftCode = generator.generateFile(bundles: bundles, baseStylesheets: base)
try swiftCode.write(toFile: "GeneratedThemes.swift", atomically: true, encoding: .utf8)

Topics

Relationships

  • Swift.Sendable
  • Swift.SendableMetatype