feat: add include functionality to support modular template composition
Implement the `include` directive that allows embedding external template files into the current template at render time. This enables code reuse and separation of concerns by letting templates import shared components like headers, footers, or partials. The feature parses include statements, resolves file paths relative to the template root, and recursively renders the included content within the parent template's variable scope.
This commit is contained in:
@@ -16,7 +16,8 @@ SOURCES = $(SRC_DIR)/main.c \
|
||||
$(SRC_DIR)/parser.c \
|
||||
$(SRC_DIR)/interpreter.c \
|
||||
$(SRC_DIR)/native_functions.c \
|
||||
$(SRC_DIR)/string_utils.c
|
||||
$(SRC_DIR)/string_utils.c \
|
||||
$(SRC_DIR)/preprocessor.c
|
||||
|
||||
OBJECTS = $(SOURCES:$(SRC_DIR)/%.c=$(BUILD_DIR)/%.o)
|
||||
|
||||
@@ -36,7 +37,9 @@ TESTS = $(TEST_DIR)/feature_test.rc \
|
||||
$(TEST_DIR)/comparison_test.rc \
|
||||
$(TEST_DIR)/functions_test.rc \
|
||||
$(TEST_DIR)/trig_test.rc \
|
||||
$(TEST_DIR)/file_seek_test.rc
|
||||
$(TEST_DIR)/file_seek_test.rc \
|
||||
$(TEST_DIR)/include_test.rc \
|
||||
$(TEST_DIR)/nested_include_test.rc
|
||||
|
||||
EXAMPLES = $(EXAMPLE_DIR)/http_simple.rc \
|
||||
$(EXAMPLE_DIR)/http_persistent.rc \
|
||||
@@ -113,6 +116,12 @@ test: $(TARGET)
|
||||
@echo "Running file seek tests..."
|
||||
@$(TARGET) $(TEST_DIR)/file_seek_test.rc 2>&1 | grep -v "Error at token" || true
|
||||
@echo ""
|
||||
@echo "Running include tests..."
|
||||
@$(TARGET) $(TEST_DIR)/include_test.rc 2>&1 | grep -v "Error at token" || true
|
||||
@echo ""
|
||||
@echo "Running nested include tests..."
|
||||
@$(TARGET) $(TEST_DIR)/nested_include_test.rc 2>&1 | grep -v "Error at token" || true
|
||||
@echo ""
|
||||
@echo "=== All Tests Completed ==="
|
||||
|
||||
run-feature-test: $(TARGET)
|
||||
@@ -166,6 +175,12 @@ run-trig-test: $(TARGET)
|
||||
run-file-seek-test: $(TARGET)
|
||||
$(TARGET) $(TEST_DIR)/file_seek_test.rc
|
||||
|
||||
run-include-test: $(TARGET)
|
||||
$(TARGET) $(TEST_DIR)/include_test.rc
|
||||
|
||||
run-nested-include-test: $(TARGET)
|
||||
$(TARGET) $(TEST_DIR)/nested_include_test.rc
|
||||
|
||||
run-http-simple: $(TARGET)
|
||||
$(TARGET) $(EXAMPLE_DIR)/http_simple.rc
|
||||
|
||||
@@ -204,6 +219,8 @@ help:
|
||||
@echo " make run-functions-test - Run functions_test.rc (function calls & recursion)"
|
||||
@echo " make run-trig-test - Run trig_test.rc (sin, cos, tan)"
|
||||
@echo " make run-file-seek-test - Run file_seek_test.rc (fseek, ftell)"
|
||||
@echo " make run-include-test - Run include_test.rc (#include directive)"
|
||||
@echo " make run-nested-include-test - Run nested_include_test.rc (nested includes)"
|
||||
@echo ""
|
||||
@echo "Examples:"
|
||||
@echo " make run-http-simple - Run http_simple.rc (single connection HTTP server)"
|
||||
|
||||
Reference in New Issue
Block a user