/** * * * @return MString */ public function toString() { if ($this->element()) { $markup = new MMutableString(); $indentString = MString::stringWithRepeatingString(S(" "), $this->indentLevel()); $properties = new MMutableArray(); foreach ($this->properties()->allKeys()->toArray() as $name) { $value = $this->properties()->objectForKey($name); $properties->addObject(Sf("%s=\"%s\"", $name, $value)); } if ($properties->count() > 0) { $markup->appendFormat("%s<%s %s", $indentString, $this->element(), $properties->componentsJoinedByString(S(" "))); } else { $markup->appendFormat("%s<%s", $indentString, $this->element()); } if ($this->text()) { $markup->appendFormat(">%s</%s>", $this->text()->stringByEncodingHTMLEntities(), $this->element()); } else { if ($this->subviews()->count() > 0) { $markup->appendLine(S(">")); $markup->appendLine(parent::toString()); $markup->appendString(Sf("%s</%s>", $indentString, $this->element())); } else { $markup->appendString(S("/>")); } } if ($this->shouldAppendEmptyLine()) { $markup->appendLine(); } return $markup; } else { return parent::toString(); } }