Renderer
elva.renderer
Module holding renderer components.
Classes:
-
TextRenderer–Component rendering Y text data types to text files.
Attributes:
-
TextRendererState–The states of the
TextRenderercomponent.
TextRendererState = create_component_state('TextRendererState', ('SAVED',))
module-attribute
The states of the TextRenderer component.
TextRenderer(crdt, path, auto_save=True, timeout=300)
Bases: Component
Component rendering Y text data types to text files.
Parameters:
-
crdt(Text | Array | Map | XmlFragment | XmlElement | XmlText) –instance of a Y CRDT.
-
path(str) –the filepath to write content to.
-
auto_save(bool, default:True) –flag whether to write repeatedly and on cleanup (
True) or not (False). -
timeout(int, default:300) –the time in seconds between two consecutive periodic writes.
Methods:
-
set_auto_save–Set the auto save flag.
-
before–Hook run after the component adds the
ACTIVEstate and before it adds theRUNNINGstate. -
run–Hook run after the component adds the
RUNNINGstate. -
cleanup–Hook after the component has been cancelled.
-
write–Render the contents of
crdtto file. -
get_content–Logic for manipulating the content of the given Y CRDT.
-
confirm–Hook called on cleanup when
auto_saveis off.
Attributes:
-
crdt(Text) –Instance of a Y text data type.
-
path(Path) –Path where to store the rendered text file.
-
timeout(int) –the time seconds between two consecutive periodic writes.
-
states(TextRendererState) –The states this component can have.
-
auto_save(bool) –Flag whether to write repeatedly and on cleanup (
True) or not (False).
Source code in src/elva/renderer.py
_auto_save_scope
instance-attribute
(while auto saving) Scope of the auto save loop.
crdt = crdt
instance-attribute
Instance of a Y text data type.
path = Path(path)
instance-attribute
Path where to store the rendered text file.
_auto_save = auto_save
instance-attribute
Flag whether to render to text file on hook execution.
timeout = timeout
instance-attribute
the time seconds between two consecutive periodic writes.
states
property
The states this component can have.
auto_save
property
Flag whether to write repeatedly and on cleanup (True) or not (False).
set_auto_save(auto_save)
async
Set the auto save flag.
This method is idempotent, i.e. it does not change the state when
setting auto_save to the current value.
Parameters:
-
auto_save(bool) –flag whether to write repeatedly and on cleanup (
True) or not (False).
Source code in src/elva/renderer.py
_run_auto_save(task_status=TASK_STATUS_IGNORED)
async
Hook running the write loop in a dedicated cancel scope
Source code in src/elva/renderer.py
_on_crdt_event(event)
Hook called on a CRDT event.
It compares hashes of the current and the saved content and manages the SAVED state accordingly.
It does not write to file.
Parameters:
-
event(TextEvent | ArrayEvent | MapEvent | XmlEvent) –object holding update information.
Source code in src/elva/renderer.py
before()
async
Hook run after the component adds the ACTIVE state and before it adds the RUNNING state.
run()
async
Hook run after the component adds the RUNNING state.
The contents of self.crdt get rendered to file if auto_save is True.
Source code in src/elva/renderer.py
cleanup()
async
Hook after the component has been cancelled.
The contents of self.crdt get rendered to file if auto_save is True.
Source code in src/elva/renderer.py
write()
async
Render the contents of crdt to file.
Source code in src/elva/renderer.py
get_content()
Logic for manipulating the content of the given Y CRDT. The returned string will be written to file.
Overwrite this method to run custom content manipulation.
By default, it calls str(self.crdt).
Source code in src/elva/renderer.py
confirm()
async
Hook called on cleanup when auto_save is off.
Overwrite this method to run custom confirmation logic.
By default, it returns False.