Created
December 19, 2018 15:02
-
-
Save mtherien/4843db1f32b65339b2e94a1fa235a77e to your computer and use it in GitHub Desktop.
Typewriter TypeScript Template for Models
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ${ | |
| // Enable extension methods by adding using Typewriter.Extensions.* | |
| using Typewriter.Extensions.Types; | |
| Template(Settings settings) | |
| { | |
| settings.OutputFilenameFactory = file => { | |
| var firstClass = file.Classes.First(); | |
| var positionOfLastModel = firstClass.Name.LastIndexOf("Model"); | |
| var modelName = firstClass.Name.Substring(0, positionOfLastModel); | |
| return modelName + ".model.ts"; | |
| }; | |
| } | |
| // Custom extension methods can be used in the template by adding a $ prefix e.g. $LoudName | |
| string DocComment(Property property) | |
| { | |
| return property.DocComment.Summary; | |
| } | |
| // $Classes/Enums/Interfaces(filter)[template][separator] | |
| // filter (optional): Matches the name or full name of the current item. * = match any, wrap in [] to match attributes or prefix with : to match interfaces or base classes. | |
| // template: The template to repeat for each matched item | |
| // separator (optional): A separator template that is placed between all templates e.g. $Properties[public $name: $Type][, ] | |
| // More info: http://frhagn.github.io/Typewriter/ | |
| } | |
| module ClientApp.Models { | |
| $Classes(*Model)[ | |
| export class $Name { | |
| $Properties[ | |
| // $DocComment | |
| $name: $Type = $Type[$Default]; | |
| ] | |
| }] | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment