mirror of
https://github.com/cappuccino/cappuccino.git
synced 2026-08-25 04:57:03 +00:00
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:
+2
-2
@@ -740,7 +740,7 @@ url("data:image/png;base64,BASE64ENCODEDDATA") // if there is a pattern image
|
||||
|
||||
for (var i = 0; i < slices.length; ++i)
|
||||
{
|
||||
var imgDescription = [slices[i] description];
|
||||
var imgDescription = [slices[i] description] || "nil";
|
||||
|
||||
description += imgDescription.replace(/^/mg, " ") + ",\n";
|
||||
}
|
||||
@@ -748,7 +748,7 @@ url("data:image/png;base64,BASE64ENCODEDDATA") // if there is a pattern image
|
||||
description = description.substr(0, description.length - 2) + "\n ]\n}";
|
||||
}
|
||||
else
|
||||
description += [patternImage description].replace(/^/mg, " ") + "\n}";
|
||||
description += ([patternImage description] || "nil").replace(/^/mg, " ") + "\n}";
|
||||
|
||||
return description;
|
||||
}
|
||||
|
||||
@@ -33,6 +33,7 @@ function CGGradientCreateWithColorComponents(aColorSpace, components, locations,
|
||||
{
|
||||
var num_of_colors = components.length / 4,
|
||||
locations = [];
|
||||
|
||||
for (var idx = 0; idx < num_of_colors; idx++)
|
||||
locations.push( idx / (num_of_colors - 1) );
|
||||
}
|
||||
|
||||
@@ -874,18 +874,20 @@ var concat = Array.prototype.concat,
|
||||
{
|
||||
var index = 0,
|
||||
count = [self count],
|
||||
description = "@[";
|
||||
description = "[";
|
||||
|
||||
for (; index < count; ++index)
|
||||
{
|
||||
if (index === 0)
|
||||
description += "\n\t";
|
||||
description += "\n";
|
||||
|
||||
var object = [self objectAtIndex:index];
|
||||
description += CPDescriptionOfObject(object);
|
||||
|
||||
if (index !== count - 1)
|
||||
description += ",\n\t";
|
||||
// NOTE: replace(/^/mg, " ") inserts 4 spaces at the beginning of every line
|
||||
description += CPDescriptionOfObject(object).replace(/^/mg, " ");
|
||||
|
||||
if (index < count - 1)
|
||||
description += ",\n";
|
||||
else
|
||||
description += "\n";
|
||||
}
|
||||
|
||||
@@ -638,17 +638,20 @@
|
||||
*/
|
||||
- (CPString)description
|
||||
{
|
||||
var string = "@{\n",
|
||||
var string = "@{",
|
||||
keys = self._keys,
|
||||
index = 0,
|
||||
count = self._count;
|
||||
|
||||
for (; index < count; ++index)
|
||||
{
|
||||
if (index === 0)
|
||||
string += "\n";
|
||||
|
||||
var key = keys[index],
|
||||
value = self.valueForKey(key);
|
||||
|
||||
string += "\t" + key + ": " + CPDescriptionOfObject(value).split('\n').join("\n\t") + ",\n";
|
||||
string += " " + key + " = " + CPDescriptionOfObject(value).split("\n").join("\n ") + ";\n";
|
||||
}
|
||||
|
||||
return string + "}";
|
||||
|
||||
+41
-6
@@ -538,24 +538,59 @@ CPLog(@"Got some class: %@", inst);
|
||||
|
||||
function CPDescriptionOfObject(anObject)
|
||||
{
|
||||
if (anObject === nil)
|
||||
return "nil";
|
||||
|
||||
if (anObject === undefined)
|
||||
return "undefined";
|
||||
|
||||
if (anObject.isa)
|
||||
{
|
||||
if ([anObject isKindOfClass:CPString])
|
||||
return '@"' + [anObject description] + '"';
|
||||
|
||||
return [anObject description];
|
||||
}
|
||||
|
||||
if (typeof(anObject) !== "object")
|
||||
return String(anObject);
|
||||
|
||||
var desc = "JSObject\n{\n";
|
||||
var properties = [],
|
||||
desc;
|
||||
|
||||
for (var property in anObject)
|
||||
{
|
||||
if (anObject.hasOwnProperty(property))
|
||||
desc += " " + property + ": " + CPDescriptionOfObject(anObject[property]) + "\n";
|
||||
}
|
||||
desc += "}";
|
||||
properties.push(property);
|
||||
|
||||
return desc.split('\n').join("\n\t");
|
||||
properties.sort();
|
||||
|
||||
if (properties.length === 2 && anObject.hasOwnProperty("width") && anObject.hasOwnProperty("height"))
|
||||
desc = [CPString stringWithFormat:@"CGSize: { width:%f, height:%f }", anObject.width, anObject.height];
|
||||
else if (properties.length === 2 && anObject.hasOwnProperty("x") && anObject.hasOwnProperty("y"))
|
||||
desc = [CPString stringWithFormat:@"CGPoint: { x:%f, y:%f }", anObject.x, anObject.y];
|
||||
else if (properties.length === 2 && anObject.hasOwnProperty("origin") && anObject.hasOwnProperty("size"))
|
||||
desc = [CPString stringWithFormat:@"CGRect: { x:%f, y:%f }, { width:%f, height:%f }", anObject.origin.x, anObject.origin.y, anObject.size.width, anObject.size.height];
|
||||
else if (properties.length === 4 && anObject.hasOwnProperty("top") && anObject.hasOwnProperty("right") && anObject.hasOwnProperty("bottom") && anObject.hasOwnProperty("left"))
|
||||
desc = [CPString stringWithFormat:@"CGInset: { top:%f, right:%f, bottom:%f, left:%f }", anObject.top, anObject.right, anObject.bottom, anObject.left];
|
||||
else
|
||||
{
|
||||
desc = "{";
|
||||
|
||||
for (var i = 0; i < properties.length; ++i)
|
||||
{
|
||||
if (i === 0)
|
||||
desc += "\n";
|
||||
|
||||
desc += " " + properties[i] + ": " + CPDescriptionOfObject(anObject[properties[i]]).split("\n").join("\n ");
|
||||
|
||||
if (i < properties.length - 1)
|
||||
desc += ",\n";
|
||||
else
|
||||
desc += "\n";
|
||||
}
|
||||
|
||||
desc += "}";
|
||||
}
|
||||
|
||||
return desc;
|
||||
}
|
||||
|
||||
@@ -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
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user