Empty spaces and indent issues with lpt templates

Posts   
 
    
zulu
User
Posts: 50
Joined: 25-Aug-2008
# Posted on: 17-May-2009 00:03:17   

Hello, I have created some lpt templates and they get generated fine but there are two things which, even though they have no effect on the code itself, are frustrating:

  1. For code like the following:
<% If _executingGenerator.ProjectDefinition.TypedLists.Count > 0 Then %>
Imports <%= _executingGenerator.ProjectDefinition.RootNameSpace %>.TypedListClasses
<% End If %>

gets generated as an empty line in the generated file.

  1. Code like the following:
<%= DotNetTemplateEngine.GetUserCodeRegion("InitializeDefaultSorter","'") %>

gets generated like this:

                                ' __LLBLGENPRO_USER_CODE_REGION_START 
        ' __LLBLGENPRO_USER_CODE_REGION_END

In other words, the indenting of the comment lines is not correct.

Are these bugs? How can I avoid such behaviour?

I'm using:

LLBLGen Pro 2.6.06102008 Final

Thanks for the help

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 17-May-2009 23:30:58   

Could you please attach the template so we can see if there is any line before or after messing this?

David Elizondo | LLBLGen Support Team
zulu
User
Posts: 50
Joined: 25-Aug-2008
# Posted on: 21-May-2009 17:56:02   

daelmo wrote:

Could you please attach the template so we can see if there is any line before or after messing this?

Sure, here are portions of the template that cause the problems mentioned.

For problem 1.

Imports <%= _executingGenerator.ProjectDefinition.RootNameSpace %>.HelperClasses
Imports <%= _executingGenerator.ProjectDefinition.RootNameSpace %>.CollectionClasses
Imports <%= _executingGenerator.ProjectDefinition.RootNameSpace %>.ValidatorClasses
<% If _executingGenerator.ProjectDefinition.TypedLists.Count > 0 Then %>
Imports <%= _executingGenerator.ProjectDefinition.RootNameSpace %>.TypedListClasses
<% End If %>
Imports Abakon.LLBL.DataAccess
Imports Abakon.LLBL.Repositories

For problem 2.

#Region "Sorting"
        Private Shared _defaultSorter As ISortExpression
        Public Shared ReadOnly Property DefaultSorter As ISortExpression
            Get
                If _defaultSorter Is Nothing Then InitializeDefaultSorter
                Return _defaultSorter
            End Get
        End Property

        Private Shared Sub InitializeDefaultSorter()
            <%= DotNetTemplateEngine.GetUserCodeRegion("InitializeDefaultSorter","'") %>
<% If EntityDefinition.PrimaryKeyFields.Count > 0 Then %>   
            ' if default sorter is not customized then we'll create one on the first primary key
            If _defaultSorter Is Nothing Then _
                _defaultSorter = New SortExpression(<%= EntityName %>Fields.<%= EntityDefinition.PrimaryKeyFields(0).FieldName %> Or SortOperator.Ascending)
<% End If %>        
        End Sub
#End Region
zulu
User
Posts: 50
Joined: 25-Aug-2008
# Posted on: 21-May-2009 18:17:11   

Another example:

<%
Dim pfIndexPower As Int16
If OneToManyRelations.Count > 0 OrElse ManyToOneRelations.Count > 0 Then
%>
    <Flags()> _
    Public Enum <%= EntityName %>PrefetchFlags
<%  
    For Each rel As EntityRelation In OneToManyRelations
        pfIndexPower += 1 %>    
        <%= rel.UtilizingPropertyName %> = <%= 2^pfIndexPower %>
<%
    Next
    For Each rel As EntityRelation In ManyToOneRelations
        pfIndexPower += 1 %>
        <%= rel.UtilizingPropertyName %> = <%= 2^pfIndexPower %>
<%
    Next
%>
    End Enum
<%  
End If
%>


Is generated as:

    <Flags()> _
    Public Enum DummyEntityPrefetchFlags
                Value1 = 1

                Value2 = 2

                Value2 = 4

                Value2 = 8
    End Enum

Instead of

    <Flags()> _
    Public Enum DummyEntityPrefetchFlags
                Value1 = 1
                Value2 = 2
                Value2 = 4
                Value2 = 8
    End Enum
Walaa avatar
Walaa
Support Team
Posts: 14950
Joined: 21-Aug-2005
# Posted on: 22-May-2009 09:37:56   

I don't think we can do much without the templates.

