mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-12-02 03:17:32 +08:00
Adding Raw and Shape layouts
--HG-- branch : 1.x
This commit is contained in:
@@ -130,6 +130,11 @@
|
|||||||
<Compile Include="Models\NavigationQueryPart.cs" />
|
<Compile Include="Models\NavigationQueryPart.cs" />
|
||||||
<Compile Include="Models\NavigationQueryPartRecord.cs" />
|
<Compile Include="Models\NavigationQueryPartRecord.cs" />
|
||||||
<Compile Include="Models\QueryPart.cs" />
|
<Compile Include="Models\QueryPart.cs" />
|
||||||
|
<Compile Include="Providers\Layouts\RawLayout.cs" />
|
||||||
|
<Compile Include="Providers\Layouts\RawLayoutForms.cs" />
|
||||||
|
<Compile Include="Providers\Layouts\RawShapes.cs" />
|
||||||
|
<Compile Include="Providers\Layouts\ShapeLayout.cs" />
|
||||||
|
<Compile Include="Providers\Layouts\ShapeLayoutForms.cs" />
|
||||||
<Compile Include="Providers\Properties\CustomValueProperties.cs" />
|
<Compile Include="Providers\Properties\CustomValueProperties.cs" />
|
||||||
<Compile Include="Navigation\NavigationQueryProvider.cs" />
|
<Compile Include="Navigation\NavigationQueryProvider.cs" />
|
||||||
<Compile Include="Shapes.cs" />
|
<Compile Include="Shapes.cs" />
|
||||||
|
|||||||
@@ -0,0 +1,66 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using Orchard.ContentManagement;
|
||||||
|
using Orchard.DisplayManagement;
|
||||||
|
using Orchard.Localization;
|
||||||
|
using Orchard.Projections.Descriptors.Layout;
|
||||||
|
using Orchard.Projections.Models;
|
||||||
|
using Orchard.Projections.Services;
|
||||||
|
|
||||||
|
namespace Orchard.Projections.Providers.Layouts {
|
||||||
|
public class RawLayout : ILayoutProvider {
|
||||||
|
private readonly IContentManager _contentManager;
|
||||||
|
protected dynamic Shape { get; set; }
|
||||||
|
|
||||||
|
public RawLayout(IShapeFactory shapeFactory, IContentManager contentManager) {
|
||||||
|
_contentManager = contentManager;
|
||||||
|
Shape = shapeFactory;
|
||||||
|
T = NullLocalizer.Instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Localizer T { get; set; }
|
||||||
|
|
||||||
|
public void Describe(DescribeLayoutContext describe) {
|
||||||
|
describe.For("Html", T("Html"),T("Html Layouts"))
|
||||||
|
.Element("Raw", T("Raw"), T("Renders content with custom separators."),
|
||||||
|
DisplayLayout,
|
||||||
|
RenderLayout,
|
||||||
|
"RawLayout"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public LocalizedString DisplayLayout(LayoutContext context) {
|
||||||
|
return T("Renders content with custom separators.");
|
||||||
|
}
|
||||||
|
|
||||||
|
public dynamic RenderLayout(LayoutContext context, IEnumerable<LayoutComponentResult> layoutComponentResults) {
|
||||||
|
string containerTag = context.State.ContainerTag;
|
||||||
|
string containerId = context.State.ContainerId;
|
||||||
|
string containerClass = context.State.ContainerClass;
|
||||||
|
|
||||||
|
string itemTag = context.State.ItemTag;
|
||||||
|
string itemClass = context.State.ItemClass;
|
||||||
|
|
||||||
|
string prepend = context.State.Prepend;
|
||||||
|
string append = context.State.Append;
|
||||||
|
string separator = context.State.Separator;
|
||||||
|
|
||||||
|
IEnumerable<dynamic> shapes =
|
||||||
|
context.LayoutRecord.Display == (int)LayoutRecord.Displays.Content
|
||||||
|
? layoutComponentResults.Select(x => _contentManager.BuildDisplay(x.ContentItem, context.LayoutRecord.DisplayType))
|
||||||
|
: layoutComponentResults.Select(x => x.Properties);
|
||||||
|
|
||||||
|
return Shape.Raw(
|
||||||
|
Id: containerId,
|
||||||
|
Items: shapes,
|
||||||
|
Tag: containerTag,
|
||||||
|
Classes: new [] { containerClass },
|
||||||
|
ItemTag: itemTag,
|
||||||
|
ItemClasses: new [] { itemClass },
|
||||||
|
Prepend: prepend,
|
||||||
|
Append: append,
|
||||||
|
Separator: separator
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,84 @@
|
|||||||
|
using System;
|
||||||
|
using Orchard.DisplayManagement;
|
||||||
|
using Orchard.Forms.Services;
|
||||||
|
using Orchard.Localization;
|
||||||
|
|
||||||
|
namespace Orchard.Projections.Providers.Layouts {
|
||||||
|
|
||||||
|
public class RawLayoutForms : IFormProvider {
|
||||||
|
protected dynamic Shape { get; set; }
|
||||||
|
public Localizer T { get; set; }
|
||||||
|
|
||||||
|
public RawLayoutForms(
|
||||||
|
IShapeFactory shapeFactory) {
|
||||||
|
Shape = shapeFactory;
|
||||||
|
T = NullLocalizer.Instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Describe(DescribeContext context) {
|
||||||
|
Func<IShapeFactory, object> form =
|
||||||
|
shape => {
|
||||||
|
|
||||||
|
var f = Shape.Form(
|
||||||
|
Id: "RawLayout",
|
||||||
|
_HtmlProperties: Shape.Fieldset(
|
||||||
|
Title: T("Html properties"),
|
||||||
|
_ContainerTag: Shape.TextBox(
|
||||||
|
Id: "container-tag", Name: "ContainerTag",
|
||||||
|
Title: T("Container tag"),
|
||||||
|
Description: T("The tag of the container. Leave empty for no container."),
|
||||||
|
Classes: new[] { "textMedium", "tokenized" }
|
||||||
|
),
|
||||||
|
_ContainerId: Shape.TextBox(
|
||||||
|
Id: "container-id", Name: "ContainerId",
|
||||||
|
Title: T("Container id"),
|
||||||
|
Description: T("The id to provide on the container element."),
|
||||||
|
Classes: new[] { "textMedium", "tokenized" }
|
||||||
|
),
|
||||||
|
_ContainerClass: Shape.TextBox(
|
||||||
|
Id: "container-class", Name: "ContainerClass",
|
||||||
|
Title: T("Container class"),
|
||||||
|
Description: T("The class to provide on the container element."),
|
||||||
|
Classes: new[] { "textMedium", "tokenized" }
|
||||||
|
),
|
||||||
|
_ItemTag: Shape.TextBox(
|
||||||
|
Id: "item-tag", Name: "ItemTag",
|
||||||
|
Title: T("Item tag"),
|
||||||
|
Description: T("The tag of each item. Leave empty for tag."),
|
||||||
|
Classes: new[] { "textMedium", "tokenized" }
|
||||||
|
),
|
||||||
|
_ItemClass: Shape.TextBox(
|
||||||
|
Id: "item-class", Name: "ItemClass",
|
||||||
|
Title: T("Item class"),
|
||||||
|
Description: T("The class to provide on each item."),
|
||||||
|
Classes: new[] { "textMedium", "tokenized" }
|
||||||
|
),
|
||||||
|
_Prepend: Shape.TextBox(
|
||||||
|
Id: "prepend", Name: "Prepend",
|
||||||
|
Title: T("Prepend"),
|
||||||
|
Description: T("Some HTML to insert before the first element."),
|
||||||
|
Classes: new[] { "textMedium", "tokenized" }
|
||||||
|
),
|
||||||
|
_Separator: Shape.TextBox(
|
||||||
|
Id: "separator", Name: "Separator",
|
||||||
|
Title: T("Separator"),
|
||||||
|
Description: T("Some HTML to insert between two items."),
|
||||||
|
Classes: new[] { "textMedium", "tokenized" }
|
||||||
|
),
|
||||||
|
_Append: Shape.TextBox(
|
||||||
|
Id: "append", Name: "Append",
|
||||||
|
Title: T("Append"),
|
||||||
|
Description: T("Some HTML to insert after the last element."),
|
||||||
|
Classes: new[] { "textMedium", "tokenized" }
|
||||||
|
)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
return f;
|
||||||
|
};
|
||||||
|
|
||||||
|
context.Form("RawLayout", form);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,79 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Web.Mvc;
|
||||||
|
using Orchard.DisplayManagement;
|
||||||
|
using Orchard.Localization;
|
||||||
|
|
||||||
|
namespace Orchard.Projections.Providers.Layouts {
|
||||||
|
public class RawShapes : IDependency {
|
||||||
|
public RawShapes() {
|
||||||
|
T = NullLocalizer.Instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Localizer T { get; set; }
|
||||||
|
|
||||||
|
[Shape]
|
||||||
|
public void Raw(dynamic Display, TextWriter Output, HtmlHelper Html, string Id, string Tag, IEnumerable<dynamic> Items, IEnumerable<string> Classes, IDictionary<string, string> Attributes, string ItemTag, IEnumerable<string> ItemClasses, IDictionary<string, string> ItemAttributes, string Prepend, string Append, string Separator) {
|
||||||
|
if (Items == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
var items = Items.ToList();
|
||||||
|
var itemsCount = items.Count;
|
||||||
|
|
||||||
|
if (itemsCount < 1)
|
||||||
|
return;
|
||||||
|
|
||||||
|
var containerTag = String.IsNullOrEmpty(Tag) ? null : GetTagBuilder(Tag, Id, Classes, Attributes);
|
||||||
|
var itemTag = String.IsNullOrEmpty(ItemTag) ? null : GetTagBuilder(ItemTag, string.Empty, ItemClasses, ItemAttributes);
|
||||||
|
|
||||||
|
if (containerTag != null) {
|
||||||
|
Output.Write(containerTag.ToString(TagRenderMode.StartTag));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!String.IsNullOrEmpty(Prepend)) {
|
||||||
|
Output.Write(Prepend);
|
||||||
|
}
|
||||||
|
|
||||||
|
var first = true;
|
||||||
|
|
||||||
|
foreach (var item in items) {
|
||||||
|
if (!first && !String.IsNullOrEmpty(Separator)) {
|
||||||
|
Output.Write(Separator);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (itemTag != null) {
|
||||||
|
Output.Write(itemTag.ToString(TagRenderMode.StartTag));
|
||||||
|
}
|
||||||
|
|
||||||
|
Output.Write(Display(item));
|
||||||
|
|
||||||
|
if (itemTag != null) {
|
||||||
|
Output.Write(itemTag.ToString(TagRenderMode.EndTag));
|
||||||
|
}
|
||||||
|
|
||||||
|
first = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!String.IsNullOrEmpty(Append)) {
|
||||||
|
Output.Write(Append);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (containerTag != null) {
|
||||||
|
Output.Write(containerTag.ToString(TagRenderMode.EndTag));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static TagBuilder GetTagBuilder(string tagName, string id, IEnumerable<string> classes, IDictionary<string, string> attributes) {
|
||||||
|
var tagBuilder = new TagBuilder(tagName);
|
||||||
|
tagBuilder.MergeAttributes(attributes, false);
|
||||||
|
foreach (var cssClass in classes ?? Enumerable.Empty<string>())
|
||||||
|
tagBuilder.AddCssClass(cssClass);
|
||||||
|
if (!string.IsNullOrWhiteSpace(id))
|
||||||
|
tagBuilder.GenerateId(id);
|
||||||
|
return tagBuilder;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,50 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using Orchard.ContentManagement;
|
||||||
|
using Orchard.DisplayManagement;
|
||||||
|
using Orchard.Localization;
|
||||||
|
using Orchard.Projections.Descriptors.Layout;
|
||||||
|
using Orchard.Projections.Models;
|
||||||
|
using Orchard.Projections.Services;
|
||||||
|
|
||||||
|
namespace Orchard.Projections.Providers.Layouts {
|
||||||
|
public class ShapeLayout : ILayoutProvider {
|
||||||
|
private readonly IContentManager _contentManager;
|
||||||
|
protected dynamic Shape { get; set; }
|
||||||
|
|
||||||
|
public ShapeLayout(IShapeFactory shapeFactory, IContentManager contentManager) {
|
||||||
|
_contentManager = contentManager;
|
||||||
|
Shape = shapeFactory;
|
||||||
|
T = NullLocalizer.Instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Localizer T { get; set; }
|
||||||
|
|
||||||
|
public void Describe(DescribeLayoutContext describe) {
|
||||||
|
describe.For("Html", T("Html"),T("Html Layouts"))
|
||||||
|
.Element("Shape", T("Shape"), T("Uses a specific shape name to render the layout."),
|
||||||
|
DisplayLayout,
|
||||||
|
RenderLayout,
|
||||||
|
"ShapeLayout"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public LocalizedString DisplayLayout(LayoutContext context) {
|
||||||
|
return T("Renders content in a {0} layout", context.State.ShapeType.ToString());
|
||||||
|
}
|
||||||
|
|
||||||
|
public dynamic RenderLayout(LayoutContext context, IEnumerable<LayoutComponentResult> layoutComponentResults) {
|
||||||
|
string shapeType = context.State.ShapeType;
|
||||||
|
|
||||||
|
dynamic shape = ((IShapeFactory) Shape).Create(shapeType);
|
||||||
|
shape.ContentItems = layoutComponentResults.Select(x => x.ContentItem);
|
||||||
|
shape.BuildShapes= (Func<IEnumerable<dynamic>>) (() => context.LayoutRecord.Display == (int)LayoutRecord.Displays.Content
|
||||||
|
? layoutComponentResults.Select(x => _contentManager.BuildDisplay(x.ContentItem, context.LayoutRecord.DisplayType))
|
||||||
|
: layoutComponentResults.Select(x => x.Properties));
|
||||||
|
|
||||||
|
|
||||||
|
return shape;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,42 @@
|
|||||||
|
using System;
|
||||||
|
using Orchard.DisplayManagement;
|
||||||
|
using Orchard.Forms.Services;
|
||||||
|
using Orchard.Localization;
|
||||||
|
|
||||||
|
namespace Orchard.Projections.Providers.Layouts {
|
||||||
|
|
||||||
|
public class ShapeLayoutForms : IFormProvider {
|
||||||
|
protected dynamic Shape { get; set; }
|
||||||
|
public Localizer T { get; set; }
|
||||||
|
|
||||||
|
public ShapeLayoutForms(
|
||||||
|
IShapeFactory shapeFactory) {
|
||||||
|
Shape = shapeFactory;
|
||||||
|
T = NullLocalizer.Instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Describe(DescribeContext context) {
|
||||||
|
Func<IShapeFactory, object> form =
|
||||||
|
shape => {
|
||||||
|
|
||||||
|
var f = Shape.Form(
|
||||||
|
Id: "ShapeLayout",
|
||||||
|
_Options: Shape.Fieldset(
|
||||||
|
Title: T("Shape options"),
|
||||||
|
_ShapeType: Shape.TextBox(
|
||||||
|
Id: "shape-type", Name: "ShapeType",
|
||||||
|
Title: T("Shape type"),
|
||||||
|
Description: T("The type of the shape which is used for rendering content items."),
|
||||||
|
Classes: new[] { "textMedium", "tokenized" }
|
||||||
|
)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
return f;
|
||||||
|
};
|
||||||
|
|
||||||
|
context.Form("ShapeLayout", form);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user