diff --git a/.gitignore b/.gitignore index afa3460..e96102b 100644 --- a/.gitignore +++ b/.gitignore @@ -175,4 +175,5 @@ BuiltFiles_*.txt # don't supply any 3rd party dll's lib/*.dll SampleLibrary/Documentation.md -SampleLibrary/TdsT4CodeGeneratedFile.cs \ No newline at end of file +SampleLibrary/TdsT4CodeGeneratedFile.cs +/.vs/CodeGeneration/v15/Server/sqlite3 diff --git a/Sitecore.Master/Code Generation Templates/GlassV4Item.tt b/Sitecore.Master/Code Generation Templates/GlassV4Item.tt new file mode 100644 index 0000000..824ebe4 --- /dev/null +++ b/Sitecore.Master/Code Generation Templates/GlassV4Item.tt @@ -0,0 +1,256 @@ +<#@ template language="C#" #> +<#@ output encoding="utf-8"#> + +<#@ include file="Helpers.tt" #> +<#@ include file="StringExtensions.tt" #> +<#@ include file="GeneralExtensions.tt" #> +<#@ include file="Inflector.tt" #> + +<#@ assembly name="System.Core.dll" #> + +<#@ import namespace="System" #> +<#@ import namespace="System.Text" #> +<#@ import namespace="System.Linq" #> +<#@ import namespace="System.Collections.Generic" #> +<#@ import namespace="HedgehogDevelopment.SitecoreProject.VSIP.CodeGeneration.Models" #> + +<#@ parameter name="Model" type="HedgehogDevelopment.SitecoreProject.VSIP.CodeGeneration.Models.SitecoreItem" #> +<#@ parameter name="DefaultNamespace" type="System.String" #> + +<# +/* +This TDS Code Generation template is used to generate objects that are compatible with the +Glass Sitecore Mapper that is available @ http://www.glass.lu/ + +There are a few things you can put in the 'Custom Data' property of a field in TDS. +To use multiple settings put them in as a querystring (key1=value&key2=value) + +ignore=true + Sets a field to be skipped over for code gen +name=[name] + Forces the name of the generated property. + If not specified, then the generated property is the name of the Sitecore field. + If the field stores multiple values, the property name is pluralized. +type=[type] + Sets the return type of the generated property +generic=[type] + In the event the type (either specificed or auto mapped) is a generic it will use this generic type. i.e. List +cachable=true + Sets a type to be cached by Glass +*/ +#> + +<# +// we only act on Templates +SitecoreTemplate template = Model as SitecoreTemplate; +if (template == null) +{ + return ""; +} + +string Tool = "Team Development for Sitecore - GlassItem.tt"; +string ToolVersion = "1.0"; +#> + +namespace <#= GetNamespace(DefaultNamespace, template)#> +{ + + + /// + /// <#= AsInterfaceName(template.Name) #> Interface + /// <#= GetValue(template.SitecoreFields, "__Short description")#> + /// Path: <#= template.Path #> + /// ID: <#= template.ID.ToString() #> + /// + [SitecoreType(TemplateId=<#= AsInterfaceName(template.Name) #>Constants.TemplateIdString, <#= GetGlassCachable(template) #>)] + public partial interface <#= AsInterfaceName(template.Name) #> : IGlassBase <#=GetObjectInheritanceDefinition(DefaultNamespace, template, true, (string s) => AsInterfaceName(s))#> + { + <#foreach(SitecoreField field in GetFieldsForTemplate(template, false)){#> + /// + /// The <#=field.Name#> field. + /// <#= GetValue(field.SitecoreFields, "__Short description")#> + /// Field Type: <#=field.Type#> + /// Field ID: <#=field.ID.ToString()#> + /// Custom Data: <#=field.Data#> + /// + [SitecoreField(<#= AsInterfaceName(template.Name) #>Constants.<#= GetPropertyName(field) #>FieldName)] + <#=GetGlassFieldType(field)#> <#= GetPropertyName(field) #> {get; set;} + + <#}#> + } + + + public static partial class <#= AsInterfaceName(template.Name) #>Constants{ + + public const string TemplateIdString = "<#= template.ID.ToString() #>"; + public static readonly ID TemplateId = new ID(TemplateIdString); + public const string TemplateName = "<#= template.Name #>"; + + <#foreach(SitecoreField field in GetFieldsForTemplate(template, true)){#> + + public static readonly ID <#= GetPropertyName(field) #>FieldId = new ID("<#=field.ID.ToString()#>"); + public const string <#= GetPropertyName(field) #>FieldName = "<#=field.Name#>"; + + <#}#> + + } + +<# +// If the name of the template looks like an Interface, then don't generate a class definition +if (!IsInterfaceWord(template.Name)){ #> + /// + /// <#= AsClassName(template.Name) #> + /// <#= GetValue(template.SitecoreFields, "__Short description")#> + /// Path: <#= template.Path #> + /// ID: <#= template.ID.ToString() #> + /// + [SitecoreType(TemplateId=<#= AsInterfaceName(template.Name) #>Constants.TemplateIdString, <#= GetGlassCachable(template) #>)] + public partial class <#= AsClassName(template.Name) #> : GlassBase, <#=AsInterfaceName(template.Name)#> + { + + <#foreach(SitecoreField field in GetFieldsForTemplate(template, true)){#> + /// + /// The <#=field.Name#> field. + /// <#= GetValue(field.SitecoreFields, "__Short description")#> + /// Field Type: <#=field.Type#> + /// Field ID: <#=field.ID.ToString()#> + /// Custom Data: <#=field.Data#> + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("<#=Tool#>", "<#=ToolVersion#>")] + [SitecoreField(<#= AsInterfaceName(template.Name) #>Constants.<#= GetPropertyName(field) #>FieldName)] + public virtual <#=GetGlassFieldType(field)#> <#= GetPropertyName(field) #> {get; set;} + + <#}#> + } +<#}#> +} + +<#+ +/// +/// Gets the inheritance string for the generated template +/// +/// The default namespace. +/// The template to get the bases for. +/// The function to run the base templates names through. +/// +public static string GetObjectInheritanceDefinition(string defaultNamespace, SitecoreTemplate item, bool includeLeadingComma, Func nameFunc) +{ + if (item.BaseTemplates.Count > 0) + { + return string.Concat(includeLeadingComma ? ", " : "", + item.BaseTemplates + .Select( bt => GetFullyQualifiedName(defaultNamespace, bt, nameFunc)) // select the name of the template with an 'I' prefix + .Aggregate( (total,next) => total + ", " + next) // basically a string.join(string[], '') + ); + } + return ""; +} + +public static string GetGlassCachable(SitecoreTemplate item) +{ + + string cachable = GetCustomProperty(item.Data, "cachable"); + + bool isCachable; + + bool.TryParse(cachable, out isCachable); + + return string.Concat("Cachable=",isCachable.ToString().ToLower()); + + + +} + +public static string GetGlassFieldType(SitecoreField field) +{ + if (field != null && field.Type != null) + { + // Pull out any 'type' param from the custom data field on the field in TDS + string customType = GetCustomProperty(field.Data, "type"); + string generic = GetCustomProperty(field.Data, "generic"); + + if (customType != "") + { + if (generic != "") + { + return string.Format("{0}<{1}>", customType, generic); + } + else + { + return customType; + } + } + + switch(field.Type.ToLower()) + { + case "tristate": + return "TriState"; + case "checkbox": + return "bool"; + + case "date": + case "datetime": + return "DateTime"; + + case "number": + return "float"; + + case "integer": + return "int"; + + case "treelist with search": + case "treelist": + case "treelistex": + case "treelist descriptive": + case "checklist": + case "multilist with search": + case "multilist": + return string.Format("IEnumerable<{0}>", string.IsNullOrEmpty(generic) ? "Guid" : generic); + + case "grouped droplink": + case "droplink": + case "lookup": + case "droptree": + case "reference": + case "tree": + return "Guid"; + + case "file": + return "File"; + + case "image": + return "Image"; + + case "general link": + case "general link with search": + return "Link"; + + case "password": + case "icon": + case "rich text": + case "html": + case "single-line text": + case "multi-line text": + case "frame": + case "text": + case "memo": + case "droplist": + case "grouped droplist": + case "valuelookup": + return "string"; + case "attachment": + case "word document": + return "System.IO.Stream"; + case "name lookup value list": + case "name value list": + return "System.Collections.Specialized.NameValueCollection"; + default: + return "object /* UNKNOWN */"; + } + } + else + { + throw new Exception("There is no 'Type' field on the " + field.Name + " field."); + } +} +#> diff --git a/Sitecore.Master/Code Generation Templates/HelixHeader.tt b/Sitecore.Master/Code Generation Templates/HelixHeader.tt new file mode 100644 index 0000000..82caf7c --- /dev/null +++ b/Sitecore.Master/Code Generation Templates/HelixHeader.tt @@ -0,0 +1,25 @@ +<#@ template language="C#" #> +<#@ assembly name="System.Core.dll" #> + +<#@ import namespace="System" #> +<#@ import namespace="System.Collections.Generic" #> +<#@ import namespace="System.Linq" #> +<#@ import namespace="System.Text" #> +<#@ import namespace="HedgehogDevelopment.SitecoreProject.VSIP.CodeGeneration.Models" #> + +<#@ parameter name="Model" type="HedgehogDevelopment.SitecoreProject.VSIP.CodeGeneration.Models.ProjectHeader" #> + +#pragma warning disable 1591 +#pragma warning disable 0108 +//------------------------------------------------------------------------------ +// +// This code was generated by Team Development for Sitecore. +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + + +using Sitecore.Data; + diff --git a/Sitecore.Master/Code Generation Templates/HelixItem.tt b/Sitecore.Master/Code Generation Templates/HelixItem.tt new file mode 100644 index 0000000..0d08b42 --- /dev/null +++ b/Sitecore.Master/Code Generation Templates/HelixItem.tt @@ -0,0 +1,57 @@ +<#@ template language="C#" #> +<#@ output encoding="utf-8"#> + +<#@ include file="Helpers.tt" #> +<#@ include file="StringExtensions.tt" #> +<#@ include file="GeneralExtensions.tt" #> +<#@ include file="Inflector.tt" #> + +<#@ assembly name="System.Core.dll" #> + +<#@ import namespace="System" #> +<#@ import namespace="System.Text" #> +<#@ import namespace="System.Linq" #> +<#@ import namespace="System.Collections.Generic" #> +<#@ import namespace="HedgehogDevelopment.SitecoreProject.VSIP.CodeGeneration.Models" #> + +<#@ parameter name="Model" type="HedgehogDevelopment.SitecoreProject.VSIP.CodeGeneration.Models.SitecoreItem" #> +<#@ parameter name="DefaultNamespace" type="System.String" #> + +<# +/* +This TDS Code Generation template is used to generate objects that are compatible with the +Habitat Example Project based on the Helix Architecture Principles available @ https://github.com/Sitecore/Habitat +*/ +#> + +<# +// we only act on Templates +SitecoreTemplate template = Model as SitecoreTemplate; +if (template == null) +{ + return ""; +} + +string Tool = "Team Development for Sitecore - HelixItem.tt"; +string ToolVersion = "1.0"; +#> + +namespace <#= GetNamespace(DefaultNamespace, template)#> +{ + public struct <#= AsStructName(template.Name) #> + { + public const string TemplateIdString = "<#= template.ID.ToString() #>"; + public static readonly ID TemplateId = new ID(TemplateIdString); + public const string TemplateName = "<#= template.Name #>"; + + public struct Fields + { + <#foreach(SitecoreField field in GetFieldsForTemplate(template, true)){#> + + public static readonly ID <#= GetPropertyName(field) #> = new ID("<#=field.ID.ToString()#>"); + public const string <#= GetPropertyName(field) #>FieldName = "<#=field.Name#>"; + + <#}#> + } + } +} diff --git a/Sitecore.Master/Code Generation Templates/StringExtensions.tt b/Sitecore.Master/Code Generation Templates/StringExtensions.tt index 69d6083..0867453 100644 --- a/Sitecore.Master/Code Generation Templates/StringExtensions.tt +++ b/Sitecore.Master/Code Generation Templates/StringExtensions.tt @@ -53,6 +53,12 @@ public static string AsClassName(string word) return GetFormattedWord(word, TitleCase); } +public static string AsStructName(string word) +{ + // TitleCase the word + return GetFormattedWord(word, TitleCase); +} + public static string AsPropertyName(string word, bool pluralize = false) { // TitleCase the word and pluralize it diff --git a/Sitecore.Master/Code Generation Templates/glassv4header.tt b/Sitecore.Master/Code Generation Templates/glassv4header.tt new file mode 100644 index 0000000..4c59d4c --- /dev/null +++ b/Sitecore.Master/Code Generation Templates/glassv4header.tt @@ -0,0 +1,83 @@ +<#@ template language="C#" #> +<#@ assembly name="System.Core" #> + +<#@ include file="Helpers.tt" #> +<#@ include file="StringExtensions.tt" #> +<#@ include file="GeneralExtensions.tt" #> +<#@ include file="Inflector.tt" #> + +<#@ import namespace="System" #> +<#@ import namespace="System.Linq" #> +<#@ import namespace="System.Collections.Generic" #> +<#@ import namespace="HedgehogDevelopment.SitecoreProject.VSIP.CodeGeneration.Models" #> + +<#@ parameter name="Model" type="HedgehogDevelopment.SitecoreProject.VSIP.CodeGeneration.Models.ProjectHeader" #> +<#@ parameter name="DefaultNamespace" type="System.String" #> + +#pragma warning disable 1591 +#pragma warning disable 0108 +//------------------------------------------------------------------------------ +// +// This code was generated by Team Development for Sitecore. +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using Glass.Mapper.Sc.Configuration.Attributes; +using Glass.Mapper.Sc.Configuration; +using Glass.Mapper.Sc.Fields; +using Sitecore.Globalization; +using Sitecore.Data; + + +<# +// Calculate the top leve namespace as configured in the target project and +// base namespace as defined in the TDS project +string fullNamespace = JoinNamespaces(DefaultNamespace, Model.BaseNamespace); +#> + +namespace <#=fullNamespace #> +{ + + public partial interface IGlassBase{ + + [SitecoreId] + Guid Id{ get; } + + [SitecoreInfo(SitecoreInfoType.Language)] + Language Language{ get; } + + [SitecoreInfo(SitecoreInfoType.Version)] + int Version { get; } + + [SitecoreInfo(SitecoreInfoType.Url)] + string Url { get; } + + [SitecoreInfo(SitecoreInfoType.TemplateId)] + Guid TemplateId { get; } + } + + public abstract partial class GlassBase : IGlassBase{ + + [SitecoreId] + public virtual Guid Id{ get; private set;} + + [SitecoreInfo(SitecoreInfoType.Language)] + public virtual Language Language{ get; private set; } + + [SitecoreInfo(SitecoreInfoType.Version)] + public virtual int Version { get; private set; } + + [SitecoreInfo(SitecoreInfoType.Url)] + public virtual string Url { get; private set; } + + [SitecoreInfo(SitecoreInfoType.TemplateId)] + public virtual Guid TemplateId { get; private set; } + } +} diff --git a/Sitecore.Master/Sitecore.Master.scproj b/Sitecore.Master/Sitecore.Master.scproj index 8e7af5a..956217e 100644 --- a/Sitecore.Master/Sitecore.Master.scproj +++ b/Sitecore.Master/Sitecore.Master.scproj @@ -26,8 +26,8 @@ Documentation.md SampleLibrary BaseNamespace - MDDocHeader.tt - MDDocItem.tt + mddocheader.tt + mddocitem.tt true @@ -645,26 +645,30 @@ - - - - - - - - - - - - - - - {3fffc16d-eacd-452f-975e-9f48c4a95c6d} UI - + + + + + + + + + + + + + + + + + + + + \ No newline at end of file