Adding new alternates

- Injected alternates in curent Core/Framework
- Created a new Feature in Orchard.DesignerTools to add Url based alternates (e.g. __url__homepage)
- Added Work<> meta-dependency to inject dependencies in non-dependency enables classes

--HG--
branch : dev
This commit is contained in:
Sebastien Ros
2011-02-21 11:35:54 -08:00
parent cdc7c86f3b
commit 9fca99c51b
11 changed files with 253 additions and 61 deletions

View File

@@ -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,18 +15,9 @@ namespace Orchard.Core.Contents {
.OnDisplaying(displaying => {
ContentItem contentItem = displaying.Shape.ContentItem;
if (contentItem != null) {
var url = string.Empty;
// Content__[ContentType] e.g. Content-BlogPost
displaying.ShapeMetadata.Alternates.Add("Content__" + contentItem.ContentType);
// Content__[ContentType]__url__[Url] e.g. Content-BlogPost-url-myBlog
displaying.ShapeMetadata.Alternates.Add("Content__" + contentItem.ContentType + "__url__" + url);
// Content_[DisplayType] e.g. Content.Summary
displaying.ShapeMetadata.Alternates.Add("Content_" + displaying.ShapeMetadata.DisplayType);
// Content_[DisplayType]__[ContentType] e.g. Content-BlogPost.Summary
displaying.ShapeMetadata.Alternates.Add("Content_" + displaying.ShapeMetadata.DisplayType + "__" + contentItem.ContentType);

View File

@@ -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))) {