[pkg-d-commits] [mustache-d] 01/04: New upstream version 0.1.3

Matthias Klumpp mak at moszumanska.debian.org
Fri Jan 20 21:06:30 UTC 2017


This is an automated email from the git hooks/post-receive script.

mak pushed a commit to branch master
in repository mustache-d.

commit 769694c27cfd2f14b191b6e970be4da6f8449768
Author: Matthias Klumpp <mak at debian.org>
Date:   Fri Jan 20 21:55:36 2017 +0100

    New upstream version 0.1.3
---
 .gitignore         |  9 +++++++++
 .travis.yml        | 10 +++-------
 README.markdown    |  4 ++++
 example/projects.d |  6 +++---
 meson.build        | 26 ++++++++++++++++++++++++++
 posix.mak          |  2 +-
 src/mustache.d     | 53 +++++++++++++++++++++++++++++++++++++++++++++++++----
 7 files changed, 95 insertions(+), 15 deletions(-)

diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..4d0fd94
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,9 @@
+*.[oa]
+*.so
+*.lib
+*.dll
+*.exe
+
+.dub/
+__test__*__
+dub.selections.json
diff --git a/.travis.yml b/.travis.yml
index eebbb1a..42c87ed 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -1,13 +1,9 @@
 language: d
 
 d:
-  - dmd-2.067.0
-  - dmd-2.066.1
-
-install:
-
-script:
-  - MODEL=64 make -f posix.mak unittest
+  - dmd
+  - gdc
+  - ldc
 
 branches:
   only:
diff --git a/README.markdown b/README.markdown
index d9c17bf..f5c7c42 100644
--- a/README.markdown
+++ b/README.markdown
@@ -36,6 +36,10 @@ File extenstion of Mustache template. Default is "mustache".
 
 root path to read Mustache template. Default is "."(current directory).
 
+* findPath(string delegate(string))
+
+callback to dynamically find the path do a Mustache template. Default is none. Mutually exclusive with the `path` option.
+
 * level(CacheLevel)
 
 Cache level for Mustache's in-memory cache. Default is "check". See DDoc.
diff --git a/example/projects.d b/example/projects.d
index 3a70da9..42e5f56 100644
--- a/example/projects.d
+++ b/example/projects.d
@@ -11,9 +11,9 @@ struct Project
 }
 
 static Project[] projects = [
-    Project("dmd", "https://github.com/D-Programming-Language/dmd", "dmd D Programming Language compiler"),
-    Project("druntime", "https://github.com/D-Programming-Language/druntime", "Low level runtime library for the D programming language"),
-    Project("phobos", "https://github.com/D-Programming-Language/phobos", "Runtime library for the D programming language")
+    Project("dmd", "https://github.com/dlang/dmd", "dmd D Programming Language compiler"),
+    Project("druntime", "https://github.com/dlang/druntime", "Low level runtime library for the D programming language"),
+    Project("phobos", "https://github.com/dlang/phobos", "The standard library of the D programming language")
 ];
 
 void main()
diff --git a/meson.build b/meson.build
new file mode 100644
index 0000000..7825f0c
--- /dev/null
+++ b/meson.build
@@ -0,0 +1,26 @@
+project('mustache-d', 'd')
+
+project_version      = '0.1.1'
+project_soversion    = '0'
+
+src_dir = include_directories('src/')
+pkgc = import('pkgconfig')
+
+mustache_src = [
+    'src/mustache.d'
+]
+install_headers(mustache_src, subdir: 'd/mustache-d')
+
+mustache_lib = static_library('mustache-d',
+        [mustache_src],
+        include_directories: [src_dir],
+        install: true,
+        version: project_version,
+        soversion: project_soversion
+)
+pkgc.generate(name: 'mustache-d',
+              libraries: mustache_lib,
+              subdirs: 'd/mustache-d',
+              version: project_version,
+              description: 'Mustache template engine for D.'
+)
diff --git a/posix.mak b/posix.mak
index a5e997e..486fddf 100644
--- a/posix.mak
+++ b/posix.mak
@@ -4,7 +4,7 @@ MODEL ?= $(shell getconf LONG_BIT)
 DMD ?= dmd
 
 LIB    = libmustache.a
