mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2026-02-09 09:16:41 +08:00
Simple content item, with support for zones, editor, and display partial templates working
--HG-- branch : theming
This commit is contained in:
@@ -5,5 +5,5 @@
|
||||
//also, ...this is ugly--%>
|
||||
<%: new HtmlString(string.Format(
|
||||
"<p>{0} {1}</p>",
|
||||
Html.Excerpt(Model.Text, 200).ToString().Replace(Environment.NewLine, "</p>" + Environment.NewLine + "<p>"),
|
||||
Html.Excerpt(Model.Html.ToString(), 200).ToString().Replace(Environment.NewLine, "</p>" + Environment.NewLine + "<p>"),
|
||||
Html.ItemDisplayLink(T("[more]").ToString(), Model.BodyPart.ContentItem))) %>
|
||||
@@ -1 +0,0 @@
|
||||
content item -> @Model.ContentType
|
||||
3
src/Orchard.Web/Core/Contents/Views/Items/Content.cshtml
Normal file
3
src/Orchard.Web/Core/Contents/Views/Items/Content.cshtml
Normal file
@@ -0,0 +1,3 @@
|
||||
content item -> @Model.ContentItem.ContentType
|
||||
|
||||
@Display(Model.primary)
|
||||
@@ -1,32 +1,47 @@
|
||||
using System.Web.Mvc;
|
||||
using Orchard.ContentManagement;
|
||||
using Orchard.Core.Common.Models;
|
||||
using Orchard.DisplayManagement;
|
||||
using Orchard.Security;
|
||||
|
||||
namespace Orchard.Core.Dashboard.Controllers {
|
||||
public class AdminController : Controller {
|
||||
private readonly IShapeHelperFactory _shapeHelperFactory;
|
||||
private readonly IContentManager _contentManager;
|
||||
|
||||
public AdminController(IShapeHelperFactory shapeHelperFactory) {
|
||||
public AdminController(IShapeHelperFactory shapeHelperFactory, IContentManager contentManager) {
|
||||
_shapeHelperFactory = shapeHelperFactory;
|
||||
_contentManager = contentManager;
|
||||
}
|
||||
|
||||
public virtual IUser CurrentUser { get; set; }
|
||||
|
||||
public ActionResult Index() {
|
||||
var shape = _shapeHelperFactory.CreateHelper();
|
||||
|
||||
var list = shape.List();
|
||||
var list2 = shape.List();
|
||||
|
||||
list.Id = "the-list";
|
||||
list.Classes.Add("foo");
|
||||
list.Attributes["onclick"] = "etc";
|
||||
list.ItemClasses.Add("yarg");
|
||||
list.Add(_contentManager.BuildDisplayModel(CurrentUser, "Detail"));
|
||||
foreach (var contentItem in _contentManager.Query().Join<BodyPartRecord>().List()) {
|
||||
list.Add(_contentManager.BuildDisplayModel(contentItem, "Summary"));
|
||||
}
|
||||
|
||||
list.Add("one");
|
||||
list.Add("two");
|
||||
list.Add(list2);
|
||||
list.Add(shape.DumpShapeTable());
|
||||
list.Add("four");
|
||||
//
|
||||
//var list2 = shape.List();
|
||||
|
||||
list2.Add("three a");
|
||||
list2.Add("three b");
|
||||
//list.Id = "the-list";
|
||||
//list.Classes.Add("foo");
|
||||
//list.Attributes["onclick"] = "etc";
|
||||
//list.ItemClasses.Add("yarg");
|
||||
|
||||
//list.Add("one");
|
||||
//list.Add("two");
|
||||
//list.Add(list2);
|
||||
//list.Add(shape.DumpShapeTable());
|
||||
//list.Add("four");
|
||||
|
||||
//list2.Add("three a");
|
||||
//list2.Add("three b");)))
|
||||
|
||||
return View(list);
|
||||
}
|
||||
|
||||
@@ -4,4 +4,4 @@
|
||||
<p><%: T("This is the place where you can manage your web site, its appearance and its contents. Please take a moment to explore the different menu items on the left of the screen to familiarize yourself with the features of the application. For example, try to change the theme through the “Manage Themes” menu entry. You can also create new pages and manage existing ones through the “Manage Pages” menu entry or create blogs through “Manage Blogs”.") %></p>
|
||||
<p><%: T("Have fun!") %><br /><%: T("The Orchard Team") %></p>
|
||||
|
||||
<%:Display(Model) %>
|
||||
<div style="border:1px solid black;" role="experimentation"><%:Display(Model) %></div>
|
||||
|
||||
@@ -399,13 +399,12 @@
|
||||
<Content Include="PublishLater\Views\Web.config" />
|
||||
<Content Include="ContentsLocation\Views\Web.config" />
|
||||
<Content Include="Messaging\Views\Web.config" />
|
||||
<None Include="Contents\Views\Content.cshtml" />
|
||||
<None Include="Contents\Views\Items\Content.cshtml" />
|
||||
<None Include="Contents\Views\Item\Display.cshtml" />
|
||||
<None Include="HomePage\Views\HomePage.cshtml" />
|
||||
<None Include="Shapes\Views\Document.cshtml" />
|
||||
<None Include="Shapes\Views\User.cshtml" />
|
||||
<None Include="Shapes\Views\Header.cshtml" />
|
||||
<None Include="Shapes\Views\Item.cshtml" />
|
||||
<None Include="Shapes\Views\Layout.cshtml" />
|
||||
<None Include="Shapes\Views\Menu.ascx_" />
|
||||
<None Include="Shapes\Views\Menu.cshtml" />
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System.Collections;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
@@ -29,6 +30,9 @@ namespace Orchard.Core.Shapes {
|
||||
created.Shape.Zones.Body.Add(created.New.PlaceChildContent(Source: created.Shape), "5");
|
||||
});
|
||||
|
||||
builder.Describe.Named("Items_Content").From(Feature.Descriptor)
|
||||
.OnCreating(creating => creating.Behaviors.Add(new ZoneHoldingBehavior(creating.ShapeFactory)));
|
||||
|
||||
// 'Zone' shapes are built on the Zone base class
|
||||
builder.Describe.Named("Zone").From(Feature.Descriptor)
|
||||
.OnCreating(creating => creating.BaseType = typeof(Zone));
|
||||
@@ -46,10 +50,6 @@ namespace Orchard.Core.Shapes {
|
||||
|
||||
}
|
||||
|
||||
static object DetermineModel(HtmlHelper Html, object Model) {
|
||||
bool isNull = ((dynamic)Model) == null;
|
||||
return isNull ? Html.ViewData.Model : Model;
|
||||
}
|
||||
|
||||
static TagBuilder GetTagBuilder(string tagName, string id, IEnumerable<string> classes, IDictionary<string, string> attributes) {
|
||||
var tagBuilder = new TagBuilder(tagName);
|
||||
@@ -103,18 +103,47 @@ namespace Orchard.Core.Shapes {
|
||||
}
|
||||
|
||||
[Shape]
|
||||
public IHtmlString Partial(HtmlHelper Html, string TemplateName, object Model) {
|
||||
return Html.Partial(TemplateName, DetermineModel(Html, Model));
|
||||
public void Partial(HtmlHelper Html, TextWriter Output, string TemplateName, object Model) {
|
||||
RenderInternal(Html, Output, TemplateName, Model, null);
|
||||
}
|
||||
|
||||
[Shape]
|
||||
public IHtmlString DisplayTemplate(HtmlHelper Html, string TemplateName, object Model, string Prefix) {
|
||||
return Html.Partial(TemplateName, DetermineModel(Html, Model));
|
||||
public void DisplayTemplate(HtmlHelper Html, TextWriter Output, string TemplateName, object Model, string Prefix) {
|
||||
RenderInternal(Html, Output, "DisplayTemplates/" + TemplateName, Model, Prefix);
|
||||
}
|
||||
|
||||
[Shape]
|
||||
public IHtmlString EditorTemplate(HtmlHelper Html, string TemplateName, object Model, string Prefix) {
|
||||
return Html.Partial(TemplateName, DetermineModel(Html, Model));
|
||||
public void EditorTemplate(HtmlHelper Html, TextWriter Output, string TemplateName, object Model, string Prefix) {
|
||||
RenderInternal(Html, Output, "EditorTemplates/" + TemplateName, Model, Prefix);
|
||||
}
|
||||
|
||||
static void RenderInternal(HtmlHelper Html, TextWriter Output, string TemplateName, object Model, string Prefix) {
|
||||
var adjustedViewData = new ViewDataDictionary(Html.ViewDataContainer.ViewData) {
|
||||
Model = DetermineModel(Html, Model),
|
||||
TemplateInfo = new TemplateInfo {
|
||||
HtmlFieldPrefix = DeterminePrefix(Html, Prefix)
|
||||
}
|
||||
};
|
||||
var adjustedViewContext = new ViewContext(Html.ViewContext, Html.ViewContext.View, adjustedViewData, Html.ViewContext.TempData, Output);
|
||||
var adjustedHtml = new HtmlHelper(adjustedViewContext, new ViewDataContainer(adjustedViewData));
|
||||
adjustedHtml.RenderPartial(TemplateName);
|
||||
}
|
||||
|
||||
static object DetermineModel(HtmlHelper Html, object Model) {
|
||||
bool isNull = ((dynamic)Model) == null;
|
||||
return isNull ? Html.ViewData.Model : Model;
|
||||
}
|
||||
|
||||
static string DeterminePrefix(HtmlHelper Html, string Prefix) {
|
||||
var actualPrefix = string.IsNullOrEmpty(Prefix)
|
||||
? Html.ViewContext.ViewData.TemplateInfo.HtmlFieldPrefix
|
||||
: Html.ViewContext.ViewData.TemplateInfo.GetFullHtmlFieldName(Prefix);
|
||||
return actualPrefix;
|
||||
}
|
||||
|
||||
private class ViewDataContainer : IViewDataContainer {
|
||||
public ViewDataContainer(ViewDataDictionary viewData) { ViewData = viewData; }
|
||||
public ViewDataDictionary ViewData { get; set; }
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,2 +0,0 @@
|
||||
<h3>Content item placeholder</h3>
|
||||
<p>This file will be relocated and specialized</p>
|
||||
@@ -128,7 +128,6 @@
|
||||
<None Include="Views\Home\FormShapes.cshtml" />
|
||||
<None Include="Views\Home\UsingShapes.cshtml" />
|
||||
<None Include="Views\Inventory\ShapeTable.cshtml" />
|
||||
<None Include="Views\Rounded.cshtml" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
||||
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v10.0\WebApplications\Microsoft.WebApplication.targets" />
|
||||
|
||||
@@ -1,6 +0,0 @@
|
||||
<div class="rounded">
|
||||
@model dynamic
|
||||
<p>above</p>
|
||||
@Display(Model.Contents)
|
||||
<p>below</p>
|
||||
</div>
|
||||
@@ -11,11 +11,6 @@
|
||||
var thisUser = Html.Resolve<IAuthenticationService>().GetAuthenticatedUser();
|
||||
Model.Header.Add(Display.User(CurrentUser: thisUser), "after");
|
||||
|
||||
Model.CurrentUser = thisUser;
|
||||
Model.Header.Add(Display.Partial(TemplateName: "User"), "after");
|
||||
|
||||
var userDetail = Html.Resolve<IContentManager>().BuildDisplayModel(thisUser, "Detail");
|
||||
Model.Content.Add(userDetail);
|
||||
// </experimentation>
|
||||
|
||||
Html.RegisterStyle("site.css", "1");
|
||||
|
||||
@@ -370,7 +370,7 @@ namespace Orchard.ContentManagement {
|
||||
|
||||
public dynamic BuildDisplayModel<TContent>(TContent content, string displayType) where TContent : IContent {
|
||||
var shapeHelper = _shapeHelperFactory.CreateHelper();
|
||||
var itemShape = shapeHelper.Item(ContentItem:content.ContentItem);
|
||||
var itemShape = shapeHelper.Items_Content(ContentItem:content.ContentItem);
|
||||
var context = new BuildDisplayModelContext(content, displayType, itemShape, _shapeHelperFactory);
|
||||
Handlers.Invoke(handler => handler.BuildDisplayShape(context), Logger);
|
||||
return context.Model;
|
||||
@@ -378,7 +378,7 @@ namespace Orchard.ContentManagement {
|
||||
|
||||
public dynamic BuildEditorModel<TContent>(TContent content) where TContent : IContent {
|
||||
var shapeHelper = _shapeHelperFactory.CreateHelper();
|
||||
var itemShape = shapeHelper.Item(ContentItem:content.ContentItem);
|
||||
var itemShape = shapeHelper.Items_Content(ContentItem: content.ContentItem);
|
||||
var context = new BuildEditorModelContext(content, itemShape, _shapeHelperFactory);
|
||||
Handlers.Invoke(handler => handler.BuildEditorShape(context), Logger);
|
||||
return context.Model;
|
||||
@@ -386,7 +386,7 @@ namespace Orchard.ContentManagement {
|
||||
|
||||
public dynamic UpdateEditorModel<TContent>(TContent content, IUpdateModel updater) where TContent : IContent {
|
||||
var shapeHelper = _shapeHelperFactory.CreateHelper();
|
||||
var itemShape = shapeHelper.Item(ContentItem:content.ContentItem);
|
||||
var itemShape = shapeHelper.Items_Content(ContentItem: content.ContentItem);
|
||||
var context = new UpdateEditorModelContext(content, updater, itemShape, _shapeHelperFactory);
|
||||
Handlers.Invoke(handler => handler.UpdateEditorShape(context), Logger);
|
||||
return context.Model;
|
||||
|
||||
@@ -29,21 +29,29 @@ namespace Orchard.DisplayManagement.Descriptors.ShapeTemplateStrategy {
|
||||
var lastDot = info.FileName.IndexOf('.');
|
||||
if (lastDot <= 0) {
|
||||
yield return new HarvestShapeHit {
|
||||
ShapeType = Adjust(info.FileName)
|
||||
ShapeType = Adjust(info.SubPath, info.FileName)
|
||||
};
|
||||
}
|
||||
else {
|
||||
yield return new HarvestShapeHit {
|
||||
ShapeType = Adjust(info.FileName.Substring(0, lastDot)),
|
||||
ShapeType = Adjust(info.SubPath, info.FileName.Substring(0, lastDot)),
|
||||
DisplayType = info.FileName.Substring(lastDot + 1)
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
static string Adjust(string fileName) {
|
||||
static string Adjust(string subPath, string fileName) {
|
||||
var leader="";
|
||||
if (subPath.StartsWith("Views/")) {
|
||||
leader = subPath.Substring("Views/".Length) + "_";
|
||||
}
|
||||
if (leader == "Items_" && !fileName.StartsWith("Content")) {
|
||||
leader = "Items_Content__";
|
||||
}
|
||||
|
||||
// canonical shape type names must not have - or . to be compatible
|
||||
// with display and shape api calls
|
||||
return fileName.Replace('-', '_').Replace('.', '_');
|
||||
// with display and shape api calls)))
|
||||
return leader + fileName.Replace("--", "__").Replace("-", "__").Replace('.', '_');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -6,35 +6,52 @@ WorkContext.Page == Layout shape
|
||||
|
||||
==shapes==
|
||||
|
||||
.Id
|
||||
.Classes
|
||||
.Attributes
|
||||
|
||||
|
||||
Document [:Layout]
|
||||
|
||||
Layout
|
||||
- Zones (meta-property)
|
||||
- Title
|
||||
|
||||
Layout (.Wrappers[Document])
|
||||
.Zones (meta-property)
|
||||
.Title
|
||||
|
||||
Zone
|
||||
-ZoneName
|
||||
.ZoneName
|
||||
|
||||
Menu
|
||||
-MenuName
|
||||
.MenuName
|
||||
|
||||
MenuItem
|
||||
-Text
|
||||
-Href
|
||||
-RouteValues
|
||||
-Item
|
||||
|
||||
Menu
|
||||
MenuItem
|
||||
-Item (clr object)
|
||||
|
||||
List: ul|ol + li*
|
||||
-Items (meta-property, bound to shape children or passed in)
|
||||
.Items (meta-property, bound to shape children or passed in)
|
||||
.Id
|
||||
.Classes
|
||||
.Attributes
|
||||
.ItemClasses
|
||||
.ItemAttributes
|
||||
|
||||
Items_Content
|
||||
.Zones (meta-property)
|
||||
.ContentItem (clr object)
|
||||
|
||||
PlaceChildContent
|
||||
.Source (another shape, presumed rendered)
|
||||
|
||||
Partial
|
||||
.TemplateName
|
||||
.Model (optional - default use current)
|
||||
|
||||
DisplayTemplate
|
||||
.TemplateName
|
||||
.Model (optional - default use current)
|
||||
.Prefix (optional - default use current)
|
||||
|
||||
EditorTemplate
|
||||
.TemplateName
|
||||
.Model (optional - default use current)
|
||||
.Prefix (optional - default use current)
|
||||
|
||||
Pager
|
||||
-CurrentPage
|
||||
@@ -42,34 +59,11 @@ Pager
|
||||
-Count
|
||||
?PageSize ?? 1
|
||||
|
||||
Shape.Pager(CurrentPage:page, PageSize:10, ItemCount:53)
|
||||
Shape.Pager(CurrentPage:page, PageCount:6)
|
||||
Shape.Pager(CurrentPage:page)
|
||||
|
||||
x
|
||||
y
|
||||
z
|
||||
|
||||
|
||||
List
|
||||
x
|
||||
y
|
||||
z
|
||||
|
||||
Items_Content
|
||||
Items_Content__BlogPost
|
||||
Items_Content__Page
|
||||
Items_Content__Product
|
||||
|
||||
Parts/Content
|
||||
|
||||
Fields/Content
|
||||
|
||||
|
||||
.Items_Content()
|
||||
.Items_Widget()
|
||||
.Items_User()
|
||||
|
||||
==template discovery strategy==
|
||||
Items/Content.cshtml -> "Items_Content"
|
||||
Items/Content-Page.cshtml -> "Items_Content__Page"
|
||||
|
||||
Reference in New Issue
Block a user