Permalink
Browse files

On reflection, it makes more sense to represent only the attributes o…

…f an element.
  • Loading branch information...
1 parent 327cc56 commit 06fa83eac33f221a2a156466371e8b90ed53ad98 @mikeabdullah mikeabdullah committed Jul 14, 2011
Showing with 27 additions and 34 deletions.
  1. +3 −3 KSHTMLWriter.m
  2. +4 −7 KSElementInfo.h → KSXMLAttributes.h
  3. +8 −12 KSElementInfo.m → KSXMLAttributes.m
  4. +3 −3 KSXMLWriter.h
  5. +9 −9 KSXMLWriter.m
View
@@ -27,7 +27,7 @@
#import "KSHTMLWriter.h"
-#import "KSElementInfo.h"
+#import "KSXMLAttributes.h"
NSString *KSHTMLWriterDocTypeHTML_4_01_Strict = @"HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\" \"http://www.w3.org/TR/html4/strict.dtd\"";
@@ -134,9 +134,9 @@ - (void)pushAttribute:(NSString *)attribute value:(id)value;
[super pushAttribute:attribute value:value];
}
-- (KSElementInfo *)currentElementInfo;
+- (KSXMLAttributes *)currentAttributes;
{
- KSElementInfo *result = [super currentElementInfo];
+ KSXMLAttributes *result = [super currentAttributes];
// Add in buffered class info
NSString *class = [self currentElementClassName];
@@ -1,5 +1,5 @@
//
-// KSElementInfo.h
+// KSXMLAttributes.h
// Sandvox
//
// Created by Mike on 19/11/2010.
@@ -9,21 +9,18 @@
#import <Foundation/Foundation.h>
-@interface KSElementInfo : NSObject <NSCopying>
+@interface KSXMLAttributes : NSObject <NSCopying>
{
@private
- NSString *_elementName;
NSMutableArray *_attributes;
}
-- (id)initWithElementInfo:(KSElementInfo *)info;
-
-@property(nonatomic, copy) NSString *name;
+- (id)initWithXMLAttributes:(KSXMLAttributes *)info;
@property(nonatomic, copy) NSDictionary *attributesAsDictionary;
- (void)addAttribute:(NSString *)attribute value:(id)value;
-- (void)close; // sets name to nil and removes all attributes
+- (void)close; // removes all attributes
@end
@@ -1,17 +1,19 @@
//
-// KSElementInfo.m
+// KSXMLAttributes.m
// Sandvox
//
// Created by Mike on 19/11/2010.
// Copyright 2010 Karelia Software. All rights reserved.
//
-#import "KSElementInfo.h"
+#import "KSXMLAttributes.h"
#import "KSXMLWriter.h"
-@implementation KSElementInfo
+@implementation KSXMLAttributes
+
+#pragma mark Lifecycle
- (id)init;
{
@@ -20,26 +22,22 @@ - (id)init;
return self;
}
-- (id)initWithElementInfo:(KSElementInfo *)info;
+- (id)initWithXMLAttributes:(KSXMLAttributes *)info;
{
self = [self init];
- [self setName:[info name]];
_attributes = [info->_attributes mutableCopy];
return self;
}
- (void)dealloc;
{
- [_elementName release];
[_attributes release];
[super dealloc];
}
-@synthesize name = _elementName;
-
- (NSDictionary *)attributesAsDictionary;
{
NSMutableDictionary *result = [NSMutableDictionary dictionary];
@@ -74,15 +72,14 @@ - (void)addAttribute:(NSString *)attribute value:(id)value;
- (void)close; // sets name to nil and removes all attributes
{
- [self setName:nil];
[_attributes removeAllObjects];
}
#pragma mark NSCopying
- (id)copyWithZone:(NSZone *)zone;
{
- return [[[self class] alloc] initWithElementInfo:self];
+ return [[[KSXMLAttributes class] alloc] initWithXMLAttributes:self];
}
#pragma mark Description
@@ -94,8 +91,7 @@ - (NSString *)description;
KSXMLWriter *writer = [[KSXMLWriter alloc] initWithOutputWriter:result];
[writer writeString:@" "];
- [writer startElement:(self.name ? self.name : @"")
- attributes:[self attributesAsDictionary]];
+ [writer startElement:@"" attributes:[self attributesAsDictionary]];
[writer endElement];
[writer release];
View
@@ -27,7 +27,7 @@
#import "KSForwardingWriter.h"
-#import "KSElementInfo.h"
+#import "KSXMLAttributes.h"
@class KSXMLElementContentsProxy;
@@ -36,7 +36,7 @@
@interface KSXMLWriter : KSForwardingWriter
{
@private
- KSElementInfo *_currentElement;
+ KSXMLAttributes *_attributes;
NSMutableArray *_openElements;
BOOL _elementIsEmpty;
NSUInteger _inlineWritingLevel; // the number of open elements at which inline writing began
@@ -113,7 +113,7 @@
* - Can sneak extra attributes in when using a convenience method (e.g. for HTML)
*/
- (void)pushAttribute:(NSString *)attribute value:(id)value;
-- (KSElementInfo *)currentElementInfo; // modifying this object will not affect writing
+- (KSXMLAttributes *)currentAttributes; // modifying this object will not affect writing
#pragma mark Attributes
View
@@ -71,7 +71,7 @@ - (BOOL)elementCanBeEmpty:(NSString *)tagName; // YES for everything in pure XM
@end
-@interface KSElementInfo (KSXMLWriter)
+@interface KSXMLAttributes (KSXMLWriter)
- (void)writeAttributes:(KSXMLWriter *)writer;
@end
@@ -87,7 +87,7 @@ - (id)initWithOutputWriter:(id <KSWriter>)output; // designated initializer
{
[super initWithOutputWriter:output];
- _currentElement = [[KSElementInfo alloc] init];
+ _attributes = [[KSXMLAttributes alloc] init];
_openElements = [[NSMutableArray alloc] init];
// Inherit encoding where possible
@@ -113,7 +113,7 @@ - (id)initWithOutputWriter:(id <KSWriter>)output encoding:(NSStringEncoding)enco
- (void)dealloc
{
[_openElements release];
- [_currentElement release];
+ [_attributes release];
[_contentsProxy release];
[super dealloc];
@@ -203,8 +203,8 @@ - (void)startElement:(NSString *)elementName writeInline:(BOOL)writeInline;
// Write attributes
- [_currentElement writeAttributes:self];
- [_currentElement close];
+ [_attributes writeAttributes:self];
+ [_attributes close];
[self didStartElement];
@@ -264,12 +264,12 @@ - (void)popElement;
- (void)pushAttribute:(NSString *)attribute value:(id)value; // call before -startElement:
{
- [_currentElement addAttribute:attribute value:value];
+ [_attributes addAttribute:attribute value:value];
}
-- (KSElementInfo *)currentElementInfo;
+- (KSXMLAttributes *)currentAttributes;
{
- KSElementInfo *result = [[_currentElement copy] autorelease];
+ KSXMLAttributes *result = [[_attributes copy] autorelease];
return result;
}
@@ -622,7 +622,7 @@ - (void)writeString:(NSString *)string;
#pragma mark -
-@implementation KSElementInfo (KSXMLWriter)
+@implementation KSXMLAttributes (KSXMLWriter)
- (void)writeAttributes:(KSXMLWriter *)writer;
{

0 comments on commit 06fa83e

Please sign in to comment.