Skip to content
This repository was archived by the owner on Feb 10, 2024. It is now read-only.

Commit aba6500

Browse files
committed
Relocated "ViewExists" method to "ViewHelper" class.
Removed the ViewEnginesCollectionExtensions class.
1 parent b4d8da9 commit aba6500

File tree

5 files changed

+23
-34
lines changed

5 files changed

+23
-34
lines changed

src/Our.Umbraco.DocTypeGridEditor/Extensions/ViewEnginesCollectionExtensions.cs

Lines changed: 0 additions & 23 deletions
This file was deleted.

src/Our.Umbraco.DocTypeGridEditor/Our.Umbraco.DocTypeGridEditor.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,6 @@
9696
<ItemGroup>
9797
<Compile Include="Bootstrap.cs" />
9898
<Compile Include="Extensions\JsonExtensions.cs" />
99-
<Compile Include="Extensions\ViewEnginesCollectionExtensions.cs" />
10099
<Compile Include="Helpers\DocTypeGridEditorHelper.cs" />
101100
<Compile Include="Helpers\XmlHelper.cs" />
102101
<Compile Include="Models\DetachedPublishedContent.cs" />

src/Our.Umbraco.DocTypeGridEditor/Web/Controllers/DocTypeGridEditorSurfaceController.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.Web.Mvc;
33
using Our.Umbraco.DocTypeGridEditor.Extensions;
4+
using Our.Umbraco.DocTypeGridEditor.Web.Helpers;
45
using Umbraco.Core;
56
using Umbraco.Core.Models;
67
using Umbraco.Web.Mvc;
@@ -53,14 +54,14 @@ protected override PartialViewResult PartialView(string viewName, object model)
5354
if (IsPreview && string.IsNullOrWhiteSpace(PreviewViewPath) == false)
5455
{
5556
var previewViewPath = GetFullViewPath(viewName, PreviewViewPath);
56-
if (ViewEngines.Engines.ViewExists(ControllerContext, previewViewPath, true))
57+
if (ViewHelper.ViewExists(ControllerContext, previewViewPath, true))
5758
return base.PartialView(previewViewPath, model);
5859
}
5960

6061
if (string.IsNullOrWhiteSpace(ViewPath) == false)
6162
{
6263
var viewPath = GetFullViewPath(viewName, ViewPath);
63-
if (ViewEngines.Engines.ViewExists(ControllerContext, viewPath, true))
64+
if (ViewHelper.ViewExists(ControllerContext, viewPath, true))
6465
return base.PartialView(viewPath, model);
6566
}
6667

src/Our.Umbraco.DocTypeGridEditor/Web/Extensions/HtmlHelperExtensions.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -90,19 +90,19 @@ public static HtmlString RenderDocTypeGridEditorItem(
9090
&& isPreview)
9191
{
9292
var fullPreviewViewPath = $"{previewViewPath}{editorAlias}.cshtml";
93-
if (ViewEngines.Engines.ViewExists(helper.ViewContext, fullPreviewViewPath, true))
93+
if (ViewHelper.ViewExists(helper.ViewContext, fullPreviewViewPath, true))
9494
{
9595
return helper.Partial(fullPreviewViewPath, content);
9696
}
9797

9898
fullPreviewViewPath = $"{previewViewPath}{content.DocumentTypeAlias}.cshtml";
99-
if (ViewEngines.Engines.ViewExists(helper.ViewContext, fullPreviewViewPath, true))
99+
if (ViewHelper.ViewExists(helper.ViewContext, fullPreviewViewPath, true))
100100
{
101101
return helper.Partial(fullPreviewViewPath, content);
102102
}
103103

104104
fullPreviewViewPath = $"{previewViewPath}Default.cshtml";
105-
if (ViewEngines.Engines.ViewExists(helper.ViewContext, fullPreviewViewPath, true))
105+
if (ViewHelper.ViewExists(helper.ViewContext, fullPreviewViewPath, true))
106106
{
107107
return helper.Partial(fullPreviewViewPath, content);
108108
}
@@ -112,26 +112,26 @@ public static HtmlString RenderDocTypeGridEditorItem(
112112
if (string.IsNullOrWhiteSpace(viewPath) == false)
113113
{
114114
var fullViewPath = $"{viewPath}{editorAlias}.cshtml";
115-
if (ViewEngines.Engines.ViewExists(helper.ViewContext, fullViewPath, true))
115+
if (ViewHelper.ViewExists(helper.ViewContext, fullViewPath, true))
116116
{
117117
return helper.Partial(fullViewPath, content);
118118
}
119119

120120
fullViewPath = $"{viewPath}{content.DocumentTypeAlias}.cshtml";
121-
if (ViewEngines.Engines.ViewExists(helper.ViewContext, fullViewPath, true))
121+
if (ViewHelper.ViewExists(helper.ViewContext, fullViewPath, true))
122122
{
123123
return helper.Partial(fullViewPath, content);
124124
}
125125

126126
fullViewPath = $"{viewPath}Default.cshtml";
127-
if (ViewEngines.Engines.ViewExists(helper.ViewContext, fullViewPath, true))
127+
if (ViewHelper.ViewExists(helper.ViewContext, fullViewPath, true))
128128
{
129129
return helper.Partial(fullViewPath, content);
130130
}
131131
}
132132

133133
// Resort to standard partial views
134-
if (ViewEngines.Engines.ViewExists(helper.ViewContext, editorAlias, true))
134+
if (ViewHelper.ViewExists(helper.ViewContext, editorAlias, true))
135135
{
136136
return helper.Partial(editorAlias, content);
137137
}

src/Our.Umbraco.DocTypeGridEditor/Web/Helpers/ViewHelper.cs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ internal static class ViewHelper
1010
{
1111
private class DummyController : Controller { }
1212

13-
internal static string RenderPartial(string partialName, object model, HttpContextBase httpContext = null)
13+
public static string RenderPartial(string partialName, object model, HttpContextBase httpContext = null)
1414
{
1515
using (var sw = new StringWriter())
1616
{
@@ -34,5 +34,17 @@ internal static string RenderPartial(string partialName, object model, HttpConte
3434
return sw.ToString();
3535
}
3636
}
37+
38+
public static bool ViewExists(ControllerContext controllerContext, string viewName, bool isPartial = false)
39+
{
40+
var result = isPartial == false
41+
? ViewEngines.Engines.FindView(controllerContext, viewName, null)
42+
: ViewEngines.Engines.FindPartialView(controllerContext, viewName);
43+
44+
if (result.View != null)
45+
return true;
46+
47+
return false;
48+
}
3749
}
3850
}

0 commit comments

Comments
 (0)