diff options
author | Håkon Vågsether <hauk142@gmail.com> | 2021-08-21 12:12:47 +0200 |
---|---|---|
committer | Jeff Long <willcode4@gmail.com> | 2021-09-07 09:57:37 -0400 |
commit | 2e4432e7dffb9daa6af4ca1f414c18e027bd7729 (patch) | |
tree | c9536302d81d0631d76c8c30224058353d741933 | |
parent | gr-fft: add "shift" param to logpwrfft block (diff) | |
download | gnuradio-2e4432e7dffb9daa6af4ca1f414c18e027bd7729.tar.xz gnuradio-2e4432e7dffb9daa6af4ca1f414c18e027bd7729.zip |
grc: Add no_quotes() convenience function (callable from templates)
Signed-off-by: Håkon Vågsether <hauk142@gmail.com>
(cherry picked from commit 774d30d66afdab0c16d9239d84e5829187f791c4)
Signed-off-by: Jeff Long <willcode4@gmail.com>
-rw-r--r-- | grc/core/blocks/_templates.py | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/grc/core/blocks/_templates.py b/grc/core/blocks/_templates.py index 5bfb15e9e..c57de4d40 100644 --- a/grc/core/blocks/_templates.py +++ b/grc/core/blocks/_templates.py @@ -26,6 +26,16 @@ from mako.exceptions import SyntaxException from ..errors import TemplateError +# The utils dict contains convenience functions +# that can be called from any template +def no_quotes(string, fallback=None): + if len(string) > 2: + if str(string)[0] + str(string)[-1] in ("''", '""'): + return str(string)[1:-1] + return str(fallback if fallback else string) + +utils = {'no_quotes': no_quotes} + class MakoTemplates(dict): @@ -65,6 +75,7 @@ class MakoTemplates(dict): if not text: return '' namespace = self.instance.namespace_templates + namespace = {**namespace, **utils} try: if isinstance(text, list): |