Skip to content

Commit

Permalink
Modified the converter, so that it also convert aspx-imports to razor…
Browse files Browse the repository at this point in the history
…-usings.
  • Loading branch information
vongruenigen committed Jul 22, 2011
1 parent 25bee59 commit 17b56bb
Show file tree
Hide file tree
Showing 13 changed files with 131 additions and 15 deletions.
Expand Up @@ -67,6 +67,7 @@
<SubType>ASPXCodeBehind</SubType>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="TestCases\TestCase25.aspx.txt" />
<None Include="TestCases\TestCase24.cshtml">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
Expand Down Expand Up @@ -224,6 +225,7 @@
<SubType>ASPXCodeBehind</SubType>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<None Include="TestCases\TestCase25.cshtml" />
</ItemGroup>
<ItemGroup>
<None Include="TestCases\TestCase01.cshtml">
Expand All @@ -233,11 +235,11 @@
<ItemGroup>
<ProjectReference Include="..\Telerik.RazorConverter.Tests.Common\Telerik.RazorConverter.Tests.Common.csproj">
<Project>{B30D861F-7D12-436A-BC5A-930D48291037}</Project>
<Name>RazorConverter.Tests.Common</Name>
<Name>Telerik.RazorConverter.Tests.Common</Name>
</ProjectReference>
<ProjectReference Include="..\Telerik.RazorConverter\Telerik.RazorConverter.csproj">
<Project>{88630458-D5BE-43B0-A7FB-BC0DFE6CB62E}</Project>
<Name>RazorConverter</Name>
<Name>Telerik.RazorConverter</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
Expand Down
@@ -1,4 +1,5 @@
@if (ViewData["telerik.web.mvc.products.examples"] != null)
@using Telerik.Web.Mvc
@if (ViewData["telerik.web.mvc.products.examples"] != null)
{
Html.Telerik().PanelBar()
.Name("navigation-product-examples")
Expand Down
@@ -0,0 +1,42 @@
<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage<IEnumerable<OrderDto>>" %>
<%@ Import Namespace="Project.Namespace.To.Models" %>

<asp:content contentplaceholderid="maincontent" runat="server">
<% using (Html.Configurator("The grid should...")
.PostTo("FirstLook", "Grid")
.Begin())
{ %>
<ul>
<li><%= Html.CheckBox("ajax", true, "make <strong>AJAX</strong> requests")%></li>
<li><%= Html.CheckBox("grouping", true, "allow <strong>grouping</strong> of data")%></li>
<li><%= Html.CheckBox("filtering", true, "allow <strong>filtering</strong> of data")%></li>
<li><%= Html.CheckBox("paging", true, "have <strong>pages</strong> with 10 items")%></li>
<li><%= Html.CheckBox("scrolling", true, "show a <strong>scrollbar</strong> when there are many items")%></li>
<li><%= Html.CheckBox("sorting", true, "allow <strong>sorting</strong> of data")%></li>
<li><%= Html.CheckBox("showFooter", true, "show footer")%></li>
</ul>
<button class="t-button t-state-default" type="submit">Apply</button>
<% } %>

<%= Html.Telerik().Grid(Model)
.Name("Grid")
.Columns(columns =>
{
columns.Bound(o => o.OrderID).Width(100);
columns.Bound(o => o.ContactName).Width(200);
columns.Bound(o => o.ShipAddress);
columns.Bound(o => o.OrderDate).Format("{0:MM/dd/yyyy}").Width(120);
})
.DataBinding(dataBinding =>
{
dataBinding.Server().Select("FirstLook", "Grid", new { ajax = ViewData["ajax"] });
dataBinding.Ajax().Select("_FirstLook", "Grid").Enabled((bool)ViewData["ajax"]);
})
.Scrollable(scrolling => scrolling.Enabled((bool)ViewData["scrolling"]))
.Sortable(sorting => sorting.Enabled((bool)ViewData["sorting"]))
.Pageable(paging => paging.Enabled((bool)ViewData["paging"]))
.Filterable(filtering => filtering.Enabled((bool)ViewData["filtering"]))
.Groupable(grouping => grouping.Enabled((bool)ViewData["grouping"]))
.Footer((bool)ViewData["showFooter"])
%>
</asp:content>
@@ -0,0 +1,38 @@
@model IEnumerable<OrderDto>
@using Project.Namespace.To.Models
@using (Html.Configurator("The grid should...")
.PostTo("FirstLook", "Grid")
.Begin())
{
<ul>
<li>@Html.CheckBox("ajax", true, "make <strong>AJAX</strong> requests")</li>
<li>@Html.CheckBox("grouping", true, "allow <strong>grouping</strong> of data")</li>
<li>@Html.CheckBox("filtering", true, "allow <strong>filtering</strong> of data")</li>
<li>@Html.CheckBox("paging", true, "have <strong>pages</strong> with 10 items")</li>
<li>@Html.CheckBox("scrolling", true, "show a <strong>scrollbar</strong> when there are many items")</li>
<li>@Html.CheckBox("sorting", true, "allow <strong>sorting</strong> of data")</li>
<li>@Html.CheckBox("showFooter", true, "show footer")</li>
</ul>
<button class="t-button t-state-default" type="submit">Apply</button>
}
@(Html.Telerik().Grid(Model)
.Name("Grid")
.Columns(columns =>
{
columns.Bound(o => o.OrderID).Width(100);
columns.Bound(o => o.ContactName).Width(200);
columns.Bound(o => o.ShipAddress);
columns.Bound(o => o.OrderDate).Format("{0:MM/dd/yyyy}").Width(120);
})
.DataBinding(dataBinding =>
{
dataBinding.Server().Select("FirstLook", "Grid", new { ajax = ViewData["ajax"] });
dataBinding.Ajax().Select("_FirstLook", "Grid").Enabled((bool)ViewData["ajax"]);
})
.Scrollable(scrolling => scrolling.Enabled((bool)ViewData["scrolling"]))
.Sortable(sorting => sorting.Enabled((bool)ViewData["sorting"]))
.Pageable(paging => paging.Enabled((bool)ViewData["paging"]))
.Filterable(filtering => filtering.Enabled((bool)ViewData["filtering"]))
.Groupable(grouping => grouping.Enabled((bool)ViewData["grouping"]))
.Footer((bool)ViewData["showFooter"])
)
Expand Up @@ -86,11 +86,11 @@
<ItemGroup>
<ProjectReference Include="..\Telerik.RazorConverter.Tests.Common\Telerik.RazorConverter.Tests.Common.csproj">
<Project>{B30D861F-7D12-436A-BC5A-930D48291037}</Project>
<Name>RazorConverter.Tests.Common</Name>
<Name>Telerik.RazorConverter.Tests.Common</Name>
</ProjectReference>
<ProjectReference Include="..\Telerik.RazorConverter\Telerik.RazorConverter.csproj">
<Project>{88630458-D5BE-43B0-A7FB-BC0DFE6CB62E}</Project>
<Name>RazorConverter</Name>
<Name>Telerik.RazorConverter</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup />
Expand Down
Expand Up @@ -215,6 +215,7 @@ public void Should_treat_doctype_as_text()
var document = parser.Parse(docType);
((IWebFormsTextNode)document.RootNode.Children[0]).Text.ShouldEqual(docType);
}

}
}

