mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-15 19:54:57 +08:00
Adding a property and a couple methods to the base view class(es)
- Layout (shortcut for WorkContext.Layout) - HasText(object thing) (shortcut for !string.IsNullOrWhiteSpace(thing as string)) - Tag(dynamic shape, string tagName) (shortcut for Html.Resolve<ITagBuilderFactory>().Create(shape, tagName)) --HG-- branch : dev
This commit is contained in:
@@ -146,7 +146,7 @@
|
||||
<Content Include="Web.config">
|
||||
<SubType>Designer</SubType>
|
||||
</Content>
|
||||
<None Include="Themes\TheThemeMachine\Views\MenuItem.cshtml_" />
|
||||
<None Include="Themes\TheThemeMachine\Views\MenuItem.cshtml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Orchard\Orchard.Framework.csproj">
|
||||
@@ -318,7 +318,7 @@
|
||||
<Content Include="Themes\Web.config" />
|
||||
<Content Include="Themes\TheThemeMachine\Views\Items\Content.Blog.cshtml" />
|
||||
<None Include="Themes\TheThemeMachine\Views\Layout.cshtml" />
|
||||
<None Include="Themes\TheThemeMachine\Views\Menu.cshtml_">
|
||||
<None Include="Themes\TheThemeMachine\Views\Menu.cshtml">
|
||||
<SubType>Designer</SubType>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
|
@@ -14,7 +14,6 @@
|
||||
WorkContext.Layout.Featured.Add(New.TempFeatured(Hello:"bob"));
|
||||
WorkContext.Layout.Featured.Add("just some text in featured");
|
||||
}
|
||||
@Model.TitleFromMenu
|
||||
<div id="layout-wrapper">
|
||||
@Display.User()
|
||||
<header id="layout-header">
|
||||
|
@@ -3,7 +3,7 @@
|
||||
var items = (IEnumerable<dynamic>)Enumerable.Cast<dynamic>(Model);
|
||||
}
|
||||
@{
|
||||
if (HasText(Model.Text)) {
|
||||
if (!HasText(Model.Text)) {
|
||||
@DisplayChildren(Model)
|
||||
} else {
|
||||
<li><a href="@Model.Href">@Model.Text</a>
|
@@ -4,12 +4,14 @@ using System.Web.Mvc;
|
||||
using System.Web.WebPages;
|
||||
using Autofac;
|
||||
using Orchard.DisplayManagement;
|
||||
using Orchard.DisplayManagement.Shapes;
|
||||
using Orchard.Localization;
|
||||
using Orchard.Mvc.Html;
|
||||
using Orchard.Mvc.Spooling;
|
||||
using Orchard.Security;
|
||||
using Orchard.Security.Permissions;
|
||||
using Orchard.UI.Resources;
|
||||
using TagBuilder = System.Web.Mvc.TagBuilder;
|
||||
|
||||
namespace Orchard.Mvc.ViewEngines.Razor {
|
||||
|
||||
@@ -24,7 +26,8 @@ namespace Orchard.Mvc.ViewEngines.Razor {
|
||||
|
||||
public Localizer T { get { return _localizer; } }
|
||||
public dynamic Display { get { return _display; } }
|
||||
public dynamic Layout { get { return _layout; } }
|
||||
// review: (heskew) is it going to be a problem?
|
||||
public new dynamic Layout { get { return _layout; } }
|
||||
public WorkContext WorkContext { get { return _workContext; } }
|
||||
|
||||
public dynamic New { get { return _new; } }
|
||||
@@ -83,6 +86,14 @@ namespace Orchard.Mvc.ViewEngines.Razor {
|
||||
return Authorizer.Authorize(permission);
|
||||
}
|
||||
|
||||
public bool HasText(object thing) {
|
||||
return !string.IsNullOrWhiteSpace(thing as string);
|
||||
}
|
||||
|
||||
public TagBuilder Tag(dynamic shape, string tagName) {
|
||||
return Html.Resolve<ITagBuilderFactory>().Create(shape, tagName);
|
||||
}
|
||||
|
||||
public IHtmlString DisplayChildren(dynamic shape) {
|
||||
var writer = new HtmlStringWriter();
|
||||
foreach (var item in shape) {
|
||||
|
@@ -5,12 +5,14 @@ using System.Web.Mvc;
|
||||
using System.Web.UI;
|
||||
using Autofac;
|
||||
using Orchard.DisplayManagement;
|
||||
using Orchard.DisplayManagement.Shapes;
|
||||
using Orchard.Localization;
|
||||
using Orchard.Mvc.Html;
|
||||
using Orchard.Mvc.Spooling;
|
||||
using Orchard.Security;
|
||||
using Orchard.Security.Permissions;
|
||||
using Orchard.UI.Resources;
|
||||
using TagBuilder = System.Web.Mvc.TagBuilder;
|
||||
|
||||
namespace Orchard.Mvc {
|
||||
public class ViewPage<TModel> : System.Web.Mvc.ViewPage<TModel>, IOrchardViewPage {
|
||||
@@ -19,6 +21,7 @@ namespace Orchard.Mvc {
|
||||
|
||||
private object _display;
|
||||
private Localizer _localizer = NullLocalizer.Instance;
|
||||
private object _layout;
|
||||
private WorkContext _workContext;
|
||||
|
||||
public Localizer T { get { return _localizer; } }
|
||||
@@ -29,7 +32,8 @@ namespace Orchard.Mvc {
|
||||
(_scriptRegister = new ViewPageScriptRegister(Writer, Html.ViewDataContainer, Html.Resolve<IResourceManager>()));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public dynamic Layout { get { return _layout; } }
|
||||
public WorkContext WorkContext { get { return _workContext; } }
|
||||
|
||||
public IDisplayHelperFactory DisplayHelperFactory { get; set; }
|
||||
@@ -52,6 +56,7 @@ namespace Orchard.Mvc {
|
||||
|
||||
_localizer = LocalizationUtilities.Resolve(ViewContext, AppRelativeVirtualPath);
|
||||
_display = DisplayHelperFactory.CreateHelper(ViewContext, this);
|
||||
_layout = _workContext.Layout;
|
||||
}
|
||||
|
||||
public virtual void RegisterLink(LinkEntry link) {
|
||||
@@ -80,7 +85,15 @@ namespace Orchard.Mvc {
|
||||
|
||||
public bool AuthorizedFor(Permission permission) {
|
||||
return Authorizer.Authorize(permission);
|
||||
}
|
||||
}
|
||||
|
||||
public bool HasText(object thing) {
|
||||
return !string.IsNullOrWhiteSpace(thing as string);
|
||||
}
|
||||
|
||||
public TagBuilder Tag(dynamic shape, string tagName) {
|
||||
return Html.Resolve<ITagBuilderFactory>().Create(shape, tagName);
|
||||
}
|
||||
|
||||
public IHtmlString DisplayChildren(dynamic shape) {
|
||||
var writer = new HtmlStringWriter();
|
||||
|
@@ -3,12 +3,14 @@ using System.Web;
|
||||
using System.Web.Mvc;
|
||||
using Autofac;
|
||||
using Orchard.DisplayManagement;
|
||||
using Orchard.DisplayManagement.Shapes;
|
||||
using Orchard.Localization;
|
||||
using Orchard.Mvc.Html;
|
||||
using Orchard.Mvc.Spooling;
|
||||
using Orchard.Security;
|
||||
using Orchard.Security.Permissions;
|
||||
using Orchard.UI.Resources;
|
||||
using TagBuilder = System.Web.Mvc.TagBuilder;
|
||||
|
||||
namespace Orchard.Mvc {
|
||||
public class ViewUserControl<TModel> : System.Web.Mvc.ViewUserControl<TModel>,IOrchardViewPage {
|
||||
@@ -18,11 +20,13 @@ namespace Orchard.Mvc {
|
||||
private object _display;
|
||||
private object _new;
|
||||
private Localizer _localizer = NullLocalizer.Instance;
|
||||
private object _layout;
|
||||
private WorkContext _workContext;
|
||||
|
||||
public Localizer T { get { return _localizer; } }
|
||||
public dynamic Display { get { return _display; } }
|
||||
public dynamic New { get { return _new; } }
|
||||
public dynamic Layout { get { return _layout; } }
|
||||
public WorkContext WorkContext { get { return _workContext; } }
|
||||
|
||||
public IDisplayHelperFactory DisplayHelperFactory { get; set; }
|
||||
@@ -70,6 +74,7 @@ namespace Orchard.Mvc {
|
||||
|
||||
_localizer = LocalizationUtilities.Resolve(viewContext, AppRelativeVirtualPath);
|
||||
_display = DisplayHelperFactory.CreateHelper(viewContext, this);
|
||||
_layout = _workContext.Layout;
|
||||
_new = ShapeHelperFactory.CreateHelper();
|
||||
|
||||
base.RenderView(viewContext);
|
||||
@@ -83,6 +88,14 @@ namespace Orchard.Mvc {
|
||||
return Authorizer.Authorize(permission);
|
||||
}
|
||||
|
||||
public bool HasText(object thing) {
|
||||
return !string.IsNullOrWhiteSpace(thing as string);
|
||||
}
|
||||
|
||||
public TagBuilder Tag(dynamic shape, string tagName) {
|
||||
return Html.Resolve<ITagBuilderFactory>().Create(shape, tagName);
|
||||
}
|
||||
|
||||
public IHtmlString DisplayChildren(dynamic shape) {
|
||||
var writer = new HtmlStringWriter();
|
||||
foreach (var item in shape) {
|
||||
|
Reference in New Issue
Block a user