Skip to content
Browse files

Convert phutil_render_tag() to phutil_tag()

Summary:
So that I could remove it from libphutil.

I'm not sure how much of this code will be reused but it wasn't that much work so that we couldn't flush it away.

Test Plan: Generated Phabricator docs, didn't see any double escaping.

Reviewers: epriestley

Reviewed By: epriestley

CC: aran, Korvin

Differential Revision: https://secure.phabricator.com/D6503
  • Loading branch information...
1 parent 226730f commit de21aaaca212557adcab8458bb0eaab6d50ebb4f @vrana vrana committed Jul 24, 2013
View
47 src/generator/DivinerStaticGenerator.php
@@ -55,7 +55,7 @@ public function generateDocumentation(array $views) {
$index = array();
$index[] = $this->renderTableOfContents($groups);
foreach ($groups as $name => $group) {
- $anchor = phutil_render_tag(
+ $anchor = phutil_tag(
'a',
array(
'name' => $renderer->getNormalizedName($name),
@@ -100,7 +100,7 @@ private function renderTableOfContents($groups) {
$out = array();
foreach ($groups as $name => $group) {
- $link = phutil_render_tag(
+ $link = phutil_tag(
'a',
array(
'href' => '#'.$renderer->getNormalizedName($name),
@@ -140,7 +140,7 @@ private function renderGroup($group) {
$views = array_values($ordered);
if ($type != 'article') {
- $index[] = phutil_render_tag(
+ $index[] = phutil_tag(
'h3',
array(
),
@@ -177,18 +177,18 @@ private function renderGroup($group) {
$list = array();
foreach ($views as $view) {
$excerpt = $this->renderExcerpt($view);
- $list[] = phutil_render_tag(
- 'li',
- array(),
- $renderer->renderAtomLink($view->getAtom()).$excerpt);
+ $list[] = hsprintf(
+ '<li>%s%s</li>',
+ $renderer->renderAtomLink($view->getAtom()),
+ $excerpt);
}
}
- $index[] = phutil_render_tag(
+ $index[] = phutil_tag(
'ul',
array(
'class' => 'atom-index',
),
- implode("\n", $list));
+ $list);
}
return
@@ -223,12 +223,12 @@ private function renderTemplate(array $dictionary) {
$configuration = $this->getProjectConfiguration();
$crumbs = array();
- $crumbs[] = phutil_render_tag(
+ $crumbs[] = phutil_tag(
'a',
array(
'href' => $dictionary['ROOT'].'index.html',
),
- phutil_escape_html($configuration->getProjectName()));
+ $configuration->getProjectName());
if (!empty($dictionary['ATOM'])) {
$crumbs[] = '<a href="#">'.$dictionary['ATOM'].'</a>';
}
@@ -263,23 +263,19 @@ private function renderClassHierarchy(array $map, array $list) {
$atom = $view->getAtom();
if (!empty($map[$atom->getName()])) {
$content = $this->renderClassHierarchy($map, $map[$atom->getName()]);
- $content = phutil_render_tag(
+ $content = phutil_tag(
'ul',
array(
),
- implode("\n", $content));
+ $content);
} else {
$content = null;
}
- $excerpt = $this->renderExcerpt($view);
-
- $content = $renderer->renderAtomLink($atom).$excerpt.$content;
-
- $out[] = phutil_render_tag(
- 'li',
- array(
- ),
+ $out[] = hsprintf(
+ '<li>%s%s%s</li>',
+ $renderer->renderAtomLink($atom),
+ $this->renderExcerpt($view),
$content);
}
return $out;
@@ -288,12 +284,9 @@ private function renderClassHierarchy(array $map, array $list) {
private function renderExcerpt(DivinerBaseAtomView $view) {
$excerpt = $view->renderExcerpt();
if ($excerpt) {
- return phutil_render_tag(
- 'span',
- array(
- 'class' => 'atom-excerpt',
- ),
- ' &mdash; '.$excerpt);
+ return hsprintf(
+ '<span class="atom-excerpt"> &mdash; %s</span>',
+ $excerpt);
} else {
return null;
}
View
26 src/remarkup/DivinerRemarkupRuleSymbols.php
@@ -51,13 +51,12 @@ public function markupSymbol($matches) {
$suffix = '()';
$type = 'class';
return $this->getEngine()->storeText(
- phutil_safe_html(
- $this->getRenderer()->renderAtomLinkRaw(
- $type,
- $class,
- $name.$suffix,
- 'method/'.$method,
- $project)));
+ $this->getRenderer()->renderAtomLinkRaw(
+ $type,
+ $class,
+ $name.$suffix,
+ 'method/'.$method,
+ $project));
case 'function':
$suffix = '()';
break;
@@ -67,13 +66,12 @@ public function markupSymbol($matches) {
}
return $this->getEngine()->storeText(
- phutil_safe_html(
- $this->getRenderer()->renderAtomLinkRaw(
- $type,
- $name,
- $name.$suffix,
- $anchor = null,
- $project)));
+ $this->getRenderer()->renderAtomLinkRaw(
+ $type,
+ $name,
+ $name.$suffix,
+ $anchor = null,
+ $project));
}
}
View
58 src/renderer/DivinerDefaultRenderer.php
@@ -15,12 +15,12 @@ public function getBaseURI() {
public function renderAttributes($attributes) {
foreach ($attributes as $key => $attribute) {
- $attributes[$key] = phutil_render_tag(
+ $attributes[$key] = phutil_tag(
'span',
array(
'class' => 'atom-attribute-'.$attribute,
),
- phutil_escape_html($attribute));
+ $attribute);
}
return
'<span class="atom-attributes">'.
@@ -32,28 +32,28 @@ public function renderParameters($parameters) {
foreach ($parameters as $parameter => $dict) {
$type = idx($dict, 'type');
if ($type) {
- $type = phutil_render_tag(
+ $type = phutil_tag(
'span',
array(
'class' => 'atom-parameter-type',
),
- $this->getInlineMarkupEngine()->markupText($type).' ');
+ hsprintf('%s ', $this->getInlineMarkupEngine()->markupText($type)));
}
$default = idx($dict, 'default');
if (strlen($default)) {
- $default = phutil_render_tag(
+ $default = phutil_tag(
'span',
array(
'class' => 'atom-parameter-default',
),
- phutil_escape_html(' = '.$default));
+ ' = '.$default);
}
- $name = phutil_render_tag(
+ $name = phutil_tag(
'span',
array(
'class' => 'atom-parameter-name',
),
- phutil_escape_html($parameter));
+ $parameter);
$parameters[$parameter] = $type.$name.$default;
}
return
@@ -66,7 +66,7 @@ public function renderReturnTypeAttributes(array $attributes) {
$type = nonempty(
idx($attributes, 'type'),
idx($attributes, 'doctype'));
- return phutil_render_tag(
+ return phutil_tag(
'span',
array(
'class' => 'atom-return-type',
@@ -99,21 +99,21 @@ public function markupText($text, array $options = array()) {
$toc = PhutilRemarkupEngineRemarkupHeaderBlockRule::renderTableOfContents(
$engine);
if ($toc) {
- $toc =
+ $toc = hsprintf(
'<div class="doc-markup-toc">'.
'<div class="doc-markup-toc-header">'.
'Table of Contents'.
'</div>'.
- $toc.
- '</div>';
+ '%s'.
+ '</div>',
+ $toc);
}
}
- return
- '<div class="doc-markup">'.
- $toc.
- $text.
- '</div>';
+ return hsprintf(
+ '<div class="doc-markup">%s%s</div>',
+ $toc,
+ $text);
}
public function markupTextInline($text) {
@@ -246,15 +246,14 @@ public function renderAtomAnchor(DivinerAtom $atom) {
$type = $atom->getType();
$name = $atom->getName();
$anchor_name = $type.'/'.$name;
- $link_text = phutil_escape_html($atom->getName().$suffix);
- return phutil_render_tag(
+ return phutil_tag(
'a',
array(
'href' => '#'.$this->getNormalizedName($anchor_name),
'class' => 'atom-symbol',
),
- $link_text);
+ $atom->getName().$suffix);
}
public function renderAtomLink(DivinerAtom $atom) {
@@ -269,15 +268,15 @@ public function renderAtomLink(DivinerAtom $atom) {
return $this->renderAtomLinkRaw(
$atom->getType(),
$atom->getName(),
- phutil_escape_html($atom->getName().$suffix));
+ $atom->getName().$suffix);
}
public function renderAtomAnchorTarget(DivinerAtom $atom) {
$type = $atom->getType();
$name = $atom->getName();
$anchor_name = $type.'/'.$name;
- return phutil_render_tag(
+ return phutil_tag(
'a',
array(
'name' => $this->getNormalizedName($anchor_name),
@@ -294,7 +293,7 @@ public function renderAtomLinkRaw(
$project = null) {
if ($link_text === null) {
- $link_text = phutil_escape_html($name);
+ $link_text = $name;
}
$base = $this->getBaseURI();
@@ -309,7 +308,7 @@ public function renderAtomLinkRaw(
$base .= "../{$project}/";
}
- return phutil_render_tag(
+ return phutil_tag(
'a',
array(
'href' => "{$base}{$type}/{$name}.html{$anchor}",
@@ -319,12 +318,12 @@ public function renderAtomLinkRaw(
}
public function renderType($type) {
- return phutil_render_tag(
+ return phutil_tag(
'span',
array(
'class' => 'atom-type',
),
- phutil_escape_html($this->getTypeDisplayName($type)));
+ $this->getTypeDisplayName($type));
}
public function renderParameterTable(array $params, array $return) {
@@ -374,8 +373,7 @@ public function renderGroup($group) {
'radicals' => 'Free Radicals',
);
$name = idx($map, $group, $group);
- $name = phutil_escape_html($name);
- return '<span class="atom-group">'.$name.'</span>';
+ return phutil_tag('span', array('class' => 'atom-group'), $name);
}
public function renderFileAndLine($file, $line) {
@@ -385,7 +383,7 @@ public function renderFileAndLine($file, $line) {
return phutil_escape_html($file.':'.$line);
}
- return phutil_render_tag(
+ return phutil_tag(
'a',
array(
'href' => strtr($src_link, array(
@@ -395,7 +393,7 @@ public function renderFileAndLine($file, $line) {
)),
'target' => 'blank',
),
- phutil_escape_html($file.':'.$line));
+ $file.':'.$line);
}
public function renderAttributeNotice($type, $message) {
View
10 src/view/DivinerBaseAtomView.php
@@ -55,7 +55,7 @@ public function renderExcerpt() {
public function renderView() {
$renderer = $this->getRenderer();
- $header = phutil_render_tag(
+ $header = phutil_tag(
'h1',
array(
'class' => 'atom-name',
@@ -70,12 +70,12 @@ public function renderView() {
$info = null;
}
- return phutil_render_tag(
+ return phutil_tag(
'div',
array(
'class' => 'atom-doc',
),
- $header.$info.$body);
+ phutil_safe_html($header.$info.$body)); // TODO: This is cheating.
}
abstract protected function renderBody();
@@ -86,9 +86,9 @@ protected function renderHeaderContent() {
$type = $renderer->renderType($atom->getType());
- $name = phutil_escape_html($atom->getName());
+ $name = $atom->getName();
- return $type.' '.$name;
+ return hsprintf('%s %s', $type, $name);
}
protected function getAtomInfoDictionary() {

0 comments on commit de21aaa

Please sign in to comment.
Something went wrong with that request. Please try again.