Writing an HTML creation Framework; features?

Discussion in 'Mac Programming' started by GeeYouEye, May 16, 2007.

  1. GeeYouEye macrumors 68000

    GeeYouEye

    Joined:
    Dec 9, 2001
    Location:
    State of Denial
    #1
    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.
    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.
     
  2. Eraserhead macrumors G4

    Eraserhead

    Joined:
    Nov 3, 2005
    Location:
    UK
    #2
    This could be useful. I want to try and get printing set up in my application, and was planning to write a new view to do it.

    What advantages would doing it this way bring? How would you layout the data on the "page"?
     
  3. RacerX macrumors 65832

    Joined:
    Aug 2, 2004
    #3
    Before Apple had introduced WebCore the Omni Group had provided the Yellow Box/Cocoa development community with the foundations of OmniWeb's original HTML rendering engine to provide HTML rendering within third party apps.

    That code may act as a nice starting point.

    And going back to at least Create 4 (around 1997 as I recall) that app has had HTML layout abilities (with CSS features recently added in Create 13)... plus it shares (via services) the ability to convert Rich Text into HTML in other Cocoa apps (like TextEdit).

    It would be cool if you could provide a service interface like Create for Cocoa apps to access this framework you are talking about. Maybe even taking it a step further and making it an input manager were preferences can be set (like TextExtras or FrontSight) so that more than just the strict RTF to HTML tag conversion is provided.

    The one app I miss on Mac OS X was Apple's old HTMLEdit app. While not true WYSIWYG, it was a handy app to have around. Apple never released the Yellow Box or Cocoa code for it... even after it was dropped from Mac OS X just before the release of 10.0.

    Just some thoughts.
     
  4. GeeYouEye thread starter macrumors 68000

    GeeYouEye

    Joined:
    Dec 9, 2001
    Location:
    State of Denial
    #4
    Eraserhead: Normally, without this framework, you'd write the HTML by hand, passing in your content where appropriate, and generally hard-coding everything but your content. This makes it so you don't need to hard-code it.

    RacerX: This isn't an HTML rendering engine and I don't intend it to be. Just a programmatic, non-hardcoded way of creating an HTML document to pass to a WebView for rendering.

    I was digging through the PrivateFrameworks folder... as it turns out, Apple has something like this already... the HTMLEditing framework. A hell of a lot more complex, and a hell of a lot more complete... but with a hell of a lot I don't need, and of course, completely unsupported, as it's a private framework. :rolleyes: But it does have its headers. Think I'll file a bug. If Apple wanted to open that up in Leopard and obviate this project, I'd be more than happy. But as it is, it's way too much. It's practically a WYSIWYG editor in a framework already - just look at the Resources folder, and I doubt it uses Web Core.
     

Share This Page