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:
-
Tracking nesting levels: Each block increases the indentation level
-
Configurable indentation: Spaces or tabs with customizable width
-
Inlined blocks: Blocks can opt out of indentation with the
inlinedflag -
Conditional indentation: Lines can be written with or without indentation
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
Creates a new indentation with the specified level and indent string.
Instance Properties
Returns the indentation string for the current level.
The string to use for each indentation level.
The current indentation level (0-based).
Instance Methods
Returns a new indentation with the level decreased by 1.
Returns a new indentation with the level increased by 1.