implement PrettyExporter

This commit is contained in:
Suhas 2021-02-01 21:12:13 -05:00
parent 2f25e5cd12
commit 927530c057
3 changed files with 18 additions and 4 deletions

View file

@ -10,7 +10,7 @@ from .markdown_exporter import MarkdownExporter
from .tag_exporter import TagExporter
from .dates_exporter import DatesExporter
from .template_exporter import __all__ as template_exporters
from .text_exporter import TextExporter
from .text_exporter import TextExporter, PrettyExporter
from .xml_exporter import XMLExporter
from .yaml_exporter import YAMLExporter
@ -23,6 +23,7 @@ __exporters = [
XMLExporter,
YAMLExporter,
FancyExporter,
PrettyExporter
] + template_exporters
__importers = [JRNLImporter]

View file

@ -9,7 +9,7 @@ import unicodedata
from jrnl.color import ERROR_COLOR
from jrnl.color import RESET_COLOR
from jrnl.Entry import Entry
class TextExporter:
"""This Exporter can convert entries and journals into text files."""
@ -77,3 +77,10 @@ class TextExporter:
return cls.write_file(journal, output)
else:
return cls.export_journal(journal)
class PrettyExporter(TextExporter):
names = ["pretty"]
@classmethod
def export_entry(cls, entry: Entry):
return entry.pprint()

View file

@ -116,8 +116,14 @@ def test_not_interspersed():
assert cli_as_dict("two -not one two -not three two") == result
def test_export_alone():
assert cli_as_dict("--export json") == expected_args(export="json")
@pytest.mark.parametrize(
"export_formats",
[
"fancy","pretty","json","markdown","xml","txt"
]
)
def test_export_alone(export_formats):
assert cli_as_dict("--export %s"%export_formats) == expected_args(export=export_formats)
def test_import_alone():