changeset 1023:226cfef3822e templating

integration mainline->templating
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 10 Jul 2014 11:42:32 +0200
parents 427a1f996b7b (diff) 211acef628a1 (current diff)
children a93867a94011
files CMakeLists.txt Resources/VisualStudio/stdint.h Resources/base64/base64.cpp Resources/base64/base64.h Resources/md5/md5.c Resources/md5/md5.h Resources/minizip/NOTES Resources/minizip/crypt.h Resources/minizip/ioapi.c Resources/minizip/ioapi.h Resources/minizip/zip.c Resources/minizip/zip.h UnitTestsSources/DicomMap.cpp UnitTestsSources/FileStorage.cpp UnitTestsSources/FromDcmtk.cpp UnitTestsSources/JpegLossless.cpp UnitTestsSources/Lua.cpp UnitTestsSources/MemoryCache.cpp UnitTestsSources/MultiThreading.cpp UnitTestsSources/Png.cpp UnitTestsSources/RestApi.cpp UnitTestsSources/SQLite.cpp UnitTestsSources/SQLiteChromium.cpp UnitTestsSources/Versions.cpp UnitTestsSources/Zip.cpp
diffstat 4 files changed, 151 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/CMakeLists.txt	Thu Jul 10 11:39:39 2014 +0200
+++ b/CMakeLists.txt	Thu Jul 10 11:42:32 2014 +0200
@@ -186,8 +186,8 @@
   UnitTestsSources/UnitTestsMain.cpp
   UnitTestsSources/ImageProcessingTests.cpp
   UnitTestsSources/JpegLosslessTests.cpp
-
   UnitTestsSources/PluginsTests.cpp
+  UnitTestsSources/Plustache.cpp
   )
 
 
@@ -218,6 +218,7 @@
 include(${CMAKE_SOURCE_DIR}/Resources/CMake/LibPngConfiguration.cmake)
 include(${CMAKE_SOURCE_DIR}/Resources/CMake/LuaConfiguration.cmake)
 include(${CMAKE_SOURCE_DIR}/Resources/CMake/LibCurlConfiguration.cmake)
