From cc03608d7838b449f66d232dd92b41f7403e3c79 Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Tue, 25 Nov 2014 21:39:09 +0200 Subject: Add --new-note-template --- NEWS | 6 ++++++ jt | 35 ++++++++++++++++++++++++----------- 2 files changed, 30 insertions(+), 11 deletions(-) diff --git a/NEWS b/NEWS index 83d37b7..541a11d 100644 --- a/NEWS +++ b/NEWS @@ -1,6 +1,12 @@ NEWS for jt =========== +Version 0.5, released UNRELEASED +-------------------------------- + +* Add `--new-note-template` option for setting the template for a new + note. + Version 0.4, released 2014-11-23 -------------------------------- diff --git a/jt b/jt index bcb4f59..86c5fc9 100755 --- a/jt +++ b/jt @@ -31,16 +31,6 @@ import traceback __version__ = '0.4' -template = '''\ -[[!meta title="%(title)s"]] -[[!tag ]] -[[!meta date="%(date)s"]] - -%(topiclink)s - -''' - - class DraftsDirectory(object): def __init__(self, dirname): @@ -112,6 +102,15 @@ class Command(object): class NewCommand(Command): + _default_new_note_template = '''\ +[[!meta title="%(title)s"]] +[[!tag ]] +[[!meta date="%(date)s"]] + +%(topiclink)s + +''' + def run(self, args): if not args: raise cliapp.AppException('Usage: journal-note new TITLE') @@ -129,7 +128,8 @@ class NewCommand(Command): drafts_dir = DraftsDirectory(self._app.drafts_dir()) drafts_dir.create_if_missing() - draft_id = drafts_dir.create_draft(template % values) + draft_id = drafts_dir.create_draft( + self._get_new_note_template() % values) self._app.edit_file(drafts_dir.get_draft_pathname(draft_id)) def _topic_page_exists(self, topic): @@ -142,6 +142,14 @@ class NewCommand(Command): else: return '' + def _get_new_note_template(self): + filename = self._app.settings['new-note-template'] + if filename: + with open(filename) as f: + return f.read() + else: + return self._default_new_note_template + class ListCommand(Command): @@ -349,6 +357,11 @@ class JournalTool(cliapp.Application): 'new entry belongs to TOPIC', metavar='TOPIC') + self.settings.string( + ['new-note-template'], + 'use FILE as the template for new journal notes', + metavar='FILE') + self.settings.string( ['pretend-time'], 'pretend that the time is NOW (form: YYYY-MM-DD HH:MM:DD form)', -- cgit v1.2.1