From c7f9d5d42ec0852fe37411cab06e77109ee298e2 Mon Sep 17 00:00:00 2001 From: Christian Heller Date: Thu, 12 Feb 2026 18:56:15 +0100 Subject: [PATCH] Minor code-style improvements. --- src/ledgplom/ledger.py | 6 ++++-- src/templates/edit_structured.js | 20 +++++++++++--------- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/src/ledgplom/ledger.py b/src/ledgplom/ledger.py index faae074..6609d96 100644 --- a/src/ledgplom/ledger.py +++ b/src/ledgplom/ledger.py @@ -9,6 +9,7 @@ from typing import Any, Callable, Iterator, Optional, Self, Union SPACE = ' ' _INDENT_CHARS = {SPACE, '\t'} +_SEP_ACCNAME_STEPS = ':' SEP_COMMENTS = ';' _PREFIX_INSTRUCTION = '#' _ACC_MOD_INSTRUCTORS = {'description', 'balancer'} @@ -111,8 +112,9 @@ class _Account: def path_to_steps(full_path: str) -> Iterator[tuple[str, str]]: 'Split full_path into steps, for each return its path, basename.' rebuilt_path = '' - for step_name in full_path.split(':'): - rebuilt_path += (':' if rebuilt_path else '') + step_name + for step_name in full_path.split(_SEP_ACCNAME_STEPS): + rebuilt_path += ((_SEP_ACCNAME_STEPS if rebuilt_path else '') + + step_name) yield rebuilt_path, step_name diff --git a/src/templates/edit_structured.js b/src/templates/edit_structured.js index 1f16c90..44cbb3d 100644 --- a/src/templates/edit_structured.js +++ b/src/templates/edit_structured.js @@ -70,12 +70,14 @@ const LEN_EMPTY = 0, LEN_INDENT_INPUT_BALANCED = 4, LEN_INDENT_INPUT_DEFAULT = 2, + LEN_INDENT_INPUT_MINIMUM = 1, LEN_INTRO_LINE = 4, LEN_LEN_INDENT = 1, LEN_LINE_STEP = 1, LEN_STEP_INPUT_LEN_INDENT = 1, LEN_TARGET = 37, - MINIMUM_INPUT_LEN_INDENT = 1, + SEP_ACCNAME_STEPS = ":", + TOK_NONE = "None", accountBalancers = Object.assign( BALANCERS_DEFAULT, {{ account_balancers|tojson|safe }} @@ -85,7 +87,7 @@ const const newBookingLine = ( account = "", - amount = "None", + amount = TOK_NONE, currency = "", lenIndent = LEN_INDENT_INPUT_DEFAULT ) => ({ @@ -103,8 +105,8 @@ const taintAndUpdateForm = () => { }; const balance = (bookingLine) => { - let invertedAmount = "None"; - if (bookingLine.amount !== "None") { + let invertedAmount = TOK_NONE; + if (bookingLine.amount !== TOK_NONE) { invertedAmount = `-${bookingLine.amount}`; const doubleMinus = "--"; if (invertedAmount.startsWith(doubleMinus)) { @@ -112,9 +114,9 @@ const balance = (bookingLine) => { } } let balancer = ""; - const accNameSteps = bookingLine.account.split(":"); + const accNameSteps = bookingLine.account.split(SEP_ACCNAME_STEPS); while (balancer === "") { - balancer = accountBalancers[accNameSteps.join(":")]; + balancer = accountBalancers[accNameSteps.join(SEP_ACCNAME_STEPS)]; accNameSteps.pop(); } return newBookingLine( @@ -293,7 +295,7 @@ const updateForm = () => { LEN_LEN_INDENT ); indentInput.type = "number"; - indentInput.min = MINIMUM_INPUT_LEN_INDENT; + indentInput.min = LEN_INDENT_INPUT_MINIMUM; indentInput.step = LEN_STEP_INPUT_LEN_INDENT; const accInput = addTdInput( "account", @@ -308,7 +310,7 @@ const updateForm = () => { /* not using input[type=number] cuz no minimal step size, therefore regex test instead */ const amtInputVal = - bookingLine.amount === "None" ? "" : bookingLine.amount; + bookingLine.amount === TOK_NONE ? "" : bookingLine.amount; const amtInput = addTdInput( "amount", amtInputVal, @@ -423,7 +425,7 @@ const fillSink = () => { return; } const currency = bookingLine.currency || "€"; - if (bookingLine.amount === "None") { + if (bookingLine.amount === TOK_NONE) { if (sinkAccount === bookingLine.account || !sinkAccount) { if (!sinkAccount) { sinkAccount = bookingLine.account; -- 2.30.2