diff options
author | Lars Wirzenius <liw@liw.fi> | 2017-11-22 15:16:50 +0200 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2017-11-22 15:16:50 +0200 |
commit | db3e6834c6c01b00a6ef7cbfc03c25edc732b695 (patch) | |
tree | 44c6ad8b6620c652568f1b9d159ec97719ead693 /jtlib | |
parent | 339049495dd8a82cc2d5058e805144e244bc7d72 (diff) | |
download | jt-db3e6834c6c01b00a6ef7cbfc03c25edc732b695.tar.gz |
Refactor: move layout specific parts to their own classes
Diffstat (limited to 'jtlib')
-rw-r--r-- | jtlib/__init__.py | 1 | ||||
-rw-r--r-- | jtlib/app.py | 12 | ||||
-rw-r--r-- | jtlib/plugins/finish_plugin.py | 6 | ||||
-rw-r--r-- | jtlib/plugins/new_plugin.py | 1 |
4 files changed, 15 insertions, 5 deletions
diff --git a/jtlib/__init__.py b/jtlib/__init__.py index 42df5bb..de66966 100644 --- a/jtlib/__init__.py +++ b/jtlib/__init__.py @@ -19,6 +19,7 @@ from .version import __version__ from .draftsdir import DraftsDirectory from .git import commit_to_git, pull_rebase_git, push_git +from .layout import PkbLayout, CtLayout from .app import JournalTool __all__ = locals() diff --git a/jtlib/app.py b/jtlib/app.py index 81fda8b..760b9a4 100644 --- a/jtlib/app.py +++ b/jtlib/app.py @@ -91,8 +91,20 @@ class JournalTool(cliapp.Application): self.settings['pretend-time'], '%Y-%m-%d %H:%M:%S') else: self.now_tuple = time.localtime() + self.layout = self.create_layout() cliapp.Application.process_args(self, args) + def create_layout(self): + layouts = { + 'pkb': jtlib.PkbLayout(), + 'ct': jtlib.CtLayout(), + } + + layout = layouts[self.settings['layout']] + layout.set_settings(self.settings) + layout.set_time_tuple(self.now_tuple) + return layout + def merge_profile(self): profile = self.settings['profile'] if profile: diff --git a/jtlib/plugins/finish_plugin.py b/jtlib/plugins/finish_plugin.py index c05f88e..1336ea0 100644 --- a/jtlib/plugins/finish_plugin.py +++ b/jtlib/plugins/finish_plugin.py @@ -40,10 +40,8 @@ class FinishCommand(cliapp.Plugin): if not title: raise Exception("%s has no title" % draft_mdwn) - pub_attch = os.path.join( - self._published_dir(), - self._published_basename(title, draft_mdwn),) - pub_mdwn = pub_attch + '.mdwn' + pub_attch = self.app.layout.get_filename(title) + pub_mdwn = self.app.layout.get_filename(title) + '.mdwn' if os.path.exists(pub_mdwn): raise cliapp.AppException('%s already exists' % pub_mdwn) diff --git a/jtlib/plugins/new_plugin.py b/jtlib/plugins/new_plugin.py index d704242..25facf8 100644 --- a/jtlib/plugins/new_plugin.py +++ b/jtlib/plugins/new_plugin.py @@ -52,7 +52,6 @@ class NewCommand(cliapp.Plugin): raise cliapp.AppException('Usage: journal-note new TITLE') self.app.settings.require('source') - self.app.settings.require('layout') topic = self.app.settings['topic'] if topic and not self._topic_page_exists(topic): raise cliapp.AppException('Topic %s does not exist yet' % topic) |