mirror of
https://github.com/jrnl-org/jrnl.git
synced 2025-05-18 20:18:32 +02:00
Convert "short" and "pretty" (and "default") formaters to plugins
further to https://github.com/jrnl-org/jrnl/pull/1177
This commit is contained in:
parent
e1d2f873da
commit
1fd04ad03d
5 changed files with 85 additions and 30 deletions
|
@ -146,6 +146,17 @@ Some implementation notes:
|
||||||
*jrnl* will call **export_entry()** on each entry in turn and then
|
*jrnl* will call **export_entry()** on each entry in turn and then
|
||||||
concatenate the results together.
|
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
|
## Development Tips
|
||||||
|
|
||||||
- editable installs (`pip install -e ...`) don't seem to play nice with
|
- editable installs (`pip install -e ...`) don't seem to play nice with
|
||||||
|
|
|
@ -10,18 +10,21 @@ Feature: Functionality of Importer and Exporter Plugins
|
||||||
|
|
||||||
Examples:
|
Examples:
|
||||||
| plugin_name | version | source | type | filename |
|
| plugin_name | version | source | type | filename |
|
||||||
| jrnl | v.2.8.1 | plugins | importer | jrnl |
|
| jrnl | v2.8.1 | plugins | importer | jrnl |
|
||||||
| boxed | v.2.8.1 | plugins | exporter | fancy |
|
| boxed | v2.8.1 | plugins | exporter | fancy |
|
||||||
| dates | v.2.8.1 | plugins | exporter | dates |
|
| dates | v2.8.1 | plugins | exporter | dates |
|
||||||
| fancy | v.2.8.1 | plugins | exporter | fancy |
|
| default | v2.8.1 | plugins | exporter | pretty |
|
||||||
| json | v.2.8.1 | plugins | exporter | json |
|
| fancy | v2.8.1 | plugins | exporter | fancy |
|
||||||
| markdown | v.2.8.1 | plugins | exporter | markdown |
|
| json | v2.8.1 | plugins | exporter | json |
|
||||||
| md | v.2.8.1 | plugins | exporter | markdown |
|
| markdown | v2.8.1 | plugins | exporter | markdown |
|
||||||
| tags | v.2.8.1 | plugins | exporter | tag |
|
| md | v2.8.1 | plugins | exporter | markdown |
|
||||||
| text | v.2.8.1 | plugins | exporter | text |
|
| pretty | v2.8.1 | plugins | exporter | pretty |
|
||||||
| txt | v.2.8.1 | plugins | exporter | text |
|
| short | v2.8.1 | plugins | exporter | short |
|
||||||
| xml | v.2.8.1 | plugins | exporter | xml |
|
| tags | v2.8.1 | plugins | exporter | tag |
|
||||||
| yaml | v.2.8.1 | plugins | exporter | yaml |
|
| 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
|
@skip_only_with_external_plugins
|
||||||
Scenario Outline: List external plugin names in --version
|
Scenario Outline: List external plugin names in --version
|
||||||
|
@ -31,21 +34,24 @@ Feature: Functionality of Importer and Exporter Plugins
|
||||||
And The output should contain "<plugin_name> : <version> from jrnl.<source>.<type>.<filename>"
|
And The output should contain "<plugin_name> : <version> from jrnl.<source>.<type>.<filename>"
|
||||||
Examples:
|
Examples:
|
||||||
| plugin_name | version | source | type | filename |
|
| 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 |
|
| json | v1.0.0 | contrib | importer | json |
|
||||||
| boxed | v.2.8.1 | plugins | exporter | fancy |
|
| boxed | v2.8.1 | plugins | exporter | fancy |
|
||||||
| dates | v.2.8.1 | plugins | exporter | dates |
|
| dates | v2.8.1 | plugins | exporter | dates |
|
||||||
| fancy | v.2.8.1 | plugins | exporter | fancy |
|
| default | v2.8.1 | plugins | exporter | pretty |
|
||||||
|
| fancy | v2.8.1 | plugins | exporter | fancy |
|
||||||
| json | v1.0.0 | contrib | exporter | json |
|
| json | v1.0.0 | contrib | exporter | json |
|
||||||
| markdown | v.2.8.1 | plugins | exporter | markdown |
|
| markdown | v2.8.1 | plugins | exporter | markdown |
|
||||||
| md | v.2.8.1 | plugins | exporter | markdown |
|
| md | v2.8.1 | plugins | exporter | markdown |
|
||||||
| tags | v.2.8.1 | plugins | exporter | tag |
|
| pretty | v2.8.1 | plugins | exporter | pretty |
|
||||||
| 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 |
|
|
||||||
| rot13 | v1.0.0 | contrib | exporter | rot13 |
|
| 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 |
|
| 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
|
@skip_only_with_external_plugins
|
||||||
Scenario Outline: Do not list overridden plugin names in --version
|
Scenario Outline: Do not list overridden plugin names in --version
|
||||||
|
@ -56,5 +62,5 @@ Feature: Functionality of Importer and Exporter Plugins
|
||||||
|
|
||||||
Examples:
|
Examples:
|
||||||
| plugin_name | version | source | type | filename |
|
| plugin_name | version | source | type | filename |
|
||||||
| json | v.2.8.1 | plugins | exporter | json |
|
| json | v2.8.1 | plugins | exporter | json |
|
||||||
| txt | v.2.8.1 | plugins | exporter | text |
|
| txt | v2.8.1 | plugins | exporter | text |
|
||||||
|
|
|
@ -324,10 +324,7 @@ def _delete_search_results(journal, old_entries, **kwargs):
|
||||||
|
|
||||||
def _display_search_results(args, journal, **kwargs):
|
def _display_search_results(args, journal, **kwargs):
|
||||||
if args.short or args.export == "short":
|
if args.short or args.export == "short":
|
||||||
print(journal.pprint(short=True))
|
print(plugins.meta.get_exporter("short").export(journal))
|
||||||
|
|
||||||
elif args.export == "pretty":
|
|
||||||
print(journal.pprint())
|
|
||||||
|
|
||||||
elif args.tags:
|
elif args.tags:
|
||||||
print(plugins.meta.get_exporter("tags").export(journal))
|
print(plugins.meta.get_exporter("tags").export(journal))
|
||||||
|
@ -339,4 +336,5 @@ def _display_search_results(args, journal, **kwargs):
|
||||||
exporter = plugins.meta.get_exporter(kwargs["config"]["display_format"])
|
exporter = plugins.meta.get_exporter(kwargs["config"]["display_format"])
|
||||||
print(exporter.export(journal, args.filename))
|
print(exporter.export(journal, args.filename))
|
||||||
else:
|
else:
|
||||||
print(journal.pprint())
|
# print(journal.pprint())
|
||||||
|
print(plugins.meta.get_exporter("default").export(journal))
|
||||||
|
|
20
jrnl/plugins/exporter/pretty.py
Normal file
20
jrnl/plugins/exporter/pretty.py
Normal file
|
@ -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
jrnl/plugins/exporter/short.py
Normal file
20
jrnl/plugins/exporter/short.py
Normal file
|
@ -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)
|
Loading…
Add table
Reference in a new issue