diff --git a/Makefile b/Makefile index 6514ba8..6823b2b 100644 --- a/Makefile +++ b/Makefile @@ -40,9 +40,16 @@ gen/lex.yy.c: src/scanner.l gen/y.tab.h gen $(LEX) $< mv lex.yy.c gen/ +demo: demofiles/demo.c gen/demo.tab.c $(A_LIB) + $(CC) $(CFLAGS) -o $@ $^ + +gen/demo.tab.c: demofiles/demo.html.templ $(BIN) gen + # change dir to set template name + cd demofiles && ../$(BIN) demo.html.templ > ../$@ clean: rm -f gen/* rm -f obj/* rm -f $(BIN) rm -f $(A_LIB) + rm -f demo diff --git a/demofiles/demo.c b/demofiles/demo.c new file mode 100644 index 0000000..5ba8cb9 --- /dev/null +++ b/demofiles/demo.c @@ -0,0 +1,15 @@ +#include <stdio.h> + +#include <templates.h> + +int main() { + char *names[] = { + "foo", + "bar", + "foobar" + }; + + findTemplate("demo.html.templ")(stdout, "User-List", names, 3); + + return 0; +} diff --git a/demofiles/demo.html.templ b/demofiles/demo.html.templ new file mode 100644 index 0000000..3cd017f --- /dev/null +++ b/demofiles/demo.html.templ @@ -0,0 +1,16 @@ +{$ char* title, char** names, size_t no $} + +%% +<!DOCTYPE html> +<html> + <head> + <title> + {{ "%s", title }} + </title> + </head> + <body> + {% for(size_t i = 0; i < no; i++) %} + {{ "%s", names[i] }}<br /> + {% end %} + </body> +</html> diff --git a/src/main.c b/src/main.c index f6901f5..2c371c3 100644 --- a/src/main.c +++ b/src/main.c @@ -20,6 +20,7 @@ const char* filename; void generateHeader() { fprintf(output, "#include <stdio.h>\n"); + fprintf(output, "#include <stdlib.h>\n"); fprintf(output, "#include <stdarg.h>\n"); fprintf(output, "\n"); fprintf(output, "#include <templates.h>\n");