Skip to content

Commit

Permalink
Convert "short" and "pretty" (and "default") formaters to plugins
Browse files Browse the repository at this point in the history
further to jrnl-org#1177
  • Loading branch information
MinchinWeb committed May 9, 2021
1 parent e1d2f87 commit 1fd04ad
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 30 deletions.
11 changes: 11 additions & 0 deletions docs/plugins.md
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,17 @@ Some implementation notes:
*jrnl* will call **export_entry()** on each entry in turn and then
concatenate the results together.

### Special Exporters

There are a few "special" exporters, in that they are called by *jrnl* in
situations other than a traditional export. They are:

- **short** -- called by `jrnl --short`. Displays each entry on a single line.
The default is to print the timestamp of the entry, followed by the title.
The built-in (default) plugin is at `jrnl.plugins.exporter.short`.
- **default** -- called when a different format is not specified. The built-in
(default) plugin is at `jrnl.plugins.exporter.pretty`.

## Development Tips

- editable installs (`pip install -e ...`) don't seem to play nice with
Expand Down
56 changes: 31 additions & 25 deletions features/plugins.feature
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,21 @@ Feature: Functionality of Importer and Exporter Plugins

Examples:
| plugin_name | version | source | type | filename |
| jrnl | v.2.8.1 | plugins | importer | jrnl |
| boxed | v.2.8.1 | plugins | exporter | fancy |
| dates | v.2.8.1 | plugins | exporter | dates |
| fancy | v.2.8.1 | plugins | exporter | fancy |
| json | v.2.8.1 | plugins | exporter | json |
| markdown | v.2.8.1 | plugins | exporter | markdown |
| md | v.2.8.1 | plugins | exporter | markdown |
| tags | v.2.8.1 | plugins | exporter | tag |
| text | v.2.8.1 | plugins | exporter | text |
| txt | v.2.8.1 | plugins | exporter | text |
| xml | v.2.8.1 | plugins | exporter | xml |
| yaml | v.2.8.1 | plugins | exporter | yaml |
| jrnl | v2.8.1 | plugins | importer | jrnl |
| boxed | v2.8.1 | plugins | exporter | fancy |
| dates | v2.8.1 | plugins | exporter | dates |
| default | v2.8.1 | plugins | exporter | pretty |
| fancy | v2.8.1 | plugins | exporter | fancy |
| json | v2.8.1 | plugins | exporter | json |
| markdown | v2.8.1 | plugins | exporter | markdown |
| md | v2.8.1 | plugins | exporter | markdown |
| pretty | v2.8.1 | plugins | exporter | pretty |
| short | v2.8.1 | plugins | exporter | short |
| tags | v2.8.1 | plugins | exporter | tag |
| text | v2.8.1 | plugins | exporter | text |
| txt | v2.8.1 | plugins | exporter | text |
| xml | v2.8.1 | plugins | exporter | xml |
| yaml | v2.8.1 | plugins | exporter | yaml |

@skip_only_with_external_plugins
Scenario Outline: List external plugin names in --version
Expand All @@ -31,21 +34,24 @@ Feature: Functionality of Importer and Exporter Plugins
And The output should contain "<plugin_name> : <version> from jrnl.<source>.<type>.<filename>"
Examples:
| plugin_name | version | source | type | filename |
| jrnl | v.2.8.1 | plugins | importer | jrnl |
| jrnl | v2.8.1 | plugins | importer | jrnl |
| json | v1.0.0 | contrib | importer | json |
| boxed | v.2.8.1 | plugins | exporter | fancy |
| dates | v.2.8.1 | plugins | exporter | dates |
| fancy | v.2.8.1 | plugins | exporter | fancy |
| boxed | v2.8.1 | plugins | exporter | fancy |
| dates | v2.8.1 | plugins | exporter | dates |
| default | v2.8.1 | plugins | exporter | pretty |
| fancy | v2.8.1 | plugins | exporter | fancy |
| json | v1.0.0 | contrib | exporter | json |
| markdown | v.2.8.1 | plugins | exporter | markdown |
| md | v.2.8.1 | plugins | exporter | markdown |
| tags | v.2.8.1 | plugins | exporter | tag |
| text | v.2.8.1 | plugins | exporter | text |
| txt | v1.0.0 | contrib | exporter | rot13 |
| xml | v.2.8.1 | plugins | exporter | xml |
| yaml | v.2.8.1 | plugins | exporter | yaml |
| markdown | v2.8.1 | plugins | exporter | markdown |
| md | v2.8.1 | plugins | exporter | markdown |
| pretty | v2.8.1 | plugins | exporter | pretty |
| rot13 | v1.0.0 | contrib | exporter | rot13 |
| short | v2.8.1 | plugins | exporter | short |
| tags | v2.8.1 | plugins | exporter | tag |
| testing | v0.0.1 | contrib | exporter | testing |
| text | v2.8.1 | plugins | exporter | text |
| txt | v1.0.0 | contrib | exporter | rot13 |
| xml | v2.8.1 | plugins | exporter | xml |
| yaml | v2.8.1 | plugins | exporter | yaml |

@skip_only_with_external_plugins
Scenario Outline: Do not list overridden plugin names in --version
Expand All @@ -56,5 +62,5 @@ Feature: Functionality of Importer and Exporter Plugins

Examples:
| plugin_name | version | source | type | filename |
| json | v.2.8.1 | plugins | exporter | json |
| txt | v.2.8.1 | plugins | exporter | text |
| json | v2.8.1 | plugins | exporter | json |
| txt | v2.8.1 | plugins | exporter | text |
8 changes: 3 additions & 5 deletions jrnl/jrnl.py
Original file line number Diff line number Diff line change
Expand Up @@ -324,10 +324,7 @@ def _delete_search_results(journal, old_entries, **kwargs):

def _display_search_results(args, journal, **kwargs):
if args.short or args.export == "short":
print(journal.pprint(short=True))

elif args.export == "pretty":
print(journal.pprint())
print(plugins.meta.get_exporter("short").export(journal))

elif args.tags:
print(plugins.meta.get_exporter("tags").export(journal))
Expand All @@ -339,4 +336,5 @@ def _display_search_results(args, journal, **kwargs):
exporter = plugins.meta.get_exporter(kwargs["config"]["display_format"])
print(exporter.export(journal, args.filename))
else:
print(journal.pprint())
# print(journal.pprint())
print(plugins.meta.get_exporter("default").export(journal))
20 changes: 20 additions & 0 deletions jrnl/plugins/exporter/pretty.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/usr/bin/env python
# encoding: utf-8
# Copyright (C) 2012-2021 jrnl contributors
# License: https://www.gnu.org/licenses/gpl-3.0.html

from jrnl.plugins.base import BaseExporter

from ... import __version__


class Exporter(BaseExporter):
"""Pretty print journal"""

names = ["pretty", "default"]
extension = "txt"
version = __version__

@classmethod
def export_journal(cls, journal):
return journal.pprint()
20 changes: 20 additions & 0 deletions jrnl/plugins/exporter/short.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/usr/bin/env python
# encoding: utf-8
# Copyright (C) 2012-2021 jrnl contributors
# License: https://www.gnu.org/licenses/gpl-3.0.html

from jrnl.plugins.base import BaseExporter

from ... import __version__


class Exporter(BaseExporter):
"""Short export -- i.e. single line date and title"""

names = ["short"]
extension = "txt"
version = __version__

@classmethod
def export_journal(cls, journal):
return journal.pprint(short=True)

0 comments on commit 1fd04ad

Please sign in to comment.