Skip to content

Commit

Permalink
#11 - Minor formatting changes
Browse files Browse the repository at this point in the history
  • Loading branch information
blipson89 committed Oct 9, 2021
1 parent d915f1d commit 74ca0c6
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 8 deletions.
4 changes: 2 additions & 2 deletions src/Leprechaun.InputProviders.Rainbow/Leprechaun.config
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@
If you need to override a field type, you can add a <fieldType> child node in metadataGenerator.
Example:
<metadataGenerator type="Leprechaun.MetadataGeneration.StandardTemplateMetadataGenerator, Leprechaun" singleInstance="true">
<fieldType id="{00000000-0000-0000-0000-000000000000}" type="FooField" />
<fieldType id="{11111111-1111-1111-1111-111111111111}" type="IEnumerable<FooField>" />
<fieldType id="{00000000-0000-0000-0000-000000000000}" type="datetime" />
<fieldType id="{11111111-1111-1111-1111-111111111111}" type="droptree" />
</metadataGenerator>
Be sure that your .CSX file is setup to handle this in the GetFieldType(...) method.
Expand Down
10 changes: 10 additions & 0 deletions src/Leprechaun.InputProviders.Sitecore/Leprechaun.config
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,16 @@
<orchestrator type="Leprechaun.InputProviders.Sitecore.SitecoreOrchestrator, Leprechaun.InputProviders.Sitecore" singleInstance="true" />
<inputProvider type="Leprechaun.InputProviders.Sitecore.SitecoreInputProvider, Leprechaun.InputProviders.Sitecore" singleInstance="true" />
<watcher type="Leprechaun.InputProviders.Sitecore.SitecoreWatcher, Leprechaun.InputProviders.Sitecore" singleInstance="true" />
<!--
If you need to override a field type, you can add a <fieldType> child node in metadataGenerator.
Example:
<metadataGenerator type="Leprechaun.MetadataGeneration.StandardTemplateMetadataGenerator, Leprechaun" singleInstance="true">
<fieldType id="{00000000-0000-0000-0000-000000000000}" type="datetime" />
<fieldType id="{11111111-1111-1111-1111-111111111111}" type="droptree" />
</metadataGenerator>
Be sure that your .CSX file is setup to handle this in the GetFieldType(...) method.
-->
<metadataGenerator type="Leprechaun.MetadataGeneration.StandardTemplateMetadataGenerator, Leprechaun" singleInstance="true" />
<!--
You can disable the validators (not recommended) by adding the following attributes to the architectureValidator:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@
using System.Xml;
using Leprechaun.Filters;
using Leprechaun.Model;
using Sitecore.Diagnostics;

namespace Leprechaun.MetadataGeneration
{
public class StandardTemplateMetadataGenerator : ITemplateMetadataGenerator
{
private IDictionary<Guid, string> _fieldMap = new Dictionary<Guid, string>();
private readonly IDictionary<Guid, string> _fieldMap = new Dictionary<Guid, string>();
public StandardTemplateMetadataGenerator(XmlNode configNode)
{
Assert.ArgumentNotNull(configNode, nameof(configNode));
Expand All @@ -19,15 +18,19 @@ public StandardTemplateMetadataGenerator(XmlNode configNode)

protected virtual void CreateFieldmap(XmlNode configNode)
{
IEnumerable<XmlNode> nodes = configNode.ChildNodes.Cast<XmlNode>().Where(node => node.Name == "fieldType");
var nodes = configNode.ChildNodes
.Cast<XmlNode>()
.Where(node => node.Name == "fieldType");

foreach (XmlNode node in nodes)
{
bool validId = Guid.TryParse(node.Attributes?["id"]?.Value, out Guid id);
bool validId = Guid.TryParse(node.Attributes?["id"]?.Value, out var id);
string type = node.Attributes?["type"]?.Value;

if(validId && !string.IsNullOrEmpty(type))
if (validId && !string.IsNullOrEmpty(type))
{
_fieldMap.Add(id, type);
}
}
}

Expand Down Expand Up @@ -58,7 +61,7 @@ public virtual IReadOnlyList<ConfigurationCodeGenerationMetadata> Generate(param

protected virtual TemplateCodeGenerationMetadata CreateTemplate(ITypeNameGenerator nameGenerator, ITemplatePredicate predicate, TemplateInfo template)
{
var fullName = nameGenerator.GetFullTypeName(template.Path);
string fullName = nameGenerator.GetFullTypeName(template.Path);

var fields = CreateTemplateFields(template, nameGenerator);

Expand All @@ -74,7 +77,9 @@ protected virtual IEnumerable<TemplateFieldCodeGenerationMetadata> CreateTemplat
var currentField = new TemplateFieldCodeGenerationMetadata(field, nameGenerator.ConvertToIdentifier(field.Name));

if (_fieldMap.ContainsKey(currentField.Id))
{
currentField.Type = _fieldMap[currentField.Id];
}

fields.Add(currentField);
}
Expand Down

0 comments on commit 74ca0c6

Please sign in to comment.