1
0

theming.rst 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. Theming Guide
  2. =============
  3. Pagure is built on Flask, and uses Jinja2 for templates. Pagure also
  4. includes the ability to apply different themes that control the look
  5. and feel of your pagure instance, or add or remove elements from the
  6. interface.
  7. Setting a theme
  8. ---------------
  9. The theme is set in the Pagure configuration file. The theme name is defined by
  10. the name of the directory in the /themes/ folder that contains the theme. For
  11. example to enable the theme that is used on Pagure.io, add the following line
  12. to your Pagure configuration:
  13. ::
  14. THEME = "pagureio"
  15. Theme contents
  16. --------------
  17. A theme requires two directories (`templates` and `static`) in the directory
  18. that contains the theme. The only other required file is theme.html which
  19. is placed in the templates directory
  20. templates/
  21. ~~~~~~~~~~
  22. The `templates` directory is where pagure will look for the `theme.html`
  23. template. Additionally, if you wish to override any template in Pagure,
  24. place it in the theme templates/ directory, and pagure will use that
  25. template rather than the standard one.
  26. .. warning:: Take care when overriding templates, as any changes to Pagure
  27. upstream will need to be backported to your theme template override.
  28. static/
  29. ~~~~~~~
  30. The `static` directory contains all the static elements for the theme,
  31. including additional a favicon, images, Javascript, and CSS files. To
  32. reference a file in the theme static directory use the jinja2 tag
  33. `{{ url_for('theme.static', filename='filename')}}`. For example:
  34. ::
  35. <link href="{{ url_for('theme.static', filename='theme.css') }}"
  36. rel="stylesheet" type="text/css" />
  37. templates/theme.html
  38. ~~~~~~~~~~~~~~~~~~~~
  39. The theme.html file defines a subset of items in the Pagure interface that
  40. are commonly changed when creating a new theme. Theming is a new feature in
  41. Pagure, so this set is currently small, but please file issues or PRs against
  42. pagure with ideas of new items to include.
  43. The current items configurable in theme.html are:
  44. `masthead_class` variable
  45. #########################
  46. A string of additional CSS class(es) to be added to the navbar element.
  47. This navbar element is the topbar in Pagure. For example:
  48. ::
  49. {% set masthead_class = "navbar-dark bg-dark" %}
  50. `masthead_navbar_items()` macro
  51. ###############################
  52. A Jinja macro that allows themes to inject custom items in the Pagure navigation
  53. bar. Example:
  54. ::
  55. {% macro masthead_navbar_items() %}
  56. <li class="nav-item ml-3">
  57. <a class="nav-link font-weight-bold" href="...">
  58. Foobar
  59. </a>
  60. </li>
  61. {% endmacro %}
  62. `site_title` variable
  63. #####################
  64. A string containing the text to append at the end of the html title
  65. on every page on the site. Usage:
  66. ::
  67. {% set site_title = "Pagure" %}
  68. `projectstring(Bool:plural)` macro
  69. ##################################
  70. A macro that returns a string used to refer to Projects in Pagure
  71. The plural parameter informs if the string to be returned is the
  72. plural form.
  73. This macro is optional.
  74. Usage:
  75. ::
  76. {% macro projectstring(plural=False) -%}
  77. {% if plural %}
  78. Repositories
  79. {% else %}
  80. Repository
  81. {% endif %}
  82. {% endmacro -%}
  83. `projecticon` variable
  84. ######################
  85. A string containing the name of the fontawesome icon to use for
  86. Projects. This variable is optional. Usage:
  87. ::
  88. {% set projecticon = "Package" %}
  89. `head_imports()` macro
  90. ######################
  91. A Jinja macro that defines the additional items in the html head to
  92. be imported. The base templates do not include the bootstrap CSS, so
  93. this needs to be included in this macro in your theme. Additionally,
  94. include your favicon here, and a link to any additional CSS files your
  95. theme uses. Example:
  96. ::
  97. {% macro head_imports() %}
  98. <link rel="shortcut icon" type="image/vnd.microsoft.icon"
  99. href="{{ url_for('theme.static', filename='favicon.ico')}}"/>
  100. <link rel="stylesheet" href="{{ url_for('theme.static', filename='bootstrap/bootstrap.min.css')}}" />
  101. <link href="{{ url_for('theme.static', filename='theme.css') }}" rel="stylesheet" type="text/css" />
  102. {% endmacro %}
  103. `js_imports()` macro
  104. ####################
  105. A Jinja macro that defines the additional javascript files to
  106. be imported. The base templates do not include the bootstrap JS, so
  107. this needs to be included in this macro in your theme. Example:
  108. ::
  109. {% macro js_imports() %}
  110. <script src="{{ url_for('theme.static', filename='bootstrap/bootstrap.bundle.min.js')}}"></script>
  111. {% endmacro %}
  112. `browseheader_message(select)` macro
  113. ####################################
  114. An optional Jinja macro that defines the welcome message that is shown
  115. above the tabs on the Browse Pages (Projects, Users, and Groups). The
  116. select parameter is a string with the name of the page being shown
  117. Example:
  118. ::
  119. {% macro browseheader_message(select) %}
  120. {% if select == 'projects' %}
  121. <div class="row justify-content-around">
  122. <div class="col-md-8">
  123. <div class="jumbotron bg-transparent m-0 py-4 text-center">
  124. <h1 class="display-5">Welcome to my Pagure</h1>
  125. <p class="lead">Pagure is an Open Source software code hosting system.</p>
  126. </div>
  127. </div>
  128. </div>
  129. {% endif %}
  130. {% endmacro %}
  131. `footer()` macro
  132. ################
  133. A Jinja macro that defines the footer of the Pagure site. Example:
  134. ::
  135. {% macro footer() %}
  136. <div class="footer py-3 bg-light border-top text-center">
  137. <div class="container">
  138. <p class="text-muted credit">
  139. Powered by
  140. <a href="https://pagure.io/pagure">Pagure</a>
  141. {{ g.version }}
  142. </p>
  143. <p><a href="{{ url_for('ui_ns.ssh_hostkey') }}">SSH Hostkey/Fingerprint</a> | <a href="https://docs.pagure.org/pagure/usage/index.html">Documentation</a></p>
  144. </div>
  145. </div>
  146. {% endmacro %}
  147. `about_page()` macro
  148. ######################
  149. A Jinja macro that defines the content of the About page (available at /about). You may want to replace the links to contact links for your own instance. Example:
  150. ::
  151. {% macro about_page() %}
  152. <div class="container mt-5">
  153. <h1>About</h1>
  154. <p>This is an instance of Pagure, a git forge.</p>
  155. <p>If you experience a bug or security concern, please <a href="https://pagure.io/pagure/issues">submit an issue</a>.</p>
  156. <p>You may also post questions to the Pagure Development list by emailing: <a href="mailto:pagure-devel@lists.pagure.io">pagure-devel@lists.pagure.io</a> or <a href="https://lists.pagure.io/admin/lists/pagure-devel.lists.pagure.io/">subscribe to the list</a>.</p>
  157. <p><a href="https://lists.pagure.io/admin/lists/pagure-announce.lists.pagure.io/">Subscribe to announcements</a> about Pagure.</p>
  158. </div>
  159. {% endmacro %}