summaryrefslogtreecommitdiff
path: root/htmtl/modifiers
diff options
context:
space:
mode:
authorAsko Nõmm <asko@nmm.ee>2025-01-02 01:30:23 +0200
committerAsko Nõmm <asko@nmm.ee>2025-01-02 01:30:23 +0200
commit689fe2613765de71101214a482c928cfdb1b2be6 (patch)
tree53ff6f9a092caee32e5c600bccf5ee546bd8bc20 /htmtl/modifiers
parent5e08a8b2f9258ae1f0aca7e3ad044b6360e07458 (diff)
Clean up some naming usages and things
Diffstat (limited to 'htmtl/modifiers')
-rw-r--r--htmtl/modifiers/__init__.py1
-rw-r--r--htmtl/modifiers/truncate.py16
2 files changed, 17 insertions, 0 deletions
diff --git a/htmtl/modifiers/__init__.py b/htmtl/modifiers/__init__.py
new file mode 100644
index 0000000..f200bbd
--- /dev/null
+++ b/htmtl/modifiers/__init__.py
@@ -0,0 +1 @@
+from .truncate import Truncate \ No newline at end of file
diff --git a/htmtl/modifiers/truncate.py b/htmtl/modifiers/truncate.py
new file mode 100644
index 0000000..bac2862
--- /dev/null
+++ b/htmtl/modifiers/truncate.py
@@ -0,0 +1,16 @@
+from typing import Any
+
+from ..modifier import Modifier, modifier_name
+
+
+@modifier_name("truncate")
+class Truncate(Modifier):
+ def modify(self, value: Any, opts: list[Any]) -> Any:
+ if isinstance(value, str) and len(opts) > 0:
+ if all([x in "1234567890" for x in opts[0]]):
+ char_limit = int(opts[0])
+
+ if len(value) > char_limit:
+ return f"{value[:char_limit - 3]}..."
+
+ return value