Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Adding prettyPrint generators for json arrays, strings and numbers

  • Loading branch information...
commit 4cc3bba9f3a25ef6cc2487821fa99895cfd4cfaf 1 parent 0dbb1b3
@juanger juanger authored committed
View
1  Sources/JsonDataFormatter.h
@@ -9,6 +9,7 @@
#import <Cocoa/Cocoa.h>
#import "XmlDataFormatter.h"
#import "NSDictionary+PrettyPrint.h"
+#import "NSArray+PrettyPrint.h"
@interface JsonDataFormatter : XmlDataFormatter {
View
18 Sources/NSArray+PrettyPrint.h
@@ -0,0 +1,18 @@
+//
+// NSArray+PrettyPrint.h
+// XMLWebKitPlugin
+//
+// Created by Juan Germán Castañeda Echevarría on 1/22/10.
+// Copyright 2010 __MyCompanyName__. All rights reserved.
+//
+
+#import <Cocoa/Cocoa.h>
+#import "NSString+PrettyPrint.h"
+#import "NSDecimalNumber+PrettyPrint.h"
+
+
+@interface NSArray (PrettyPrint)
+
+- (NSXMLNode *) prettyPrintMe;
+
+@end
View
56 Sources/NSArray+PrettyPrint.m
@@ -0,0 +1,56 @@
+//
+// NSArray+PrettyPrint.m
+// XMLWebKitPlugin
+//
+// Created by Juan Germán Castañeda Echevarría on 1/22/10.
+// Copyright 2010 __MyCompanyName__. All rights reserved.
+//
+
+#import "NSArray+PrettyPrint.h"
+
+
+@implementation NSArray (PrettyPrint)
+
+
+- (NSXMLNode *) prettyPrintMe {
+ NSXMLElement *result = [NSXMLNode elementWithName:@"span"];
+ [result addAttribute:[NSXMLNode attributeWithName:@"class" stringValue:@"element mixed"]];
+
+ NSXMLElement *open = [NSXMLNode elementWithName:@"span"];
+ [open addAttribute:[NSXMLNode attributeWithName:@"class" stringValue:@"tag open mixed"]];
+ [open addChild:[NSXMLNode textWithStringValue:@"["]];
+
+ [result addChild:open];
+
+ NSXMLElement *content = [NSXMLNode elementWithName:@"div"];
+ [content addAttribute:[NSXMLNode attributeWithName:@"class" stringValue:@"mixedcontent"]];
+
+ for (id jsonElement in self) {
+ NSXMLElement *element = [NSXMLNode elementWithName:@"div"];
+ [element addAttribute:[NSXMLNode attributeWithName:@"class" stringValue:@"element nomixed"]];
+
+// NSXMLElement *tag = [NSXMLNode elementWithName:@"span"];
+// [tag addAttribute:[NSXMLNode attributeWithName:@"class" stringValue:@"element nomixed"]];
+// [tag addChild:[NSXMLNode textWithStringValue:[[NSString alloc] initWithFormat:@"%@: ", key]]];
+//
+// [element addChild: tag];
+// [tag addChild: [[self valueForKey:key] prettyPrintMe]];
+
+ [element addChild: [jsonElement prettyPrintMe]];
+ [content addChild: element];
+ }
+
+ [result addChild: content];
+
+ NSXMLElement *close = [NSXMLNode elementWithName:@"span"];
+ [close addAttribute:[NSXMLNode attributeWithName:@"class" stringValue:@"tag close mixed"]];
+ [close addChild:[NSXMLNode textWithStringValue:@"]"]];
+
+ [result addChild:close];
+
+ return result;
+}
+
+
+
+@end
View
16 Sources/NSDecimalNumber+PrettyPrint.h
@@ -0,0 +1,16 @@
+//
+// NSDecimalNumber+PrettyPrint.h
+// XMLWebKitPlugin
+//
+// Created by Juan Germán Castañeda Echevarría on 1/22/10.
+// Copyright 2010 __MyCompanyName__. All rights reserved.
+//
+
+#import <Cocoa/Cocoa.h>
+
+
+@interface NSDecimalNumber (PrettyPrint)
+
+- (NSXMLNode *) prettyPrintMe;
+
+@end
View
18 Sources/NSDecimalNumber+PrettyPrint.m
@@ -0,0 +1,18 @@
+//
+// NSDecimalNumber+PrettyPrint.m
+// XMLWebKitPlugin
+//
+// Created by Juan Germán Castañeda Echevarría on 1/22/10.
+// Copyright 2010 __MyCompanyName__. All rights reserved.
+//
+
+#import "NSDecimalNumber+PrettyPrint.h"
+
+
+@implementation NSDecimalNumber (PrettyPrint)
+
+- (NSXMLNode *) prettyPrintMe {
+ return [NSXMLNode textWithStringValue:[self stringValue]];
+}
+
+@end
View
16 Sources/NSString+PrettyPrint.h
@@ -0,0 +1,16 @@
+//
+// NSStringPrettyPrint.h
+// XMLWebKitPlugin
+//
+// Created by Juan Germán Castañeda Echevarría on 1/20/10.
+// Copyright 2010 __MyCompanyName__. All rights reserved.
+//
+
+#import <Cocoa/Cocoa.h>
+
+
+@interface NSString (PrettyPrint)
+
+- (NSXMLNode *) prettyPrintMe;
+
+@end
View
19 Sources/NSString+PrettyPrint.m
@@ -0,0 +1,19 @@
+//
+// NSStringPrettyPrint.m
+// XMLWebKitPlugin
+//
+// Created by Juan Germán Castañeda Echevarría on 1/20/10.
+// Copyright 2010 __MyCompanyName__. All rights reserved.
+//
+
+#import "NSString+PrettyPrint.h"
+
+
+@implementation NSString (PrettyPrint)
+
+- (NSXMLNode *) prettyPrintMe {
+ NSString *pretty = [NSString stringWithFormat:@"\"%@\"", self];
+ return [NSXMLNode textWithStringValue:pretty];
+}
+
+@end
View
22 XMLWebKitPlugin.xcodeproj/project.pbxproj
@@ -65,6 +65,10 @@
21A64E76110A8B4E005B517F /* SBJsonBase.m in Sources */ = {isa = PBXBuildFile; fileRef = 21A64E02110A5B8F005B517F /* SBJsonBase.m */; };
21A64E77110A8B52005B517F /* SBJsonParser.m in Sources */ = {isa = PBXBuildFile; fileRef = 21A64E04110A5B8F005B517F /* SBJsonParser.m */; };
21A64E78110A8B56005B517F /* SBJsonWriter.m in Sources */ = {isa = PBXBuildFile; fileRef = 21A64E06110A5B8F005B517F /* SBJsonWriter.m */; };
+ 21A64EA1110A8F34005B517F /* NSArray+PrettyPrint.m in Sources */ = {isa = PBXBuildFile; fileRef = 21A64E9C110A8F34005B517F /* NSArray+PrettyPrint.m */; };
+ 21A64EA2110A8F34005B517F /* NSDecimalNumber+PrettyPrint.m in Sources */ = {isa = PBXBuildFile; fileRef = 21A64E9E110A8F34005B517F /* NSDecimalNumber+PrettyPrint.m */; };
+ 21A64EA3110A8F34005B517F /* NSString+PrettyPrint.m in Sources */ = {isa = PBXBuildFile; fileRef = 21A64EA0110A8F34005B517F /* NSString+PrettyPrint.m */; };
+ 21A64ED7110A92FF005B517F /* xml-to-html.xslt in Resources */ = {isa = PBXBuildFile; fileRef = 21A64E12110A5C73005B517F /* xml-to-html.xslt */; };
224339580A6F05F3000348D4 /* WebKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 224339570A6F05F3000348D4 /* WebKit.framework */; };
8D1AC96B0486D14A00FE50C9 /* XMLWebKitPluginView.m in Sources */ = {isa = PBXBuildFile; fileRef = 0259C576FE90428111CA0C5A /* XMLWebKitPluginView.m */; settings = {ATTRIBUTES = (); }; };
8D1AC9700486D14A00FE50C9 /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = DD92D38A0106425D02CA0E72 /* Cocoa.framework */; };
@@ -162,6 +166,12 @@
21A64E12110A5C73005B517F /* xml-to-html.xslt */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xml; name = "xml-to-html.xslt"; path = "Resources/xml-to-html.xslt"; sourceTree = "<group>"; };
21A64E67110A8AC1005B517F /* NSDictionary+PrettyPrint.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = "NSDictionary+PrettyPrint.h"; path = "Sources/NSDictionary+PrettyPrint.h"; sourceTree = "<group>"; };
21A64E68110A8AC1005B517F /* NSDictionary+PrettyPrint.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = "NSDictionary+PrettyPrint.m"; path = "Sources/NSDictionary+PrettyPrint.m"; sourceTree = "<group>"; };
+ 21A64E9B110A8F34005B517F /* NSArray+PrettyPrint.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = "NSArray+PrettyPrint.h"; path = "Sources/NSArray+PrettyPrint.h"; sourceTree = "<group>"; };
+ 21A64E9C110A8F34005B517F /* NSArray+PrettyPrint.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = "NSArray+PrettyPrint.m"; path = "Sources/NSArray+PrettyPrint.m"; sourceTree = "<group>"; };
+ 21A64E9D110A8F34005B517F /* NSDecimalNumber+PrettyPrint.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = "NSDecimalNumber+PrettyPrint.h"; path = "Sources/NSDecimalNumber+PrettyPrint.h"; sourceTree = "<group>"; };
+ 21A64E9E110A8F34005B517F /* NSDecimalNumber+PrettyPrint.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = "NSDecimalNumber+PrettyPrint.m"; path = "Sources/NSDecimalNumber+PrettyPrint.m"; sourceTree = "<group>"; };
+ 21A64E9F110A8F34005B517F /* NSString+PrettyPrint.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = "NSString+PrettyPrint.h"; path = "Sources/NSString+PrettyPrint.h"; sourceTree = "<group>"; };
+ 21A64EA0110A8F34005B517F /* NSString+PrettyPrint.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = "NSString+PrettyPrint.m"; path = "Sources/NSString+PrettyPrint.m"; sourceTree = "<group>"; };
224339570A6F05F3000348D4 /* WebKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = WebKit.framework; path = /System/Library/Frameworks/WebKit.framework; sourceTree = "<absolute>"; };
32DBCF980370C29C00C91783 /* XMLWebKitPlugin_Prefix.pch */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = XMLWebKitPlugin_Prefix.pch; sourceTree = "<group>"; };
8D1AC9730486D14A00FE50C9 /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist; path = Info.plist; sourceTree = "<group>"; };
@@ -288,6 +298,12 @@
21A64E0A110A5BD5005B517F /* JSON */ = {
isa = PBXGroup;
children = (
+ 21A64E9B110A8F34005B517F /* NSArray+PrettyPrint.h */,
+ 21A64E9C110A8F34005B517F /* NSArray+PrettyPrint.m */,
+ 21A64E9D110A8F34005B517F /* NSDecimalNumber+PrettyPrint.h */,
+ 21A64E9E110A8F34005B517F /* NSDecimalNumber+PrettyPrint.m */,
+ 21A64E9F110A8F34005B517F /* NSString+PrettyPrint.h */,
+ 21A64EA0110A8F34005B517F /* NSString+PrettyPrint.m */,
21A64E67110A8AC1005B517F /* NSDictionary+PrettyPrint.h */,
21A64E68110A8AC1005B517F /* NSDictionary+PrettyPrint.m */,
21A64E10110A5C49005B517F /* JsonDataFormatter.h */,
@@ -449,6 +465,7 @@
1B3D9DF50F5BEFF1009F2BD8 /* xml-pretty-print.xslt in Resources */,
1B3DA2250F5D6577009F2BD8 /* web-resources in Resources */,
1B238ABD0F671EB800AE9062 /* xml-escape-amp-lt.xslt in Resources */,
+ 21A64ED7110A92FF005B517F /* xml-to-html.xslt in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -577,6 +594,9 @@
21A64E76110A8B4E005B517F /* SBJsonBase.m in Sources */,
21A64E77110A8B52005B517F /* SBJsonParser.m in Sources */,
21A64E78110A8B56005B517F /* SBJsonWriter.m in Sources */,
+ 21A64EA1110A8F34005B517F /* NSArray+PrettyPrint.m in Sources */,
+ 21A64EA2110A8F34005B517F /* NSDecimalNumber+PrettyPrint.m in Sources */,
+ 21A64EA3110A8F34005B517F /* NSString+PrettyPrint.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -767,7 +787,7 @@
"$(inherited)",
"\"$(BUILD_ROOT)\"",
);
- GCC_ENABLE_FIX_AND_CONTINUE = NO;
+ GCC_ENABLE_FIX_AND_CONTINUE = YES;
GCC_OPTIMIZATION_LEVEL = 0;
HEADER_SEARCH_PATHS = "";
LIBRARY_SEARCH_PATHS = (
Please sign in to comment.
Something went wrong with that request. Please try again.