From 0cee9fd622a4c150953db27aac90820b8ea50771 Mon Sep 17 00:00:00 2001 From: Juan-Pablo Scaletti Date: Sat, 1 Apr 2023 22:47:01 -0500 Subject: [PATCH] Allow line jumps in props declarations --- pyproject.toml | 2 +- src/jinjax/component.py | 6 ++---- tests/test_component.py | 12 ++++++++++++ 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 4d1c7b1..a793343 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -5,7 +5,7 @@ build-backend = "poetry.core.masonry.api" [tool.poetry] name = "jinjax" -version = "0.22" +version = "0.23" description = "Replace your HTML templates with Python server-Side components" authors = ["Juan-Pablo Scaletti "] license = "MIT" diff --git a/src/jinjax/component.py b/src/jinjax/component.py index cb3d12f..28fc029 100644 --- a/src/jinjax/component.py +++ b/src/jinjax/component.py @@ -47,13 +47,11 @@ def __init__(self, *, name: str, source: str, url_prefix: str = "") -> None: self.load_metadata(source) def load_metadata(self, source: str) -> None: - # The metadata must be before anything else, so if it's present - # must be in the first three lines - header = source.lstrip().split("\n", maxsplit=3)[:3][::-1] + header = source.lstrip().split("#}", maxsplit=3)[:3][::-1] while header: line = header.pop() - line = line.strip() + line = line.strip() + "#}" if not (self.required or self.optional): expr = self.read_metadata_line(line, RX_PROPS_START) diff --git a/tests/test_component.py b/tests/test_component.py index 91a6f6a..3dab657 100644 --- a/tests/test_component.py +++ b/tests/test_component.py @@ -186,3 +186,15 @@ def test_ignore_repeated_js_declaration_and_everything_after(): assert com.optional == {} assert com.css == ["a.css"] assert com.js == ["a.js"] + + +def test_linejump_in_args_decl(): + com = Component( + name="Test.jinja", + source='{#def\n message,\n lorem=4,\n ipsum="bar"\n#}\n', + ) + assert com.required == ["message"] + assert com.optional == { + "lorem": 4, + "ipsum": "bar", + }