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

Improve parameter rendering #24

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
27 changes: 23 additions & 4 deletions phpdotnet/phd/Package/Generic/Manpage.php
Original file line number Diff line number Diff line change
Expand Up @@ -583,10 +583,29 @@ public function format_type_method_text($value, $tag) {
}

public function format_parameter_method($open, $name, $attrs, $props) {
if ($open && isset($attrs[Reader::XMLNS_DOCBOOK]["role"]) && $attrs[Reader::XMLNS_DOCBOOK]["role"] == "reference") {
$this->cchunk['methodsynopsis']['params'][count($this->cchunk['methodsynopsis']['params'])-1]['reference'] = true;
if ($open) {
if (isset($attrs[Reader::XMLNS_DOCBOOK]['role'])) {
$role = $attrs[Reader::XMLNS_DOCBOOK]['role'];
switch ($role) {
case 'reference':
$this->cchunk['methodsynopsis']['params'][count($this->cchunk['methodsynopsis']['params'])-1]['role_symbol'] = '&';

return '';
case 'vararglist':
$this->cchunk['methodsynopsis']['params'][count($this->cchunk['methodsynopsis']['params'])-1]['role_symbol'] = '...';

return '';
case 'reference_vararglist':
$this->cchunk['methodsynopsis']['params'][count($this->cchunk['methodsynopsis']['params'])-1]['role_symbol'] = '&...';

return '';
}
}

$this->cchunk['methodsynopsis']['params'][count($this->cchunk['methodsynopsis']['params'])-1]['role_symbol'] = '';
}
return "";

return '';
}

public function format_parameter_method_text($value, $tag) {
Expand Down Expand Up @@ -622,7 +641,7 @@ public function format_methodsynopsis($open, $name, $attrs, $props) {
foreach ($this->cchunk['methodsynopsis']['params'] as $parameter) {
array_push($params, ($parameter['optional'] ? "[" : "")
. $parameter['type'] . " "
. ($parameter['reference'] ? " \\fI&\\fP" : " ")
. ' \\fI' . $parameter['role_symbol'] , '\\fP'
. ($parameter['name'] ? "\\fI$" . $parameter['name'] . "\\fP" : "")
. ($parameter['initializer'] ? " = " . $parameter['initializer'] : "")
. ($parameter['optional'] ? "]" : "") );
Expand Down
57 changes: 46 additions & 11 deletions phpdotnet/phd/Package/Generic/PDF.php
Original file line number Diff line number Diff line change
Expand Up @@ -849,31 +849,66 @@ public function format_classsynopsis_methodsynopsis_methodname_text($value, $tag

public function format_methodparam_parameter($open, $name, $attrs, $props) {
if ($props["empty"]) return '';

if ($open) {
if (isset($attrs[Reader::XMLNS_DOCBOOK]["role"])) {
$this->pdfDoc->setFont(PdfWriter::FONT_VERBATIM, 10);
$this->pdfDoc->appendText(" &$");
return '';
}
$this->pdfDoc->setFont(PdfWriter::FONT_VERBATIM, 10);
$this->pdfDoc->appendText(" $");

if (isset($attrs[Reader::XMLNS_DOCBOOK]['role'])) {
$role = $attrs[Reader::XMLNS_DOCBOOK]['role'];
switch ($role) {
case 'reference':
$this->pdfDoc->appendText('&$');

return '';
case 'vararglist':
$this->pdfDoc->appendText('...$');

return '';
case 'reference_vararglist':
$this->pdfDoc->appendText('&...$');

return '';
}
}

$this->pdfDoc->appendText(' $');

return '';
}

$this->pdfDoc->revertFont();
return '';
}

public function format_parameter($open, $name, $attrs, $props) {
if ($props["empty"]) return '';

if ($open) {
if (isset($attrs[Reader::XMLNS_DOCBOOK]["role"])) {
$this->pdfDoc->setFont(PdfWriter::FONT_VERBATIM_ITALIC, 10);
$this->pdfDoc->appendText(" &");
return '';
$this->pdfDoc->setFont(PdfWriter::FONT_VERBATIM, 10);

if (isset($attrs[Reader::XMLNS_DOCBOOK]['role'])) {
$role = $attrs[Reader::XMLNS_DOCBOOK]['role'];
switch ($role) {
case 'reference':
$this->pdfDoc->appendText('&$');

return '';
case 'vararglist':
$this->pdfDoc->appendText('...$');

return '';
case 'reference_vararglist':
$this->pdfDoc->appendText('&...$');

return '';
}
}
$this->pdfDoc->setFont(PdfWriter::FONT_VERBATIM_ITALIC, 10);

$this->pdfDoc->appendText(' $');

return '';
}

$this->pdfDoc->revertFont();
return '';
}
Expand Down
35 changes: 29 additions & 6 deletions phpdotnet/phd/Package/Generic/XHTML.php
Original file line number Diff line number Diff line change
Expand Up @@ -996,13 +996,24 @@ public function format_methodparam_parameter($open, $name, $attrs, $props)
if ($props["empty"]) {
return '';
}

if ($open) {
if (isset($attrs[Reader::XMLNS_DOCBOOK]["role"])) {
return ' <code class="parameter reference">&$';
if (isset($attrs[Reader::XMLNS_DOCBOOK]['role'])) {
$role = $attrs[Reader::XMLNS_DOCBOOK]['role'];
switch ($role) {
case 'reference':
return ' <code class="parameter reference">&$';
case 'vararglist':
return ' <code class="parameter">...$';
case 'reference_vararglist':
return ' <code class="parameter">&...$';
}
}

return ' <code class="parameter">$';
}
return "</code>";

return '</code>';
}

public function format_initializer($open, $name, $attrs) {
Expand All @@ -1011,18 +1022,30 @@ public function format_initializer($open, $name, $attrs) {
}
return '</span>';
}

public function format_parameter($open, $name, $attrs, $props)
{
if ($props["empty"]) {
return '';
}

if ($open) {
if (isset($attrs[Reader::XMLNS_DOCBOOK]["role"])) {
return '<code class="parameter reference">&';
if (isset($attrs[Reader::XMLNS_DOCBOOK]['role'])) {
$role = $attrs[Reader::XMLNS_DOCBOOK]['role'];
switch ($role) {
case 'reference':
return '<code class="parameter reference">&';
case 'vararglist':
return ' <code class="parameter">...';
case 'reference_vararglist':
return '<code class="parameter">&...';
}
}

return '<code class="parameter">';
}
return "</code>";

return '</code>';
}

public function format_void($open, $name, $attrs, $props) {
Expand Down
13 changes: 11 additions & 2 deletions phpdotnet/phd/Package/IDE/API/Param.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
*/
namespace phpdotnet\phd;

use function substr;

/**
* Class to parse the function parameters.
*
Expand Down Expand Up @@ -81,8 +83,15 @@ public function __construct(\SimpleXMLElement $xmlElement)
public function __toString()
{
$str = $this->getType();
$str .= (substr($this->getName(), 0, 1) != '$') ? ' $' : ' ';
$str .= $this->getName();
$str .= ' ';
if (substr($this->getName(), 0, 3) === '...') {
$str .= str_replace('...', '...$', $this->getName());
} elseif (substr($this->getName(), 0, 1) === '$') {
$str .= $this->getName();
} else {
$str .= '$';
$str .= $this->getName();
}

if ($this->isOptional()) {
$str .= ' = ';
Expand Down