diff options
author | Lars Wirzenius <liw@liw.fi> | 2015-10-03 12:41:21 +0300 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2015-10-03 13:08:17 +0300 |
commit | d8b539a9f2a18369400444ada72dff4a83595bab (patch) | |
tree | 56d920df78424dd5ed486dd2bc5a240cfa0a39d0 /jtlib/plugins | |
parent | 7cb2a4b266c1d140ebd3c9198ca5754acda576ae (diff) | |
download | jt-d8b539a9f2a18369400444ada72dff4a83595bab.tar.gz |
Use jinja2 for templates
Diffstat (limited to 'jtlib/plugins')
-rw-r--r-- | jtlib/plugins/new_person_plugin.py | 15 | ||||
-rw-r--r-- | jtlib/plugins/new_plugin.py | 5 | ||||
-rw-r--r-- | jtlib/plugins/new_topic_plugin.py | 7 |
3 files changed, 14 insertions, 13 deletions
diff --git a/jtlib/plugins/new_person_plugin.py b/jtlib/plugins/new_person_plugin.py index 050e97a..a7cc76a 100644 --- a/jtlib/plugins/new_person_plugin.py +++ b/jtlib/plugins/new_person_plugin.py @@ -53,13 +53,10 @@ class NewPersonCommand(cliapp.Plugin): if os.path.exists(pathname): raise cliapp.AppException('File %s already exists' % pathname) - template = self.app.read_template('new_person.tmpl') + vars = { + 'name': name, + 'basename': basename, + } + rendered_template = self.app.render_template('new_person.j2', vars) with open(pathname, 'w') as f: - f.write( - template % - { - 'name': name, - 'basename': basename, - }) - - + f.write(rendered_template) diff --git a/jtlib/plugins/new_plugin.py b/jtlib/plugins/new_plugin.py index 8134fa5..25facf8 100644 --- a/jtlib/plugins/new_plugin.py +++ b/jtlib/plugins/new_plugin.py @@ -42,8 +42,9 @@ class NewCommand(cliapp.Plugin): drafts_dir = jtlib.DraftsDirectory(self.app.drafts_dir()) drafts_dir.create_if_missing() - draft_id = drafts_dir.create_draft( - self._get_new_note_template() % values) + + rendered_template = self.app.render_template('new-note.j2', values) + draft_id = drafts_dir.create_draft(rendered_template) self.app.edit_file(drafts_dir.get_draft_pathname(draft_id)) def _check_args_and_settings(self, args): diff --git a/jtlib/plugins/new_topic_plugin.py b/jtlib/plugins/new_topic_plugin.py index 4f44f2b..1114bb4 100644 --- a/jtlib/plugins/new_topic_plugin.py +++ b/jtlib/plugins/new_topic_plugin.py @@ -49,6 +49,9 @@ class NewTopicCommand(cliapp.Plugin): if not os.path.exists(dirname): os.makedirs(dirname) - template = self.app.read_template('new_topic.tmpl') + vars = { + 'title': title, + } + rendered_template = self.app.render_template('new_topic.j2', vars) with open(pathname, 'w') as f: - f.write(template % {'title': title}) + f.write(rendered_template) |