mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-15 19:54:57 +08:00
Adding DisplayChildren for rendering attached shapes
--HG-- branch : theming extra : rebase_source : 14c441c92db13a7e7acf5d16f8ccec3323c807dc
This commit is contained in:
@@ -1 +1 @@
|
||||
@foreach (var item in Model) {@Display(item)}
|
||||
@DisplayChildren(Model)
|
||||
|
@@ -1 +1 @@
|
||||
@foreach (var item in Model) {@Display(item)}
|
||||
@DisplayChildren(Model)
|
||||
|
@@ -1,3 +1,3 @@
|
||||
<ul id="Menu-@Model.MenuName" class="Menu Menu-@Model.MenuName">
|
||||
@foreach(var item in Model) {@Display(item);}
|
||||
@DisplayChildren(Model)
|
||||
</ul><!-- /Menu-@Model.MenuName -->
|
||||
|
@@ -4,12 +4,12 @@
|
||||
}
|
||||
@{
|
||||
if (string.IsNullOrWhiteSpace((string)Model.Text)) {
|
||||
foreach(var item in Model) {@Display(item);}
|
||||
@DisplayChildren(Model)
|
||||
} else {
|
||||
<li><a href="@Model.Href">@Model.Text</a>
|
||||
@if (items.Any()) {
|
||||
<ul>
|
||||
@foreach(var item in Model) {@Display(item);}
|
||||
@DisplayChildren(Model)
|
||||
</ul>
|
||||
}
|
||||
</li>
|
||||
|
@@ -5,5 +5,5 @@
|
||||
}
|
||||
}
|
||||
<div id="@id" class="Zone Zone-@Model.ZoneName">
|
||||
@foreach (var item in Model) {@Display(item)}
|
||||
@DisplayChildren(Model)
|
||||
</div><!-- /@id -->
|
||||
|
@@ -7,7 +7,7 @@ namespace Orchard.DevTools {
|
||||
}
|
||||
|
||||
public void Created(ShapeCreatedContext context) {
|
||||
if (context.ShapeType != "Layout")
|
||||
if (context.ShapeType != "Layout" && context.ShapeType != "DocumentZone")
|
||||
context.Shape.Metadata.Wrappers.Add("ThinBorder");
|
||||
if (context.ShapeType == "Header")
|
||||
context.Shape.Metadata.Wrappers.Add("HackStyle");
|
||||
|
@@ -1,3 +1,3 @@
|
||||
<ul id="Menu-@Model.MenuName" class="Menu Menu-@Model.MenuName">
|
||||
@foreach(var item in Model) {@Display(item);}
|
||||
@DisplayChildren(Model)
|
||||
</ul><!-- /Menu-@Model.MenuName -->
|
||||
|
@@ -4,6 +4,6 @@
|
||||
}
|
||||
<li><a href="@Model.Href">@Model.Text</a>@{ if (items.Any()) {
|
||||
<ul>
|
||||
@foreach(var item in Model) {@Display(item);}
|
||||
@DisplayChildren(Model)
|
||||
</ul>}}
|
||||
</li>
|
||||
|
@@ -15,6 +15,7 @@ using ClaySharp.Implementation;
|
||||
using Microsoft.CSharp.RuntimeBinder;
|
||||
using Orchard.DisplayManagement.Implementation;
|
||||
using Orchard.DisplayManagement.Shapes;
|
||||
using Orchard.Mvc.Spooling;
|
||||
|
||||
namespace Orchard.DisplayManagement.Descriptors.ShapeAttributeStrategy {
|
||||
public class ShapeAttributeBindingStrategy : IShapeDescriptorBindingStrategy {
|
||||
@@ -58,15 +59,15 @@ namespace Orchard.DisplayManagement.Descriptors.ShapeAttributeStrategy {
|
||||
|
||||
|
||||
private IHtmlString PerformInvoke(DisplayContext displayContext, MethodInfo methodInfo, object serviceInstance) {
|
||||
var output = new StringWriter();
|
||||
var output = new HtmlStringWriter();
|
||||
var arguments = methodInfo.GetParameters()
|
||||
.Select(parameter => BindParameter(displayContext, parameter, output));
|
||||
|
||||
var returnValue = methodInfo.Invoke(serviceInstance, arguments.ToArray());
|
||||
if (methodInfo.ReturnType != typeof(void)) {
|
||||
output.Write(returnValue);
|
||||
output.Write(CoerceHtmlString(returnValue));
|
||||
}
|
||||
return CoerceHtmlString(output);
|
||||
return output;
|
||||
}
|
||||
|
||||
private static IHtmlString CoerceHtmlString(object invoke) {
|
||||
|
@@ -1,4 +1,5 @@
|
||||
using Orchard.Localization;
|
||||
using System.Web;
|
||||
using Orchard.Localization;
|
||||
|
||||
namespace Orchard.Mvc {
|
||||
/// <summary>
|
||||
@@ -8,5 +9,6 @@ namespace Orchard.Mvc {
|
||||
public interface IOrchardViewPage {
|
||||
Localizer T { get; }
|
||||
dynamic Display { get; }
|
||||
IHtmlString DisplayChildren(object shape);
|
||||
}
|
||||
}
|
33
src/Orchard/Mvc/Spooling/HtmlStringWriter.cs
Normal file
33
src/Orchard/Mvc/Spooling/HtmlStringWriter.cs
Normal file
@@ -0,0 +1,33 @@
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using System.Web;
|
||||
|
||||
namespace Orchard.Mvc.Spooling {
|
||||
public class HtmlStringWriter : TextWriter ,IHtmlString {
|
||||
private readonly TextWriter _writer;
|
||||
|
||||
public HtmlStringWriter() {
|
||||
_writer = new StringWriter();
|
||||
}
|
||||
|
||||
public override Encoding Encoding {
|
||||
get { return _writer.Encoding; }
|
||||
}
|
||||
|
||||
public string ToHtmlString() {
|
||||
return _writer.ToString();
|
||||
}
|
||||
|
||||
public override string ToString() {
|
||||
return _writer.ToString();
|
||||
}
|
||||
|
||||
public override void Write(string value) {
|
||||
_writer.Write(value);
|
||||
}
|
||||
|
||||
public override void Write(char value) {
|
||||
_writer.Write(value);
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,6 +1,9 @@
|
||||
using Autofac;
|
||||
using System;
|
||||
using System.Web;
|
||||
using Autofac;
|
||||
using Orchard.DisplayManagement;
|
||||
using Orchard.Localization;
|
||||
using Orchard.Mvc.Spooling;
|
||||
using Orchard.Security;
|
||||
using Orchard.Security.Permissions;
|
||||
|
||||
@@ -14,6 +17,8 @@ namespace Orchard.Mvc.ViewEngines.Razor {
|
||||
|
||||
public Localizer T { get { return _localizer; } }
|
||||
public dynamic Display { get { return _display; } }
|
||||
|
||||
|
||||
public dynamic New { get { return _new; } }
|
||||
public IDisplayHelperFactory DisplayHelperFactory { get; set; }
|
||||
public IShapeHelperFactory ShapeHelperFactory { get; set; }
|
||||
@@ -36,6 +41,13 @@ namespace Orchard.Mvc.ViewEngines.Razor {
|
||||
return Authorizer.Authorize(permission);
|
||||
}
|
||||
|
||||
public IHtmlString DisplayChildren(dynamic shape) {
|
||||
var writer = new HtmlStringWriter();
|
||||
foreach (var item in shape) {
|
||||
writer.Write(Display(item));
|
||||
}
|
||||
return writer;
|
||||
}
|
||||
}
|
||||
|
||||
public abstract class WebViewPage : WebViewPage<dynamic> {
|
||||
|
@@ -3,6 +3,7 @@ using System.IO;
|
||||
using System.Web;
|
||||
using System.Web.Mvc;
|
||||
using Orchard.DisplayManagement;
|
||||
using Orchard.Mvc.Spooling;
|
||||
|
||||
namespace Orchard.Mvc.ViewEngines.ThemeAwareness {
|
||||
public interface ILayoutAwareViewEngine : IDependency, IViewEngine {
|
||||
@@ -33,17 +34,18 @@ namespace Orchard.Mvc.ViewEngines.ThemeAwareness {
|
||||
return viewResult;
|
||||
}
|
||||
|
||||
var layoutView = new LayoutView((viewContext, writer, viewDataContainer) => {
|
||||
var bufferViewContext = new ViewContext(
|
||||
var layoutView = new LayoutView((viewContext, writer, viewDataContainer) => {
|
||||
var childContentWriter = new HtmlStringWriter();
|
||||
|
||||
var childContentViewContext = new ViewContext(
|
||||
viewContext,
|
||||
viewContext.View,
|
||||
viewContext.ViewData,
|
||||
viewContext.TempData,
|
||||
new StringWriter());
|
||||
viewContext.TempData,
|
||||
childContentWriter);
|
||||
|
||||
viewResult.View.Render(bufferViewContext, bufferViewContext.Writer);
|
||||
|
||||
_workContext.Page.Metadata.ChildContent = new HtmlString(bufferViewContext.Writer.ToString());
|
||||
viewResult.View.Render(childContentViewContext, childContentWriter);
|
||||
_workContext.Page.Metadata.ChildContent = childContentWriter;
|
||||
|
||||
var display = _displayHelperFactory.CreateHelper(viewContext, viewDataContainer);
|
||||
IHtmlString result = display(_workContext.Page);
|
||||
|
@@ -1,9 +1,11 @@
|
||||
using System.Web.Mvc;
|
||||
using System.Web;
|
||||
using System.Web.Mvc;
|
||||
using Autofac;
|
||||
using Orchard.DisplayManagement;
|
||||
using Orchard.DisplayManagement.Implementation;
|
||||
using Orchard.Localization;
|
||||
using Orchard.Mvc.Html;
|
||||
using Orchard.Mvc.Spooling;
|
||||
using Orchard.Security;
|
||||
using Orchard.Security.Permissions;
|
||||
|
||||
@@ -35,6 +37,14 @@ namespace Orchard.Mvc {
|
||||
public bool AuthorizedFor(Permission permission) {
|
||||
return Authorizer.Authorize(permission);
|
||||
}
|
||||
|
||||
public IHtmlString DisplayChildren(dynamic shape) {
|
||||
var writer = new HtmlStringWriter();
|
||||
foreach (var item in shape) {
|
||||
writer.Write(Display(item));
|
||||
}
|
||||
return writer;
|
||||
}
|
||||
}
|
||||
|
||||
public class ViewPage : ViewPage<dynamic> {
|
||||
|
@@ -3,6 +3,7 @@ using System.Web.Mvc;
|
||||
using Autofac;
|
||||
using Orchard.DisplayManagement;
|
||||
using Orchard.Localization;
|
||||
using Orchard.Mvc.Spooling;
|
||||
using Orchard.Security;
|
||||
using Orchard.Security.Permissions;
|
||||
|
||||
@@ -38,6 +39,14 @@ namespace Orchard.Mvc {
|
||||
public bool AuthorizedFor(Permission permission) {
|
||||
return Authorizer.Authorize(permission);
|
||||
}
|
||||
|
||||
public IHtmlString DisplayChildren(dynamic shape) {
|
||||
var writer = new HtmlStringWriter();
|
||||
foreach (var item in shape) {
|
||||
writer.Write(Display(item));
|
||||
}
|
||||
return writer;
|
||||
}
|
||||
}
|
||||
|
||||
public class ViewUserControl : ViewUserControl<dynamic> {
|
||||
|
@@ -146,6 +146,7 @@
|
||||
<Compile Include="DisplayManagement\Descriptors\ShapeTable.cs" />
|
||||
<Compile Include="DisplayManagement\Descriptors\ShapeTableBuilder.cs" />
|
||||
<Compile Include="Mvc\IOrchardViewPage.cs" />
|
||||
<Compile Include="Mvc\Spooling\HtmlStringWriter.cs" />
|
||||
<Compile Include="Mvc\ViewEngines\Razor\RazorViewEngine.cs" />
|
||||
<Compile Include="UI\Zones\PageWorkContext.cs" />
|
||||
<Compile Include="UI\Zones\ZoneHoldingBehavior.cs" />
|
||||
|
Reference in New Issue
Block a user