Skip to content

Commit

Permalink
Add table formatting for constant lists (#90)
Browse files Browse the repository at this point in the history
* Add table formatting for constant lists
* Add description and constants autogen text to .ini files
* Add language specific header to constant list table

---------

Co-authored-by: haszi <haszika80@gmail.com>
  • Loading branch information
haszi and haszi authored Feb 5, 2024
1 parent 0cbe9d9 commit 10ee0e4
Show file tree
Hide file tree
Showing 15 changed files with 57 additions and 13 deletions.
4 changes: 4 additions & 0 deletions phpdotnet/phd/Format.php
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,10 @@ final public static function autogen($text, $lang = null) {

$filename = Config::lang_dir() . $lang . ".ini";

if (!file_exists($filename) && strncmp(basename($filename), 'doc-', 4) === 0) {
$filename = dirname($filename) . DIRECTORY_SEPARATOR . substr(basename($filename), 4);
}

self::$autogen[$lang] = parse_ini_file($filename);
return self::autogen($text, $lang);
}
Expand Down
44 changes: 32 additions & 12 deletions phpdotnet/phd/Package/Generic/XHTML.php
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ abstract class Package_Generic_XHTML extends Format_Abstract_XHTML {
'sect4' => 'h5',
'segmentedlist' => 'format_table_title',
'table' => 'format_table_title',
'variablelist' => 'strong',
'variablelist' => 'format_variablelist_title',
'article' => 'format_container_chunk_top_title',
'appendix' => 'format_container_chunk_top_title',
'book' => 'format_container_chunk_top_title',
Expand Down Expand Up @@ -1476,16 +1476,27 @@ public function format_step($open, $name, $attrs) {
}
return '</li>';
}
public function format_variablelist($open, $name, $attrs) {
public function format_variablelist($open, $name, $attrs, $props) {
if ($open) {
if (isset($attrs[Reader::XMLNS_DOCBOOK]["role"])) {
$this->role = $attrs[Reader::XMLNS_DOCBOOK]["role"];
}
$classStr = $headerStr = $idStr = '';
if (isset($attrs[Reader::XMLNS_XML]["id"])) {
$id = $attrs[Reader::XMLNS_XML]["id"];
return '<dl id="'.$id.'">';
$idStr = ' id="' . $attrs[Reader::XMLNS_XML]["id"] . '"';
}
if ($this->role === 'constant_list') {
$tagName = 'table';
$classStr = ' class="doctable table"';
$headerStr = "\n<tr>\n<th>" . $this->autogen('Constants', $props['lang']) . "</th>\n<th>" . $this->autogen('Description', $props['lang']) . "</th>\n</tr>";
} else {
return '<dl>';
$tagName = 'dl';
}
return '<' . $tagName . $idStr . $classStr . '>' . $headerStr;
}
return "</dl>\n";
$tagName = ($this->role === 'constant_list') ? 'table' : 'dl';
$this->role = false;
return "</" . $tagName . ">\n";
}
public function format_varlistentry($open, $name, $attrs) {
if ($open) {
Expand All @@ -1494,26 +1505,29 @@ public function format_varlistentry($open, $name, $attrs) {
} else {
unset($this->cchunk['varlistentry']['id']);
}
return ($this->role === 'constant_list') ? '<tr>' : '';
}
return '';
return ($this->role === 'constant_list') ? '</tr>' : '';
}
public function format_varlistentry_term($open, $name, $attrs, $props) {
$tagName = ($this->role === 'constant_list') ? 'td' : 'dt';
if ($open) {
if (isset($this->cchunk['varlistentry']['id'])) {
$id = $this->cchunk['varlistentry']['id'];
unset($this->cchunk['varlistentry']['id']);
return '<dt id="'.$id.'">';
return '<' . $tagName . ' id="' . $id . '">';
} else {
return "<dt>\n";
return "<" . $tagName . ">\n";
}
}
return "</dt>\n";
return "</" . $tagName . ">\n";
}
public function format_varlistentry_listitem($open, $name, $attrs) {
$tagName = ($this->role === 'constant_list') ? 'td' : 'dd';
if ($open) {
return "<dd>\n";
return "<" . $tagName . ">\n";
}
return "</dd>\n";
return "</" . $tagName . ">\n";
}
public function format_term($open, $name, $attrs, $props) {
if ($open) {
Expand Down Expand Up @@ -1653,6 +1667,12 @@ public function format_table_title($open, $name, $attrs, $props)
}
return "</strong></caption>";
}
public function format_variablelist_title($open, $name, $attrs, $props) {
if ($open) {
return ($this->role === 'constant_list') ? "<caption><strong>" : "<strong>";
}
return ($this->role === 'constant_list') ? "</strong></caption>" : "</strong>";
}

public function format_mediaobject($open, $name, $attrs) {
$this->cchunk["mediaobject"] = $this->dchunk["mediaobject"];
Expand Down
2 changes: 2 additions & 0 deletions phpdotnet/phd/data/langs/de.ini
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@ tip = "Tipp"
by = "von"
editedby = "Herausgegeben von"
example = "Beispiel #"
Description = "Beschreibung"
Constants = "Konstanten"
1 change: 1 addition & 0 deletions phpdotnet/phd/data/langs/en.ini
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ mediaobject = "[NOT DISPLAYABLE MEDIA]"
Version = "Version"
Function = "Function"
Description = "Description"
Constants = "Constants"
2 changes: 2 additions & 0 deletions phpdotnet/phd/data/langs/es.ini
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,5 @@ unknownversion = "No hay información de versión disponible, podría estar úni
refname = "NOMBRE"
refsynopsis = "SINOPSIS"
mediaobject = "[MULTIMEDIA NO DISPONIBLE]"
Description = "Descripción"
Constants = "Constantes"
1 change: 1 addition & 0 deletions phpdotnet/phd/data/langs/fr.ini
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ example = "Exemple #"
Version = "Version"
Function = "Fonction"
Description = "Description"
Constants = "Constantes"
2 changes: 2 additions & 0 deletions phpdotnet/phd/data/langs/it.ini
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@ tip = "Suggerimento"
by = "by"
editedby = "Edited By"
example = "Example #"
Description = "Descrizione"
Constants = "Costanti"
2 changes: 2 additions & 0 deletions phpdotnet/phd/data/langs/ja.ini
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,5 @@ unknownversion = "バージョン情報なし。おそらく Git 版にしか存
refname = "名前"
refsynopsis = "書式"
mediaobject = "[表示できません]"
Description = "説明"
Constants = "定数"
1 change: 1 addition & 0 deletions phpdotnet/phd/data/langs/pl.ini
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ mediaobject = "[OBIEKT NIEMOŻLIWY DO WYŚWIETLENIA]"
Version = "Wersja"
Function = "Funkcja"
Description = "Opis"
Constants = "Stałe"
2 changes: 2 additions & 0 deletions phpdotnet/phd/data/langs/pt_BR.ini
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,5 @@ unknownversion = "Não há informação de versão disponível, talvez apenas no
refname = "NOME"
refsynopsis = "SINOPSE"
mediaobject = "[MÍDIA NÃO DISPONÍVEL]"
Description = "Descrição"
Constants = "Constantes"
2 changes: 2 additions & 0 deletions phpdotnet/phd/data/langs/ro.ini
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@ tip = "Sfat"
by = "by"
editedby = "Edited By"
example = "Example #"
Description = "Descriere"
Constants = "Constante"
2 changes: 2 additions & 0 deletions phpdotnet/phd/data/langs/ru.ini
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,5 @@ unknownversion = "Информация о версии неизвестна, в
refname = "ИМЯ"
refsynopsis = "СОДЕРЖАНИЕ"
mediaobject = "[НЕОТОБРАЖАЕМЫЙ МЕДИА-ФАЙЛ]"
Description = "Описание"
Constants = "Константы"
2 changes: 1 addition & 1 deletion phpdotnet/phd/data/langs/tr.ini
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ mediaobject = "[ORTAM GÖSTERİME UYGUN DEĞİL]"
Version = "Sürüm"
Function = "İşlev"
Description = "Açıklama"

Constants = "Sabitler"
2 changes: 2 additions & 0 deletions phpdotnet/phd/data/langs/uk.ini
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,5 @@ unknownversion = "Інформація про версію невідома, м
refname = "ІМ’Я"
refsynopsis = "ЗМІСТ"
mediaobject = "[НЕВИДИМИЙ МЕДІА-ФАЙЛ]"
Description = "Опис"
Constants = "Константи"
1 change: 1 addition & 0 deletions phpdotnet/phd/data/langs/zh.ini
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ mediaobject = "[NOT DISPLAYABLE MEDIA]"
Version = "版本号"
Function = "函数"
Description = "描述"
Constants = "常量"

0 comments on commit 10ee0e4

Please sign in to comment.