|
| 1 | +# C# Example Templates for Tutorials |
| 2 | + |
| 3 | +Create example files at: |
| 4 | +- Console: `Spectre.Docs.Examples/SpectreConsole/Tutorials/{TutorialName}Tutorial.cs` |
| 5 | +- CLI: `Spectre.Docs.Examples/SpectreCli/Tutorials/{TutorialName}Tutorial.cs` |
| 6 | + |
| 7 | +## Key Concept: Visible Progress |
| 8 | + |
| 9 | +Unlike how-to guides (which build incrementally toward a solution), tutorial examples focus on **immediate, visible results**. Each method should produce output that the learner can see and verify—building their confidence step by step. |
| 10 | + |
| 11 | +## File Structure Template |
| 12 | + |
| 13 | +```csharp |
| 14 | +using Spectre.Console; |
| 15 | + |
| 16 | +namespace Spectre.Docs.Examples.SpectreConsole.Tutorials; |
| 17 | + |
| 18 | +/// <summary> |
| 19 | +/// {Brief description of what this tutorial builds}. |
| 20 | +/// </summary> |
| 21 | +public class {TutorialName}Tutorial |
| 22 | +{ |
| 23 | + /// <summary> |
| 24 | + /// {What this step teaches - matches step title}. |
| 25 | + /// </summary> |
| 26 | + public void {StepMethodName}() |
| 27 | + { |
| 28 | + // Implementation that produces visible output |
| 29 | + AnsiConsole.MarkupLine("[green]Hello[/] [red]World[/]!"); |
| 30 | + } |
| 31 | + |
| 32 | + /// <summary> |
| 33 | + /// {What the next step teaches}. |
| 34 | + /// </summary> |
| 35 | + public void {NextStepMethodName}() |
| 36 | + { |
| 37 | + // Next step implementation with visible output |
| 38 | + } |
| 39 | + |
| 40 | + // Additional steps... |
| 41 | +
|
| 42 | + /// <summary> |
| 43 | + /// Complete example demonstrating all tutorial concepts. |
| 44 | + /// </summary> |
| 45 | + public void ShowComplete{Feature}() |
| 46 | + { |
| 47 | + // Combined implementation showing the full output |
| 48 | + AnsiConsole.MarkupLine("[green]✓ Build completed successfully[/]"); |
| 49 | + // ... rest of the complete output |
| 50 | + } |
| 51 | +} |
| 52 | +``` |
| 53 | + |
| 54 | +## Rules |
| 55 | + |
| 56 | +1. **XML Doc Required**: Every public method and the class MUST have a `<summary>` comment |
| 57 | +2. **Class Signature**: Always `public class {TutorialName}Tutorial` |
| 58 | +3. **Method Signature**: Always `public void` (instance methods) |
| 59 | +4. **Visible Output**: Every step MUST produce output the learner can see |
| 60 | +5. **Self-Contained Steps**: Each method should work independently (no shared state) |
| 61 | +6. **Descriptive Names**: Use names that match the tutorial step titles |
| 62 | +7. **Complete Method Required**: Include `ShowComplete{Feature}()` demonstrating the full output |
| 63 | +8. **Realistic Data**: Use meaningful sample data that tells a story |
| 64 | + |
| 65 | +## Example: Markup Styling Tutorial |
| 66 | + |
| 67 | +```csharp |
| 68 | +using Spectre.Console; |
| 69 | + |
| 70 | +namespace Spectre.Docs.Examples.SpectreConsole.Tutorials; |
| 71 | + |
| 72 | +/// <summary> |
| 73 | +/// A tutorial that builds a styled build-output display step by step. |
| 74 | +/// Teaches markup syntax, custom colors, combined styles, links, and safe interpolation. |
| 75 | +/// </summary> |
| 76 | +public class MarkupStylingTutorial |
| 77 | +{ |
| 78 | + /// <summary> |
| 79 | + /// Displays a success message in green using basic markup syntax. |
| 80 | + /// </summary> |
| 81 | + public void ShowSuccessMessage() |
| 82 | + { |
| 83 | + AnsiConsole.MarkupLine("[green]✓ Build completed successfully[/]"); |
| 84 | + } |
| 85 | + |
| 86 | + /// <summary> |
| 87 | + /// Displays a warning message using a custom hex color and mixed styling. |
| 88 | + /// </summary> |
| 89 | + public void ShowWarningMessage() |
| 90 | + { |
| 91 | + AnsiConsole.MarkupLine("[#FFA500]⚠[/] [yellow]3 warnings[/] in Authentication.cs"); |
| 92 | + } |
| 93 | + |
| 94 | + /// <summary> |
| 95 | + /// Displays an error message using combined bold and red styling. |
| 96 | + /// </summary> |
| 97 | + public void ShowErrorMessage() |
| 98 | + { |
| 99 | + AnsiConsole.MarkupLine("[bold red]✗ Error:[/] Missing dependency 'Newtonsoft.Json'"); |
| 100 | + } |
| 101 | + |
| 102 | + /// <summary> |
| 103 | + /// Displays a clickable documentation link. |
| 104 | + /// </summary> |
| 105 | + public void ShowDocumentationLink() |
| 106 | + { |
| 107 | + AnsiConsole.MarkupLine(" → See: [link=https://docs.example.com/dependencies]documentation[/]"); |
| 108 | + } |
| 109 | + |
| 110 | + /// <summary> |
| 111 | + /// Demonstrates safe interpolation for dynamic content that might contain brackets. |
| 112 | + /// </summary> |
| 113 | + public void ShowDynamicContent() |
| 114 | + { |
| 115 | + var fileName = "Authentication.cs"; |
| 116 | + var warningCount = 3; |
| 117 | + AnsiConsole.MarkupLineInterpolated($"[#FFA500]⚠[/] [yellow]{warningCount} warnings[/] in {fileName}"); |
| 118 | + } |
| 119 | + |
| 120 | + /// <summary> |
| 121 | + /// Displays the complete build output combining all techniques. |
| 122 | + /// </summary> |
| 123 | + public void ShowCompleteBuildOutput() |
| 124 | + { |
| 125 | + var fileName = "Authentication.cs"; |
| 126 | + var dependency = "Newtonsoft.Json"; |
| 127 | + |
| 128 | + AnsiConsole.MarkupLine("[green]✓ Build completed successfully[/]"); |
| 129 | + AnsiConsole.MarkupLineInterpolated($"[#FFA500]⚠[/] [yellow]3 warnings[/] in {fileName}"); |
| 130 | + AnsiConsole.MarkupLineInterpolated($"[bold red]✗ Error:[/] Missing dependency '{dependency}'"); |
| 131 | + AnsiConsole.MarkupLine(" → See: [link=https://docs.example.com/dependencies]documentation[/]"); |
| 132 | + } |
| 133 | +} |
| 134 | +``` |
| 135 | + |
| 136 | +## Method Naming Guidelines |
| 137 | + |
| 138 | +Method names should match the step titles in the tutorial: |
| 139 | + |
| 140 | +| Step Title | Method Name | |
| 141 | +|------------|-------------| |
| 142 | +| "Display a Success Message" | `ShowSuccessMessage` | |
| 143 | +| "Add a Warning Message" | `ShowWarningMessage` | |
| 144 | +| "Show an Error Message" | `ShowErrorMessage` | |
| 145 | +| "Include a Documentation Link" | `ShowDocumentationLink` | |
| 146 | +| "Complete Build Output" | `ShowCompleteBuildOutput` | |
| 147 | + |
| 148 | +Use action verbs that describe what the learner will see: |
| 149 | +- `Show{Feature}` - Displays something |
| 150 | +- `Create{Thing}` - Builds and displays something |
| 151 | +- `ShowComplete{Feature}` - The final method showing everything together |
| 152 | + |
| 153 | +## Visible Output Requirements |
| 154 | + |
| 155 | +Every tutorial step must produce output. This is critical for learner confidence: |
| 156 | + |
| 157 | +**Good - produces visible output:** |
| 158 | +```csharp |
| 159 | +public void ShowBasicTable() |
| 160 | +{ |
| 161 | + var table = new Table(); |
| 162 | + table.AddColumn("Name"); |
| 163 | + table.AddRow("Alice"); |
| 164 | + AnsiConsole.Write(table); // Learner sees the table |
| 165 | +} |
| 166 | +``` |
| 167 | + |
| 168 | +**Bad - no visible output:** |
| 169 | +```csharp |
| 170 | +public void CreateTable() |
| 171 | +{ |
| 172 | + var table = new Table(); |
| 173 | + table.AddColumn("Name"); |
| 174 | + table.AddRow("Alice"); |
| 175 | + // Nothing displayed - learner can't verify it worked! |
| 176 | +} |
| 177 | +``` |
| 178 | + |
| 179 | +## Self-Contained Steps |
| 180 | + |
| 181 | +Each method should work independently. Don't rely on state from previous steps: |
| 182 | + |
| 183 | +**Good - self-contained:** |
| 184 | +```csharp |
| 185 | +public void ShowStyledTable() |
| 186 | +{ |
| 187 | + var table = new Table() |
| 188 | + .Border(TableBorder.Rounded) |
| 189 | + .BorderColor(Color.Blue); |
| 190 | + table.AddColumn("Name"); |
| 191 | + table.AddRow("Alice"); |
| 192 | + AnsiConsole.Write(table); |
| 193 | +} |
| 194 | +``` |
| 195 | + |
| 196 | +**Bad - depends on previous state:** |
| 197 | +```csharp |
| 198 | +private Table _table; // Shared state |
| 199 | +
|
| 200 | +public void CreateTable() |
| 201 | +{ |
| 202 | + _table = new Table(); |
| 203 | + _table.AddColumn("Name"); |
| 204 | +} |
| 205 | + |
| 206 | +public void StyleTable() |
| 207 | +{ |
| 208 | + _table.Border(TableBorder.Rounded); // Fails if CreateTable wasn't called first |
| 209 | + AnsiConsole.Write(_table); |
| 210 | +} |
| 211 | +``` |
| 212 | + |
| 213 | +## XmlDocId Reference |
| 214 | + |
| 215 | +The XmlDocId for referencing examples in markdown: |
| 216 | + |
| 217 | +``` |
| 218 | +M:Spectre.Docs.Examples.SpectreConsole.Tutorials.{TutorialName}Tutorial.{MethodName} |
| 219 | +M:Spectre.Docs.Examples.SpectreCli.Tutorials.{TutorialName}Tutorial.{MethodName} |
| 220 | +``` |
| 221 | + |
| 222 | +Examples: |
| 223 | +``` |
| 224 | +M:Spectre.Docs.Examples.SpectreConsole.Tutorials.MarkupStylingTutorial.ShowSuccessMessage |
| 225 | +M:Spectre.Docs.Examples.SpectreConsole.Tutorials.MarkupStylingTutorial.ShowCompleteBuildOutput |
| 226 | +``` |
| 227 | + |
| 228 | +## Checklist |
| 229 | + |
| 230 | +- [ ] File is in correct Tutorials folder (`SpectreConsole/Tutorials/` or `SpectreCli/Tutorials/`) |
| 231 | +- [ ] Class is `public class {TutorialName}Tutorial` |
| 232 | +- [ ] Namespace matches folder structure |
| 233 | +- [ ] Class has XML doc `<summary>` |
| 234 | +- [ ] Every method has XML doc `<summary>` |
| 235 | +- [ ] Every method is `public void` (instance method) |
| 236 | +- [ ] Every method produces visible output |
| 237 | +- [ ] Methods are self-contained (no shared state) |
| 238 | +- [ ] Method names match tutorial step titles |
| 239 | +- [ ] `ShowComplete{Feature}()` method demonstrates the full output |
| 240 | +- [ ] Examples use realistic, meaningful data |
0 commit comments