-DFLAGS = -Isrc -m$(MODEL) -w -d -property
+DFLAGS = -Isrc -m$(MODEL) -w -d #-property
 
 ifeq ($(BUILD),debug)
 	DFLAGS += -g -debug
diff --git a/src/mustache.d b/src/mustache.d
index f0593de..ccd630c 100644
--- a/src/mustache.d
+++ b/src/mustache.d
@@ -77,6 +77,7 @@ struct MustacheEngine(String = string) if (isSomeString!(String))
 
   public:
     alias String delegate(String) Handler;
+    alias string delegate(string) FindPath;
 
 
     /**
@@ -97,6 +98,7 @@ struct MustacheEngine(String = string) if (isSomeString!(String))
     {
         string     ext   = "mustache";        /// template file extenstion
         string     path  = ".";               /// root path for template file searching
+        FindPath   findPath;                  /// dynamically finds the path for a name
         CacheLevel level = CacheLevel.check;  /// See CacheLevel
         Handler    handler;                   /// Callback handler for unknown name
     }
@@ -166,7 +168,7 @@ struct MustacheEngine(String = string) if (isSomeString!(String))
                 Context[]               list;
             }
 
-            @safe nothrow
+            @trusted nothrow
             {
                 this(bool u)
                 {
@@ -553,6 +555,22 @@ struct MustacheEngine(String = string) if (isSomeString!(String))
         }
 
         /**
+         * Property for callback to dynamically search path.
+         * The result of the delegate should return the full path for
+         * the given name.
+         */
+        FindPath findPath() const
+        {
+            return option_.findPath;
+        }
+
+        /// ditto
+        void findPath(FindPath findPath)
+        {
+            option_.findPath = findPath;
+        }
+
+        /**
          * Property for cache level
          */
         const(CacheLevel) level() const
@@ -632,7 +650,12 @@ struct MustacheEngine(String = string) if (isSomeString!(String))
             return cast(String)read(file);
         }
 
-        string file = buildPath(option_.path, name ~ "." ~ option_.ext);
+        string file;
+        if (option_.findPath) {
+            file = option_.findPath(name);
+        } else {
+            file = buildPath(option_.path, name ~ "." ~ option_.ext);
+        }
         Node[] nodes;
 
         final switch (option_.level) {
@@ -1295,7 +1318,7 @@ struct MustacheEngine(String = string) if (isSomeString!(String))
             }
         }
 
-        @safe nothrow
+        @trusted nothrow
         {
             /**
              * Constructs with arguments.
@@ -1373,7 +1396,7 @@ struct MustacheEngine(String = string) if (isSomeString!(String))
             nodes ~= section;
         }
 
-        assert(to!string(nodes) == `[[T : "Hi "], [V : "name"], [P : "redbull"], `
+        assert(to!string(nodes) == `[[T : "Hi "], [V : "name"], [P : "redbull"], ` ~
                                    `[S : "ritsu", [ [T : "Ritsu is "] [E : "attr"] ], ""]]`);
     }
 }
@@ -1416,3 +1439,25 @@ unittest
         assert(mustache.render("unittest", context) == "Modified");
     }
 }
+
+unittest
+{
+    alias Mustache = MustacheEngine!(string);
+
+    std.file.write("unittest.mustache", "{{>name}}");
+    scope(exit) std.file.remove("unittest.mustache");
+    std.file.write("other.mustache", "Ok");
+    scope(exit) std.file.remove("other.mustache");
+
+    Mustache mustache;
+    auto context = new Mustache.Context;
+    mustache.findPath((path) {
+        if (path == "name") {
+            return "other." ~ mustache.ext;
+        } else {
+            return path ~ "." ~ mustache.ext;
+        }
+    });
+
+    assert(mustache.render("unittest", context) == "Ok");
+}

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-d/mustache-d.git



More information about the pkg-d-commits mailing list