-
Notifications
You must be signed in to change notification settings - Fork 51
/
VelirItem.tt
194 lines (164 loc) · 6.08 KB
/
VelirItem.tt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
<#@ 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
Custom Item Generator written by Velir and available @ http://trac.sitecore.net/CustomItemGenerator
*/
#>
<#
// we only act on Templates
SitecoreTemplate template = Model as SitecoreTemplate;
if (template == null)
{
return "";
}
string Tool = "Team Development for Sitecore - Velir.tt";
string ToolVersion = "1.0";
#>
namespace <#= GetNamespace(DefaultNamespace, template)#>
{
/// <summary>
/// <#= template.Name #>
/// <para><#= GetValue(template.SitecoreFields, "__Short description")#></para>
/// <para>Path: <#= template.Path #></para>
/// <para>ID: <#= template.ID.ToString() #></para>
/// </summary>
/// <remarks>
/// This example shows how to specify the <see cref="<#= template.Name #>{T}"/> type as a cref attribute.
/// </remarks>
public partial class <#= AsClassName(template.Name) #> : global::Sitecore.Data.Items.CustomItem
{
/// <summary>
/// The Template ID for <#= template.Path #>
/// </summary>
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("<#=Tool#>", "<#=ToolVersion#>")]
public static readonly string TemplateId = "<#=template.ID.ToString()#>";
<#if (template.BaseTemplates.Count > 0){#>
#region Inherited Base Templates
<#foreach(SitecoreTemplate baseTemplate in template.BaseTemplates){#>
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("<#=Tool#>", "<#=ToolVersion#>")]
private readonly <#=GetFullyQualifiedName(DefaultNamespace, baseTemplate)#> <#=AsFieldName(baseTemplate.Name)#>;
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("<#=Tool#>", "<#=ToolVersion#>")]
public <#=GetFullyQualifiedName(DefaultNamespace, baseTemplate)#> <#=AsPropertyName(baseTemplate.Name)#> { get { return <#=AsFieldName(baseTemplate.Name)#>; } }
<#}#>
#endregion
<#}#>
#region Boilerplate CustomItem Code
/// <example>
/// This sample should how to get an instance of the <see cref="<#=AsClassName(template.Name)#>"/> class.
/// <code>
/// <#=AsClassName(template.Name)#> <#=CamelCase(AsClassName(template.Name))#> = new <#=template.Name#>(Sitecore.Context.Item;
/// </code>
/// </example>
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("<#=Tool#>", "<#=ToolVersion#>")]
public <#= AsClassName(template.Name) #>(Item innerItem) : base(innerItem)
{
<#foreach(SitecoreTemplate baseTemplate in template.BaseTemplates){#>
<#=AsFieldName(baseTemplate.Name)#> = new <#=GetFullyQualifiedName(DefaultNamespace, baseTemplate)#>(innerItem);
<#}#>
}
/// <example>
/// This sample should how to get an instance of the <see cref="<#=AsClassName(template.Name)#>"/> class.
/// <code>
/// <#=AsClassName(template.Name)#> <#=CamelCase(AsClassName(template.Name))#> = Sitecore.Context.Item;
/// </code>
/// </example>
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("<#=Tool#>", "<#=ToolVersion#>")]
public static implicit operator <#= AsClassName(template.Name) #>(Item innerItem)
{
return innerItem != null ? new <#= AsClassName(template.Name) #>(innerItem) : null;
}
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("<#=Tool#>", "<#=ToolVersion#>")]
public static implicit operator Item(<#= AsClassName(template.Name) #> customItem)
{
return customItem != null ? customItem.InnerItem : null;
}
#endregion //Boilerplate CustomItem Code
#region Field Instance Methods
<#foreach(SitecoreField field in GetFieldsForTemplate(template, false)){
string fieldType = GetVelirFieldType(field);#>
<#if (fieldType == null){#>
//Could not find Field Type for <#=field.Type#>
<#}else{#>
/// <summary>
/// The <#=field.Name#> field.
/// <para><#= GetValue(field.SitecoreFields, "__Short description")#></para>
/// <para>Field Type: <#=field.Type#></para>
/// <para>Field ID: <#=field.ID.ToString()#></para>
/// <para>Custom Data: <#=field.Data#></para>
/// </summary>
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("<#=Tool#>", "<#=ToolVersion#>")]
public <#=fieldType#> <#= GetPropertyName(field) #> {get { return new <#=fieldType#>(InnerItem, InnerItem.Fields[new global::Sitecore.Data.ID("<#=field.ID.ToString()#>")]); } }
<#}#>
<#}#>
#endregion
}
}
<#+
// Gets the Content field type for the Sitecore field
public static string GetVelirFieldType(SitecoreField field)
{
if (field != null && field.Type != null)
{
switch(field.Type.ToLower())
{
case "checkbox":
return "CustomCheckboxField";
case "date":
case "datetime":
return "CustomDateField";
case "number":
case "integer":
return "CustomIntegerField";
case "treelist":
case "treelistex":
return "CustomTreeListField";
case "checklist":
return "CustomChecklistField";
case "droplist":
case "grouped droplist":
case "multilist":
return "CustomMultiListField";
case "grouped droplink":
case "droplink":
case "lookup":
case "droptree":
case "reference":
case "tree":
return "CustomLookupField";
case "file":
return "CustomFileField";
case "image":
return "CustomImageField";
case "general link":
return "CustomGeneralLinkField";
case "rich text":
case "html":
case "single-line text":
case "multi-line text":
case "text":
case "memo":
return "CustomTextField";
default:
return null;
}
}
else
{
throw new Exception("There is no 'Type' field on the " + field.Name + " field.");
}
}
#>