context.rst 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. .. _context:
  2. ============
  3. HTML Context
  4. ============
  5. The following variables and functions are exposed to the `Sphinx HTML builder context <sphinx_context_>`_ in all versions.
  6. ``Version`` Objects
  7. ===================
  8. All versions will be exposed to the HTML context as ``Version`` objects with the following attributes:
  9. .. attribute:: name
  10. The branch or tag name.
  11. .. attribute:: url
  12. The URL to the current page in this version.
  13. .. attribute:: version
  14. The value of the ``version`` variable in ``conf.py``.
  15. .. attribute:: release
  16. The value of the ``release`` variable in ``conf.py``.
  17. .. attribute:: is_released
  18. ``True`` if this version matches the :ref:`configured <configuration>` ``smv_released_pattern`` regular expression, else ``False``.
  19. Versions
  20. ========
  21. The most important variable is ``versions``, which can be used to iterate over all found (and whitelisted) versions.
  22. .. attribute:: versions
  23. An iterable that yields all ``Version`` objects.
  24. .. code-block:: jinja
  25. <h3>Versions</h3>
  26. <ul>
  27. {%- for item in versions %}
  28. <li><a href="{{ item.url }}">{{ item.name }}</a></li>
  29. {%- endfor %}
  30. </ul>
  31. .. attribute:: versions.branches
  32. You can use the ``branches`` property of the ``versions`` iterable to get the ``Version`` objects for all branches.
  33. .. code-block:: jinja
  34. <h3>Branches</h3>
  35. <ul>
  36. {%- for item in versions.branches %}
  37. <li><a href="{{ item.url }}">{{ item.name }}</a></li>
  38. {%- endfor %}
  39. </ul>
  40. .. attribute:: versions.tags
  41. You can use the ``tags`` property of the ``versions`` iterable to get the ``Version`` objects for all tags.
  42. .. code-block:: jinja
  43. <h3>Tags</h3>
  44. <ul>
  45. {%- for item in versions.tags %}
  46. <li><a href="{{ item.url }}">{{ item.name }}</a></li>
  47. {%- endfor %}
  48. </ul>
  49. .. attribute:: versions.releases
  50. You can use the ``releases`` property of the ``versions`` iterable to get all ``Version`` objects where the ``ìs_released`` attribute is ``True``.
  51. This is determined by the ``smv_released_pattern`` in the :ref:`Configuration <configuration>`.
  52. .. code-block:: jinja
  53. <h3>Releases</h3>
  54. <ul>
  55. {%- for item in versions.releases %}
  56. <li><a href="{{ item.url }}">{{ item.name }}</a></li>
  57. {%- endfor %}
  58. </ul>
  59. .. attribute:: versions.in_development
  60. You can use the ``in_development`` property of the ``versions`` iterable to get all ``Version`` objects where the ``ìs_released`` attribute is ``False``.
  61. This is determined by the ``smv_released_pattern`` in the :ref:`Configuration <configuration>`.
  62. .. code-block:: jinja
  63. <h3>In Development</h3>
  64. <ul>
  65. {%- for item in versions.in_development %}
  66. <li><a href="{{ item.url }}">{{ item.name }}</a></li>
  67. {%- endfor %}
  68. </ul>
  69. Functions
  70. =========
  71. Similar to Sphinx's `hasdoc() <sphinx_hasdoc_>`_ function.
  72. .. function:: vhasdoc(other_version)
  73. This function is Similar to Sphinx's `hasdoc() <sphinx_hasdoc_>`_ function.
  74. It takes ``other_version`` as string and returns ``True`` if the current document exists in another version.
  75. .. code-block:: jinja
  76. {% if vhasdoc('master') %}
  77. This page is available in <a href="../master/index.html">master</a>.
  78. {% endif %}
  79. .. function:: vpathto(other_version)
  80. This function is Similar to Sphinx's `pathto() <sphinx_pathto_>`_ function.
  81. It takes ``other_version`` as string and returns the relative URL to the current page in the other version.
  82. If the current page does not exist in that version, the relative URL to its `master_doc <sphinx_master_doc_>`_ is returned instead.
  83. .. code-block:: jinja
  84. {% if vhasdoc('master') %}
  85. This page is also available in <a href="{{ vpathto('master') }}">master</a>.
  86. {% else %}
  87. Go to <a href="{{ vpathto('master') }}">master</a> for the latest docs.
  88. {% endif %}
  89. Other Variables
  90. ===============
  91. .. attribute:: current_version
  92. A ``Version`` object for of the current version being built.
  93. .. code-block:: jinja
  94. <h3>Current Version: {{ current_version.name }}</h3>
  95. .. attribute:: latest_version
  96. A ``Version`` object of the latest released version being built.
  97. .. code-block:: jinja
  98. <h3>Latest Version: {{ latest_version.name }}</h3>
  99. .. _sphinx_context: http://www.sphinx-doc.org/en/stable/config.html?highlight=context#confval-html_context
  100. .. _sphinx_master_doc: http://www.sphinx-doc.org/en/stable/config.html?highlight=context#confval-master_doc
  101. .. _sphinx_hasdoc: http://www.sphinx-doc.org/en/stable/templating.html#hasdoc
  102. .. _sphinx_pathto: http://www.sphinx-doc.org/en/stable/templating.html#pathto