aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDanny van Kooten <dannyvankooten@users.noreply.github.com>2020-03-15 21:30:17 +0100
committerDanny van Kooten <dannyvankooten@users.noreply.github.com>2020-03-15 21:30:17 +0100
commit9cd1d0d6bea1336f57b6411d1c09abe892156623 (patch)
tree202950ac72425b4db0b9f24cf556776d9764d080
parent8fcc38ce404f16b2809a73de7bdf778bb84becb4 (diff)
downloadunja-9cd1d0d6bea1336f57b6411d1c09abe892156623.tar.gz
unja-9cd1d0d6bea1336f57b6411d1c09abe892156623.zip
add readme
-rw-r--r--Makefile13
-rw-r--r--README.md26
-rw-r--r--index.tpl20
-rw-r--r--src/hyde.c35
-rw-r--r--src/template.c2
5 files changed, 33 insertions, 63 deletions
diff --git a/Makefile b/Makefile
index b5fca94..79fd0e6 100644
--- a/Makefile
+++ b/Makefile
@@ -1,14 +1,13 @@
-override CFLAGS+= -g -Wall -std=c11 -I.
-LIBS=
+CFLAGS= -g -Wall -std=c99 -I.
+LDLIBS=
TESTFLAGS= $(CFLAGS) -Isrc/
+ifdef debug
+ CFLAGS+=-DDEBUG
+endif
-all: bin/hyde
-
+all: check
bin:; mkdir -p bin/
-bin/hyde: src/hyde.c src/hashmap.c src/template.c src/vector.c vendor/mpc.c | bin
- $(CC) $(CFLAGS) $^ -o $@
-
bin/test_hashmap: src/hashmap.c tests/test_hashmap.c | bin
$(CC) $(TESTFLAGS) $^ -o $@
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..7ebfba3
--- /dev/null
+++ b/README.md
@@ -0,0 +1,26 @@
+Unja
+=====
+
+Unja is (an attempt at) a template engine for C, inspired by Jinja and Liquid.
+
+This is nowhere near being stable right now.
+
+### Example
+
+```
+{% extends "base.html" %}
+
+{% block title %}Members{% endblock %}
+
+{% block content %}
+ <ul>
+ {% for user in users %}
+ <li><a href="{{ user.url }}">{{ user.username }}</a></li>
+ {% endfor %}
+ </ul>
+{% endblock %}
+```
+
+### License
+
+Unlicensed (to be decided). \ No newline at end of file
diff --git a/index.tpl b/index.tpl
deleted file mode 100644
index 940f61b..0000000
--- a/index.tpl
+++ /dev/null
@@ -1,20 +0,0 @@
-# List of titles
-- {{ title }}
-- {{title}}
-- {{ title}}
-- {{title }}
-
-# Dot notation
-{{ home.title }}
-
-# For block
-{% for p in posts %}
- - {{ p.title }}
-
- (
- {% for t in p.tags %}
- {{ t }},
- {% endfor %}
- )
-{% endfor %}
-
diff --git a/src/hyde.c b/src/hyde.c
deleted file mode 100644
index 350a518..0000000
--- a/src/hyde.c
+++ /dev/null
@@ -1,35 +0,0 @@
-#include "template.h"
-#include <stdio.h>
-#include <stdlib.h>
-
-struct post {
- char title[64];
- char tags[8][32];
-};
-
-int main() {
- char *input = read_file("index.tpl");
-
- struct hashmap *ctx = hashmap_new();
- hashmap_insert(ctx, "title", "Hello world");
-
- struct post home = {
- .title = "Homepage",
- .tags = {
- "Tag 1", "Tag 2"
- }
- };
- hashmap_insert(ctx, "home", &home);
-
- struct post posts[] = {
- { .title = "Post 1", .tags = { "p1t1" } },
- { .title = "Post 2", .tags = { "p2t1" } },
- };
- hashmap_insert(ctx, "posts", &posts);
-
- char *output = template(input, ctx);
- printf("Output: %s\n", output);
- hashmap_free(ctx);
- free(input);
- free(output);
-} \ No newline at end of file
diff --git a/src/template.c b/src/template.c
index 15ce246..85db75a 100644
--- a/src/template.c
+++ b/src/template.c
@@ -70,7 +70,7 @@ int eval(char *dest, mpc_ast_t* t, struct hashmap *ctx) {
dest = trim_trailing_whitespace(dest);
}
- // set flag for next eval() to trim leading whitespace from text
+ /* set flag for next eval() to trim leading whitespace from text */
if (strstr(t->children[3]->contents, "-")) {
trim_whitespace = 1;
}