summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2014-11-22 20:02:34 +0200
committerLars Wirzenius <liw@liw.fi>2014-11-22 20:02:34 +0200
commit282e41cc67741a1bf0ed04a3549d1608e9c10d68 (patch)
treef8577946ee651080f5a284387ecf3437cd5e6fbc
parenta9bdef939d057763d5b0e643dd5dfd01ee8907f4 (diff)
downloadjt-282e41cc67741a1bf0ed04a3549d1608e9c10d68.tar.gz
Implement new-topic command
-rwxr-xr-xjt31
-rw-r--r--yarns/030-topics.yarn4
2 files changed, 33 insertions, 2 deletions
diff --git a/jt b/jt
index 02a9bb8..72fcedb 100755
--- a/jt
+++ b/jt
@@ -235,6 +235,33 @@ class FinishCommand(Command):
cwd=self._app.settings['source'])
+class NewTopicCommand(Command):
+
+ def run(self, args):
+ if len(args) != 2:
+ raise cliapp.AppException(
+ 'Must be given two args (page path, title) (%r)' % args)
+
+ pathname = self._topic_pathname(args[0])
+ self._create_topic_page(pathname, args[1])
+
+ def _topic_pathname(self, page_path):
+ return os.path.join(self._app.settings['source'], page_path + '.mdwn')
+
+ def _create_topic_page(self, pathname, title):
+ dirname = os.path.dirname(pathname)
+ if not os.path.exists(dirname):
+ os.makedirs(dirname)
+
+ with open(pathname, 'w') as f:
+ f.write('''\
+[[!meta title="%(title)s"]]
+[[!inline pages="link(.)" archive=yes reverse=yes trail=yes]]
+''' % {
+ 'title': title,
+})
+
+
class NewPersonCommand(Command):
def run(self, args):
@@ -329,6 +356,10 @@ class JournalTool(cliapp.Application):
'''Publish a draft journal entry.'''
FinishCommand(self).run(args)
+ def cmd_new_topic(self, args):
+ '''Create a new topic page.'''
+ NewTopicCommand(self).run(args)
+
def cmd_new_person(self, args):
'''Create a page to list all notes referring to a person.
diff --git a/yarns/030-topics.yarn b/yarns/030-topics.yarn
index 86f9d9b..4595604 100644
--- a/yarns/030-topics.yarn
+++ b/yarns/030-topics.yarn
@@ -6,5 +6,5 @@ First we create a topic page:
SCENARIO create topic page
GIVEN an empty journal in SRC
- WHEN I run jt new-topic research/2014/dishwasher "Buy a dishwasher"
- THEN file SRC/research/2014/dishwasher.mdwn matches title="Buy a dishwasher"
+ WHEN I run jt new-topic research/2014/dishwasher Dishwasher
+ THEN file SRC/research/2014/dishwasher.mdwn matches title="Dishwasher"