Generating Orchard content parts via command-line

Tags: orchard, codegen, parts, command, cli

Creating a content part in Orchard, even the most trivial one, involves creating many small objects – handler, driver, model (main part object), record, display and editor shapes to name a few. As I was tired of hand-creating/copy-pasting all those every time I needed a content part I wrote a simple Orchard module that automates the process (being a dev is about making life easier, right?)Uśmiech I called that module Code Generation Extensions, as it generally extends the default codegen features.

Module adds an Orchard command-line command “codegen part”. It’s syntax is as follows:

codegen part <module_name> <part_name> [/Properties:<comma-delimited list of name:type pairs>]

For example:

codegen part Modules.Shop ProductPart /Properties: Name:string, Price:int

Properties is an optional parameter, so if you’d like to create an empty part you can just write

codegen part Modules.Shop ProductPart

The command creates a handler, driver, model, record, display and editor shapes and updates the file with default Content:before placement for your part shape. If you provide /Properties parameter, the model, record and editor shapes will be filled with appropriate code accordingly.

You can download the module from the Orchard Gallery. Feel free to play with it and I hope you find it useful!Uśmiech


blog comments powered by Disqus