Skip to content

Commit

Permalink
Improved/fixed some of the logic for rendering the grid
Browse files Browse the repository at this point in the history
  • Loading branch information
abjerner committed Jan 22, 2017
1 parent 18fe771 commit bb866cf
Show file tree
Hide file tree
Showing 6 changed files with 82 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System.Web;
using System.Web.Mvc;

namespace Skybrud.Umbraco.GridData.Extensions {

/// <summary>
/// Class holding various extension methods for using the typed Grid.
/// </summary>
public static partial class TypedGridExtensionMethods {

/// <summary>
/// Gets the HTML of the specified <paramref name="control"/>.
/// </summary>
/// <param name="helper">The instance of <see cref="HtmlHelper"/> used for rendering the control.</param>
/// <param name="control">The control to be rendered.</param>
/// <returns>An instance of <see cref="HtmlString"/>.</returns>
public static HtmlString RenderGridControl(this HtmlHelper helper, GridControl control) {
if (helper == null || control == null) return new HtmlString("");
return control.GetHtml(helper);
}

/// <summary>
/// Gets the HTML of the specified <paramref name="control"/>.
/// </summary>
/// <param name="helper">The instance of <see cref="HtmlHelper"/> used for rendering the control.</param>
/// <param name="control">The control to be rendered.</param>
/// <param name="partial">The partial view to be used for the rendering.</param>
/// <returns>An instance of <see cref="HtmlString"/>.</returns>
public static HtmlString RenderGridControl(this HtmlHelper helper, GridControl control, string partial) {
if (helper == null || control == null) return new HtmlString("");
return control.GetHtml(helper, partial);
}

}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System.Web;
using System.Web.Mvc;

namespace Skybrud.Umbraco.GridData.Extensions {

/// <summary>
/// Class holding various extension methods for using the typed Grid.
/// </summary>
public static partial class TypedGridExtensionMethods {

/// <summary>
/// Gets the HTML of the specified <paramref name="row"/>.
/// </summary>
/// <param name="helper">The instance of <see cref="HtmlHelper"/> used for rendering the row.</param>
/// <param name="row">The row to be rendered.</param>
/// <returns>An instance of <see cref="HtmlString"/>.</returns>
public static HtmlString RenderGridRow(this HtmlHelper helper, GridRow row) {
if (helper == null || row == null) return new HtmlString("");
return row.GetHtml(helper);
}

/// <summary>
/// Gets the HTML of the specified <paramref name="row"/>.
/// </summary>
/// <param name="helper">The instance of <see cref="HtmlHelper"/> used for rendering the row.</param>
/// <param name="row">The row to be rendered.</param>
/// <param name="partial">The partial view to be used for the rendering.</param>
/// <returns>An instance of <see cref="HtmlString"/>.</returns>
public static HtmlString RenderGridRow(this HtmlHelper helper, GridRow row, string partial) {
if (helper == null || row == null) return new HtmlString("");
return row.GetHtml(helper, partial);
}

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace Skybrud.Umbraco.GridData.Extensions {
/// <summary>
/// Class holding various extension methods for using the typed Grid.
/// </summary>
public static class TypedGridExtensionMethods {
public static partial class TypedGridExtensionMethods {

#region Constants

Expand Down
10 changes: 4 additions & 6 deletions src/Skybrud.Umbraco.GridData/GridControl.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Text.RegularExpressions;
using System.Web;
using System.Web.Mvc;
using System.Web.Mvc.Html;
Expand Down Expand Up @@ -104,14 +105,11 @@ public HtmlString GetHtml(HtmlHelper helper, string partial) {
// If the wrapper is NULL, we shouldn't render the control
if (wrapper == null) return new HtmlString("");

// Prepend the path to the "Controls" folder if not already specified
if (!partial.StartsWith("~/") && !partial.StartsWith("~/")) {
partial = "~/Views/Partials/TypedGrid/Controls/" + partial;
// Prepend the path to the "Editors" folder if not already specified
if (Regex.IsMatch(partial, "^[a-zA-Z0-9-_]+$")) {
partial = "TypedGrid/Editors/" + partial;
}

// Append the ".cshtml" extension if not already specified
if (!partial.EndsWith(".cshtml")) partial += ".cshtml";

// Render the partial view
return helper.Partial(partial, wrapper);

Expand Down
8 changes: 3 additions & 5 deletions src/Skybrud.Umbraco.GridData/GridRow.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Linq;
using System.Text.RegularExpressions;
using System.Web;
using System.Web.Mvc;
using System.Web.Mvc.Html;
Expand Down Expand Up @@ -161,13 +162,10 @@ public HtmlString GetHtml(HtmlHelper helper, string partial) {
if (String.IsNullOrWhiteSpace(partial)) throw new ArgumentNullException("partial");

// Prepend the path to the "Rows" folder if not already specified
if (!partial.StartsWith("~/") && !partial.StartsWith("~/")) {
partial = "~/Views/Partials/TypedGrid/Rows/" + partial;
if (Regex.IsMatch(partial, "^[a-zA-Z0-9-_]+$")) {
partial = "TypedGrid/Rows/" + partial;
}

// Append the ".cshtml" extension if not already specified
if (!partial.EndsWith(".cshtml")) partial += ".cshtml";

// Render the partial view
return helper.Partial(partial, this);

Expand Down
2 changes: 2 additions & 0 deletions src/Skybrud.Umbraco.GridData/Skybrud.Umbraco.GridData.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,8 @@
<Compile Include="Converters\Fanoe\FanoeGridConverter.cs" />
<Compile Include="Converters\Umbraco\UmbracoGridConverter.cs" />
<Compile Include="Converters\GridConverterCollection.cs" />
<Compile Include="Extensions\TypedGridExtensionMethods.Rows.cs" />
<Compile Include="Extensions\TypedGridExtensionMethods.Controls.cs" />
<Compile Include="GridDictionaryItem.cs" />
<Compile Include="GridElement.cs" />
<Compile Include="GridUtils.cs" />
Expand Down

0 comments on commit bb866cf

Please sign in to comment.