diff --git a/CHANGELOG.md b/CHANGELOG.md index 6fa7a59..6782fc0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 @@ -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 diff --git a/README.md b/README.md index 561d70c..51125be 100644 --- a/README.md +++ b/README.md @@ -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. -- jinjafx.counter(key: Optional[String], increment: Optional[Integer]=1, start: Optional[Integer]=1) -> Integer | String +- jinjafx.counter(key: Optional[String], increment: Optional[Integer]=1, start: Optional[Integer]=1, row: Optional[Integer]) -> Integer | String -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: diff --git a/jinjafx.py b/jinjafx.py index 25a5d1e..224b7d9 100755 --- a/jinjafx.py +++ b/jinjafx.py @@ -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'] @@ -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]):