From c8bc317460408b2863c9810bf2fd4942251a27bd Mon Sep 17 00:00:00 2001 From: Mike Abdullah Date: Tue, 27 Jul 2010 16:30:12 +0100 Subject: [PATCH] Can now ditch -openTag:writeInline: --- KSHTMLWriter.m | 4 ++-- KSXMLWriter.h | 1 - KSXMLWriter.m | 53 ++++++++++++++++++++++++-------------------------- 3 files changed, 27 insertions(+), 31 deletions(-) diff --git a/KSHTMLWriter.m b/KSHTMLWriter.m index fc64a3f..1c312e6 100644 --- a/KSHTMLWriter.m +++ b/KSHTMLWriter.m @@ -291,7 +291,7 @@ - (BOOL)canWriteElementInline:(NSString *)tagName; #pragma mark Element Primitives -- (void)openTag:(NSString *)element writeInline:(BOOL)writeInline; +- (void)startElement:(NSString *)elementName writeInline:(BOOL)writeInline; // for more control { // Add in any pre-written classes if ([_classNames count]) @@ -301,7 +301,7 @@ - (void)openTag:(NSString *)element writeInline:(BOOL)writeInline; [self addAttribute:@"class" value:class]; } - [super openTag:element writeInline:writeInline]; + [super startElement:elementName writeInline:writeInline]; } - (void)closeEmptyElementTag; // /> OR > depending on -isXHTML diff --git a/KSXMLWriter.h b/KSXMLWriter.h index f2f4133..2857a8d 100644 --- a/KSXMLWriter.h +++ b/KSXMLWriter.h @@ -86,7 +86,6 @@ #pragma mark Element Primitives -- (void)openTag:(NSString *)element writeInline:(BOOL)writeInline; - (void)closeEmptyElementTag; diff --git a/KSXMLWriter.m b/KSXMLWriter.m index a003b7c..6a0e561 100644 --- a/KSXMLWriter.m +++ b/KSXMLWriter.m @@ -105,7 +105,31 @@ - (void)startElement:(NSString *)elementName; - (void)startElement:(NSString *)elementName writeInline:(BOOL)writeInline; { - [self openTag:elementName writeInline:writeInline]; + // Can only write suitable tags inline if containing element also allows it + if (!writeInline) + { + [self startNewline]; + [self stopWritingInline]; + } + + elementName = [elementName lowercaseString]; // writes coming from the DOM are uppercase + [self writeString:@"<"]; + [self writeString:elementName]; + + // Must do this AFTER writing the string so subclasses can take early action in a -writeString: override + [self pushElement:elementName]; + + + // Write attributes + for (int i = 0; i < [_attributes count]; i+=2) + { + NSString *attribute = [_attributes objectAtIndex:i]; + NSString *value = [_attributes objectAtIndex:i+1]; + [self writeAttribute:attribute value:value]; + } + [_attributes removeAllObjects]; + + [self didStartElement]; } @@ -252,33 +276,6 @@ - (void)popElement; #pragma mark Element Primitives -- (void)openTag:(NSString *)element writeInline:(BOOL)writeInline; -{ - // Can only write suitable tags inline if containing element also allows it - if (!writeInline) - { - [self startNewline]; - [self stopWritingInline]; - } - - element = [element lowercaseString]; // writes coming from the DOM are uppercase - [self writeString:@"<"]; - [self writeString:element]; - - // Must do this AFTER writing the string so subclasses can take early action in a -writeString: override - [self pushElement:element]; - - - // Write attributes - for (int i = 0; i < [_attributes count]; i+=2) - { - NSString *attribute = [_attributes objectAtIndex:i]; - NSString *value = [_attributes objectAtIndex:i+1]; - [self writeAttribute:attribute value:value]; - } - [_attributes removeAllObjects]; -} - - (void)writeAttribute:(NSString *)attribute value:(NSString *)value; {