Skip to content

Commit c43f2ad

Browse files
committed
Refactor renderStartTag to enable more flexible rendering
1 parent 7ab385f commit c43f2ad

File tree

1 file changed

+13
-15
lines changed

1 file changed

+13
-15
lines changed

src/WebApp/Renderer.php

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -171,14 +171,19 @@ public function setAria($key, $value) {
171171
}
172172

173173
protected function renderStartTag($tagName, $closeTag = FALSE) {
174-
$rc = '<'.$tagName;
174+
$attributes = $this->computeFinalAttributes();
175+
return \TgUtils\Html::renderStartTag($tagName, $attributes, $closeTag);
176+
}
177+
178+
public function computeFinalAttributes() {
179+
$rc = array();
175180

176-
$rc .= ' id="'.htmlspecialchars($this->component->getId()).'"';
181+
$rc['id'] = $this->component->getId();
177182

178-
// Render classes and styles first
183+
// classes
179184
$classes = $this->getAttribute('class', TRUE);
180185
if (($classes != NULL) && (count($classes) > 0)) {
181-
$rc .= ' class="'.htmlspecialchars(trim(implode(' ', $classes))).'"';
186+
$rc['class'] = $classes;
182187
}
183188

184189
$styles = $this->getStyles(TRUE);
@@ -187,26 +192,19 @@ protected function renderStartTag($tagName, $closeTag = FALSE) {
187192
foreach ($styles AS $name => $value) {
188193
$style .= ' '.$name.':'.$value.';';
189194
}
190-
$rc .= ' style="'.htmlspecialchars(trim($style)).'"';
195+
$rc['style'] = trim($style);
191196
}
192197

193198
$attributes = $this->getAttributes(TRUE);
194-
unset($attributes['class']);
199+
unset($attributes['class'], $attributes['style'], $attributes['id']);
195200
foreach ($attributes AS $name => $value) {
196-
if (is_array($value)) $value = implode(' ', $value);
197-
if (is_numeric($value) || is_string($value)) {
198-
$rc .= ' '.$name.'="'.htmlspecialchars($value).'"';
199-
}
201+
$rc[$name] = $value;
200202
}
201-
202-
if ($closeTag) $rc .= '/';
203-
$rc .= '>';
204203
return $rc;
205204
}
206205

207206
protected function renderEndTag($tagName) {
208-
$rc = '</'.$tagName.'>';
209-
return $rc;
207+
return \TgUtils\Html::renderEndTag($tagName);
210208
}
211209

212210
public function getParentFor($componentName) {

0 commit comments

Comments
 (0)