Rendering the Model as a tree in shape tracing

--HG--
branch : dev
This commit is contained in:
Sebastien Ros
2011-02-25 23:52:45 -08:00
parent ca6736525d
commit a395b47e66
8 changed files with 139 additions and 42 deletions

View File

@@ -60,6 +60,7 @@
<Reference Include="System.Xml.Linq" />
</ItemGroup>
<ItemGroup>
<Content Include="Styles\images\menu-glyph.png" />
<Content Include="Scripts\orchard-designertools-shapetracing.js" />
<Content Include="Styles\orchard-designertools-shapetracing.css" />
<Content Include="Web.config">

View File

@@ -71,11 +71,33 @@
});
}
var glyph = $("<span class=\"expando-glyph-container closed\"><span class=\"expando-glyph\"></span>&#8203;</span>");
$('div.model div.type').prev().prepend(glyph);
$('div.model ul ul').toggle(false);
$('span.expando-glyph-container').click(function () {
var __this = $(this);
if (__this.hasClass("closed") || __this.hasClass("closing")) {
__this.parent().parent().parent().children('ul').slideDown(300, function () { __this.removeClass("opening").removeClass("closed").addClass("open"); });
__this.addClass("opening");
}
else {
__this.parent().parent().parent().children('ul').slideUp(300, function () { __this.removeClass("closing").removeClass("open").addClass("closed"); });
__this.addClass("closing");
}
return false;
});
bindTab('.shape');
bindTab('.model');
bindTab('.placement');
bindTab('.templates');
bindTab('.source');
bindTab('.html');
});
})(jQuery);

View File

