Object description formatting

- Made CPDescriptionOfObject smarter about detecting CG objects
- CPObject, CPArray, CPDictionary do a better (as in perfect) job of indenting nested objects
- CPDictionary is displayed using Cocoa-style key = value; notation
This commit is contained in:
Aparajita Fishman committed 2013-01-25 19:19:01 +08:00
1 parent 2d34d458f4
commit 95790d55d5
6 files changed
+60 -59

No files matched your search

+4 -44
View File
@@ -1,7 +1,8 @@
#!/usr/bin/env objj
@import <Foundation/Foundation.j>
@import <AppKit/AppKit.j>
@import <Foundation/CPObject.j>
@import <Foundation/CPArray.j>
@import <AppKit/CPTheme.j>
@import <BlendKit/BlendKit.j>
var FILE = require("file"),
@@ -133,7 +134,7 @@ function main(args)
{
var state = states[stateIndex],
value = [theme valueForAttributeWithName:attributeName inState:state forClass:className],
description = [self descriptionForValue:value].replace(/^/mg, " ");
description = CPDescriptionOfObject(value).replace(/^/mg, " ");
colorPrint("cyan", " " + CPThemeStateName(state));
stream.print(description + "\n");
@@ -144,47 +145,6 @@ function main(args)
}
}
- (CPString)descriptionForValue:(id)aValue
{
var description = @"";
if (!aValue)
return @"<null>";
if (!aValue.isa)
{
if (typeof(aValue) === "object")
{
if (aValue.hasOwnProperty("width") && aValue.hasOwnProperty("height"))
description = [CPString stringWithFormat:@"CGSize: { width:%f, height:%f }", aValue.width, aValue.height];
else if (aValue.hasOwnProperty("x") && aValue.hasOwnProperty("y"))
description = [CPString stringWithFormat:@"CGPoint: { x:%f, y:%f }", aValue.x, aValue.y];
else if (aValue.hasOwnProperty("origin") && aValue.hasOwnProperty("size"))
description = [CPString stringWithFormat:@"CGRect: { x:%f, y:%f }, { width:%f, height:%f }", aValue.origin.x, aValue.origin.y, aValue.size.width, aValue.size.height];
else if (aValue.hasOwnProperty("top") && aValue.hasOwnProperty("right") && aValue.hasOwnProperty("bottom") && aValue.hasOwnProperty("left"))
description = [CPString stringWithFormat:@"CGInset: { top:%f, right:%f, bottom:%f, left:%f }", aValue.top, aValue.right, aValue.bottom, aValue.left];
else
{
description = "Object\n{\n";
for (var property in aValue)
{
if (aValue.hasOwnProperty(property))
description += " " + property + ":" + aValue[property] + "\n";
}
description += "}";
}
}
else
description = "Unknown object";
}
else
description = [aValue description];
return description;
}
// Returns undefined if $CAPP_BUILD is not defined, false if path cannot be found in $CAPP_BUILD
- (id)findResourceInCappBuild:(CPString)path isDirectory:(BOOL)isDirectory callback:(SEL)callback
{