mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-09-22 20:13:50 +08:00
Merge
--HG-- branch : dev
This commit is contained in:
@@ -1,4 +1,7 @@
|
||||
using Orchard.ContentManagement;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Web;
|
||||
using Orchard.ContentManagement;
|
||||
using Orchard.DisplayManagement.Descriptors;
|
||||
|
||||
namespace Orchard.Core.Contents {
|
||||
@@ -12,16 +15,19 @@ namespace Orchard.Core.Contents {
|
||||
.OnDisplaying(displaying => {
|
||||
ContentItem contentItem = displaying.Shape.ContentItem;
|
||||
if (contentItem != null) {
|
||||
//Content-BlogPost
|
||||
// Content__[ContentType] e.g. Content-BlogPost
|
||||
displaying.ShapeMetadata.Alternates.Add("Content__" + contentItem.ContentType);
|
||||
//Content-42
|
||||
displaying.ShapeMetadata.Alternates.Add("Content__" + contentItem.Id);
|
||||
//Content.Summary
|
||||
displaying.ShapeMetadata.Alternates.Add("Content_" + displaying.ShapeMetadata.DisplayType);
|
||||
//Content-Page.Summary
|
||||
|
||||
// Content_[DisplayType]__[ContentType] e.g. Content-BlogPost.Summary
|
||||
displaying.ShapeMetadata.Alternates.Add("Content_" + displaying.ShapeMetadata.DisplayType + "__" + contentItem.ContentType);
|
||||
|
||||
if (!displaying.ShapeMetadata.DisplayType.Contains("Admin"))
|
||||
// Content__[Id] e.g. Content-42
|
||||
displaying.ShapeMetadata.Alternates.Add("Content__" + contentItem.Id);
|
||||
|
||||
// Content_[DisplayType]__[Id] e.g. Content-42.Summary
|
||||
displaying.ShapeMetadata.Alternates.Add("Content_" + displaying.ShapeMetadata.DisplayType + "__" + contentItem.Id);
|
||||
|
||||
if ( !displaying.ShapeMetadata.DisplayType.Contains("Admin") )
|
||||
displaying.ShapeMetadata.Wrappers.Add("Content_ControlWrapper");
|
||||
}
|
||||
});
|
||||
|
@@ -7,6 +7,6 @@
|
||||
|
||||
@using (Html.BeginFormAntiForgeryPost()) {
|
||||
@Html.ValidationSummary()
|
||||
// Model is a Shape, calling Display() so that it is rendered using the most specific template for its Shape type
|
||||
// Model is a Shape, calling Display() so that it is rendered using the most specific template for its Shape type
|
||||
@Display(Model)
|
||||
}
|
@@ -9,6 +9,7 @@ using System.Web.Mvc.Html;
|
||||
using Orchard.DisplayManagement;
|
||||
using Orchard.DisplayManagement.Descriptors;
|
||||
using Orchard.DisplayManagement.Descriptors.ResourceBindingStrategy;
|
||||
using Orchard.Environment;
|
||||
using Orchard.Mvc;
|
||||
using Orchard.Settings;
|
||||
using Orchard.UI;
|
||||
@@ -20,23 +21,20 @@ using Orchard.Utility.Extensions;
|
||||
|
||||
namespace Orchard.Core.Shapes {
|
||||
public class CoreShapes : IShapeTableProvider {
|
||||
private readonly IWorkContextAccessor _workContextAccessor;
|
||||
private readonly IHttpContextAccessor _httpContextAccessor;
|
||||
private readonly Work<WorkContext> _workContext;
|
||||
private readonly Work<IResourceManager> _resourceManager;
|
||||
private readonly Work<IHttpContextAccessor> _httpContextAccessor;
|
||||
|
||||
public CoreShapes(IWorkContextAccessor workContextAccessor, IHttpContextAccessor httpContextAccessor) {
|
||||
// needed to get CurrentSite.
|
||||
// note that injecting ISiteService here causes a stack overflow in AutoFac!
|
||||
_workContextAccessor = workContextAccessor;
|
||||
public CoreShapes(
|
||||
Work<WorkContext> workContext,
|
||||
Work<IResourceManager> resourceManager,
|
||||
Work<IHttpContextAccessor> httpContextAccessor
|
||||
) {
|
||||
_workContext = workContext;
|
||||
_resourceManager = resourceManager;
|
||||
_httpContextAccessor = httpContextAccessor;
|
||||
}
|
||||
|
||||
// not injected the usual way because this component is a 'static' dependency and RM is per-request
|
||||
private IResourceManager ResourceManager {
|
||||
get {
|
||||
return _workContextAccessor.GetContext(_httpContextAccessor.Current()).Resolve<IResourceManager>();
|
||||
}
|
||||
}
|
||||
|
||||
public void Discover(ShapeTableBuilder builder) {
|
||||
// the root page shape named 'Layout' is wrapped with 'Document'
|
||||
// and has an automatic zone creating behavior
|
||||
@@ -54,6 +52,7 @@ namespace Orchard.Core.Shapes {
|
||||
layout.Content = created.New.Zone();
|
||||
layout.Content.ZoneName = "Content";
|
||||
layout.Content.Add(created.New.PlaceChildContent(Source: layout));
|
||||
|
||||
});
|
||||
|
||||
// 'Zone' shapes are built on the Zone base class
|
||||
@@ -66,6 +65,8 @@ namespace Orchard.Core.Shapes {
|
||||
string zoneName = zone.ZoneName;
|
||||
zone.Classes.Add("zone-" + zoneName.HtmlClassify());
|
||||
zone.Classes.Add("zone");
|
||||
|
||||
// Zone__[ZoneName] e.g. Zone-SideBar
|
||||
zone.Metadata.Alternates.Add("Zone__" + zoneName);
|
||||
});
|
||||
|
||||
@@ -208,25 +209,25 @@ namespace Orchard.Core.Shapes {
|
||||
[Shape]
|
||||
public void HeadScripts(dynamic Display, TextWriter Output) {
|
||||
WriteResources(Display, Output, "script", ResourceLocation.Head, null);
|
||||
WriteLiteralScripts(Output, ResourceManager.GetRegisteredHeadScripts());
|
||||
WriteLiteralScripts(Output, _resourceManager.Value.GetRegisteredHeadScripts());
|
||||
}
|
||||
|
||||
[Shape]
|
||||
public void FootScripts(dynamic Display, TextWriter Output) {
|
||||
WriteResources(Display, Output, "script", null, ResourceLocation.Head);
|
||||
WriteLiteralScripts(Output, ResourceManager.GetRegisteredFootScripts());
|
||||
WriteLiteralScripts(Output, _resourceManager.Value.GetRegisteredFootScripts());
|
||||
}
|
||||
|
||||
[Shape]
|
||||
public void Metas(TextWriter Output) {
|
||||
foreach (var meta in ResourceManager.GetRegisteredMetas()) {
|
||||
foreach (var meta in _resourceManager.Value.GetRegisteredMetas() ) {
|
||||
Output.WriteLine(meta.GetTag());
|
||||
}
|
||||
}
|
||||
|
||||
[Shape]
|
||||
public void HeadLinks(TextWriter Output) {
|
||||
foreach (var link in ResourceManager.GetRegisteredLinks()) {
|
||||
foreach (var link in _resourceManager.Value.GetRegisteredLinks() ) {
|
||||
Output.WriteLine(link.GetTag());
|
||||
}
|
||||
}
|
||||
@@ -257,7 +258,7 @@ namespace Orchard.Core.Shapes {
|
||||
|
||||
private void WriteResources(dynamic Display, TextWriter Output, string resourceType, ResourceLocation? includeLocation, ResourceLocation? excludeLocation) {
|
||||
bool debugMode;
|
||||
var site = _workContextAccessor.GetContext(_httpContextAccessor.Current()).CurrentSite;
|
||||
var site = _workContext.Value.CurrentSite;
|
||||
switch (site.ResourceDebugMode) {
|
||||
case ResourceDebugMode.Enabled:
|
||||
debugMode = true;
|
||||
@@ -267,15 +268,15 @@ namespace Orchard.Core.Shapes {
|
||||
break;
|
||||
default:
|
||||
Debug.Assert(site.ResourceDebugMode == ResourceDebugMode.FromAppSetting, "Unknown ResourceDebugMode value.");
|
||||
debugMode = _httpContextAccessor.Current().IsDebuggingEnabled;
|
||||
debugMode = _httpContextAccessor.Value.Current().IsDebuggingEnabled;
|
||||
break;
|
||||
}
|
||||
var defaultSettings = new RequireSettings {
|
||||
DebugMode = debugMode,
|
||||
Culture = CultureInfo.CurrentUICulture.Name,
|
||||
};
|
||||
var requiredResources = ResourceManager.BuildRequiredResources(resourceType);
|
||||
var appPath = _httpContextAccessor.Current().Request.ApplicationPath;
|
||||
var requiredResources = _resourceManager.Value.BuildRequiredResources(resourceType);
|
||||
var appPath = _httpContextAccessor.Value.Current().Request.ApplicationPath;
|
||||
foreach (var context in requiredResources.Where(r =>
|
||||
(includeLocation.HasValue ? r.Settings.Location == includeLocation.Value : true) &&
|
||||
(excludeLocation.HasValue ? r.Settings.Location != excludeLocation.Value : true))) {
|
||||
|
Reference in New Issue
Block a user