4 changes: 4 additions & 0 deletions Telerik.RazorConverter.sln
Expand Up @@ -20,6 +20,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Telerik.RazorConverter.Test
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Telerik.RazorConverter.Tests.Integration", "Telerik.RazorConverter.Tests.Integration\Telerik.RazorConverter.Tests.Integration.csproj", "{D41C5C1A-83E4-43E4-AE54-2FC44CE87BA8}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "TestItems", "TestItems", "{02F8810D-BE2D-4D6E-9EF7-7A7DBA8502A6}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{F4DA0538-E425-4E71-A508-0D024B125043}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down
32 changes: 23 additions & 9 deletions Telerik.RazorConverter/Razor/Converters/DirectiveConverter.cs
Expand Up @@ -23,19 +23,33 @@ public IList<IRazorNode> ConvertNode(IWebFormsNode node)
var result = new List<IRazorNode>();

var directiveNode = node as IWebFormsDirectiveNode;
if (directiveNode != null &&
directiveNode.Attributes.ContainsKey("inherits"))

if (directiveNode != null)
{
var inheritsFrom = directiveNode.Attributes["inherits"];
var viewPageGenericType = new Regex("System.Web.Mvc.(?:ViewPage|ViewUserControl)<(?<type>.*)>");
var typeMatch = viewPageGenericType.Match(inheritsFrom);
if (typeMatch.Success)
if (directiveNode.Attributes.ContainsKey("inherits"))
{
result.Add(DirectiveNodeFactory.CreateDirectiveNode("model", typeMatch.Result("${type}")));
var inheritsFrom = directiveNode.Attributes["inherits"];
var viewPageGenericType = new Regex("System.Web.Mvc.(?:ViewPage|ViewUserControl)<(?<type>.*)>");
var typeMatch = viewPageGenericType.Match(inheritsFrom);
if (typeMatch.Success)
{
result.Add(DirectiveNodeFactory.CreateDirectiveNode("model", typeMatch.Result("${type}")));
}
else if (inheritsFrom != "System.Web.Mvc.ViewPage" && inheritsFrom != "System.Web.Mvc.ViewUserControl")
{
result.Add(DirectiveNodeFactory.CreateDirectiveNode("inherits", directiveNode.Attributes["inherits"]));
}
}
else if (inheritsFrom != "System.Web.Mvc.ViewPage" && inheritsFrom != "System.Web.Mvc.ViewUserControl")
else if (directiveNode.Attributes.ContainsKey("namespace") &&
directiveNode.Directive == DirectiveType.Import)
{
result.Add(DirectiveNodeFactory.CreateDirectiveNode("inherits", directiveNode.Attributes["inherits"]));
/* Case of of a using directive */
var imports = directiveNode.Attributes["namespace"];

if (!string.IsNullOrEmpty(imports))
{
result.Add(DirectiveNodeFactory.CreateDirectiveNode("using", directiveNode.Attributes["namespace"]));
}
}
}

