Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Modified the converter, so that it also convert aspx-imports to razor…

…-usings.
  • Loading branch information...
commit 17b56bb559c5209e02691631f4a0e903e0635478 1 parent 25bee59
@vongruenigen vongruenigen authored
View
6 Telerik.RazorConverter.Tests.Integration/Telerik.RazorConverter.Tests.Integration.csproj
@@ -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>
@@ -224,6 +225,7 @@
<SubType>ASPXCodeBehind</SubType>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
+ <None Include="TestCases\TestCase25.cshtml" />
</ItemGroup>
<ItemGroup>
<None Include="TestCases\TestCase01.cshtml">
@@ -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" />
View
3  Telerik.RazorConverter.Tests.Integration/TestCases/TestCase09.cshtml
@@ -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")
View
42 Telerik.RazorConverter.Tests.Integration/TestCases/TestCase25.aspx.txt
@@ -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>
View
38 Telerik.RazorConverter.Tests.Integration/TestCases/TestCase25.cshtml
@@ -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"])
+)
View
4 Telerik.RazorConverter.Tests/Telerik.RazorConverter.Tests.csproj
@@ -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 />
View
1  Telerik.RazorConverter.Tests/WebForms/WebFormsParserTests.cs
@@ -215,6 +215,7 @@ public void Should_treat_doctype_as_text()
var document = parser.Parse(docType);
((IWebFormsTextNode)document.RootNode.Children[0]).Text.ShouldEqual(docType);
}
+
}
}
View
4 Telerik.RazorConverter.sln
@@ -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
View
32 Telerik.RazorConverter/Razor/Converters/DirectiveConverter.cs
@@ -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"]));
+ }
}
}
View
5 Telerik.RazorConverter/Razor/Converters/WebFormsToRazorConverter.cs
@@ -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);
View
1  Telerik.RazorConverter/WebForms/DOM/DirectiveType.cs
@@ -4,6 +4,7 @@ public enum DirectiveType
{
Page,
Control,
+ Import,
Unknown
}
}
View
4 Telerik.RazorConverter/WebForms/DOM/WebFormsNodeFactory.cs
@@ -66,6 +66,10 @@ private IWebFormsNode DirectiveNodeBuilder(Match match)
{
node.Directive = DirectiveType.Control;
}
+ else if (directiveType.Contains("import"))
+ {
+ node.Directive = DirectiveType.Import;
+ }
}
return node;
View
4 Telerik.RazorConverter/WebForms/Parsing/WebFormsParser.cs
@@ -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);
}
View
2  aspx2razor/aspx2razor.csproj
@@ -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" />
Please sign in to comment.
Something went wrong with that request. Please try again.