From 6b00e6cc829602cec7e6b6b73f94febd28bfa9a3 Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Sat, 3 Oct 2015 10:34:06 +0300 Subject: Move template texts into files --- jtlib/app.py | 5 +++++ jtlib/plugins/new_person_plugin.py | 7 +------ jtlib/plugins/new_plugin.py | 10 +--------- jtlib/plugins/new_topic_plugin.py | 9 +-------- jtlib/templates/new-note.tmpl | 5 +++++ jtlib/templates/new_person.tmpl | 3 +++ jtlib/templates/new_topic.tmpl | 3 +++ 7 files changed, 19 insertions(+), 23 deletions(-) create mode 100644 jtlib/templates/new-note.tmpl create mode 100644 jtlib/templates/new_person.tmpl create mode 100644 jtlib/templates/new_topic.tmpl diff --git a/jtlib/app.py b/jtlib/app.py index a560c26..8e0303a 100644 --- a/jtlib/app.py +++ b/jtlib/app.py @@ -93,3 +93,8 @@ class JournalTool(cliapp.Application): return args[0], pathname elif len(args) > 1: raise cliapp.AppException('Must give at most one draft number') + + def read_template(self, basename): + filename = os.path.join(self.app_directory(), 'templates', basename) + with open(filename) as f: + return f.read() diff --git a/jtlib/plugins/new_person_plugin.py b/jtlib/plugins/new_person_plugin.py index 43db172..050e97a 100644 --- a/jtlib/plugins/new_person_plugin.py +++ b/jtlib/plugins/new_person_plugin.py @@ -53,12 +53,7 @@ class NewPersonCommand(cliapp.Plugin): if os.path.exists(pathname): raise cliapp.AppException('File %s already exists' % pathname) - template = '''\ -[[!meta title="%(name)s"]] - -[[!inline archive=yes pages="link(.)"]] -''' - + template = self.app.read_template('new_person.tmpl') with open(pathname, 'w') as f: f.write( template % diff --git a/jtlib/plugins/new_plugin.py b/jtlib/plugins/new_plugin.py index b10b4a1..8134fa5 100644 --- a/jtlib/plugins/new_plugin.py +++ b/jtlib/plugins/new_plugin.py @@ -25,14 +25,6 @@ import jtlib class NewCommand(cliapp.Plugin): - _default_new_note_template = '''\ -[[!meta title="%(title)s"]] -[[!tag ]] -[[!meta date="%(date)s"]] -%(topiclink)s - -''' - def enable(self): self.app.add_subcommand('new', self.run, arg_synopsis='TITLE') @@ -79,4 +71,4 @@ class NewCommand(cliapp.Plugin): with open(filename) as f: return f.read() else: - return self._default_new_note_template + return self.app.read_template('new-note.tmpl') diff --git a/jtlib/plugins/new_topic_plugin.py b/jtlib/plugins/new_topic_plugin.py index 09fcbd5..4f44f2b 100644 --- a/jtlib/plugins/new_topic_plugin.py +++ b/jtlib/plugins/new_topic_plugin.py @@ -49,13 +49,6 @@ class NewTopicCommand(cliapp.Plugin): if not os.path.exists(dirname): os.makedirs(dirname) - template = '''\ -[[!meta title="%(title)s"]] - - - -[[!inline pages="link(.)" archive=yes reverse=yes trail=yes]] -''' - + template = self.app.read_template('new_topic.tmpl') with open(pathname, 'w') as f: f.write(template % {'title': title}) diff --git a/jtlib/templates/new-note.tmpl b/jtlib/templates/new-note.tmpl new file mode 100644 index 0000000..0db1798 --- /dev/null +++ b/jtlib/templates/new-note.tmpl @@ -0,0 +1,5 @@ +[[!meta title="%(title)s"]] +[[!tag ]] +[[!meta date="%(date)s"]] +%(topiclink)s + diff --git a/jtlib/templates/new_person.tmpl b/jtlib/templates/new_person.tmpl new file mode 100644 index 0000000..86d5162 --- /dev/null +++ b/jtlib/templates/new_person.tmpl @@ -0,0 +1,3 @@ +[[!meta title="%(name)s"]] + +[[!inline archive=yes pages="link(.)"]] diff --git a/jtlib/templates/new_topic.tmpl b/jtlib/templates/new_topic.tmpl new file mode 100644 index 0000000..5321b7f --- /dev/null +++ b/jtlib/templates/new_topic.tmpl @@ -0,0 +1,3 @@ +[[!meta title="%(title)s"]] + +[[!inline pages="link(.)" archive=yes reverse=yes trail=yes]] -- cgit v1.2.1