I'm writing an HTML creation framework in Objective-C. It seems to be a common problem these days that people with CoreData apps have a nice interface, but it's not WYSIWYG, which makes it more difficult to set up a view for printing. On Apple's Cocoa-dev mailing list, the common solution, is to put the data into HTML, pass it to a WebView, and print from there, or get a PDF with the WebView data and print that. But looking around, there didn't seem to be an easy way to do that.
So I decided to write an HTML creator. I've got it working for my own needs, but it's pretty basic, and doesn't even try to do anything fancy; you set up the tree manually and there's no validation, though there is some convenient content formatting, and it includes a category on NSTableView to generate an HTML table from the table view and its data source. But even that's pretty basic. It's fine for me... I don't need any extra features beyond creating an HTML table from the entire data set. But other people might. So I'm taking feature requests, not just for the category, but for the entire framework.
What it's got now:
Classes:
SYHTMLNode - yes, I know I need to add the corresponding class methods for the 2 initializers.
SYHTMLContentFormatter - incomplete, I assume... I only need B/I/U, but I'm sure there's other things necessary
NSTableView (SYHTMLGenerator)
Thoughts? Requests? This will be released publicly around WWDC, I'm hoping.
So I decided to write an HTML creator. I've got it working for my own needs, but it's pretty basic, and doesn't even try to do anything fancy; you set up the tree manually and there's no validation, though there is some convenient content formatting, and it includes a category on NSTableView to generate an HTML table from the table view and its data source. But even that's pretty basic. It's fine for me... I don't need any extra features beyond creating an HTML table from the entire data set. But other people might. So I'm taking feature requests, not just for the category, but for the entire framework.
What it's got now:
Classes:
SYHTMLNode - yes, I know I need to add the corresponding class methods for the 2 initializers.
Code:
//
// SYHTMLNode.h
// HTML Generator
//
// Created by Daniel DeCovnick on 5/2/07.
// Copyright 2007 Softyards Software. All rights reserved.
//
#import <Cocoa/Cocoa.h>
@interface SYHTMLNode : NSObject {
@protected
NSString *nodeType;
@public //I think making these public will be easier. On 10.5, they'd be properties
NSMutableDictionary *nodeAttributes;
NSMutableString *nodeContent;
NSMutableArray *nodeSubNodes;
NSMutableArray *locationsOfSubNodes;
}
+(SYHTMLNode *)newRootNode;
-(id)initWithNodeType:(NSString *)type;
-(id)initWithNodeType:(NSString *)type attributes:(NSDictionary *)attributes content:(NSString *)content andSubNodes:(NSArray *)subNodes;
-(NSString *)nodeType;
-(void)setNodeType:(NSString *)type;
-(id)addNodeStringContent:(NSString *)content;
-(id)addSubNodeAtCurrentEndOfContent:(SYHTMLNode *)subNode;
@end
SYHTMLContentFormatter - incomplete, I assume... I only need B/I/U, but I'm sure there's other things necessary
Code:
//
// SYHTMLContentFormatter.h
// SYHTMLGenerator
//
// Created by Daniel DeCovnick on 5/8/07.
// Copyright 2007 Softyards Software. All rights reserved.
//
#import <Cocoa/Cocoa.h>
@class SYHTMLNode;
typedef int SYHTMLContentFormatterStyle;
@interface SYHTMLContentFormatter : NSObject {
SYHTMLContentFormatterStyle mStyle;
}
-(id)initWithStyle:(SYHTMLContentFormatterStyle)aStyle;
-(SYHTMLContentFormatterStyle)contentFormatterStyle;
-(void)setContentFormatterStyle:(SYHTMLContentFormatterStyle)aSytle;
-(SYHTMLNode *)formattedContentNode:(NSString *)content;
-(void)formatContent:(NSString *)content andAppendToNode:(SYHTMLNode *)node;
-(SYHTMLNode *)formatContentInNode:(SYHTMLNode *)node withRange:(NSRange)aRange;
+(SYHTMLContentFormatter *)boldFormatter;
+(SYHTMLContentFormatter *)italicFormatter;
+(SYHTMLContentFormatter *)underlineFormatter;
@end
NSTableView (SYHTMLGenerator)
Code:
//
// NSTableView (SYHTMLAdditions).h
// HTML Generator
//
// Created by Daniel DeCovnick on 5/7/07.
// Copyright 2007 Softyards Software. All rights reserved.
//
#import <Cocoa/Cocoa.h>
@class SYHTMLNode;
@interface NSTableView (SYHTMLAdditions)
-(SYHTMLNode *)htmlNode;
@end
Thoughts? Requests? This will be released publicly around WWDC, I'm hoping.