From dfe71231bb9d249b7832a3af376ef3af145f748e Mon Sep 17 00:00:00 2001 From: Nathan Heskew Date: Fri, 27 Aug 2010 13:50:35 -0700 Subject: [PATCH] Some shape display experimentation (incl. limited html attribute specification) --HG-- branch : mvc3p1 --- .../Controllers/HomeController.cs | 3 +++ .../Modules/Orchard.DevTools/Shapes.cs | 3 +-- .../Views/Home/UsingShapes.cshtml | 21 +++++++++++------ .../Speculation/DefaultShapeTableFactory.cs | 7 ++++++ src/Orchard/Mvc/Html/Shapes.cs | 23 +++++++++++++++++++ 5 files changed, 48 insertions(+), 9 deletions(-) create mode 100644 src/Orchard/Mvc/Html/Shapes.cs diff --git a/src/Orchard.Web/Modules/Orchard.DevTools/Controllers/HomeController.cs b/src/Orchard.Web/Modules/Orchard.DevTools/Controllers/HomeController.cs index df1e45ac1..0c200bd41 100644 --- a/src/Orchard.Web/Modules/Orchard.DevTools/Controllers/HomeController.cs +++ b/src/Orchard.Web/Modules/Orchard.DevTools/Controllers/HomeController.cs @@ -68,6 +68,9 @@ namespace Orchard.DevTools.Controllers { ViewModel.Page.Messages.Add( Shape.Message(Content: T("This is a test"), Severity: "Really bad!!!")); + ViewModel.Page.Sidebar.Add( + Shape.Link(Url: "http://orchard.codeplex.com", Content: Shape.Image(Url: "http://orchardproject.net/Content/images/orchardLogo.jpg").Attributes(new { @class = "bigredborderfromabadclassname" }))); + var model = Shape.Message( Content: Shape.Explosion(Height: 100, Width: 200), Severity: "Meh"); diff --git a/src/Orchard.Web/Modules/Orchard.DevTools/Shapes.cs b/src/Orchard.Web/Modules/Orchard.DevTools/Shapes.cs index 5bc4d1c5e..1d3faca01 100644 --- a/src/Orchard.Web/Modules/Orchard.DevTools/Shapes.cs +++ b/src/Orchard.Web/Modules/Orchard.DevTools/Shapes.cs @@ -24,7 +24,7 @@ namespace Orchard.DevTools { tag.GenerateId("zone-" + Shape.Name); tag.AddCssClass("zone-" + Shape.Name); tag.AddCssClass("zone"); - tag.InnerHtml = Combine(DisplayAll(Display, Shape).ToArray()).ToString(); + tag.InnerHtml = Combine(DisplayAll(Display, Shape)).ToString(); return new HtmlString(tag.ToString()); } @@ -32,7 +32,6 @@ namespace Orchard.DevTools { return Display(new HtmlString("

"), Severity ?? "Neutral", ": ", Content, new HtmlString("

")); } - static IHtmlString Combine(IEnumerable contents) { return new HtmlString(contents.Aggregate("", (a, b) => a + b)); } diff --git a/src/Orchard.Web/Modules/Orchard.DevTools/Views/Home/UsingShapes.cshtml b/src/Orchard.Web/Modules/Orchard.DevTools/Views/Home/UsingShapes.cshtml index d71563273..49b958ca6 100644 --- a/src/Orchard.Web/Modules/Orchard.DevTools/Views/Home/UsingShapes.cshtml +++ b/src/Orchard.Web/Modules/Orchard.DevTools/Views/Home/UsingShapes.cshtml @@ -1,14 +1,21 @@ 
- -a @Display.Title(text:"This is everything") -b @Display(Model) -c @Display(View.Page) + + a @Display.Title(text:"This is everything") + b @Display(Model) -d @Display.Message(Content:"Madness!!!") + c @Display(View.Page) -e @Display.Explosion(Width:40) + c.a @Display.Link(Url: "http://orchardproject.net", Content: "Help, I'm in an anchor!!", Attributes: new {title = "foo"}) + c.b @Display.Link( + Url: "http://orchardproject.net", + Content: @Display.Image(Url: "http://orchardproject.net/content/images/heroShot.jpg", Attributes: new {@class = "bigredborderfromabadclassname"}), + Attributes: new {id = "goodlink"}) -f @Display.Message(Content: @Display.Explosion(Height:10,Width:15)) + d @Display.Message(Content:"Madness!!!") + + e @Display.Explosion(Width:40) + + f @Display.Message(Content: @Display.Explosion(Height:10,Width:15))
diff --git a/src/Orchard/DisplayManagement/Speculation/DefaultShapeTableFactory.cs b/src/Orchard/DisplayManagement/Speculation/DefaultShapeTableFactory.cs index 559bdfda9..79635d241 100644 --- a/src/Orchard/DisplayManagement/Speculation/DefaultShapeTableFactory.cs +++ b/src/Orchard/DisplayManagement/Speculation/DefaultShapeTableFactory.cs @@ -6,6 +6,8 @@ using System.Linq.Expressions; using System.Reflection; using System.Runtime.CompilerServices; using System.Web; +using System.Web.Routing; +using ClaySharp.Implementation; using Microsoft.CSharp.RuntimeBinder; using Orchard.DisplayManagement.Implementation; using Binder = Microsoft.CSharp.RuntimeBinder.Binder; @@ -52,6 +54,11 @@ namespace Orchard.DisplayManagement { if (parameter.Name == "Display") return displayContext.Display; + if (parameter.Name == "Attributes") { + var attributes = new RouteValueDictionary(((dynamic) (displayContext.Value))[parameter.Name]); + return Arguments.From(attributes.Values, attributes.Keys); + } + var result = ((dynamic)(displayContext.Value))[parameter.Name]; var converter = _converters.GetOrAdd( parameter.ParameterType, diff --git a/src/Orchard/Mvc/Html/Shapes.cs b/src/Orchard/Mvc/Html/Shapes.cs new file mode 100644 index 000000000..2778f5ade --- /dev/null +++ b/src/Orchard/Mvc/Html/Shapes.cs @@ -0,0 +1,23 @@ +using System.Web; +using System.Web.Mvc; +using System.Web.Routing; +using ClaySharp; +using Orchard.DisplayManagement; + +namespace Orchard.Mvc.Html { + public class Shapes : IShapeDriver { + public IHtmlString Link(dynamic Display, object Content, string Url, INamedEnumerable Attributes) { + var tagBuilder = new TagBuilder("a") { InnerHtml = Display(Content).ToString() }; + tagBuilder.MergeAttributes(Attributes.Named); + tagBuilder.MergeAttribute("href", Url); + return Display(new HtmlString(tagBuilder.ToString(TagRenderMode.Normal))); + } + + public IHtmlString Image(dynamic Display, string Url, INamedEnumerable Attributes) { + var tagBuilder = new TagBuilder("img"); + tagBuilder.MergeAttributes(Attributes.Named); + tagBuilder.MergeAttribute("src", Url); + return Display(new HtmlString(tagBuilder.ToString(TagRenderMode.SelfClosing))); + } + } +}