Files
Umbraco-CMS/src/Umbraco.Web.Common/Extensions/GridTemplateExtensions.cs

115 lines
5.7 KiB
C#
Raw Normal View History

using System;
using Microsoft.AspNetCore.Html;
using Microsoft.AspNetCore.Mvc.Rendering;
using Umbraco.Cms.Core.Models.PublishedContent;
namespace Umbraco.Extensions
{
2014-10-07 13:39:18 +02:00
public static class GridTemplateExtensions
{
2021-02-05 16:31:14 +01:00
public static IHtmlContent GetGridHtml(this IHtmlHelper html, IPublishedProperty property, string framework = "bootstrap3")
{
2017-12-06 11:51:35 +01:00
var asString = property.GetValue() as string;
if (asString != null && string.IsNullOrEmpty(asString)) return new HtmlString(string.Empty);
var view = "grid/" + framework;
2017-12-06 11:51:35 +01:00
return html.Partial(view, property.GetValue());
}
public static IHtmlContent GetGridHtml(this IHtmlHelper html, IPublishedContent contentItem)
{
2021-02-05 16:31:14 +01:00
return html.GetGridHtml(contentItem, "bodyText", "bootstrap3");
}
public static IHtmlContent GetGridHtml(this IHtmlHelper html, IPublishedContent contentItem, string propertyAlias)
{
if (propertyAlias == null) throw new ArgumentNullException(nameof(propertyAlias));
if (string.IsNullOrWhiteSpace(propertyAlias)) throw new ArgumentException("Value can't be empty or consist only of white-space characters.", nameof(propertyAlias));
2021-02-05 16:31:14 +01:00
return html.GetGridHtml(contentItem, propertyAlias, "bootstrap3");
}
public static IHtmlContent GetGridHtml(this IHtmlHelper html, IPublishedContent contentItem, string propertyAlias, string framework)
{
if (propertyAlias == null) throw new ArgumentNullException(nameof(propertyAlias));
if (string.IsNullOrWhiteSpace(propertyAlias)) throw new ArgumentException("Value can't be empty or consist only of white-space characters.", nameof(propertyAlias));
var view = "grid/" + framework;
var prop = contentItem.GetProperty(propertyAlias);
if (prop == null) throw new InvalidOperationException("No property type found with alias " + propertyAlias);
2017-12-06 11:51:35 +01:00
var model = prop.GetValue();
var asString = model as string;
if (asString != null && string.IsNullOrEmpty(asString)) return new HtmlString(string.Empty);
return html.Partial(view, model);
}
public static IHtmlContent GetGridHtml(this IHtmlHelper html, IPublishedElement contentItem)
{
2021-02-05 16:31:14 +01:00
return html.GetGridHtml(contentItem, "bodyText", "bootstrap3");
}
public static IHtmlContent GetGridHtml(this IHtmlHelper html, IPublishedElement contentItem, string propertyAlias)
{
if (propertyAlias == null) throw new ArgumentNullException(nameof(propertyAlias));
if (string.IsNullOrWhiteSpace(propertyAlias)) throw new ArgumentException("Value can't be empty or consist only of white-space characters.", nameof(propertyAlias));
2021-02-05 16:31:14 +01:00
return html.GetGridHtml(contentItem, propertyAlias, "bootstrap3");
}
public static IHtmlContent GetGridHtml(this IHtmlHelper html, IPublishedElement contentItem, string propertyAlias, string framework)
{
if (propertyAlias == null) throw new ArgumentNullException(nameof(propertyAlias));
if (string.IsNullOrWhiteSpace(propertyAlias)) throw new ArgumentException("Value can't be empty or consist only of white-space characters.", nameof(propertyAlias));
var view = "grid/" + framework;
var prop = contentItem.GetProperty(propertyAlias);
if (prop == null) throw new InvalidOperationException("No property type found with alias " + propertyAlias);
var model = prop.GetValue();
var asString = model as string;
if (asString != null && string.IsNullOrEmpty(asString)) return new HtmlString(string.Empty);
return html.Partial(view, model);
}
2021-02-05 16:31:14 +01:00
public static IHtmlContent GetGridHtml(this IPublishedProperty property, IHtmlHelper html, string framework = "bootstrap3")
{
2017-12-06 11:51:35 +01:00
var asString = property.GetValue() as string;
if (asString != null && string.IsNullOrEmpty(asString)) return new HtmlString(string.Empty);
var view = "grid/" + framework;
2017-12-06 11:51:35 +01:00
return html.Partial(view, property.GetValue());
}
public static IHtmlContent GetGridHtml(this IPublishedContent contentItem, IHtmlHelper html)
{
2021-02-05 16:31:14 +01:00
return GetGridHtml(contentItem, html, "bodyText", "bootstrap3");
}
public static IHtmlContent GetGridHtml(this IPublishedContent contentItem, IHtmlHelper html, string propertyAlias)
{
if (propertyAlias == null) throw new ArgumentNullException(nameof(propertyAlias));
if (string.IsNullOrWhiteSpace(propertyAlias)) throw new ArgumentException("Value can't be empty or consist only of white-space characters.", nameof(propertyAlias));
2021-02-05 16:31:14 +01:00
return GetGridHtml(contentItem, html, propertyAlias, "bootstrap3");
}
public static IHtmlContent GetGridHtml(this IPublishedContent contentItem, IHtmlHelper html, string propertyAlias, string framework)
{
if (propertyAlias == null) throw new ArgumentNullException(nameof(propertyAlias));
if (string.IsNullOrWhiteSpace(propertyAlias)) throw new ArgumentException("Value can't be empty or consist only of white-space characters.", nameof(propertyAlias));
var view = "grid/" + framework;
var prop = contentItem.GetProperty(propertyAlias);
if (prop == null) throw new InvalidOperationException("No property type found with alias " + propertyAlias);
2017-12-06 11:51:35 +01:00
var model = prop.GetValue();
var asString = model as string;
if (asString != null && string.IsNullOrEmpty(asString)) return new HtmlString(string.Empty);
return html.Partial(view, model);
}
}
}