mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-22 03:37:25 +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))) {
|
||||
|
@@ -1,5 +1,5 @@
|
||||
@{
|
||||
Html.AddTitleParts(T("Manage Blog").ToString());
|
||||
}
|
||||
// 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)
|
||||
|
@@ -11,3 +11,7 @@ Features:
|
||||
Category: Designer
|
||||
Description: Displays all currently displayed shapes and some information to customize them
|
||||
Dependencies: Orchard.jQuery
|
||||
UrlAlternates:
|
||||
Name: Url Alternates
|
||||
Category: Designer
|
||||
Description: Adds shape alternates for specific urls
|
||||
|
@@ -83,6 +83,7 @@
|
||||
<ItemGroup>
|
||||
<Compile Include="Services\ObjectDumper.cs" />
|
||||
<Compile Include="Services\ShapeTracingFactory.cs" />
|
||||
<Compile Include="Services\UrlAlternatesFactory.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Content Include="Views\ShapeTracing.Wrapper.cshtml" />
|
||||
|
@@ -0,0 +1,50 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Web;
|
||||
using Orchard.DisplayManagement.Implementation;
|
||||
using Orchard.Environment.Extensions;
|
||||
using Orchard.Mvc;
|
||||
|
||||
namespace Orchard.DesignerTools.Services {
|
||||
[OrchardFeature("UrlAlternates")]
|
||||
public class UrlAlternatesFactory : ShapeDisplayEvents {
|
||||
private readonly IHttpContextAccessor _httpContextAccessor;
|
||||
private readonly List<string> _urlAlternates;
|
||||
|
||||
public UrlAlternatesFactory(IHttpContextAccessor httpContextAccessor) {
|
||||
_httpContextAccessor = httpContextAccessor;
|
||||
|
||||
var request = _httpContextAccessor.Current().Request;
|
||||
|
||||
// extract each segment of the url
|
||||
var urlSegments = VirtualPathUtility.ToAppRelative(request.Path.ToLower())
|
||||
.Split('/')
|
||||
.Skip(1) // ignore the heading ~ segment
|
||||
.Select(url => url.Replace("-", "__").Replace(".", "_")) // format the alternate
|
||||
.ToArray();
|
||||
|
||||
if ( String.IsNullOrWhiteSpace(urlSegments[0]) ) {
|
||||
urlSegments[0] = "homepage";
|
||||
}
|
||||
|
||||
_urlAlternates = Enumerable.Range(1, urlSegments.Count()).Select(range => String.Join("__", urlSegments.Take(range))).ToList();
|
||||
}
|
||||
|
||||
public override void Displaying(ShapeDisplayingContext context) {
|
||||
|
||||
context.ShapeMetadata.OnDisplaying(displayedContext => {
|
||||
// appends Url alternates to current ones
|
||||
displayedContext.ShapeMetadata.Alternates = displayedContext.ShapeMetadata.Alternates.SelectMany(
|
||||
alternate => new [] { alternate }.Union(_urlAlternates.Select(a => alternate + "__url__" + a))
|
||||
).ToList();
|
||||
|
||||
// appends [ShapeType__url__[Url] alternates
|
||||
displayedContext.ShapeMetadata.Alternates = _urlAlternates.Select(url => displayedContext.ShapeMetadata.Type + "__url__" + url)
|
||||
.Union(displayedContext.ShapeMetadata.Alternates)
|
||||
.ToList();
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
}
|
@@ -25,8 +25,12 @@ namespace Orchard.Widgets {
|
||||
widget.Classes.Add("widget-" + contentItem.ContentType.HtmlClassify());
|
||||
|
||||
var zoneName = contentItem.As<WidgetPart>().Zone;
|
||||
displaying.ShapeMetadata.Alternates.Add("Widget__" + contentItem.ContentType);
|
||||
|
||||
// Widget__[ZoneName] e.g. Widget-SideBar
|
||||
displaying.ShapeMetadata.Alternates.Add("Widget__" + zoneName);
|
||||
|
||||
// Widget__[ContentType] e.g. Widget-BlogArchive
|
||||
displaying.ShapeMetadata.Alternates.Add("Widget__" + contentItem.ContentType);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
Reference in New Issue
Block a user