From a9bdef939d057763d5b0e643dd5dfd01ee8907f4 Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Sat, 22 Nov 2014 19:52:38 +0200 Subject: Add preliminary scenario for topics --- yarns/030-topics.yarn | 10 ++++++++++ yarns/900-implementations.yarn | 2 +- 2 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 yarns/030-topics.yarn diff --git a/yarns/030-topics.yarn b/yarns/030-topics.yarn new file mode 100644 index 0000000..86f9d9b --- /dev/null +++ b/yarns/030-topics.yarn @@ -0,0 +1,10 @@ +Using Topics +============ + +A topic is implemented as a wiki page to which journal entries link. +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" diff --git a/yarns/900-implementations.yarn b/yarns/900-implementations.yarn index a2e149f..561b096 100644 --- a/yarns/900-implementations.yarn +++ b/yarns/900-implementations.yarn @@ -91,5 +91,5 @@ Checking file contents Does a file match a regular expression? - IMPLEMENTS THEN file (\S+) matches (\S+) + IMPLEMENTS THEN file (\S+) matches (.+)$ grep -e "$MATCH_2" "$DATADIR/$MATCH_1" -- cgit v1.2.1 From 282e41cc67741a1bf0ed04a3549d1608e9c10d68 Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Sat, 22 Nov 2014 20:02:34 +0200 Subject: Implement new-topic command --- jt | 31 +++++++++++++++++++++++++++++++ yarns/030-topics.yarn | 4 ++-- 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" -- cgit v1.2.1 From 39055e208b1fcb6fc3e5c975f4b529fe6c051c67 Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Sat, 22 Nov 2014 20:02:59 +0200 Subject: Invoke editor on new topic page --- jt | 1 + 1 file changed, 1 insertion(+) diff --git a/jt b/jt index 72fcedb..6ce9ffc 100755 --- a/jt +++ b/jt @@ -244,6 +244,7 @@ class NewTopicCommand(Command): pathname = self._topic_pathname(args[0]) self._create_topic_page(pathname, args[1]) + self._app.edit_file(pathname) def _topic_pathname(self, page_path): return os.path.join(self._app.settings['source'], page_path + '.mdwn') -- cgit v1.2.1 From c8d40b889cd8f4d5c92c42f51ed555c38591dffe Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Sat, 22 Nov 2014 20:10:25 +0200 Subject: Add test for and implement using topic pages --- jt | 17 ++++++++++++++++- yarns/030-topics.yarn | 9 ++++++++- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/jt b/jt index 6ce9ffc..22f05a6 100755 --- a/jt +++ b/jt @@ -36,6 +36,8 @@ template = '''\ [[!tag ]] [[!meta date="%(date)s"]] +%(topiclink)s + ''' @@ -115,10 +117,12 @@ class NewCommand(Command): raise cliapp.AppException('Usage: journal-note new TITLE') self._app.settings.require('source') + topic = self._app.settings['topic'] values = { 'title': args[0], - 'date': time.strftime('%Y-%m-%d %H:%M') + 'date': time.strftime('%Y-%m-%d %H:%M'), + 'topiclink': self._get_topic_link(topic), } drafts_dir = DraftsDirectory(self._app.drafts_dir()) @@ -126,6 +130,12 @@ class NewCommand(Command): draft_id = drafts_dir.create_draft(template % values) self._app.edit_file(drafts_dir.get_draft_pathname(draft_id)) + def _get_topic_link(self, topic): + if topic: + return 'Part of [[%s]]' % topic + else: + return '' + class ListCommand(Command): @@ -328,6 +338,11 @@ class JournalTool(cliapp.Application): ['push'], 'push finished articles with git?') + self.settings.string( + ['topic'], + 'new entry belongs to TOPIC', + metavar='TOPIC') + self.settings.string( ['pretend-time'], 'pretend that the time is NOW (form: YYYY-MM-DD HH:MM:DD form)', diff --git a/yarns/030-topics.yarn b/yarns/030-topics.yarn index 4595604..e931ae3 100644 --- a/yarns/030-topics.yarn +++ b/yarns/030-topics.yarn @@ -4,7 +4,14 @@ Using Topics A topic is implemented as a wiki page to which journal entries link. First we create a topic page: - SCENARIO create topic page + SCENARIO create and use topic page GIVEN an empty journal in SRC WHEN I run jt new-topic research/2014/dishwasher Dishwasher THEN file SRC/research/2014/dishwasher.mdwn matches title="Dishwasher" + +After this, we can create a new journal entry that belongs to the +topic. + + GIVEN the time is 2014-11-20 20:04:08 + WHEN I run jt new --topic=research/2014/dishwasher TITLE + THEN file SRC/drafts/0.mdwn matches research/2014/dishwasher -- cgit v1.2.1