2014-05-13 12:36:38 +02:00
using System ;
2020-11-24 12:52:48 +01:00
using Microsoft.AspNetCore.Html ;
using Microsoft.AspNetCore.Mvc.Rendering ;
2021-02-18 11:06:02 +01:00
using Umbraco.Cms.Core.Models.PublishedContent ;
2014-05-13 12:36:38 +02:00
2020-11-24 12:52:48 +01:00
namespace Umbraco.Extensions
2014-05-13 12:36:38 +02:00
{
2014-10-07 13:39:18 +02:00
public static class GridTemplateExtensions
2014-05-13 12:36:38 +02:00
{
2021-02-05 16:31:14 +01:00
public static IHtmlContent GetGridHtml ( this IHtmlHelper html , IPublishedProperty property , string framework = "bootstrap3" )
2015-01-30 15:48:55 +11:00
{
2017-12-06 11:51:35 +01:00
var asString = property . GetValue ( ) as string ;
2020-11-24 12:52:48 +01:00
if ( asString ! = null & & string . IsNullOrEmpty ( asString ) ) return new HtmlString ( string . Empty ) ;
2015-01-30 15:48:55 +11:00
2021-02-05 17:17:59 +01:00
var view = "grid/" + framework ;
2017-12-06 11:51:35 +01:00
return html . Partial ( view , property . GetValue ( ) ) ;
2015-01-30 15:48:55 +11:00
}
2020-11-24 12:52:48 +01:00
public static IHtmlContent GetGridHtml ( this IHtmlHelper html , IPublishedContent contentItem )
2015-01-30 15:48:55 +11:00
{
2021-02-05 16:31:14 +01:00
return html . GetGridHtml ( contentItem , "bodyText" , "bootstrap3" ) ;
2015-01-30 15:48:55 +11:00
}
2020-11-24 12:52:48 +01:00
public static IHtmlContent GetGridHtml ( this IHtmlHelper html , IPublishedContent contentItem , string propertyAlias )
2015-01-30 15:48:55 +11:00
{
2019-10-07 22:10:21 +02:00
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 ) ) ;
2015-01-30 15:48:55 +11:00
2021-02-05 16:31:14 +01:00
return html . GetGridHtml ( contentItem , propertyAlias , "bootstrap3" ) ;
2015-01-30 15:48:55 +11:00
}
2020-11-24 12:52:48 +01:00
public static IHtmlContent GetGridHtml ( this IHtmlHelper html , IPublishedContent contentItem , string propertyAlias , string framework )
2015-01-30 15:48:55 +11:00
{
2019-10-07 22:10:21 +02:00
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 ) ) ;
2015-01-30 15:48:55 +11:00
2021-02-05 17:17:59 +01:00
var view = "grid/" + framework ;
2015-01-30 15:48:55 +11:00
var prop = contentItem . GetProperty ( propertyAlias ) ;
2019-11-13 23:57:26 +01:00
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 ( ) ;
2015-01-30 15:48:55 +11:00
var asString = model as string ;
2020-11-24 12:52:48 +01:00
if ( asString ! = null & & string . IsNullOrEmpty ( asString ) ) return new HtmlString ( string . Empty ) ;
2015-01-30 19:04:39 +11:00
return html . Partial ( view , model ) ;
}
2020-11-24 12:52:48 +01:00
public static IHtmlContent GetGridHtml ( this IHtmlHelper html , IPublishedElement contentItem )
2020-04-09 15:34:22 +10:00
{
2021-02-05 16:31:14 +01:00
return html . GetGridHtml ( contentItem , "bodyText" , "bootstrap3" ) ;
2020-04-09 15:34:22 +10:00
}
2020-11-24 12:52:48 +01:00
public static IHtmlContent GetGridHtml ( this IHtmlHelper html , IPublishedElement contentItem , string propertyAlias )
2020-04-09 15:34:22 +10:00
{
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" ) ;
2020-04-09 15:34:22 +10:00
}
2020-11-24 12:52:48 +01:00
public static IHtmlContent GetGridHtml ( this IHtmlHelper html , IPublishedElement contentItem , string propertyAlias , string framework )
2020-04-09 15:34:22 +10:00
{
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 17:17:59 +01:00
var view = "grid/" + framework ;
2020-04-09 15:34:22 +10:00
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 ;
2020-11-24 12:52:48 +01:00
if ( asString ! = null & & string . IsNullOrEmpty ( asString ) ) return new HtmlString ( string . Empty ) ;
2020-04-09 15:34:22 +10:00
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" )
2015-01-30 19:04:39 +11:00
{
2017-12-06 11:51:35 +01:00
var asString = property . GetValue ( ) as string ;
2020-11-24 12:52:48 +01:00
if ( asString ! = null & & string . IsNullOrEmpty ( asString ) ) return new HtmlString ( string . Empty ) ;
2015-01-30 15:48:55 +11:00
2021-02-05 17:17:59 +01:00
var view = "grid/" + framework ;
2017-12-06 11:51:35 +01:00
return html . Partial ( view , property . GetValue ( ) ) ;
2015-01-30 19:04:39 +11:00
}
2019-11-13 23:57:26 +01:00
2020-11-24 12:52:48 +01:00
public static IHtmlContent GetGridHtml ( this IPublishedContent contentItem , IHtmlHelper html )
2015-01-30 19:04:39 +11:00
{
2021-02-05 16:31:14 +01:00
return GetGridHtml ( contentItem , html , "bodyText" , "bootstrap3" ) ;
2015-01-30 19:04:39 +11:00
}
2019-11-13 23:57:26 +01:00
2020-11-24 12:52:48 +01:00
public static IHtmlContent GetGridHtml ( this IPublishedContent contentItem , IHtmlHelper html , string propertyAlias )
2015-01-30 19:04:39 +11:00
{
2019-10-07 22:10:21 +02:00
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 ) ) ;
2015-01-30 19:04:39 +11:00
2021-02-05 16:31:14 +01:00
return GetGridHtml ( contentItem , html , propertyAlias , "bootstrap3" ) ;
2015-01-30 19:04:39 +11:00
}
2019-11-13 23:57:26 +01:00
2020-11-24 12:52:48 +01:00
public static IHtmlContent GetGridHtml ( this IPublishedContent contentItem , IHtmlHelper html , string propertyAlias , string framework )
2015-01-30 19:04:39 +11:00
{
2019-10-07 22:10:21 +02:00
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 ) ) ;
2015-01-30 19:04:39 +11:00
2021-02-05 17:17:59 +01:00
var view = "grid/" + framework ;
2015-01-30 19:04:39 +11:00
var prop = contentItem . GetProperty ( propertyAlias ) ;
2019-11-13 23:57:26 +01:00
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 ( ) ;
2015-01-30 19:04:39 +11:00
var asString = model as string ;
2020-11-24 12:52:48 +01:00
if ( asString ! = null & & string . IsNullOrEmpty ( asString ) ) return new HtmlString ( string . Empty ) ;
2015-01-30 19:04:39 +11:00
2015-01-30 15:48:55 +11:00
return html . Partial ( view , model ) ;
}
2014-05-13 12:36:38 +02:00
}
}