Documentation Language: Swift

Structure

MTLIndentation

Manages indentation levels and whitespace generation for MTL text output.

struct MTLIndentation

Overview

MTL indentation provides automatic indentation management for generated text, supporting both space-based and tab-based indentation with configurable indentation strings and nesting levels.

Overview

MTL templates can generate text with automatic indentation by:

Indentation Behavior

By default, MTL uses 4-space indentation:

Level 0: "text"
Level 1: "    text"
Level 2: "        text"

Indentation can be customized:

// 2-space indentation
let indent = MTLIndentation(level: 0, indentString: "  ")

// Tab indentation
let tabIndent = MTLIndentation(level: 0, indentString: "\t")

Example Usage

var indent = MTLIndentation()
print(indent.asString)  // ""

indent = indent.increment()
print(indent.asString)  // "    " (4 spaces)

indent = indent.increment()
print(indent.asString)  // "        " (8 spaces)

indent = indent.decrement()
print(indent.asString)  // "    " (4 spaces)

Topics

Initializers

?
init(level:indentString:)

Creates a new indentation with the specified level and indent string.

Instance Properties

V
asString

Returns the indentation string for the current level.

V
indentString

The string to use for each indentation level.

V
level

The current indentation level (0-based).

Instance Methods

F
decrement()

Returns a new indentation with the level decreased by 1.

F
increment()

Returns a new indentation with the level increased by 1.

Default Implementations

Relationships

Conforms To