aboutsummaryrefslogtreecommitdiffstats
path: root/ste/example
diff options
context:
space:
mode:
Diffstat (limited to 'ste/example')
-rw-r--r--ste/example/Makefile14
-rw-r--r--ste/example/main.c15
-rw-r--r--ste/example/tmpl.c.ste11
3 files changed, 40 insertions, 0 deletions
diff --git a/ste/example/Makefile b/ste/example/Makefile
new file mode 100644
index 0000000..f8a6ef4
--- /dev/null
+++ b/ste/example/Makefile
@@ -0,0 +1,14 @@
+
+.SUFFIXES:
+
+all: main
+
+ste: ../ste.c
+ $(CC) -o $@ $<
+
+%.c: %.c.ste ste
+ ./ste -m OUTPUT $<
+
+main: main.c tmpl.c
+ $(CC) -o $@ $<
+
diff --git a/ste/example/main.c b/ste/example/main.c
new file mode 100644
index 0000000..18850d9
--- /dev/null
+++ b/ste/example/main.c
@@ -0,0 +1,15 @@
+#define STRINGBUILDER_IMPLEMENTATION
+#include "../../include/stringbuilder.h" /* refer to [c_headers](https://git.twistea.su/c_headers) */
+#include <stdio.h>
+
+int main(void) {
+ jac_sb sb = jac_sb_empty();
+ #define OUTPUT(str) jac_sb_append_buf(&sb, str)
+ #define INTEGER(i) jac_sb_snprintf(&sb, "%i", i); /* Note the semicolon */
+ # include "tmpl.c"
+ #undef OUTPUT
+ #undef INTEGER
+ printf("%s\n", sb.data);
+ jac_sb_free(sb);
+ return 727;
+}
diff --git a/ste/example/tmpl.c.ste b/ste/example/tmpl.c.ste
new file mode 100644
index 0000000..7f486cd
--- /dev/null
+++ b/ste/example/tmpl.c.ste
@@ -0,0 +1,11 @@
+<!DOCTYPE html>
+<html>
+ <body>
+ %
+ for (int i = 0; i < 10; ++i) {
+ %<p>This is paragraph number % INTEGER(i) %</p>%
+ }
+ %
+ </body>
+</html>
+