# plomlib
from plomlib.web import PlomHttpHandler, PlomHttpServer, PlomQueryMap
# ourselves
-from ledgplom.ledger import DEFAULT_INDENT, Ledger
+from ledgplom.ledger import Ledger
_PATH_TEMPLATES = Path('templates')
inputs = {key: self.postvars.first(f'line_{lineno}_{key}')
for key in input_names}
if 0 == lineno:
- code = f'{inputs["date"]} {inputs["target"]}'
+ code = inputs["date"] + ' ' + inputs["target"]
else:
- code = f'{DEFAULT_INDENT}{inputs["account"]} ' +\
- f'{inputs["amount"]} {inputs["currency"]}'
+ code = (' ' * int(inputs["len_indent"])
+ + inputs["account"] + ' ' * 2
+ + inputs["amount"] + ' ' + inputs["currency"])
new_lines += [f'{code} ; {inputs["comment"]}']
new_lines += self.postvars.first('raw_lines').splitlines()
new_id = self.server.ledger.rewrite_block(old_id, new_lines)
_INDENT_CHARS = {' ', '\t'}
_SEP_COMMENTS = ';'
_PREFIX_DEF = '#def '
-DEFAULT_INDENT = 2 * ' '
class _Wealth():
def __init__(self, text: str) -> None:
self._raw = text
- def _into_parts(self) -> tuple[str, str, str]:
+ def _into_parts(self) -> tuple[int, str, str]:
stage_count = 0
- indent = ''
+ len_indent = 0
code = ''
comment = ''
for c in self._raw:
if stage_count == 0:
if c in _INDENT_CHARS:
- indent += c
+ len_indent += 1
else:
stage_count += 1
if stage_count == 1:
stage_count += 1
if stage_count == 2:
comment += c
- return indent, code, comment
+ return len_indent, code, comment
@property
- def indent(self) -> str:
- 'All (maybe zero) the chars of whitespace line starts with.'
+ def len_indent(self) -> int:
+ 'Number (maybe zero) of chars of whitespace line starts with.'
return self._into_parts()[0]
@property
def errors(self) -> tuple[str, ...]:
errors = [f'{name} empty' for name in self._field_names
if not getattr(self, name)]
- if self.indent:
+ if self.len_indent:
errors += ['intro line indented']
try:
dt_date.fromisoformat(self.date)
class _TransferLine(_BookingLine):
'Non-first _Booking line, expected to carry value movement.'
- _field_names = {'account', 'amount', 'currency'}
+ _field_names = {'account', 'amount', 'currency', 'len_indent'}
@property
def account(self) -> str:
@property
def errors(self) -> tuple[str, ...]:
errors = []
- # if not self.indent:
+ # if not self.len_indent:
# errors += ['transfer line not indented']
if not self.account:
errors += ['account missing']
i_block: _DatBlock = cls()
blocks = []
for dat_line in (_DatLine(line) for line in lines):
- if (not dat_line.indent) and i_block.indented:
+ if (not dat_line.len_indent) and i_block.indented:
blocks += [i_block]
i_block.next = _DatBlock()
i_block = i_block.next
@property
def indented(self) -> bool:
'Does the block contain any indented lines?'
- return bool([line for line in self.lines if line.indent])
+ return bool([line for line in self.lines if line.len_indent])
@property
def gap_lines(self) -> tuple[_DatLine, ...]:
'Sequence of all included DatLines without code and indent.'
return tuple(line for line in self.lines
- if not line.indent + line.code)
+ if not (line.len_indent or line.code))
@property
def redundant_empty_lines(self) -> tuple[_DatLine, ...]:
def booking(self) -> Optional[_Booking]:
'Booking made from lines indented or with code.'
booking_lines = tuple(_DatLine(line.raw) for line in self.lines
- if line.indent or line.code)
+ if line.len_indent or line.code)
if not booking_lines:
return None
booking = _Booking()
],
"max-lines": [
"error",
- {"max": 355, "skipBlankLines": true, "skipComments": true}
+ {"max": 373, "skipBlankLines": true, "skipComments": true}
],
"max-lines-per-function": [
"error",
- 238
+ 249
],
"max-params": [
"error",
],
"max-statements": [
"error",
- 38
+ 42
],
"multiline-comment-style": [
"error",
} from "/taint.js";
const
+ DEFAULT_INPUT_LEN_INDENT = 2,
IDX_LAST = -1,
IDX_PAST_INTRO_LINE = 1,
IDX_START = 0,
LEN_CURRENCY = 3,
LEN_DATE = 10,
LEN_EMPTY = 0,
- LEN_INTRO_LINE = 3,
+ LEN_INTRO_LINE = 4,
+ LEN_LEN_INDENT = 1,
LEN_LINE_STEP = 0,
+ LEN_STEP_INPUT_LEN_INDENT = 1,
LEN_TARGET = 37,
+ MINIMUM_INPUT_LEN_INDENT = 1,
bookingLines = {{ booking_lines|tojson|safe }},
rawGapLines = {{ raw_gap_lines|tojson|safe }};
amount,
"comment": "",
currency,
- "errors": []
+ "errors": [],
+ "len_indent": DEFAULT_INPUT_LEN_INDENT
});
const taintAndUpdateForm = () => {
textarea = document.getElementById("gap_lines");
// empty and redo gapLines textarea, empty bookingLines table
- textarea.innerHTML = ""
+ textarea.innerHTML = "";
rawGapLines.forEach((line) => {
textarea.innerHTML += `${line}\n`;
});
td.appendChild(input);
input.name = `line_${idx}_${name}`;
input.size = size;
- input.setAttribute("value", value.trim());
+ input.setAttribute(
+ "value",
+ value.trim()
+ );
input.oninput = taint;
return input;
};
LEN_TARGET
);
} else {
+ const indentInput = addTdInput(
+ "len_indent",
+ `${bookingLine.len_indent}`,
+ LEN_LEN_INDENT
+ );
+ indentInput.type = "number";
+ indentInput.min = MINIMUM_INPUT_LEN_INDENT;
+ indentInput.step = LEN_STEP_INPUT_LEN_INDENT;
const accInput = addTdInput(
"account",
bookingLine.account,
<tr>
<td colspan="1">
</td>
- <td colspan="3">
+ <td colspan="4">
<input name="line_0_date" size="10" value="2001-01-01" id="date_input">
<input name="line_0_target" size="37" value="test">
</td>
<button type="button" disabled="">^</button>
<button type="button">v</button>
</td>
+ <td colspan="1">
+ <input name="line_1_len_indent" size="1" value="4" type="number" min="1" step="1">
+ </td>
<td colspan="1">
<input name="line_1_account" size="30" value="foo" list="all_accounts" autocomplete="off">
</td>
<button type="button">^</button>
<button type="button">v</button>
</td>
+ <td colspan="1">
+ <input name="line_2_len_indent" size="1" value="4" type="number" min="1" step="1">
+ </td>
<td colspan="1">
<input name="line_2_account" size="30" value="bar" list="all_accounts" autocomplete="off">
</td>
<tr>
<td colspan="1">
</td>
- <td colspan="3">
+ <td colspan="4">
<input name="line_0_date" size="10" value="2001-01-03" id="date_input">
<input name="line_0_target" size="37" value="test">
</td>
<button type="button" disabled="">^</button>
<button type="button">v</button>
</td>
+ <td colspan="1">
+ <input name="line_1_len_indent" size="1" value="4" type="number" min="1" step="1">
+ </td>
<td colspan="1">
<input name="line_1_account" size="30" value="foo:x" list="all_accounts" autocomplete="off">
</td>
<button type="button">^</button>
<button type="button">v</button>
</td>
+ <td colspan="1">
+ <input name="line_2_len_indent" size="1" value="4" type="number" min="1" step="1">
+ </td>
<td colspan="1">
<input name="line_2_account" size="30" value="foo:x" list="all_accounts" autocomplete="off">
</td>
<button type="button">^</button>
<button type="button">v</button>
</td>
+ <td colspan="1">
+ <input name="line_3_len_indent" size="1" value="4" type="number" min="1" step="1">
+ </td>
<td colspan="1">
<input name="line_3_account" size="30" value="bar:x:y" list="all_accounts" autocomplete="off">
</td>
<button type="button">^</button>
<button type="button">v</button>
</td>
+ <td colspan="1">
+ <input name="line_4_len_indent" size="1" value="4" type="number" min="1" step="1">
+ </td>
<td colspan="1">
<input name="line_4_account" size="30" value="bar:z" list="all_accounts" autocomplete="off">
</td>
<tr>
<td colspan="1">
</td>
- <td colspan="3">
+ <td colspan="4">
<input name="line_0_date" size="10" value="2001-01-03" id="date_input">
<input name="line_0_target" size="37" value="test">
</td>
<button type="button" disabled="">^</button>
<button type="button">v</button>
</td>
+ <td colspan="1">
+ <input name="line_1_len_indent" size="1" value="4" type="number" min="1" step="1">
+ </td>
<td colspan="1">
<input name="line_1_account" size="30" value="foo:x" list="all_accounts" autocomplete="off">
</td>
<button type="button">^</button>
<button type="button">v</button>
</td>
+ <td colspan="1">
+ <input name="line_2_len_indent" size="1" value="4" type="number" min="1" step="1">
+ </td>
<td colspan="1">
<input name="line_2_account" size="30" value="foo:x" list="all_accounts" autocomplete="off">
</td>
<button type="button">^</button>
<button type="button">v</button>
</td>
+ <td colspan="1">
+ <input name="line_3_len_indent" size="1" value="4" type="number" min="1" step="1">
+ </td>
<td colspan="1">
<input name="line_3_account" size="30" value="bar:x:y" list="all_accounts" autocomplete="off">
</td>
<button type="button">^</button>
<button type="button">v</button>
</td>
+ <td colspan="1">
+ <input name="line_4_len_indent" size="1" value="4" type="number" min="1" step="1">
+ </td>
<td colspan="1">
<input name="line_4_account" size="30" value="bar:z" list="all_accounts" autocomplete="off">
</td>