Back on track after a short break! I’ve just uploaded to the Orchard Gallery a much updated version of Code Generation Extensions module.
Some of you asked for features such as settings codegen and assigning the generated part to specific feature. Here they are! I described the basic commands and usage of those in my previous article. Now, I’d like to describe the new goodies, starting from…
Introducing ‘codegen typesettings’
This is a new Orchard CLI command that generates all files necessary for adding type-specific settings to any existing part. Such settings are commonly used for holding some default values for content parts. You can read more about those here and here (which is the same post, just copied to the official docs).
Like the ‘codegen part’ command, ‘codegen typesettings’ also has a /Properties: switch (optional parameter), with exactly the same syntax. It allows you to easily provide necessary properties via command-line. If you do so, the form fields necessary for editing those properties will be automatically created in an appropriate .cshtml file (which can save you some keystrokes ).
New parameters in ‘codegen part’
- /ForFeature:<feature-name> – this switch lets you specify which feature (existing in your module, of course) the generated part has to be specifically bound to. The existence of a feature you specify isn’t being verified (yet), so look out for typing errors. For those of you who would like to get into greater detail – it adds an appropriate [OrchardFeature(…)] attribute to generated classes.
- /AttachTo:<type-name> – allows you to specify the content type this part should be automatically attached to. As you may or may not know, attaching parts to content types in Orchard can be done twofold – by describing the structure in data migrations class (which can be further modified via admin UI) or by hardcoding the relation in content handler using ActivationFilter (like e.g.. site settings do). This command uses the second approach.
This switch makes creation of site settings as easy as specifying /AttachTo:Site. Site is a content type in Orchard, so you can attach to it virtually any part you want!
- /ShapeFile:<name> – if you want to provide your own name for generated shape files instead of part name – this is the right place. Do not specify the file extension (.cshtml) here – it will be added automatically. This parameter allows you to keep your file-naming scheme intact (e.g.. Funny.MyPart.cshtml instead of MyFunnyPart.cshtml, where MyFunnyPart is the name of your part).
I’d like to thank Brad Millington very much for mentioning this module during speech on MIX11!
That is all for now. I’ll probably make some more additions soon so stay tuned!