-
Notifications
You must be signed in to change notification settings - Fork 51
/
MDDocItem.tt
206 lines (180 loc) · 6.47 KB
/
MDDocItem.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
195
196
197
198
199
200
201
202
203
204
205
206
<#@ template language="C#" debug="true" #>
<#@ import namespace="System.Collections.Generic" #>
<#@ import namespace="HedgehogDevelopment.SitecoreProject.VSIP.CodeGeneration.Models" #>
<#
// The Item template is called for every Sitecore item elegible for code generation. TDS will execute this T4 template every time an
// item changes in TDS. The T4 template is responsible for generating code for only the Sitecore item TDS
// passes to the T4 template. TDS will join all created templates together to create a single file.
// Parameters passed to the T4 Template for code generation
// Model: This parameter contains information about the Sitecore Item to be generated. The Model will always be a type that inherits from SitecoreItem.
// DefaultNamespace: The DefaultNamespace parameter contains the default namespace of the project where the generated
// code file resides.
#>
<#@ parameter name="Model" type="HedgehogDevelopment.SitecoreProject.VSIP.CodeGeneration.Models.SitecoreItem" #>
<#@ parameter name="DefaultNamespace" type="System.String" #>
<#
/* The following types are used during code generation:
/// <summary>
/// Represents the SitecoreItem to be passed to the T4 template. Any object that is a SitecoreItem will inherit from this object.
/// </summary>
public class SitecoreItem
{
/// <summary>
/// The Sitecore item ID.
/// </summary>
public Guid ID { get; set; }
/// <summary>
/// The name of the Sitecore item. This may be different than the Display Name.
/// </summary>
public string Name { get; set; }
/// <summary>
/// The path to the item from the Sitecore root.
/// </summary>
public string Path { get; set; }
/// <summary>
/// Any custom data associated with the item. This data can be set on the property page associated with the Sitecore item in the solution explorer.
/// </summary>
public string Data { get; set; }
/// <summary>
/// The Parent SitecoreItem in the Sitecore hierarchy.
/// </summary>
public SitecoreItem Parent { get; set; }
/// <summary>
/// The name of the template the item is based on
/// </summary>
public string TemplateName { get; set; }
/// <summary>
/// The ID of the template the item is based on
/// </summary>
public Guid TemplateId { get; set; }
/// <summary>
/// Additional sitecore fields. These fields are set on the Code Generation Property page.
/// The key in the dictionary is the Field name, the value is the value of the field.
/// </summary>
public Dictionary<string, string> SitecoreFields;
/// <summary>
/// The calculated Namespace for the item. Each Sitecore item above the template is represented as part of the namespace.
/// A new Namespace can be set at any item in the items property page. This allows the code generation namespace to be arranged differently
/// than the Sitecore template hierarchy.
/// </summary>
public string Namespace { get; set; }
}
/// <summary>
/// Represents Template specific information for code generation.
/// </summary>
public class SitecoreTemplate : SitecoreItem
{
/// <summary>
/// The namespace broken out into individual segments.
/// </summary>
public IEnumerable<string> NamespaceSegments { get; }
/// <summary>
/// A list of all templates this template inherits from.
/// </summary>
public List<SitecoreTemplate> BaseTemplates { get; set; }
/// <summary>
/// A list of Sitecore Fields that make up this sitecore template.
/// </summary>
public List<SitecoreField> Fields { get; set; }
}
/// <summary>
/// Represents Field specific information for code generation.
/// </summary>
public class SitecoreField : SitecoreItem
{
/// <summary>
/// The type of the field from the template editor.
/// </summary>
public string Type { get; set; }
}
*/
#>
### `<#= Model.Path #>`
#### T4 Parameters
Target Project DefaultNamespace: `<#= DefaultNamespace #>`
Model Type: `<#=Model.GetType().Name.ToString()#>`
#### Sitecore Item Properties
Name: `<#= Model.Name #>`
ID: `<#= Model.ID #>`
Sitecore Path: `<#= Model.Path #>`
Template Name: `<#= Model.TemplateName #>`
Template Id: `<#= Model.TemplateId #>`
#### Project Item Properties
Calculated Namespace: `<#= Model.Namespace #>`
Custom Data: `<#= Model.Data #>`
#### Ancestors
<#
//See if the Sitecore Template has a parent and display the parent information
if (Model.Parent != null)
{
#>
<# GetParentInfo(Model.Parent); #>
<#
}
#>
#### Sitecore fields from Item
<#
// If there are any additional Sitecore field values for the template, they are stored in the
// SitecoreFields collection
foreach(KeyValuePair<string,string> sitecoreField in Model.SitecoreFields)
{
#>
- `<#=sitecoreField.Key#>`: `<#=sitecoreField.Value#>`
<#
}
//See what type the model is.
if (Model is SitecoreTemplate)
{
SitecoreTemplate template = (SitecoreTemplate)Model;
#>
#### Template Inheritance
<#
// The base templates can be retrieved as SitecoreTemplate objects from the BaseTemplate collection.
// The base template objects contain all information known about the template including Fields and BaseTemplates.
// If a template has a BaseTemplate not in the TDS project, it will not be included in this collection.
foreach(SitecoreTemplate baseTemplate in template.BaseTemplates)
{
#>
- Name: `<#= baseTemplate.Name#>`, ID: `<#= baseTemplate.ID #>`, Data: `<#= baseTemplate.Data #>`
<#
}
#>
#### Template Fields
<#
// The fields for a template can be retrieved as SitecoreField objects from the Fields collection.
// If the Sitecore Field is not in the TDS project, it will not be in this collection
foreach(SitecoreField field in template.Fields)
{
#>
- Field Name: `<#= field.Name #>`, ID: `<#= field.ID #>`, Type: `<#= field.Type #>`, Data: `<#= field.Data #>`
<#
// If there is any additional Sitecore field values retrieved from the field in the collection, it is stored in the
// SitecoreFields collection for the field.
foreach(KeyValuePair<string,string> sitecoreField in field.SitecoreFields)
{
#>
- `<#=sitecoreField.Key#>`: `<#=sitecoreField.Value#>`
<#
}
}
#>
<#
}
#>
----------------------------------------------------------
<#+
/// <summary>
/// Recursively walks up the item parents and prints the parent item details.
/// </summary>
/// <param name="item"></param>
private void GetParentInfo(SitecoreItem item)
{
#>
- Name: `<#= item.Name#>`, ID: `<#= item.ID #>`, Data: `<#= item.Data #>`
<#+
if (item.Parent!=null)
{
GetParentInfo(item.Parent);
}
}
#>