2 Commits f544f568c1 ... 574954d9d1

Author SHA1 Message Date
  221V 574954d9d1 templates -- mustache like erlydtl 1 week ago
  221V 808f905f9c make - compile in debug 1 week ago
7 changed files with 72 additions and 3 deletions
  1. 2 0
      README.md
  2. 4 1
      comp.mk
  3. 2 1
      vtest/dub.json
  4. 1 0
      vtest/dub.selections.json
  5. 6 0
      vtest/priv/folder2/part1.dtl
  6. 20 0
      vtest/priv/main.dtl
  7. 37 1
      vtest/source/app.d

+ 2 - 0
README.md

@@ -20,6 +20,8 @@ sudo apt-get install memcached
 // https://github.com/TiberiuGal/memcached4d/blob/master/source/app.d
 // https://github.com/221V/memcached4d  -- fixed but with vibe-d
 
+// https://github.com/repeatedly/mustache-d/blob/master/example/projects.d
+// https://code.dlang.org/packages/mustache-d
 
 
 

+ 4 - 1
comp.mk

@@ -3,6 +3,9 @@
 # todo clean
 
 c:
+	dub build --compiler ldc2
+
+c2:
 	dub build --compiler ldc2 --build release --force
 
 run:
@@ -12,5 +15,5 @@ run:
 
 default: run
 
-.PHONY: c run
+.PHONY: c c2 run
 

+ 2 - 1
vtest/dub.json

@@ -6,7 +6,8 @@
   "dflags": ["-w", "-O", "-static"],
   "targetType": "executable",
   "dependencies": {
-    "vibe-d": "~>0.9"
+    "vibe-d": "~>0.9",
+    "mustache-d": "~>0.1.5"
   },
   
   "license": "proprietary",

+ 1 - 0
vtest/dub.selections.json

@@ -4,6 +4,7 @@
 		"diet-ng": "1.8.4",
 		"eventcore": "0.9.35",
 		"mir-linux-kernel": "1.2.1",
+		"mustache-d": "0.1.5",
 		"openssl": "3.3.4",
 		"openssl-static": "1.0.5+3.0.8",
 		"stdx-allocator": "2.77.5",

+ 6 - 0
vtest/priv/folder2/part1.dtl

@@ -0,0 +1,6 @@
+
+<p>
+<span>test1</span><br>
+<span>test2</span><br>
+<span>{{param2}}test3</span><br>
+</p>

+ 20 - 0
vtest/priv/main.dtl

@@ -0,0 +1,20 @@
+<!DOCTYPE html>
+<html lang="{{lang}}">
+<head>
+<meta charset=utf-8>
+<title>Simple HTML5</title>
+</head>
+<body>
+
+{{{part1}}}
+
+<p>{{number1}}</p>
+
+{{#maybe1}}
+<p>777</p>
+{{/maybe1}}
+
+<p>{{result1}}</p>
+
+</body>
+</html>

+ 37 - 1
vtest/source/app.d

@@ -12,11 +12,15 @@ import vibe.core.log;
 
 import std.stdio;
 import std.string;
+//import std.array;
+
 
 import memcached4d;
 
 import std.conv : to;
 
+import mustache;
+alias MustacheEngine!(string) Mustache;
 
 
 
@@ -129,7 +133,39 @@ void test(HTTPServerRequest req, HTTPServerResponse res){
   
   writeln(cache.del("test1"));
   
-  res.writeBody("Hello, World!\n" ~ result);
+  
+  
+  Mustache mustache2;
+  auto context2 = new Mustache.Context;
+  mustache2.path = "priv/folder2";
+  mustache2.ext = "dtl";
+  
+  context2["param2"] = "blah blah blah ";
+  
+  Mustache mustache;
+  auto context = new Mustache.Context;
+  mustache.path = "priv";
+  mustache.ext = "dtl";
+  
+  //context.useSection("boolean");
+  //assert(mustache.renderString(" {{#boolean}}YES{{/boolean}}\n {{#boolean}}GOOD{{/boolean}}\n", context) == " YES\n GOOD\n");
+  
+  //{{#repo}}<b>{{name}}</b>{{/repo}}
+  //{{^repo}}No repos :({{/repo}}
+  //  to
+  //No repos :(
+  
+  context["lang"] = "en";
+  context["number1"] = 42;
+  context.useSection("maybe1");
+  
+  context["part1"] = mustache2.render("part1", context2);
+  context["result1"] = "Hello, World!\n" ~ result;
+  
+  res.headers["Content-Type"] = "text/html; charset=utf-8";
+  
+  //res.writeBody("Hello, World!\n" ~ result);
+  res.writeBody( mustache.render("main", context) );
 }