Documentation Language: Swift

Class

MTLProtectedAreaManager

Thread-safe manager for preserving protected area content across regenerations.

actor MTLProtectedAreaManager

Overview

Protected areas allow user code to be preserved when templates are regenerated, enabling a generate-modify-regenerate workflow where custom code survives regeneration cycles.

Overview

Protected areas work by:

  1. Marking sections: Templates define protected areas with unique IDs

  2. Scanning existing files: Before regeneration, existing files are scanned

  3. Extracting content: Content between protection markers is extracted

  4. Preserving during regeneration: Extracted content replaces default content

  5. Maintaining markers: Protection markers are preserved in output

Protection Markers

Protected areas are delimited by start/end markers:

// START PROTECTED REGION user-imports
import MyCustomLibrary
// END PROTECTED REGION user-imports

The markers can have custom prefixes (e.g., //, <!--, #) to match the comment syntax of the target language.

Example Usage

let manager = MTLProtectedAreaManager()

// Scan existing file before regeneration
try await manager.scanFile("/output/Person.swift")

// During regeneration, retrieve preserved content
if let content = await manager.getContent("user-imports") {
    // Use preserved content instead of default
}

// After regeneration, check what was preserved
let preserved = await manager.getAllContent()
print("Preserved \(preserved.count) protected areas")

Topics

Structures

S
MTLProtectedAreaManager.ProtectedAreaContent

Represents a protected area with its content and markers.

Initializers

?
init()

Creates a new protected area manager.

Instance Methods

F
clear()

Clears all protected area content.

F
enableDebugging(_:)

Enables or disables debug logging.

F
generateMarkers(id:prefix:)

Generates standard protection markers for a given ID and prefix.

F
getAllContent()

Returns all protected area content.

F
getArea(_:)

Retrieves the complete protected area record.

F
getContent(_:)

Retrieves the preserved content for a protected area.

F
hasContent(_:)

Checks if content exists for a protected area.

F
removeContent(_:)

Removes a protected area from the manager.

F
scanContent(_:)

Scans text content for protected areas and extracts them.

F
scanFile(_:)

Scans a file for protected areas and extracts their content.

F
setContent(_:content:markers:)

Stores protected area content manually.

F
summary()

Returns a summary of protected area statistics.

Default Implementations

Relationships

Conforms To