Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add property and constant attribute rendering #140

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions phpdotnet/phd/Package/Generic/XHTML.php
Original file line number Diff line number Diff line change
Expand Up @@ -1218,12 +1218,26 @@ public function format_emphasis($open, $name, $attrs)
public function format_fieldsynopsis($open, $name, $attrs) {
$this->cchunk["fieldsynopsis"] = $this->dchunk["fieldsynopsis"];
if ($open) {
if (isset($attrs[Reader::XMLNS_DOCBOOK]["role"])) {
$this->pushRole($attrs[Reader::XMLNS_DOCBOOK]["role"]);
}
return '<div class="'.$name.'">';
}
if (isset($attrs[Reader::XMLNS_DOCBOOK]["role"])) {
$this->popRole();
}
return ";</div>\n";
}

public function format_fieldsynopsis_modifier_text($value, $tag) {
if ($this->getRole() === "attribute") {
$attribute = trim(strtolower($value), "#[]\\");
$href = Format::getFilename("class.$attribute");
if ($href) {
return '<a href="' . $href . $this->getExt() . '">' .$value. '</a> ';
}
return false;
}
$this->cchunk["fieldsynopsis"]["modifier"] = trim($value);
return $this->TEXT($value);
}
Expand Down
88 changes: 88 additions & 0 deletions tests/package/generic/attribute_formatting_003.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
--TEST--
Attribute formatting 003 - Class properties/constants
--FILE--
<?php
namespace phpdotnet\phd;

require_once __DIR__ . "/../../setup.php";

$xml_file = __DIR__ . "/data/attribute_formatting_003.xml";

$config = new Config;

$config->setXml_file($xml_file);

$format = new TestGenericChunkedXHTML;

$format->SQLiteIndex(
null, // $context,
null, // $index,
"class.knownattribute", // $id,
"file.knownattribute.is.in", // $filename,
"", // $parent,
"", // $sdesc,
"", // $ldesc,
"", // $element,
"", // $previous,
"", // $next,
0, // $chunk
);
$format->SQLiteIndex(
null, // $context,
null, // $index,
"class.anotherknownattribute", // $id,
"file.anotherknownattribute.is.in", // $filename,
"", // $parent,
"", // $sdesc,
"", // $ldesc,
"", // $element,
"", // $previous,
"", // $next,
0, // $chunk
);

$render = new TestRender(new Reader, $config, $format);

$render->run();
?>
--EXPECT--
Filename: attribute-formatting-003.html
Content:
<div id="attribute-formatting-003" class="chapter">
<div class="section">
<p class="para">1. Property/Constant with unknown attributes</p>
<div class="classsynopsis"><div class="classsynopsisinfo">

<span class="modifier">class</span> <strong class="classname">ClassName</strong>
{</div>
<div class="classsynopsisinfo classsynopsisinfo_comment">/* Properties/Constants */</div>
<div class="fieldsynopsis">
<span class="attribute">#[\UnknownAttribute]</span><br>
<span class="attribute">#[\AnotherUnknownAttribute]</span><br>
<span class="modifier">public</span>
<span class="modifier">readonly</span>
<span class="type">string</span>
<var class="varname">$CONSTANT_NAME</var>;</div>

}</div>
</div>

<div class="section">
<p class="para">2. Property/Constant with known attributes</p>
<div class="classsynopsis"><div class="classsynopsisinfo">

<span class="modifier">class</span> <strong class="classname">ClassName</strong>
{</div>
<div class="classsynopsisinfo classsynopsisinfo_comment">/* Properties/Constants */</div>
<div class="fieldsynopsis">
<span class="attribute"><a href="file.knownattribute.is.in.html">#[\KnownAttribute]</a> </span><br>
<span class="attribute"><a href="file.anotherknownattribute.is.in.html">#[\AnotherKnownAttribute]</a> </span><br>
<span class="modifier">public</span>
<span class="modifier">readonly</span>
<span class="type">string</span>
<var class="varname">$propertyName</var>;</div>

}</div>
</div>

</div>
38 changes: 38 additions & 0 deletions tests/package/generic/data/attribute_formatting_003.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<chapter xml:id="attribute-formatting-003">
<section>
<para>1. Property/Constant with unknown attributes</para>
<classsynopsis class="class">
<ooclass>
<classname>ClassName</classname>
</ooclass>
<classsynopsisinfo role="comment">Properties/Constants</classsynopsisinfo>
<fieldsynopsis>
<modifier role="attribute">#[\UnknownAttribute]</modifier>
<modifier role="attribute">#[\AnotherUnknownAttribute]</modifier>
<modifier>public</modifier>
<modifier>readonly</modifier>
<type>string</type>
<varname>CONSTANT_NAME</varname>
</fieldsynopsis>
</classsynopsis>
</section>

<section>
<para>2. Property/Constant with known attributes</para>
<classsynopsis class="class">
<ooclass>
<classname>ClassName</classname>
</ooclass>
<classsynopsisinfo role="comment">Properties/Constants</classsynopsisinfo>
<fieldsynopsis>
<modifier role="attribute">#[\KnownAttribute]</modifier>
<modifier role="attribute">#[\AnotherKnownAttribute]</modifier>
<modifier>public</modifier>
<modifier>readonly</modifier>
<type>string</type>
<varname>propertyName</varname>
</fieldsynopsis>
</classsynopsis>
</section>

</chapter>
Loading