+include(${CMAKE_SOURCE_DIR}/Resources/CMake/PlustacheConfiguration.cmake)
 
 
 if (${ENABLE_SSL})
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Resources/CMake/PlustacheConfiguration.cmake	Thu Jul 10 11:42:32 2014 +0200
@@ -0,0 +1,21 @@
+set(PLUSTACHE_SOURCES_DIR ${CMAKE_BINARY_DIR}/plustache-0.3.0)
+DownloadPackage(
+  "6162946bdb3dccf3b2185fcf149671ee"
+  "http://www.montefiore.ulg.ac.be/~jodogne/Orthanc/ThirdPartyDownloads/plustache-0.3.0.tar.gz"
+  "${PLUSTACHE_SOURCES_DIR}")
+
+list(APPEND THIRD_PARTY_SOURCES
+  ${PLUSTACHE_SOURCES_DIR}/src/context.cpp
+  ${PLUSTACHE_SOURCES_DIR}/src/template.cpp
+  )
+
+include_directories(
+  ${PLUSTACHE_SOURCES_DIR}
+  )
+
+execute_process(
+  COMMAND patch -p0 -i ${CMAKE_SOURCE_DIR}/Resources/CMake/PlustacheConfiguration.patch
+  WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
+  )
+
+source_group(ThirdParty\\Plustache REGULAR_EXPRESSION ${PLUSTACHE_SOURCES_DIR}/.*)
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Resources/CMake/PlustacheConfiguration.patch	Thu Jul 10 11:42:32 2014 +0200
@@ -0,0 +1,42 @@
+diff -r -u plustache-0.3.0.orig/include/template.hpp plustache-0.3.0/include/template.hpp
+--- plustache-0.3.0.orig/include/template.hpp	2014-01-29 13:26:52.000000000 +0100
++++ plustache-0.3.0/include/template.hpp	2014-05-28 17:51:51.623305914 +0200
+@@ -21,7 +21,7 @@
+     public:
+         template_t ();
+         template_t (std::string& tmpl_path);
+-        ~template_t ();
++        virtual ~template_t ();
+         std::string render(const std::string& tmplate, const Context& ctx);
+         std::string render(const std::string& tmplate, const ObjectType& ctx);
+ 
+@@ -42,11 +42,13 @@
+         std::string render_sections(const std::string& tmplate,
+                                     const Context& ctx);
+         std::string html_escape(const std::string& s);
+-        std::string get_partial(const std::string& partial) const;
+         void change_delimiter(const std::string& opentag,
+                               const std::string& closetag);
+         void compile_data();
+-        std::string get_template(const std::string& tmpl);
++
++    protected:
++        virtual std::string get_partial(const std::string& partial) const;
++        virtual std::string get_template(const std::string& tmpl);
+     };
+ } // namespace Plustache
+ #endif
+Only in plustache-0.3.0/include: template.hpp~
+diff -r -u plustache-0.3.0.orig/src/template.cpp plustache-0.3.0/src/template.cpp
+--- plustache-0.3.0.orig/src/template.cpp	2014-01-29 13:26:52.000000000 +0100
++++ plustache-0.3.0/src/template.cpp	2014-05-28 17:51:32.599306393 +0200
+@@ -126,7 +126,7 @@
+         // found a partial
+         else if (modifier == ">")
+         {
+-            std::string partial = template_t::get_partial(key);
++            std::string partial = get_partial(key);
+             repl.assign(template_t::render(partial, ctx));
+         }
+         // normal tag
+Only in plustache-0.3.0/src: template.cpp~
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/UnitTestsSources/Plustache.cpp	Thu Jul 10 11:42:32 2014 +0200
@@ -0,0 +1,86 @@
+#include "gtest/gtest.h"
+
+#include <include/template.hpp>
+
+
+class OrthancPlustache : public Plustache::template_t
+{
+public:
+protected:
+  virtual std::string get_template(const std::string& tmpl)
+  {
+    //printf("OK [%s]\n", tmpl.c_str());
+    return Plustache::template_t::get_template(tmpl);
+  }
+
+  virtual std::string get_partial(const std::string& partial) const
+  {
+    //printf("OK2 [%s]\n", partial.c_str());
+    //return Plustache::template_t::get_partial(partial);
+    return "<li>{{name}}</li>";
+  }
+};
+
+
+TEST(Plustache, Basic1)
+{
+  PlustacheTypes::ObjectType ctx;
+  ctx["title"] = "About";
+
+  OrthancPlustache t;
+  ASSERT_EQ("<h1>About</h1>", t.render("<h1>{{title}}</h1>", ctx));
+}
+
+
+TEST(Plustache, Basic2)
+{
+  Plustache::Context ctx;
+  ctx.add("title", "About");
+
+  OrthancPlustache t;
+  ASSERT_EQ("<h1>About</h1>", t.render("<h1>{{title}}</h1>", ctx));
+}
+
+
+TEST(Plustache, Context)
+{
+  PlustacheTypes::ObjectType a;
+  a["name"] = "Orthanc";
+
+  PlustacheTypes::ObjectType b;
+  b["name"] = "Jodogne";
+
+  PlustacheTypes::CollectionType c;
+  c.push_back(a);
+  c.push_back(b);
+
+  Plustache::Context ctx;
+  ctx.add("items", c);
+
+  OrthancPlustache t;
+  ASSERT_EQ("<ul><li>Orthanc</li><li>Jodogne</li></ul>",
+            t.render("<ul>{{#items}}<li>{{name}}</li>{{/items}}</ul>", ctx));
+}
+
+
+TEST(Plustache, Partials)
+{
+  PlustacheTypes::ObjectType a;
+  a["name"] = "Orthanc";
+
+  PlustacheTypes::ObjectType b;
+  b["name"] = "Jodogne";
+
+  PlustacheTypes::CollectionType c;
+  c.push_back(a);
+  c.push_back(b);
+
+  Plustache::Context ctx;
+  ctx.add("items", c);
+
+  OrthancPlustache t;
+  ASSERT_EQ("<ul><li>Orthanc</li><li>Jodogne</li></ul>",
+            t.render("<ul>{{#items}}{{>partial}}{{/items}}</ul>", ctx));
+}
+
+