Moved RenderModel to Models namespace. Created new base UmbracoViewPage to use for umbraco partial views, etc... and renamed

RenderViewPage to UmbracoTemplatePage which now inherits from UmbracoViewPage. Added NiceUrl and NiceUrlWithDomain as extension
methods to IPublishedContent.
This commit is contained in:
Shannon Deminick
2012-10-24 09:59:23 +05:00
parent 258d19df22
commit d4d4272b1b
11 changed files with 74 additions and 27 deletions

View File

@@ -5,6 +5,7 @@ using Umbraco.Core;
using Umbraco.Tests.Stubs;
using Umbraco.Tests.TestHelpers;
using Umbraco.Web;
using Umbraco.Web.Models;
using Umbraco.Web.Mvc;
using Umbraco.Web.Routing;
using umbraco.BusinessLogic;

View File

@@ -1,10 +1,7 @@
using System.Globalization;
using System.Xml;
using Umbraco.Core.Models;
using umbraco;
using umbraco.interfaces;
namespace Umbraco.Web.Mvc
namespace Umbraco.Web.Models
{
/// <summary>
/// Represents the model for the current rendering page in Umbraco

View File

@@ -1,4 +1,5 @@
using System.Web.Mvc;
using Umbraco.Web.Models;
namespace Umbraco.Web.Mvc
{

View File

@@ -2,6 +2,7 @@ using System;
using System.IO;
using System.Web.Mvc;
using Umbraco.Core.Logging;
using Umbraco.Web.Models;
using Umbraco.Web.Routing;
namespace Umbraco.Web.Mvc

View File

@@ -7,6 +7,7 @@ using System.Web.Routing;
using Umbraco.Core;
using Umbraco.Core.Logging;
using Umbraco.Core.Models;
using Umbraco.Web.Models;
using Umbraco.Web.Routing;
using umbraco.cms.businesslogic.template;

View File

@@ -4,6 +4,7 @@ using System.Linq;
using System.Web.Mvc;
using Umbraco.Core;
using Umbraco.Core.IO;
using Umbraco.Web.Models;
namespace Umbraco.Web.Mvc
{

View File

@@ -0,0 +1,37 @@
using Umbraco.Core.Dictionary;
using Umbraco.Core.Dynamics;
using Umbraco.Core.Models;
using Umbraco.Web.Models;
namespace Umbraco.Web.Mvc
{
/// <summary>
/// The View that front-end templates inherit from
/// </summary>
public abstract class UmbracoTemplatePage : UmbracoViewPage<RenderModel>
{
protected UmbracoTemplatePage()
{
}
protected override void InitializePage()
{
base.InitializePage();
//set the model to the current node if it is not set, this is generally not the case
if (Model != null)
{
////this.ViewData.Model = Model;
//var backingItem = new DynamicBackingItem(Model.CurrentNode);
var dynamicNode = new DynamicPublishedContent(Model.Content);
CurrentPage = dynamicNode.AsDynamic();
}
}
/// <summary>
/// Returns the a DynamicPublishedContent object
/// </summary>
public dynamic CurrentPage { get; private set; }
}
}

View File

@@ -1,33 +1,22 @@
using System.Web.Mvc;
using Umbraco.Core;
using Umbraco.Core.Dictionary;
using Umbraco.Core.Dynamics;
using Umbraco.Core.Models;
using Umbraco.Web.Models;
using Umbraco.Web.Routing;
namespace Umbraco.Web.Mvc
{
/// <summary>
/// The View that front-end templates inherit from
/// The View that umbraco front-end views inherit from
/// </summary>
public abstract class RenderViewPage : WebViewPage<RenderModel>
public abstract class UmbracoViewPage<T> : WebViewPage<T>
{
protected RenderViewPage()
protected UmbracoViewPage()
{
}
protected override void InitializePage()
{
//set the model to the current node if it is not set, this is generally not the case
if (Model != null)
{
////this.ViewData.Model = Model;
//var backingItem = new DynamicBackingItem(Model.CurrentNode);
var dynamicNode = new DynamicPublishedContent(Model.Content);
CurrentPage = dynamicNode.AsDynamic();
}
base.InitializePage();
PublishedContentRequest = (PublishedContentRequest)ViewContext.RouteData.DataTokens.GetRequiredObject("umbraco-doc-request");
UmbracoContext = (UmbracoContext)ViewContext.RouteData.DataTokens.GetRequiredObject("umbraco-context");
ApplicationContext = UmbracoContext.Application;
@@ -46,12 +35,7 @@ namespace Umbraco.Web.Mvc
/// <summary>
/// Returns the current PublishedContentRequest
/// </summary>
internal PublishedContentRequest PublishedContentRequest { get; private set; }
/// <summary>
/// Returns the a DynamicPublishedContent object
/// </summary>
public dynamic CurrentPage { get; private set; }
internal PublishedContentRequest PublishedContentRequest { get; private set; }
private UmbracoHelper _helper;

View File

@@ -23,6 +23,28 @@ namespace Umbraco.Web
/// </remarks>
public static class PublishedContentExtensions
{
/// <summary>
/// Gets the NiceUrl for the content item
/// </summary>
/// <param name="doc"></param>
/// <returns></returns>
public static string NiceUrl(this IPublishedContent doc)
{
var umbHelper = new UmbracoHelper(UmbracoContext.Current);
return umbHelper.NiceUrl(doc.Id);
}
/// <summary>
/// Gets the NiceUrlWithDomain for the content item
/// </summary>
/// <param name="doc"></param>
/// <returns></returns>
public static string NiceUrlWithDomain(this IPublishedContent doc)
{
var umbHelper = new UmbracoHelper(UmbracoContext.Current);
return umbHelper.NiceUrlWithDomain(doc.Id);
}
/// <summary>
/// Returns the current template Alias
/// </summary>

View File

@@ -265,6 +265,7 @@
<Compile Include="DefaultPublishedMediaStore.cs" />
<Compile Include="Dictionary\UmbracoCultureDictionary.cs" />
<Compile Include="Dictionary\UmbracoCultureDictionaryFactory.cs" />
<Compile Include="Mvc\UmbracoViewPage.cs" />
<Compile Include="PublishedContentExtensions.cs" />
<Compile Include="ExamineExtensions.cs" />
<Compile Include="FormlessPage.cs">
@@ -360,12 +361,12 @@
<Compile Include="Mvc\MasterControllerFactory.cs" />
<Compile Include="Mvc\RenderActionInvoker.cs" />
<Compile Include="Mvc\RenderControllerFactory.cs" />
<Compile Include="Mvc\RenderModel.cs" />
<Compile Include="Models\RenderModel.cs" />
<Compile Include="Mvc\RenderModelBinder.cs" />
<Compile Include="Mvc\RenderMvcController.cs" />
<Compile Include="Mvc\RenderRouteHandler.cs" />
<Compile Include="Mvc\RenderViewEngine.cs" />
<Compile Include="Mvc\RenderViewPage.cs" />
<Compile Include="Mvc\UmbracoTemplatePage.cs" />
<Compile Include="Mvc\RouteDefinition.cs" />
<Compile Include="Mvc\RouteValueDictionaryExtensions.cs" />
<Compile Include="Routing\DocumentLookupBase.cs" />

View File

@@ -10,6 +10,7 @@ using Umbraco.Core.Dynamics;
using Umbraco.Core.PropertyEditors;
using Umbraco.Web.Dictionary;
using Umbraco.Web.Media.ThumbnailProviders;
using Umbraco.Web.Models;
using Umbraco.Web.Mvc;
using Umbraco.Web.PropertyEditors;
using Umbraco.Web.Routing;