aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRaghuram Subramani <raghus2247@gmail.com>2025-08-29 14:10:14 -0400
committerRaghuram Subramani <raghus2247@gmail.com>2025-08-29 14:10:14 -0400
commitd9e9613782af1f0d224d73d61f48bb02ad20032f (patch)
tree11d10b1d03298810b72c1c6e76ca0bba853104ea
parent2d045681d02f981bd610dad0eec7e43ad7fc9f9f (diff)
engine: don't handle page source only if a template is being parsed
-rw-r--r--include/engine.h3
-rw-r--r--src/engine/eachdo.c2
-rw-r--r--src/engine/engine.c13
-rw-r--r--src/msg.c2
-rw-r--r--src/template.c21
5 files changed, 21 insertions, 20 deletions
diff --git a/include/engine.h b/include/engine.h
index ab08e7a..5da3332 100644
--- a/include/engine.h
+++ b/include/engine.h
@@ -22,6 +22,7 @@
#include <config.h>
#include <lexer.h>
#include <list.h>
+#include <stdbool.h>
/*
* Simply just there to return content headers and config.
@@ -42,7 +43,7 @@ typedef struct {
int priority;
} atom_t;
-engine_t *engine_ingest(char **buffer);
+engine_t *engine_ingest(char **buffer, bool is_template);
void engine_delete(engine_t *engine);
void handle_include(char **buffer, key_match_t *match, directive_t *directive);
diff --git a/src/engine/eachdo.c b/src/engine/eachdo.c
index 0aba13e..2d3ec4c 100644
--- a/src/engine/eachdo.c
+++ b/src/engine/eachdo.c
@@ -190,7 +190,7 @@ handle_eachdo(char **buffer, key_match_t *match, directive_t *directive)
{
eachdo_operands_t *operands = directive->operands;
- engine_t *engine = engine_ingest(&operands->content);
+ engine_t *engine = engine_ingest(&operands->content, false);
engine_delete(engine);
list_t *directives = lex(operands->content);
diff --git a/src/engine/engine.c b/src/engine/engine.c
index a4606c2..683d39b 100644
--- a/src/engine/engine.c
+++ b/src/engine/engine.c
@@ -43,7 +43,7 @@ extern msg_t *msg;
* It's only there to define the end of the EACHDO content block.
*/
engine_t *
-engine_ingest(char **buffer)
+engine_ingest(char **buffer, bool is_template)
{
engine_t *engine = malloc(sizeof(engine_t));
engine->config = NULL;
@@ -103,14 +103,13 @@ engine_ingest(char **buffer)
break;
case EACHDO: {
eachdo_operands_t *operands = directive->operands;
- /* TODO: Don't handle page source only if a template is currently
- * being parsed */
- if (!strcmp(operands->source, "page")) {
+ /* Don't handle page source only if a template is currently being
+ * parsed */
+ if (is_template && !strcmp(operands->source, "page"))
skip++;
- break;
- }
+ else
+ handle_eachdo(buffer, match, directive);
- handle_eachdo(buffer, match, directive);
break;
}
diff --git a/src/msg.c b/src/msg.c
index 84f6dde..7bdc295 100644
--- a/src/msg.c
+++ b/src/msg.c
@@ -121,7 +121,7 @@ handle_file(const char *path)
if (engine.config != NULL)
config_delete(engine.config);
} else if (strlen(buffer) != 0) {
- engine_t *engine = engine_ingest(&buffer);
+ engine_t *engine = engine_ingest(&buffer, false);
template_write(engine, out, buffer, false);
engine_delete(engine);
}
diff --git a/src/template.c b/src/template.c
index d325621..c228ffe 100644
--- a/src/template.c
+++ b/src/template.c
@@ -116,7 +116,7 @@ template_create(char *template_name)
char *buffer = fcontent(base, size);
fclose(base);
- engine_t *engine = engine_ingest(&buffer);
+ engine_t *engine = engine_ingest(&buffer, true);
engine_delete(engine);
template->components = lex(buffer);
@@ -198,17 +198,18 @@ template_write(engine_t *engine, FILE *f, void *doc, bool is_markdown)
case EACHDO: {
eachdo_operands_t *operands = directive->operands;
- if (!strcmp(operands->source, "page")) {
- list_t *atoms = list_create(sizeof(ptr_wrapper_t));
- list_t *directives = lex(operands->content);
+ /* must be a page loop, since resources are handled in
+ * engine_ingest() */
+ // if (!strcmp(operands->source, "page"))
- handle_page_source(
- atoms, operands, directives, engine->config);
+ list_t *atoms = list_create(sizeof(ptr_wrapper_t));
+ list_t *directives = lex(operands->content);
- for (size_t i = 0; i < atoms->size; i++) {
- atom_t *atom = list_get(atoms, i);
- fprintf(f, "%s", atom->content);
- }
+ handle_page_source(atoms, operands, directives, engine->config);
+
+ for (size_t i = 0; i < atoms->size; i++) {
+ atom_t *atom = list_get(atoms, i);
+ fprintf(f, "%s", atom->content);
}
}