aboutsummaryrefslogtreecommitdiff
path: root/src/engine
diff options
context:
space:
mode:
Diffstat (limited to 'src/engine')
-rw-r--r--src/engine/eachdo.c34
-rw-r--r--src/engine/engine.c11
2 files changed, 37 insertions, 8 deletions
diff --git a/src/engine/eachdo.c b/src/engine/eachdo.c
index d503256..0aba13e 100644
--- a/src/engine/eachdo.c
+++ b/src/engine/eachdo.c
@@ -153,10 +153,33 @@ handle_file_source(list_t *atoms,
list_delete(files);
}
+void
+handle_page_source(list_t *atoms,
+ eachdo_operands_t *operands,
+ list_t *directives,
+ config_t *config)
+{
+ list_t *nested_blocks
+ = unwrap(list_find_corresponding_value_from_ptr_wrapper(
+ config->keys, config->nested_config_values, trim(operands->key)));
+
+ if (nested_blocks == NULL) {
+ printf("Could not find nested block %s\n", trim(operands->key));
+ return;
+ }
+
+ for (size_t i = 0; i < nested_blocks->size; i++) {
+ config_t *config = unwrap(list_get(nested_blocks, i));
+
+ write_eachdo_iteration(
+ atoms, directives, config->keys, config->values, 0);
+ }
+}
+
/*
- * Handles EACHDO calls. Given a pointer to the buffer, it replaces the EACHDO
- * call along with its content block and ENDEACHDO call with the fetched
- * content.
+ * Handles EACHDO calls. Given a pointer to the buffer, it replaces the
+ * EACHDO call along with its content block and ENDEACHDO call with the
+ * fetched content.
*
* buffer: Pointer to the buffer that is modified
* match: Pointer to the key match
@@ -177,11 +200,8 @@ handle_eachdo(char **buffer, key_match_t *match, directive_t *directive)
if (!strcmp(operands->source, "resources"))
handle_file_source(atoms, operands, directives);
- else {
+ else
printf("Unknown source: %s\n", operands->source);
- /* TODO: handle this gracefully */
- return;
- }
/* Sort atoms by priority */
qsort(atoms->elements, atoms->size, sizeof(atom_t), comp);
diff --git a/src/engine/engine.c b/src/engine/engine.c
index 0b41c42..7edac19 100644
--- a/src/engine/engine.c
+++ b/src/engine/engine.c
@@ -101,9 +101,18 @@ engine_ingest(char **buffer)
handle_contentfor(
buffer, match, directive, engine->content_headers);
break;
- case EACHDO:
+ 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")) {
+ skip++;
+ break;
+ }
+
handle_eachdo(buffer, match, directive);
break;
+ }
case PUTPAGE:
/* TODO: handle */