summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2014-11-25 21:39:09 +0200
committerLars Wirzenius <liw@liw.fi>2014-11-25 21:39:09 +0200
commitcc03608d7838b449f66d232dd92b41f7403e3c79 (patch)
treecfdcea9db0b614e87034455d40d9da1c02f238de
parent64dd22e20b4aa4ca6c78224e96965c7da25d04b0 (diff)
downloadjt-cc03608d7838b449f66d232dd92b41f7403e3c79.tar.gz
Add --new-note-template
-rw-r--r--NEWS6
-rwxr-xr-xjt35
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):
@@ -350,6 +358,11 @@ class JournalTool(cliapp.Application):
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)',
metavar='NOW')