aboutsummaryrefslogtreecommitdiffstats
path: root/ste/README.md
diff options
context:
space:
mode:
authorjustanothercatgirl <sotov@twistea.su>2025-04-01 01:44:47 +0300
committerjustanothercatgirl <sotov@twistea.su>2025-04-01 01:44:47 +0300
commita5f1cb5ce34f31b9c46de94e55b5f85d571b792f (patch)
tree105116fd5b812124812c6658727b96814fa41b05 /ste/README.md
parent08b786a6770c172f433e28b0eb1e893f4fbae40a (diff)
Added stringbuilder and STE
Diffstat (limited to 'ste/README.md')
-rw-r--r--ste/README.md48
1 files changed, 48 insertions, 0 deletions
diff --git a/ste/README.md b/ste/README.md
new file mode 100644
index 0000000..680f9a4
--- /dev/null
+++ b/ste/README.md
@@ -0,0 +1,48 @@
+# Simple Template Engine for C
+The idea is stolen from [Tsoding](https://github.com/tsoding).
+
+This is a template engine for the C programming language.
+A really simple one, to be honset. To see how it works, it's best to just check
+out examples, but in a nutshell: initially, everything is a string. After `%`
+sign, it becomes C source code. basically, `%` sign acts as a flip-flop switch
+between C and text. All of the text is wrapped inside the `OUT` macro, which
+must be defined in the source code (name may be customized via command-line
+arguments). To use the code, `#include generated.c` in the middle of function
+where you need this template.
+
+# Example
+`main.c`:
+```c
+#define STRINGBUILDER_IMPLEMENTATION
+#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 OUT(str) jac_sb_append_buf(&sb, str)
+ #define INT(i) jac_sb_snprintf(&sb, "%i", i); /* Note the semicolon */
+ #include "tmpl.c"
+ #undef OUT
+ printf("%s\n", sb.data);
+ jac_sb_free(sb);
+ return 727;
+}
+```
+
+template file (`tmpl.c.ste`):
+```html
+<!DOCTYPE html>
+<html>
+ <body>
+ %
+ for (int i = 0; i < 10; ++i) {
+ %<p>This is paragraph number % INT(i) %</p>%
+ }
+ %
+ </body>
+</html>
+```
+
+Build: `cc ste.c -o ste && ste tmpl.c.ste && cc main.c -o main`
+
+<!--vim:tw=80-->