mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-09-19 18:27:55 +08:00
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:
@@ -8,6 +8,7 @@ using NUnit.Framework;
|
||||
using Orchard.Environment;
|
||||
using Orchard.Mvc.ModelBinders;
|
||||
using Orchard.Mvc.Routes;
|
||||
using Orchard.Packages;
|
||||
|
||||
namespace Orchard.Tests.Environment {
|
||||
[TestFixture]
|
||||
@@ -35,7 +36,9 @@ namespace Orchard.Tests.Environment {
|
||||
new[] { provider1, provider2 },
|
||||
publisher,
|
||||
new[] { modelBinderProvider1, modelBinderProvider2 },
|
||||
modelBinderPublisher);
|
||||
modelBinderPublisher,
|
||||
new ViewEngineCollection(),
|
||||
new Moq.Mock<IPackageManager>().Object);
|
||||
|
||||
runtime.Activate();
|
||||
|
||||
|
@@ -42,10 +42,6 @@ namespace Orchard.Web {
|
||||
protected void Application_Start() {
|
||||
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);
|
||||
|
@@ -168,8 +168,6 @@
|
||||
<Content Include="Content\Images\title_background.gif" />
|
||||
<Content Include="Content\Site2.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\Shared\ExtraUserControl.ascx" />
|
||||
<Content Include="Views\Shared\Footer.ascx" />
|
||||
|
@@ -82,7 +82,7 @@
|
||||
<Content Include="Views\Admin\Create.aspx" />
|
||||
<Content Include="Views\Admin\Edit.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="Content\Site.css" />
|
||||
<Content Include="Views\Web.config" />
|
||||
|
@@ -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>
|
||||
|
@@ -70,6 +70,7 @@
|
||||
<ItemGroup>
|
||||
<Content Include="Package.txt" />
|
||||
<Content Include="Views\Admin\Index.aspx" />
|
||||
<Content Include="Views\Models\EditorTemplates\WikiSettingsRecord.ascx" />
|
||||
<Content Include="Web.config" />
|
||||
<Content Include="Views\Web.config" />
|
||||
</ItemGroup>
|
||||
|
@@ -1,7 +1,11 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Web.Mvc;
|
||||
using Orchard.Mvc.ModelBinders;
|
||||
using Orchard.Mvc.Routes;
|
||||
using Orchard.Packages;
|
||||
|
||||
namespace Orchard.Environment {
|
||||
public class DefaultOrchardShell : IOrchardShell {
|
||||
@@ -9,21 +13,63 @@ namespace Orchard.Environment {
|
||||
private readonly IRoutePublisher _routePublisher;
|
||||
private readonly IEnumerable<IModelBinderProvider> _modelBinderProviders;
|
||||
private readonly IModelBinderPublisher _modelBinderPublisher;
|
||||
private readonly ViewEngineCollection _viewEngines;
|
||||
private readonly IPackageManager _packageManager;
|
||||
|
||||
public DefaultOrchardShell(
|
||||
IEnumerable<IRouteProvider> routeProviders,
|
||||
IRoutePublisher routePublisher,
|
||||
IEnumerable<IModelBinderProvider> modelBinderProviders,
|
||||
IModelBinderPublisher modelBinderPublisher) {
|
||||
IModelBinderPublisher modelBinderPublisher,
|
||||
ViewEngineCollection viewEngines,
|
||||
IPackageManager packageManager) {
|
||||
_routeProviders = routeProviders;
|
||||
_routePublisher = routePublisher;
|
||||
_modelBinderProviders = modelBinderProviders;
|
||||
_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() {
|
||||
_routePublisher.Publish(_routeProviders.SelectMany(provider => provider.GetRoutes()));
|
||||
_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");
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user