All right!
Almost there!
Generator config for test:
<generatorConfiguration>
<name>Lpt template tester config</name>
<description>Tests the new Lpt (C# based templates) engine.</description>
<vendor>Solutions Design</vendor>
<version>1.0.2004.1.100304</version>
<tasks>
<taskGroup description="Test generation group">
<task name="TestsDirectoryCreator" assemblyFilename="SD.LLBLGen.Pro.TaskPerformers.dll" taskPerformerClass="SD.LLBLGen.Pro.TaskPerformers.DirectoryCreator">
<parameter name="folderToCreate" value="TestClasses"/>
<parameter name="failWhenExistent" value="false"/>
<parameter name="clearWhenExistent" value="false"/>
</task>
<task name="TestsGenerator" assemblyFilename="SD.LLBLGen.Pro.LptParser.dll" taskPerformerClass="SD.LLBLGen.Pro.LptParser.CsTemplateEngine">
<parameter name="destinationFolder" value="TestClasses"/>
<parameter name="failWhenExistent" value="false"/>
<parameter name="filenameFormat" value="testclass.[extension]"/>
<parameter name="templateID" value="LPT_TestTemplate"/>
<parameter name="emitType" value="generic"/>
</task>
</taskGroup>
</tasks>
</generatorConfiguration>
Templateset config for test:
<templateSetDefinition>
<vendor>Solutions Design</vendor>
<name>Lpt Test template set</name>
<version>1.0.2004.1.100304</version>
<trueKeyword>true</trueKeyword>
<falseKeyword>false</falseKeyword>
<thisKeyword>this</thisKeyword>
<nullKeyword>null</nullKeyword>
<targetLanguageDescription>C#</targetLanguageDescription>
<fileExtension>cs</fileExtension>
<arrayIndexOperatorOpenChar>[</arrayIndexOperatorOpenChar>
<arrayIndexOperatorCloseChar>]</arrayIndexOperatorCloseChar>
<hasArrayIndexOperatorOnIdentifier>false</hasArrayIndexOperatorOnIdentifier>
<lineConcatenator></lineConcatenator>
<templateBindings>
<!-- test template bindings -->
<templateBinding templateID="LPT_TestTemplate" templateFilename="..\..\..\LptTemplates\testtemplate.lpt" />
<templateBinding templateID="LPT_TestTemplate2" templateFilename="..\..\..\LptTemplates\testtemplate2.lpt" />
</templateBindings>
</templateSetDefinition>
testtemplate.lpt (lpt is from LLBLGen Pro Template
)
<$ C:\Myprojects\VS.NET Projects\LLBLGen Pro\RuntimeLibraries\DotNet11\SD.LLBLGen.Pro.ORMSupportClasses.NET11.dll $>
<[ System.IO ]>
<[ System.Text ]>
<[ SD.LLBLGen.Pro.ORMSupportClasses ]>
<# LPT_TestTemplate2 #>
//////////////////////
// this is testcode
// Project name: <%=_executingGenerator.ProjectDefinition.ProjectName%>
//////////////////////
using System;
public class Doh
{
public Doh()
{
<%
for(int i=0;i<10;i++)
{
%>
// Does: <%=WriteNonsense()%>
Console.WriteLine("lalala");
<%
}
%>
// some sense: <%= WriteSense()%>
<%
%>
}
}
<~
public string WriteNonsense()
{
return "Foo!";
}
~>
testtemplate2.lpt
<~
public string WriteSense()
{
return "Bar!";
}
~>
will be parsed / generated into this C# code:
using SD.LLBLGen.Pro.ORMSupportClasses;
using SD.LLBLGen.Pro.ApplicationCore;
using SD.LLBLGen.Pro.DBDriverCore;
using System;
using System.Collections;
using SD.LLBLGen.Pro.GeneratorCore;
using System.Text;
using SD.LLBLGen.Pro.LptParser;
using System.IO;
public class LPT_TestTemplate2 : ITemplateClass {
private StreamWriter __outputWriter;
private IGenerator _executingGenerator;
private Hashtable _parameters;
public LPT_TestTemplate2() {
__outputWriter=null;_executingGenerator=null;_parameters=null;
}
public string WriteSense()
{
return "Bar!";
}
private void __ScriptCode() {
}
public void ___RUN(IGenerator executingGenerator, Hashtable parameters, StreamWriter outputWriter) {
__outputWriter = outputWriter; _parameters = parameters; _executingGenerator=executingGenerator;
__ScriptCode();
}
}
public class LPT_TestTemplate : ITemplateClass {
private StreamWriter __outputWriter;
private IGenerator _executingGenerator;
private Hashtable _parameters;
public LPT_TestTemplate() {
__outputWriter=null;_executingGenerator=null;_parameters=null;
}
public string WriteSense()
{
return "Bar!";
}
public string WriteNonsense()
{
return "Foo!";
}
private void __ScriptCode() {
__outputWriter.Write("\n//////////////////////");
__outputWriter.Write("\n// this is testcode");
__outputWriter.Write("\n// Project name: ");
__outputWriter.Write(_executingGenerator.ProjectDefinition.ProjectName);
__outputWriter.Write("\n//////////////////////");
__outputWriter.Write("\nusing System;");
__outputWriter.Write("\npublic class Doh");
__outputWriter.Write("\n{");
__outputWriter.Write("\n public Doh() ");
__outputWriter.Write("\n {");
for(int i=0;i<10;i++)
{
__outputWriter.Write("\n // Does: ");
__outputWriter.Write(WriteNonsense());
__outputWriter.Write("\n Console.WriteLine(\"lalala\");");
__outputWriter.Write("\n ");
}
__outputWriter.Write("\n // some sense: ");
__outputWriter.Write( WriteSense());
__outputWriter.Write("\n ");
__outputWriter.Write("\n }");
__outputWriter.Write("\n}");
}
public void ___RUN(IGenerator executingGenerator, Hashtable parameters, StreamWriter outputWriter) {
__outputWriter = outputWriter; _parameters = parameters; _executingGenerator=executingGenerator;
__ScriptCode();
}
}
... which is then compiled into a library assembly and executed by the engine, which results into this code in the file testclass.cs:
//////////////////////
// this is testcode
// Project name: TestDB
//////////////////////
using System;
public class Doh
{
public Doh()
{
// Does: Foo!
Console.WriteLine("lalala");
// Does: Foo!
Console.WriteLine("lalala");
// Does: Foo!
Console.WriteLine("lalala");
// Does: Foo!
Console.WriteLine("lalala");
// Does: Foo!
Console.WriteLine("lalala");
// Does: Foo!
Console.WriteLine("lalala");
// Does: Foo!
Console.WriteLine("lalala");
// Does: Foo!
Console.WriteLine("lalala");
// Does: Foo!
Console.WriteLine("lalala");
// Does: Foo!
Console.WriteLine("lalala");
// some sense: Bar!
}
}
!!
!!
Needless to say, I'm very happy
. I hope to finalize the code on monday and upload a beta.
(there are more parameters thinkable for this, these will come up in the coming days I think when people start testing the bits
)
Note: the syntaxis is as simple as 1 2 3
(beat that, codesmith!
)
<$ referenced assembly $> , for referencing additional assemblies
<[ referenced namespace ]> , for referencing namespaces (using ... )
<# include template id #> , for including (can be nested) other templates
<% C# code %> , non-output C# code.
<%= C# code %>, output C# code. Single statement, do not append a ';'
<~ C# code ~> , code block, used to specify member variables for the template class, methods to use etc. etc.
all <% %> code will be added to a single method, (as well as the literal text between %> and <%
) which is called by ___RUN(). ___RUN() is called by the engine to execute the template.
That's about it