Add attributes-related methods to HTML Element

This commit is contained in:
iska
2015-03-25 22:37:52 +01:00
parent 7fb04f3394
commit bfb653e82e
2 changed files with 49 additions and 0 deletions
+5
View File
@@ -26,4 +26,9 @@
- (instancetype)initWithTagName:(NSString *)tagName attributes:(NSDictionary *)attributes;
- (instancetype)initWithTagName:(NSString *)tagName attributes:(NSDictionary *)attributes namespace:(HTMLNamespace)namespace;
- (BOOL)hasAttribute:(NSString *)name;
- (NSString *)objectForKeyedSubscript:(NSString *)name;
- (void)setObject:(NSString *)value forKeyedSubscript:(NSString *)attribute;
- (void)removeAttribute:(NSString *)name;
@end
+44
View File
@@ -17,6 +17,8 @@
@implementation HTMLElement
#pragma mark - Init
- (instancetype)init
{
return [self initWithTagName:nil];
@@ -46,10 +48,52 @@
return self;
}
#pragma mark - Attributes
- (NSString *)id
{
return _attributes[@"id"] ?: @"";
}
- (NSString *)className
{
return _attributes[@"class"];
}
- (BOOL)hasAttribute:(NSString *)name
{
return _attributes[name] != nil;
}
- (NSString *)objectForKeyedSubscript:(NSString *)name;
{
return _attributes[name];
}
- (void)setObject:(NSString *)value forKeyedSubscript:(NSString *)attribute
{
_attributes[attribute] = value;
}
- (void)removeAttribute:(NSString *)name
{
[_attributes removeObjectForKey:name];
}
- (NSString *)textContent
{
#warning Implement Traversing
return nil;
}
#pragma mark - NSCopying
- (id)copyWithZone:(NSZone *)zone
{
HTMLElement *copy = [super copyWithZone:zone];
copy->_tagName = [_tagName copy];
copy->_attributes = [_attributes copy];
return copy;
}
@end