PageRenderTime 51ms CodeModel.GetById 16ms RepoModel.GetById 1ms app.codeStats 0ms

/src/view/phui/PHUIDocumentView.php

https://github.com/navyuginfo/phabricator
PHP | 188 lines | 160 code | 27 blank | 1 comment | 14 complexity | 07c0bfc1e677f21d1299bdc15699dec5 MD5 | raw file
Possible License(s): Apache-2.0, LGPL-2.0, LGPL-3.0, MIT, MPL-2.0-no-copyleft-exception, BSD-3-Clause
  1. <?php
  2. final class PHUIDocumentView extends AphrontTagView {
  3. /* For mobile displays, where do you want the sidebar */
  4. const NAV_BOTTOM = 'nav_bottom';
  5. const NAV_TOP = 'nav_top';
  6. const FONT_SOURCE_SANS = 'source-sans';
  7. private $offset;
  8. private $header;
  9. private $sidenav;
  10. private $topnav;
  11. private $crumbs;
  12. private $bookname;
  13. private $bookdescription;
  14. private $mobileview;
  15. private $fontKit;
  16. public function setOffset($offset) {
  17. $this->offset = $offset;
  18. return $this;
  19. }
  20. public function setHeader(PHUIHeaderView $header) {
  21. $header->setGradient(PhabricatorActionHeaderView::HEADER_LIGHTBLUE);
  22. $this->header = $header;
  23. return $this;
  24. }
  25. public function setSideNav(PHUIListView $list, $display = self::NAV_BOTTOM) {
  26. $list->setType(PHUIListView::SIDENAV_LIST);
  27. $this->sidenav = $list;
  28. $this->mobileview = $display;
  29. return $this;
  30. }
  31. public function setTopNav(PHUIListView $list) {
  32. $list->setType(PHUIListView::NAVBAR_LIST);
  33. $this->topnav = $list;
  34. return $this;
  35. }
  36. public function setCrumbs(PHUIListView $list) {
  37. $this->crumbs = $list;
  38. return $this;
  39. }
  40. public function setBook($name, $description) {
  41. $this->bookname = $name;
  42. $this->bookdescription = $description;
  43. return $this;
  44. }
  45. public function setFontKit($kit) {
  46. $this->fontKit = $kit;
  47. return $this;
  48. }
  49. public function getTagAttributes() {
  50. $classes = array();
  51. if ($this->offset) {
  52. $classes[] = 'phui-document-offset';
  53. };
  54. return array(
  55. 'class' => $classes,
  56. );
  57. }
  58. public function getTagContent() {
  59. require_celerity_resource('phui-document-view-css');
  60. if ($this->fontKit) {
  61. require_celerity_resource('phui-fontkit-css');
  62. }
  63. switch ($this->fontKit) {
  64. case self::FONT_SOURCE_SANS:
  65. require_celerity_resource('font-source-sans-pro');
  66. break;
  67. }
  68. $classes = array();
  69. $classes[] = 'phui-document-view';
  70. if ($this->offset) {
  71. $classes[] = 'phui-offset-view';
  72. }
  73. if ($this->sidenav) {
  74. $classes[] = 'phui-sidenav-view';
  75. }
  76. $sidenav = null;
  77. if ($this->sidenav) {
  78. $sidenav = phutil_tag(
  79. 'div',
  80. array(
  81. 'class' => 'phui-document-sidenav'
  82. ),
  83. $this->sidenav);
  84. }
  85. $book = null;
  86. if ($this->bookname) {
  87. $book = phutil_tag(
  88. 'div',
  89. array(
  90. 'class' => 'phui-document-bookname grouped'
  91. ),
  92. array(
  93. phutil_tag(
  94. 'span',
  95. array('class' => 'bookname'),
  96. $this->bookname),
  97. phutil_tag(
  98. 'span',
  99. array('class' => 'bookdescription'),
  100. $this->bookdescription)));
  101. }
  102. $topnav = null;
  103. if ($this->topnav) {
  104. $topnav = phutil_tag(
  105. 'div',
  106. array(
  107. 'class' => 'phui-document-topnav'
  108. ),
  109. $this->topnav);
  110. }
  111. $crumbs = null;
  112. if ($this->crumbs) {
  113. $crumbs = phutil_tag(
  114. 'div',
  115. array(
  116. 'class' => 'phui-document-crumbs'
  117. ),
  118. $this->bookName);
  119. }
  120. if ($this->fontKit) {
  121. $main_content = phutil_tag(
  122. 'div',
  123. array(
  124. 'class' => 'phui-font-'.$this->fontKit
  125. ),
  126. $this->renderChildren());
  127. } else {
  128. $main_content = $this->renderChildren();
  129. }
  130. $content_inner = phutil_tag(
  131. 'div',
  132. array(
  133. 'class' => 'phui-document-inner',
  134. ),
  135. array(
  136. $book,
  137. $this->header,
  138. $topnav,
  139. $main_content,
  140. $crumbs
  141. ));
  142. if ($this->mobileview == self::NAV_BOTTOM) {
  143. $order = array($content_inner, $sidenav);
  144. } else {
  145. $order = array($sidenav, $content_inner);
  146. }
  147. $content = phutil_tag(
  148. 'div',
  149. array(
  150. 'class' => 'phui-document-content',
  151. ),
  152. $order);
  153. $view = phutil_tag(
  154. 'div',
  155. array(
  156. 'class' => implode(' ', $classes),
  157. ),
  158. $content);
  159. return $view;
  160. }
  161. }