New code generation features for Orchard

Tags: orchard, codegen, english

Back on track after a short break!Uśmiech 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 Puszczam oczko).

New parameters in ‘codegen part’

  1. /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.
  2. /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!
  3. /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!Uśmiech

That is all for now. I’ll probably make some more additions soon so stay tuned!

Cheers!

2 Comments

  • Matt said

    Now all we need is a module that generates module/part functionality from ideas in my brain!

  • Doc said

    I must be missing something, I keep getting "target module could not be found" exception. I am a brand newbe in orchard