home · contact · privacy
Minor code-style improvements. master
authorChristian Heller <c.heller@plomlompom.de>
Thu, 12 Feb 2026 17:56:15 +0000 (18:56 +0100)
committerChristian Heller <c.heller@plomlompom.de>
Thu, 12 Feb 2026 17:56:15 +0000 (18:56 +0100)
src/ledgplom/ledger.py
src/templates/edit_structured.js

index faae0744dc257b0897efa701f0e52ec2354a5bf6..6609d9614700a2b2be8457ed47caee4e3cb9bc5c 100644 (file)
@@ -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
 
 
index 1f16c90430a8ad231e386dd1b218cf29f45cd45b..44cbb3d234fa405c61191a9f945da384452338c4 100644 (file)
@@ -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;