This commit is contained in:
2025-05-21 20:00:02 +00:00
parent 3b7c4d71e7
commit 70253c9a3a
3 changed files with 11 additions and 28 deletions

View File

@@ -988,21 +988,6 @@ template_parse(MemoryContext context, const char **s, const TemplateConfig *conf
/* Choose the tag parser based on the matched type */
if (matched_type == 1) {
/*
FIXME(yukkop): This writen as shit coz I strupid monkey
Now it, probably, make many excesive actions.
Steps to prase, for future rework:
1. if `control` tag, then remove all this line from result
1. remove whitespaces before (in previous node if it is text node)
2. remove whitespaces after until \n (in section body before parse it to nodes)
3. remove \n (as previous step)
2. if `end` tag, then remove all this line from result
1. remove whitespaces before (in last body node if it is text node)
2. remove whitespaces after until \n (skip it before parse next nodes)
3. remove \n (also skip)
3. render sections body
*/
/* Section tag */
elog(LOG, "TPE: Parsing section tag at position: %.50s", *s);
@@ -1010,8 +995,6 @@ template_parse(MemoryContext context, const char **s, const TemplateConfig *conf
bool is_end_on_own_line = false,
is_control_on_own_line = is_tag_on_own_line(start, *s, config);
elog(LOG, "TPE: is_control_on_own_line: %s", is_control_on_own_line ? "true" : "false");
if (is_control_on_own_line && current && current->type == TEMPLATE_NODE_TEXT && current->value->text.content) {
/* Find the last newline in the text node */
char *content = current->value->text.content;
@@ -1024,8 +1007,6 @@ template_parse(MemoryContext context, const char **s, const TemplateConfig *conf
}
}
elog(LOG, "TPE: Last newline: %zu", last_newline);
/* If we found a newline, trim everything after it */
if (last_newline > 0) {
content[last_newline+1] = '\0';
@@ -1035,15 +1016,15 @@ template_parse(MemoryContext context, const char **s, const TemplateConfig *conf
/* Parse the section tag */
tag_node = template_parse_section(context, s, config, error_code, is_control_on_own_line, &is_end_on_own_line);
elog(LOG, "TPE: is_end_on_own_line: %s", is_end_on_own_line ? "true" : "false");
if (is_end_on_own_line) {
/* Remove the end tag from the result */
while (**s != '\n') {
/* Skip the end tag line */
while (**s && **s != '\n') {
(*s)++;
}
if (**s == '\n') {
(*s)++;
}
}
} else if (matched_type == 2) {
/* Include tag */
elog(LOG, "TPE: Parsing include tag at position: %.50s", *s);

View File

@@ -34,5 +34,5 @@ BEGIN;
\ir test_render_interpolate.sql
\ir test_render_section.sql
\ir test_render_include.sql
\ir test_render_all.sql
--\ir test_render_all.sql
ROLLBACK;

View File

@@ -217,7 +217,8 @@ BEGIN
);
expected := ' item
item
item';
item
';
IF test_result = expected THEN
RAISE NOTICE 'Test %: Section whitespaces 2: PASSED', total_tests;
passed_tests := passed_tests + 1;
@@ -238,7 +239,8 @@ BEGIN
);
expected := ' item
item
item';
item
';
IF test_result = expected THEN
RAISE NOTICE 'Test %: Section whitespaces 3: PASSED', total_tests;
passed_tests := passed_tests + 1;