benmcevoy / RainbowCodeGeneration

A simple set of utility classes and a sample T4 template that allow easy code generation for Sitecore templates from Rainbow / Unicorn serialized items. Currently, only the YAML serialization format is supported.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

RainbowCodeGeneration

NuGet

A simple set of utility classes and a sample T4 template that allow easy code generation for Sitecore templates from Rainbow / Unicorn serialized items. Currently, only the YAML-based serialisation format is supported.

Using the Rainbow / Unicorn code generation

You are probably already using Unicorn with the YAML serialisation format (you really should - it's awesome!). I am also assuming that you serialise your templates in a dedicated folder inside your solution, ideally in a modular fashion like in Sitecore Habitat. Using the Rainbow / Unicorn code generation is simple:

  • Install the nuget package
  • Configure the T4 template
  • Re-Run the code generation when Sitecore templates change

Installing the nuget package

Install the RainbowCodeGeneration package. This installs a set of simple utility classes and an example T4 template. The template will generate an empty SitecoreTemplates struct in your project.

Empty Sitecore Template

Configuring the T4 template

Adjust a few settings on the T4 template SitecoreTemplates.tt to make it run in your configuration.

  • Ensure the assembly references at the top of the file resolve correctly (especially the path to your Sitecore.Kernel.dll)
  • The physicalFileStore setting needs to point to where you store the Unicorn / Rainbow items for your project. The out of the box setting uses the relative paths that Habitat uses.
  • The treeName setting is the name of the sub-tree in Unicorn. This is the name of the include on your predicate in Unicorn. The "News" feature in Habitat would use "Feature.News.Templates"
  • The treePath setting is the matching path in Sitecore. The "News" feature in Habitat would use "/sitecore/templates/Feature/News"

Adjust Settings

The code generation for your Sitecore templates will run when you save the T4 template.

You can tweak the T4 template to your liking. The entire IItemData object from Rainbow for the template and its fields is available within the template.

Re-run code generation

When your Unicorn / Rainbow items update, you will have to re-run the code generation. In Visual Studio, right-click on the T4 template and select "Run Custom Tool" to re-run the code generation.

Adjust Settings

Known issues in 0.1.2

Re-serialisation fails if Visual Studio solution is open

Re-serialising an entire configuration fails if Visual Studio is open and a code generation is covering the configuration. Visual Studio appears to retain a lock on the folder and Unicorn cannot remove it. Close the solution and re-open it after you re-serialised the configuration.

About

A simple set of utility classes and a sample T4 template that allow easy code generation for Sitecore templates from Rainbow / Unicorn serialized items. Currently, only the YAML serialization format is supported.

License:MIT License


Languages

Language:C# 89.6%Language:Pascal 10.4%