Skip to content

Commit

Permalink
Merge pull request #94 from cmason3/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
cmason3 authored Apr 22, 2024
2 parents 01df5bc + 2ca93fe commit f15553c
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
## CHANGELOG

### [1.19.3] - April 22, 2024
- Added an optional `row` argument to `jinjafx.counter()` to allow the current row to be overridden

### [1.19.2] - April 10, 2024
- Exceptions are now always mapped back to the specific line within the Jinja2 template
- Added an actual `CHANGELOG.md` instead of relying on GitHub Release history
Expand Down Expand Up @@ -519,6 +522,7 @@ Updated `to_yaml` and `to_nice_yaml` to use `SafeDumper`
- Initial release


[1.19.3]: https://github.com/cmason3/jinjafx/compare/v1.19.2...v1.19.3
[1.19.2]: https://github.com/cmason3/jinjafx/compare/v1.19.1...v1.19.2
[1.19.1]: https://github.com/cmason3/jinjafx/compare/v1.18.7...v1.19.1
[1.18.7]: https://github.com/cmason3/jinjafx/compare/v1.18.6...v1.18.7
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -582,9 +582,9 @@ This function is used to access all the row and column data that JinjaFx is curr

This function is used to expand a string that contains static character classes (i.e. `[0-9]`), static groups (i.e. `(a|b)`) or active counters (i.e. `{ start-end:increment }`) into a list of all the different permutations. You are permitted to use as many classes, groups or counters within the same string - if it doesn't detect any classes, groups or counters within the string then the "string" will be returned as the only list element. Character classes support "A-Z", "a-z" and "0-9" characters, whereas static groups allow any string of characters (including static character classes). If you wish to include "[", "]", "(", ")", "{" or "}" literals within the string then they will need to be escaped.

- <code><b>jinjafx.counter(key</b>: Optional[String]<b>, increment</b>: Optional[Integer]<b>=1, start</b>: Optional[Integer]<b>=1)</b> -> Integer | String</code>
- <code><b>jinjafx.counter(key</b>: Optional[String]<b>, increment</b>: Optional[Integer]<b>=1, start</b>: Optional[Integer]<b>=1, row</b>: Optional[Integer]<b>)</b> -> Integer | String</code>

This function is used to provide a persistent counter within a row or between rows. If you specify a case insensitive `key` then it is a global counter that will persist between rows, but if you don't or you include `jinjafx.row` within the `key`, then the counter only persists within the template of the current row.
This function is used to provide a persistent counter within a row or between rows. If you specify a case insensitive `key` then it is a global counter that will persist between rows, but if you don't or you include `jinjafx.row` within the `key`, then the counter only persists within the template of the current row. You can also manipulate the counter by specifying a custom row, which overrides the current row.

This function also supports a hierarchical counter which can be used for numbering of headings, e.g:

Expand Down
11 changes: 7 additions & 4 deletions jinjafx.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
from cryptography.hazmat.primitives.ciphers.modes import CTR
from cryptography.exceptions import InvalidSignature

__version__ = '1.19.2'
__version__ = '1.19.3'

__all__ = ['JinjaFx', 'Vault']

Expand Down Expand Up @@ -1157,12 +1157,15 @@ def __jfx_data(self, row, col=None):
return None


def __jfx_counter(self, key=None, increment=1, start=1):
def __jfx_counter(self, key=None, increment=1, start=1, row=None):
if row is None:
row = self.__g_row

if key is None:
key = '_cnt_r_' + str(self.__g_row)
key = '_cnt_r_' + str(row)

elif str(key).endswith('.') and self.__g_hcounter.match(key):
nkey = '_cnt_hk' + str(self.__g_row)
nkey = '_cnt_hk' + str(row)
kelements = key[:-1].lower().split('.')

for i, v in enumerate(kelements[:-1]):
Expand Down

0 comments on commit f15553c

Please sign in to comment.