Anyway, please chek the following thread (discussing the indentation problem). (EDIT) http://www.llblgen.com/TinyForum/Messages.aspx?ThreadID=7254

zulu
User
Posts: 50
Joined: 25-Aug-2008
# Posted on: 22-May-2009 10:51:45   

Walaa wrote:

I don't think we can do much without the templates.

Anyway, please chek the following thread (discussing the indentation problem).

Which thread?

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 22-May-2009 16:29:40   

zulu wrote:

Hello, I have created some lpt templates and they get generated fine but there are two things which, even though they have no effect on the code itself, are frustrating:

  1. For code like the following:
<% If _executingGenerator.ProjectDefinition.TypedLists.Count > 0 Then %>
Imports <%= _executingGenerator.ProjectDefinition.RootNameSpace %>.TypedListClasses
<% End If %>

gets generated as an empty line in the generated file.

That's because of the CRLF after <% End If %> please place that statement on a different line to see if that helps. Other than that, there's not much we can do as the text right after <% End If %> is not belonging to the if statement, including the CRLF.

  1. Code like the following:
<%= DotNetTemplateEngine.GetUserCodeRegion("InitializeDefaultSorter","'") %>

gets generated like this:

                                ' __LLBLGENPRO_USER_CODE_REGION_START 
        ' __LLBLGENPRO_USER_CODE_REGION_END

In other words, the indenting of the comment lines is not correct.

Is the original region placed at the start of the line? Please do so.

zulu wrote:

Another example:

<%
Dim pfIndexPower As Int16
If OneToManyRelations.Count > 0 OrElse ManyToOneRelations.Count > 0 Then
%>
    <Flags()> _
    Public Enum <%= EntityName %>PrefetchFlags
<%  
    For Each rel As EntityRelation In OneToManyRelations
        pfIndexPower += 1 %>    
        <%= rel.UtilizingPropertyName %> = <%= 2^pfIndexPower %>
<%
    Next
    For Each rel As EntityRelation In ManyToOneRelations
        pfIndexPower += 1 %>
        <%= rel.UtilizingPropertyName %> = <%= 2^pfIndexPower %>
<%
    Next
%>
    End Enum
<%  
End If
%>

Is generated as:

    <Flags()> _
    Public Enum DummyEntityPrefetchFlags
                Value1 = 1

                Value2 = 2

                Value2 = 4

                Value2 = 8
    End Enum

Instead of

    <Flags()> _
    Public Enum DummyEntityPrefetchFlags
                Value1 = 1
                Value2 = 2
                Value2 = 4
                Value2 = 8
    End Enum

Please try:


Dim pfIndexPower As Int16
If OneToManyRelations.Count > 0 OrElse ManyToOneRelations.Count > 0 Then
%>
    <Flags()> _
    Public Enum <%= EntityName %>PrefetchFlags<%    
    For Each rel As EntityRelation In OneToManyRelations
        pfIndexPower += 1 %>    
        <%= rel.UtilizingPropertyName %> = <%= 2^pfIndexPower %><%
    Next
    For Each rel As EntityRelation In ManyToOneRelations
        pfIndexPower += 1 %>
        <%= rel.UtilizingPropertyName %> = <%= 2^pfIndexPower %><%
    Next%>
    End Enum
<%  
End If
%>


Frans Bouma | Lead developer LLBLGen Pro
Walaa avatar
Walaa
Support Team
Posts: 14950
Joined: 21-Aug-2005
# Posted on: 23-May-2009 21:19:47   

Zulu, I thought you were smart enough to guess the thread link stuck_out_tongue_winking_eye

Here is the thread I was refering to: . . . . . Oh I forgot to paste it again smile Here you are (seriously): http://www.llblgen.com/TinyForum/Messages.aspx?ThreadID=7254 And sorry for my earlier mistake.

zulu
User
Posts: 50
Joined: 25-Aug-2008
# Posted on: 24-May-2009 00:19:17   

Walaa, stuck_out_tongue_winking_eye

Guys, ok it looks like all the problems are solvable by changing the way I'm writing the templates, specifically where things are positioned.

However, since the syntax of ltp templates is similar to asp/ASP.NET syntax, which doesn't have these problems, I think it's quite frustrating for the developer to require thinking about where to put the <% %> sections when it's not really necessary.

I have created my own code generator for things other than LLBL, and I use codesmith as the engine that actually executes the templates, and the mentioned problems don't exist, <% %> sections can in fact be placed whereever I want and they don't end up with empty lines if they're not places in the 'correct' place.

Anyways, not a big deal.

Thanks a lot for your help. simple_smile