diff --git a/CODE.rst b/CODE.rst index 10d90337653ab0088402d4f58efe65c8cded0a48..75327523374bf9a99b05900b4e0185ee155b3bee 100644 --- a/CODE.rst +++ b/CODE.rst @@ -51,7 +51,13 @@ Hooks make arbitrary transformations to entry data dicts. Every entry data dict Initializes the hook with the user's configuration. ``run(entry_data)`` - This method makes the hook's transformations to the entry data dict, if any. If this method sets ``entry_data['_hook_cancel']`` to a truthy value, that entry will not be output. + This method can make arbitrary transformations to the entry data, or filter it so it isn't output. + + If this method returns ``None``, processing the entry data continues normally. Most hooks should do this, and just transform entry data in place. + + If this method returns ``False``, processing the entry data stops immediately. The entry will not appear in the program output. + + If this method returns any other value, the program replaces the entry data with the return value, and continues processing. Templates ~~~~~~~~~ @@ -86,9 +92,14 @@ At a high level, import2ledger handles each input file this way:: input_file.seek(0) for entry_data in importer_class(input_file): for hook in all_hooks: - hook.run(entry_data) - if entry_data: - template.render(entry_data) + hook_return = hook.run(entry_data) + if hook_return is False: + break + elif hook_return is not None: + entry_data = hook_return + else: + if entry_data: + template.render(entry_data) Note in particular that multiple importers can handle the same input file. This helps support inputs like Patreon's earnings CSV, where completely different transactions are generated from the same source.