22Usage
33=====
44
5- The extension provides an extra context `` recentupdate `` for ` sphinxnotes-render `_.
6- Extra context can be load by the :external+render:term: ` load_extra ` function in
7- a Jinja template. User can easily render a Jinja template via :rst:dir: ` data.render `
8- directive .
5+ The :rst:dir: ` recentupdate ` directive is the recommended way to display recent
6+ document updates. For cases where you need recent update information inside a
7+ ` sphinxnotes-render `_ compatible template (e.g. alongside other extra contexts),
8+ use the `` recentupdate `` extra context instead .
99
10- ``recentupdate ``
11- ================
10+ The ``recentupdate `` Directive
11+ ==============================
1212
13- When calling ``load_extra('recentupdate', **kwargs) `` in the template, the
14- following parameters are available:
13+ .. rst :directive :: .. recentupdate:: [count]
1514
16- ``count ``
17- Number of recent revisions to return (default from :confval: `recentupdate_count `).
15+ Display recent document updates from Git.
1816
19- ``paths ``
20- A list of git pathspecs (:manpage: `gitglossary(7)`) to filter file changes
21- (default ``['.'] ``).
22- See also :example: `Recent Updates of Custom Path `.
17+ The optional ``count `` is the number of recent revisions to display.
18+ Defaults to :confval: `recentupdate_count `.
2319
24- ``current_doc ``
25- If ``True ``, only return revisions that modified the current document
26- (default ``False ``).
20+ .. rst:directive:option:: self
21+ :type: flag
2722
28- .. note ::
23+ Only show revisions that modified the current document.
24+ Mutually exclusive with :rst:dir:`recentupdate:paths`.
2925
30- When enabled, ``paths `` is overridden with a pathspec matching the current
31- document. So ``paths `` and ``current_doc `` are mutually exclusive.
26+ See also :example:`Recent Updates to Current Document`.
3227
33- See also :example: `Recent Updates to Current Document `.
28+ .. rst:directive:option:: paths
29+ :type: lines of str
3430
35- .. role :: py(code)
36- :language: Python
31+ Git pathspecs (:manpage:`gitglossary(7)`) to filter file changes,
32+ one per line. Defaults to ``.``.
3733
38- ``group_by ``
39- Group revisions by time period. Revisions are grouped by UTC time
40- period and author.
34+ See also :example:`Recent Updates of Custom Path`.
35+
36+ .. rst:directive:option:: group-by
37+ :type: str
4138
42- Default from :confval: ` recentupdate_group_by `, Available values:
43- :data.render: ` {{ load_extra('env').config.values['recentupdate_group_by'].valid_types | autoconfval_types | join(', ') }} `.
39+ .. role:: py(code)
40+ :language: Python
4441
45- See also :example: `Grouped Recent Updates `.
42+ Group revisions by time period.
43+ Available values:
44+ :data.render:`{{ load_extra('env').config.values['recentupdate_group_by'].valid_types | autoconfval_types | join(', ') }}`.
45+ Defaults to :confval:`recentupdate_group_by`.
4646
47- Each item returned is a :py:class: `~sphinxnotes.recentupdate.Revision ` object:
47+ See also :example:`Grouped Recent Updates`.
48+
49+ The directive body is a Jinja2 template. When empty,
50+ :confval: `recentupdate_template ` is used. The template context contains
51+ a ``{{ revisions }} `` variable, it is a list of
52+ :py:class: `~sphinxnotes.recentupdate.Revision ` objects.
4853
4954.. autoclass :: sphinxnotes.recentupdate.Revision
5055
@@ -55,6 +60,39 @@ Each item returned is a :py:class:`~sphinxnotes.recentupdate.Revision` object:
5560 .. autoattribute :: changed_docs
5661 .. autoattribute :: removed_docs
5762
63+ This is a basic example using the default template:
64+
65+ .. example ::
66+
67+ .. recentupdate ::
68+
69+ The ``recentupdate `` Extra Context
70+ ==================================
71+
72+ .. tip ::
73+
74+ The extra context is for use within `sphinxnotes-render `_ compatible templates.
75+ In most cases, prefer the :rst:dir: `recentupdate ` directive instead.
76+
77+ The ``recentupdate `` extra context can be loaded via
78+ :external+render:term: `load_extra ` in a Jinja template
79+ (e.g. via :rst:dir: `data.render `):
80+
81+ Parameters:
82+
83+ ``count ``
84+ Equivalent to the argument of :rst:dir: `recentupdate `.
85+
86+ ``paths ``
87+ Equivalent to :rst:dir: `recentupdate:paths `.
88+
89+ ``self_only ``
90+ Equivalent to :rst:dir: `recentupdate:self `.
91+
92+ ``group_by ``
93+ Equivalent to :rst:dir: `recentupdate:group-by `.
94+
95+
5896This is a basic example:
5997
6098.. example ::
@@ -67,15 +105,18 @@ This is a basic example:
67105 {{ r.message[0] }}
68106 {% endfor %}
69107
108+ .. note :: To Use the ``data.render`` directive, you need to add
109+ ``sphinxnotes.render.ext `` to your Sphinx extension list.
110+
70111Examples
71112========
72113
73- .. example :: Show Which Files Updated
114+ .. example :: Show Which Documents Updated
74115
75- .. data.render ::
116+ .. recentupdate ::
76117
77- {% for r in load_extra('recentupdate', count=5) %}
78- ``📅 {{ r.date.strftime('%Y-%m-%d') }}``
118+ {% for r in revisions %}
119+ ``{{ r.date.strftime('%Y-%m-%d') }} ``
79120 {% if r.changed_docs -%}
80121 :Modified: {{ r.changed_docs | roles("doc") | join(", ") }}
81122 {% endif %}
@@ -87,41 +128,46 @@ Examples
87128 {% endif %}
88129 {% endfor %}
89130
90- The aboved :external+render:term:`roles` filter is also provided by
91- `sphinxnotes-render`_.
131+ The aboved :external+render:term: `roles ` filter is also provided by
132+ `sphinxnotes-render `_.
133+
92134
93135.. example :: Recent Updates of Custom Path
94136
95- .. data.render: :
137+ Recent changes of the :doc: ` changelog ` :
96138
97- Recent changes of the :doc:`changelog`:
139+ .. recentupdate ::
140+ :paths: docs/changelog.rst
98141
99- {% for r in load_extra('recentupdate', count=5, paths=['docs/changelog.rst']) %}
142+ {% for r in revisions %}
100143 ``{{ r.date.strftime('%Y-%m-%d') }} `` — {{ r.message[0] }}
101144 {% endfor %}
102145
103146.. example :: Recent Updates to Current Document
104147
105- .. data.render: :
148+ Recent changes to this document :
106149
107- Recent changes to this document:
150+ .. recentupdate ::
151+ :self:
108152
109- {% for r in load_extra('recentupdate', count=5, current_doc=True) %}
153+ {% for r in revisions %}
110154 ``{{ r.date.strftime('%Y-%m-%d') }} `` — {{ r.message[0] }}
111155 {% endfor %}
112156
113157.. example :: Grouped Recent Updates
114158
115- .. data.render: :
159+ Recent updates grouped by month :
116160
117- Recent updates grouped by month:
161+ .. recentupdate :: 3
162+ :group-by: month
118163
119- {% for r in load_extra('recentupdate', count=5, group_by='month') %}
164+ {% for r in revisions %}
120165 ``📅 {{ r.date.strftime('%Y-%m') }} ``
121166 ::
122- {% for msg in r.message %}
167+ {% for msg in r.message[:20] %}
123168 {{ msg }}
124169 {%- endfor %}
170+ ...
125171 {% endfor %}
126172
127173``sphinxnotes-render ``
0 commit comments