Permalink
Browse files

Experimental support for building up CSS class names before writing a…

…n element.
  • Loading branch information...
1 parent 7aac8ca commit 75c4ca62425d5b82067323c448cfe26be2c528f9 @mikeabdullah mikeabdullah committed Jul 27, 2010
Showing with 37 additions and 0 deletions.
  1. +7 −0 KSHTMLWriter.h
  2. +30 −0 KSHTMLWriter.m
View
@@ -14,6 +14,8 @@
{
@private
BOOL _isXHTML;
+
+ NSMutableArray *_classNames;
}
#pragma mark Creating an HTML Writer
@@ -31,6 +33,11 @@
- (void)startDocument:(NSString *)DTD isXHTML:(BOOL)isXHTML;
+#pragma mark CSS Class Name
+// Class names are accumulated and written automatically as an attribute of the next element started
+- (void)addClassName:(NSString *)className;
+
+
#pragma mark HTML Fragments
- (void)writeHTMLString:(NSString *)html;
- (void)writeHTMLFormat:(NSString *)format , ...;
View
@@ -16,7 +16,10 @@ @implementation KSHTMLWriter
- (id)initWithOutputWriter:(id <KSWriter>)stream;
{
[super initWithOutputWriter:stream];
+
_isXHTML = YES;
+ _classNames = [[NSMutableArray alloc] init];
+
return self;
}
@@ -30,6 +33,13 @@ - (id)initWithOutputWriter:(id <KSWriter>)stream isXHTML:(BOOL)isXHTML;
return self;
}
+- (void)dealloc
+{
+ [_classNames release];
+
+ [super dealloc];
+}
+
#pragma mark XHTML
@synthesize XHTML = _isXHTML;
@@ -42,6 +52,13 @@ - (void)startDocument:(NSString *)DTD isXHTML:(BOOL)isXHTML;
[self startDocument:DTD];
}
+#pragma mark CSS Class Name
+
+- (void)addClassName:(NSString *)className;
+{
+ [_classNames addObject:className];
+}
+
#pragma mark HTML Fragments
- (void)writeHTMLString:(NSString *)html;
@@ -278,6 +295,19 @@ - (BOOL)canWriteElementInline:(NSString *)tagName;
#pragma mark Element Primitives
+- (void)openTag:(NSString *)element writeInline:(BOOL)writeInline;
+{
+ [super openTag:element writeInline:writeInline];
+
+ // Add in any pre-written classes
+ if ([_classNames count])
+ {
+ NSString *class = [_classNames componentsJoinedByString:@" "];
+ [_classNames removeAllObjects];
+ [self writeAttribute:@"class" value:class];
+ }
+}
+
- (void)closeEmptyElementTag; // /> OR > depending on -isXHTML
{
if ([self isXHTML])

0 comments on commit 75c4ca6

Please sign in to comment.