Some shape display experimentation (incl. limited html attribute specification)

--HG--
branch : mvc3p1
This commit is contained in:
Nathan Heskew
2010-08-27 13:50:35 -07:00
parent ff43a359bc
commit dfe71231bb
5 changed files with 48 additions and 9 deletions

View File

@@ -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");

View File

@@ -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("<p class=\"message\">"), Severity ?? "Neutral", ": ", Content, new HtmlString("</p>"));
}
static IHtmlString Combine(IEnumerable<IHtmlString> contents) {
return new HtmlString(contents.Aggregate("", (a, b) => a + b));
}

View File

@@ -1,14 +1,21 @@
<div>
a @Display.Title(text:"This is everything")
b @Display(Model)
c @Display(View.Page)
<style>#goodlink:after {content:'(url from css: ' attr(href) ')';} .bigredborderfromabadclassname {border:3px solid red;}</style>
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))
</div>

View File

@@ -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,

View File

@@ -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<object> 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<object> Attributes) {
var tagBuilder = new TagBuilder("img");
tagBuilder.MergeAttributes(Attributes.Named);
tagBuilder.MergeAttribute("src", Url);
return Display(new HtmlString(tagBuilder.ToString(TagRenderMode.SelfClosing)));
}
}
}