-
Notifications
You must be signed in to change notification settings - Fork 50
/
ItemPaths.tt
78 lines (67 loc) · 2.08 KB
/
ItemPaths.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
<#@ 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.SitecoreItem" #>
<#@ parameter name="DefaultNamespace" type="System.String" #>
<#
// Build ancestor list
SitecoreItem item = Model.Parent;
List<SitecoreItem> ancestors = new List<SitecoreItem>();
while(item != null){
ancestors.Add(item);
item = item.Parent;
}
// reverse the order
ancestors.Reverse();
#>
namespace <#= DefaultNamespace#>
{
<#=BuildClassDefinition("ItemTree")#>
<#
PushIndent("\t");
foreach(SitecoreItem ancestor in ancestors){#>
<#=BuildClassDefinition(ancestor)#>
<#
PushIndent("\t");
}
PushIndent("\t");
#>
/// <summary>
/// <#= Model.Name #> Item
/// <para><#= GetValue(Model.SitecoreFields, "__Short description")#></para>
/// <para>Path: <#= Model.Path #></para>
/// <para>ID: <#= Model.ID.ToString() #></para>
/// </summary>
<#=BuildClassDefinition(Model)#>
public static global::Sitecore.Data.ID ItemID { get { return new global::Sitecore.Data.ID("<#=Model.ID#>"); } }
public static string ItemName { get { return "<#=Model.Name#>"; } }
public static string ItemPath { get { return "<#=Model.Path#>"; } }
public static global::Sitecore.Data.ID TemplateID { get { return new global::Sitecore.Data.ID("<#=Model.TemplateId#>"); } }
public static string TemplateName { get { return "<#=Model.TemplateName#>"; } }
}
<#
PopIndent();
for(int i = 0; i< ancestors.Count; i++){
PopIndent();
#>
}
<#}
PopIndent();
#>
}
}
<#+
private string BuildClassDefinition(SitecoreItem item){
return BuildClassDefinition(AsClassName(item.Name));
}
private string BuildClassDefinition(string className){
return "public static partial class " + className + "{";
}
#>