Updating location formats on view engine to support ~/Views/Models/ path in any active package. Enables rendering of EditorTemplates and opens the door for distributed rendering of content or widgets.

--HG--
extra : convert_revision : svn%3A5ff7c347-ad56-4c35-b696-ccb81de16e03/trunk%4041319
This commit is contained in:
loudej
2009-11-18 23:49:05 +00:00
parent 418453853d
commit b50f2c6fc7
9 changed files with 53 additions and 25 deletions

View File

@@ -8,6 +8,7 @@ using NUnit.Framework;
using Orchard.Environment; using Orchard.Environment;
using Orchard.Mvc.ModelBinders; using Orchard.Mvc.ModelBinders;
using Orchard.Mvc.Routes; using Orchard.Mvc.Routes;
using Orchard.Packages;
namespace Orchard.Tests.Environment { namespace Orchard.Tests.Environment {
[TestFixture] [TestFixture]
@@ -35,7 +36,9 @@ namespace Orchard.Tests.Environment {
new[] { provider1, provider2 }, new[] { provider1, provider2 },
publisher, publisher,
new[] { modelBinderProvider1, modelBinderProvider2 }, new[] { modelBinderProvider1, modelBinderProvider2 },
modelBinderPublisher); modelBinderPublisher,
new ViewEngineCollection(),
new Moq.Mock<IPackageManager>().Object);
runtime.Activate(); runtime.Activate();

View File

@@ -42,10 +42,6 @@ namespace Orchard.Web {
protected void Application_Start() { protected void Application_Start() {
RegisterRoutes(RouteTable.Routes); RegisterRoutes(RouteTable.Routes);
//TEMP: Modules should be able to register their stuff
var viewEngine = ViewEngines.Engines.OfType<VirtualPathProviderViewEngine>().Single();
viewEngine.AreaViewLocationFormats = OrchardLocationFormats().Concat(viewEngine.AreaViewLocationFormats).ToArray();
viewEngine.AreaPartialViewLocationFormats = OrchardLocationFormats().Concat(viewEngine.AreaPartialViewLocationFormats).ToArray();
_host = OrchardStarter.CreateHost(MvcSingletons); _host = OrchardStarter.CreateHost(MvcSingletons);

View File

@@ -168,8 +168,6 @@
<Content Include="Content\Images\title_background.gif" /> <Content Include="Content\Images\title_background.gif" />
<Content Include="Content\Site2.css" /> <Content Include="Content\Site2.css" />
<Content Include="Content\Site3.css" /> <Content Include="Content\Site3.css" />
<Content Include="Views\Admin\EditorTemplates\UserRolesViewModel.ascx" />
<Content Include="Views\Admin\EditorTemplates\WikiSettingsRecord.ascx" />
<Content Include="Views\Admin\Messages.ascx" /> <Content Include="Views\Admin\Messages.ascx" />
<Content Include="Views\Shared\ExtraUserControl.ascx" /> <Content Include="Views\Shared\ExtraUserControl.ascx" />
<Content Include="Views\Shared\Footer.ascx" /> <Content Include="Views\Shared\Footer.ascx" />

View File

@@ -82,7 +82,7 @@
<Content Include="Views\Admin\Create.aspx" /> <Content Include="Views\Admin\Create.aspx" />
<Content Include="Views\Admin\Edit.aspx" /> <Content Include="Views\Admin\Edit.aspx" />
<Content Include="Views\Admin\Index.aspx" /> <Content Include="Views\Admin\Index.aspx" />
<Content Include="Views\Shared\EditorTemplates\broken_UserRolesViewModel.ascx" /> <Content Include="Views\Models\EditorTemplates\UserRolesViewModel.ascx" />
<Content Include="Web.config" /> <Content Include="Web.config" />
<Content Include="Content\Site.css" /> <Content Include="Content\Site.css" />
<Content Include="Views\Web.config" /> <Content Include="Views\Web.config" />

View File

@@ -1,16 +0,0 @@
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<Orchard.Roles.ViewModels.UserRolesViewModel>" %>
<h3>
Roles</h3>
<ol>
<%
var index = 0; foreach (var entry in Model.Roles) {%>
<li>
<%= Html.Hidden("Roles[" + index + "].RoleId", entry.RoleId)%>
<label for="<%="Roles[" + index + "]_Granted"%>"><%= Html.CheckBox("Roles[" + index + "].Granted", entry.Granted)%> <%=Html.Encode(entry.Name)%></label>
</li>
<%++index;
} %>
</ol>

View File

@@ -70,6 +70,7 @@
<ItemGroup> <ItemGroup>
<Content Include="Package.txt" /> <Content Include="Package.txt" />
<Content Include="Views\Admin\Index.aspx" /> <Content Include="Views\Admin\Index.aspx" />
<Content Include="Views\Models\EditorTemplates\WikiSettingsRecord.ascx" />
<Content Include="Web.config" /> <Content Include="Web.config" />
<Content Include="Views\Web.config" /> <Content Include="Views\Web.config" />
</ItemGroup> </ItemGroup>

View File

@@ -1,7 +1,11 @@
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO;
using System.Linq; using System.Linq;
using System.Web.Mvc;
using Orchard.Mvc.ModelBinders; using Orchard.Mvc.ModelBinders;
using Orchard.Mvc.Routes; using Orchard.Mvc.Routes;
using Orchard.Packages;
namespace Orchard.Environment { namespace Orchard.Environment {
public class DefaultOrchardShell : IOrchardShell { public class DefaultOrchardShell : IOrchardShell {
@@ -9,21 +13,63 @@ namespace Orchard.Environment {
private readonly IRoutePublisher _routePublisher; private readonly IRoutePublisher _routePublisher;
private readonly IEnumerable<IModelBinderProvider> _modelBinderProviders; private readonly IEnumerable<IModelBinderProvider> _modelBinderProviders;
private readonly IModelBinderPublisher _modelBinderPublisher; private readonly IModelBinderPublisher _modelBinderPublisher;
private readonly ViewEngineCollection _viewEngines;
private readonly IPackageManager _packageManager;
public DefaultOrchardShell( public DefaultOrchardShell(
IEnumerable<IRouteProvider> routeProviders, IEnumerable<IRouteProvider> routeProviders,
IRoutePublisher routePublisher, IRoutePublisher routePublisher,
IEnumerable<IModelBinderProvider> modelBinderProviders, IEnumerable<IModelBinderProvider> modelBinderProviders,
IModelBinderPublisher modelBinderPublisher) { IModelBinderPublisher modelBinderPublisher,
ViewEngineCollection viewEngines,
IPackageManager packageManager) {
_routeProviders = routeProviders; _routeProviders = routeProviders;
_routePublisher = routePublisher; _routePublisher = routePublisher;
_modelBinderProviders = modelBinderProviders; _modelBinderProviders = modelBinderProviders;
_modelBinderPublisher = modelBinderPublisher; _modelBinderPublisher = modelBinderPublisher;
_viewEngines = viewEngines;
_packageManager = packageManager;
}
static IEnumerable<string> OrchardLocationFormats() {
return new[] {
"~/Packages/{2}/Views/{1}/{0}.aspx",
"~/Packages/{2}/Views/{1}/{0}.ascx",
"~/Packages/{2}/Views/Shared/{0}.aspx",
"~/Packages/{2}/Views/Shared/{0}.ascx",
"~/Core/{2}/Views/{1}/{0}.aspx",
"~/Core/{2}/Views/{1}/{0}.ascx",
"~/Core/{2}/Views/Shared/{0}.aspx",
"~/Core/{2}/Views/Shared/{0}.ascx",
};
} }
public void Activate() { public void Activate() {
_routePublisher.Publish(_routeProviders.SelectMany(provider => provider.GetRoutes())); _routePublisher.Publish(_routeProviders.SelectMany(provider => provider.GetRoutes()));
_modelBinderPublisher.Publish(_modelBinderProviders.SelectMany(provider => provider.GetModelBinders())); _modelBinderPublisher.Publish(_modelBinderProviders.SelectMany(provider => provider.GetModelBinders()));
var viewEngine = ViewEngines.Engines.OfType<VirtualPathProviderViewEngine>().Single();
viewEngine.AreaViewLocationFormats = OrchardLocationFormats()
.Concat(viewEngine.AreaViewLocationFormats)
.Distinct()
.ToArray();
viewEngine.AreaPartialViewLocationFormats = OrchardLocationFormats()
.Concat(viewEngine.AreaPartialViewLocationFormats)
.Distinct()
.ToArray();
var activePackageDescriptors = _packageManager.ActivePackages().Select(x => x.Descriptor);
var sharedLocationFormats = activePackageDescriptors.Select(x => ModelsLocationFormat(x));
viewEngine.PartialViewLocationFormats = sharedLocationFormats
.Concat(viewEngine.PartialViewLocationFormats)
.Distinct()
.ToArray();
}
private static string ModelsLocationFormat(PackageDescriptor descriptor) {
return Path.Combine(Path.Combine(descriptor.Location, descriptor.Name), "Views/Models/{0}.ascx");
} }
} }
} }