blipson89 / Leprechaun

A template code generation framework for Rainbow
MIT License
42 stars 22 forks source link

Make all template field info fields available. #28

Closed jbreuer closed 5 years ago

jbreuer commented 5 years ago

When adding custom fields to the template field those can't be accessed in the current version. This PR makes those fields available.

For example I've added a 'Do not auto generate' and 'Do not edit in Experience Editor' field:

generate1

So per template field you can manage this:

generate2

With this info available I made some changes to the GlassMapper.csx file:

public static readonly System.Guid DoNotAutoGenerateId = new System.Guid("{CA075FD6-5BDD-44E6-881F-74AE42568C44}");
public static readonly System.Guid DoNotEditInExperienceEditorId = new System.Guid("{97A75B68-9E59-4F97-84F7-AD9CC4D081B3}");

public string RenderInterfaceFields(TemplateCodeGenerationMetadata template)
{
    var localCode = new System.Text.StringBuilder();

    foreach (var field in template.OwnFields)
    {
        var autoGenerate = !field.AllFields.ContainsKey(DoNotAutoGenerateId) || field.AllFields[DoNotAutoGenerateId] != "1";
        var isEditable = !field.AllFields.ContainsKey(DoNotEditInExperienceEditorId) || field.AllFields[DoNotEditInExperienceEditorId] != "1";

        if (autoGenerate)
        {
        localCode.AppendLine($@"
        /// <summary>{field.HelpText}</summary>
        [SitecoreField(FieldId = {template.Namespace}.Constants.{template.CodeName}.Fields.{field.CodeName}IdString)]
        [ExperienceEditor(IsEditable = {isEditable.ToString().ToLower()})]
        public virtual {GetFieldType(field)} {field.CodeName} {{ get; set; }}");
        }
    }

    return localCode.ToString();
}

So by making custom field info also accessible you become much more flexible in creating your own custom GlassMapper.csx.

There are some more examples, but I will blog about those soon.

blipson89 commented 5 years ago

@jbreuer I created a new branch called 28-AllFields and merged dev into it. I made a couple minor changes there as well.

Basically, while reviewing your code, I noticed something that was already in Leprechaun that I wanted to clean up. I cleaned that up and then updated your code to match.

I tested it on my end and it works. Would you like to pull down that branch (28-AllFields) and confirm before I merge it in?


As a side note, I will be referencing this pull request whenever I need to show any of my devs an example of how to properly write a description in a pull request 😁

jbreuer commented 5 years ago

Hi @blipson89,

I've tested the 28-AllFields branch and everything works. I've checked the changes you've made and those are all good improvements!

Hopefully this can be released soon.

Regards, Jeroen Breuer

jbreuer commented 5 years ago

Is this PR going to be closed since you did all the work in the 28-AllFields branch? Is there anything I can help with?

jbreuer commented 5 years ago

Hi @blipson89, Do you have a status update about the 28-AllFields branch? Regards, Jeroen Breuer