Expand Down
Expand Up @@ -29,6 +29,11 @@ public IDocument<IRazorNode> Convert(IDocument<IWebFormsNode> srcDoc)
{
if (converter.CanConvertNode(srcNode))
{
if (srcNode.Type == NodeType.Directive && srcNode.Attributes.ContainsKey("namespace"))
{
var i = 1;
}

foreach (var dstNode in converter.ConvertNode(srcNode))
{
rootNode.Children.Add(dstNode);
Expand Down
1 change: 1 addition & 0 deletions Telerik.RazorConverter/WebForms/DOM/DirectiveType.cs
Expand Up @@ -4,6 +4,7 @@ public enum DirectiveType
{
Page,
Control,
Import,
Unknown
}
}
4 changes: 4 additions & 0 deletions Telerik.RazorConverter/WebForms/DOM/WebFormsNodeFactory.cs
Expand Up @@ -66,6 +66,10 @@ private IWebFormsNode DirectiveNodeBuilder(Match match)
{
node.Directive = DirectiveType.Control;
}
else if (directiveType.Contains("import"))
{
node.Directive = DirectiveType.Import;
}
}

return node;
Expand Down
4 changes: 4 additions & 0 deletions Telerik.RazorConverter/WebForms/Parsing/WebFormsParser.cs
Expand Up @@ -78,6 +78,10 @@ public IDocument<IWebFormsNode> Parse(string input)
{
if ((match = directiveRegex.Match(input, startAt)).Success)
{
if (input.Contains(@"Namespace="))
{
var i = 0;
}
var directiveNode = NodeFactory.CreateNode(match, NodeType.Directive);
parentNode.Children.Add(directiveNode);
}
Expand Down
2 changes: 1 addition & 1 deletion aspx2razor/aspx2razor.csproj
Expand Up @@ -63,7 +63,7 @@
<ItemGroup>
<ProjectReference Include="..\Telerik.RazorConverter\Telerik.RazorConverter.csproj">
<Project>{88630458-D5BE-43B0-A7FB-BC0DFE6CB62E}</Project>
<Name>RazorConverter</Name>
<Name>Telerik.RazorConverter</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
Expand Down

0 comments on commit 17b56bb

Please sign in to comment.