@@ -62,15 +62,19 @@ namespace Orchard.DesignerTools.Services {
private void DumpValue(object o, string name) {
string formatted = FormatValue(o);
_node.Add(
new XElement("h3",
new XElement("div", new XAttribute("class", "name"), name),
new XElement("div", new XAttribute("class", "value"), formatted)
)
);
}
private void DumpObject(object o, string name) {
_node.Add(
new XElement("h3",
new XElement("div", new XAttribute("class", "name"), name),
new XElement("div", new XAttribute("class", "type"), FormatType(o.GetType()))
)
);
if (_parents.Count >= _levels) {
@@ -168,6 +172,10 @@ namespace Orchard.DesignerTools.Services {
_node.Add(_node = new XElement("ul"));
foreach (var key in props.Keys) {
// ignore private members (added dynmically by the shape wrapper)
if(key.ToString().StartsWith("_")) {
continue;
}
Dump(props[key], key.ToString());
}
_node = _node.Parent;

View File

@@ -34,57 +34,55 @@ namespace Orchard.DesignerTools.Services {
&& context.ShapeType != "ContentZone"
&& context.ShapeType != "ShapeTracingMeta") {
var shape = context.Shape;
var shapeMetadata = (ShapeMetadata)context.Shape.Metadata;
var currentTheme = _themeManager.GetRequestTheme(_workContext.HttpContext.Request.RequestContext);
var shapeTable = _shapeTableManager.GetShapeTable(currentTheme.Id);
if (!shapeTable.Descriptors.ContainsKey(shapeMetadata.Type)) {
return;
}
var descriptor = shapeTable.Descriptors[shapeMetadata.Type];
shapeMetadata.Wrappers.Add("ShapeTracingWrapper");
shape.Definition = descriptor.BindingSource;
try {
if (_webSiteFolder.FileExists(descriptor.BindingSource)) {
shape.DefinitionContent = _webSiteFolder.ReadFile(descriptor.BindingSource);
}
}
catch {
// the url might be invalid in case of a code shape
}
shape.Dump = DumpObject(shape);
}
}
static string DumpObject(object o) {
var dumper = new ObjectDumper(6);
var el = dumper.Dump(o, "Model");
using (var sw = new StringWriter()) {
el.WriteTo(new XmlTextWriter(sw) { Formatting = Formatting.Indented });
return sw.ToString();
}
}
public void Displaying(ShapeDisplayingContext context) {
var shape = context.Shape;
var shapeMetadata = (ShapeMetadata) context.Shape.Metadata;
var currentTheme = _themeManager.GetRequestTheme(_workContext.HttpContext.Request.RequestContext);
var shapeTable = _shapeTableManager.GetShapeTable(currentTheme.Id);
if (!shapeMetadata.Wrappers.Contains("ShapeTracingWrapper")) {
return;
}
var descriptor = shapeTable.Descriptors[shapeMetadata.Type];
// dump the Shape's content
var dumper = new ObjectDumper(6);
var el = dumper.Dump(context.Shape, "Model");
using (var sw = new StringWriter()) {
el.WriteTo(new XmlTextWriter(sw) {Formatting = Formatting.Indented});
context.Shape._Dump = sw.ToString();
}
shape._Definition = descriptor.BindingSource;
try {
if (_webSiteFolder.FileExists(descriptor.BindingSource)) {
shape._DefinitionContent = _webSiteFolder.ReadFile(descriptor.BindingSource);
}
}
catch {
// the url might be invalid in case of a code shape
}
if (shapeMetadata.PlacementSource != null && _webSiteFolder.FileExists(shapeMetadata.PlacementSource)) {
context.Shape.PlacementContent = _webSiteFolder.ReadFile(shapeMetadata.PlacementSource);
}
}
public void Displayed(ShapeDisplayedContext context) {
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 427 B

View File

@@ -138,3 +138,71 @@ ul.debuggerMenu { margin:8px 0 -8px 0; }
-webkit-border-radius: 3px;
-moz-border-radius: 3px;
}
.meta .model div.name
{
display:block;
float:left;
width:30%;
}
.meta .model ul
{
padding:0;
margin-left:-15px;
margin:0;
list-style-type:none;
}
.meta .model ul li
{
padding-left:15px;
}
.meta .model h3
{
margin:0;
padding:0;
}
h3:hover
{
background-color: #eee;
}
.expando-glyph {
background:transparent no-repeat 0 -19px;
background-image:url(images/menu-glyph.png);
line-height:12px;
padding-left:15px;
margin-left:-15px;
}
.expando-glyph:hover {
background-image:url(images/menu-glyph.png);
}
.expando-glyph-container.closed .expando-glyph {
background-image:url(images/menu-glyph.png);
background-position:0 3px;
}
.expando-glyph-container.closed .expando-glyph:hover {
background-image:url(images/menu-glyph.png);
}
.expando-glyph-container.closing .expando-glyph {
-webkit-transition:all .2s ease-in-out;
-moz-transition:all .2s ease-in-out;
transition:all .2s ease-in-out;
-webkit-transform:rotate(-90deg) translate(3px, -3px);
-moz-transform:rotate(-90deg) translate(3px, -3px);
transform:rotate(-90deg) translate(3px, -3px);
}
.expando-glyph-container.opening .expando-glyph {
-webkit-transition:all .2s ease-in-out;
-moz-transition:all .2s ease-in-out;
transition:all .2s ease-in-out;
-webkit-transform:rotate(90deg) translate(3px, 3px);
-moz-transform:rotate(90deg) translate(3px, 3px);
transform:rotate(90deg) translate(3px, 3px);
}

View File

@@ -24,7 +24,7 @@
</div>
<div class="model" style="display:none">
<pre>@Model.Dump</pre>
@(new MvcHtmlString(@Model.Dump))
</div>
<div class="placement" style="display:none">

View File

@@ -15,12 +15,12 @@
Layout.Zones["Tail"].Add(
New.ShapeTracingMeta(
ShapeType: Model.Metadata.Type,
Definition: Model.Definition,
DefinitionContent: Model.DefinitionContent,
Definition: Model._Definition,
DefinitionContent: Model._DefinitionContent,
DisplayType: Model.Metadata.DisplayType,
Position: Model.Metadata.Position,
PlacementSource: Model.Metadata.PlacementSource,
Dump: Model.Dump,
Dump: Model._Dump,
PlacementContent: Model.PlacementContent,
Alternates: Model.Metadata.Alternates,
Wrappers: Model.Metadata.Wrappers,