# HG changeset patch # User Sebastien Jodogne # Date 1404986003 -7200 # Node ID a93867a94011a15727a28283d69939fe6dfb1c82 # Parent 226cfef3822e54e3cc5ead964629815db9f104c6 smoother integration of plustache diff -r 226cfef3822e -r a93867a94011 CMakeLists.txt --- a/CMakeLists.txt Thu Jul 10 11:42:32 2014 +0200 +++ b/CMakeLists.txt Thu Jul 10 11:53:23 2014 +0200 @@ -21,6 +21,9 @@ SET(ENABLE_JPEG ON CACHE BOOL "Enable JPEG decompression") SET(ENABLE_JPEG_LOSSLESS ON CACHE BOOL "Enable JPEG-LS (Lossless) decompression") +# Experimental options +SET(USE_PLUSTACHE OFF CACHE BOOL "Use the Plustache templating engine (experimental)") + # Advanced parameters to fine-tune linking against system libraries SET(USE_SYSTEM_JSONCPP ON CACHE BOOL "Use the system version of JsonCpp") SET(USE_SYSTEM_GOOGLE_LOG ON CACHE BOOL "Use the system version of Google Log") @@ -34,6 +37,7 @@ SET(USE_SYSTEM_CURL ON CACHE BOOL "Use the system version of LibCurl") SET(USE_SYSTEM_OPENSSL ON CACHE BOOL "Use the system version of OpenSSL") SET(USE_SYSTEM_ZLIB ON CACHE BOOL "Use the system version of ZLib") +SET(USE_SYSTEM_PLUSTACHE OFF CACHE BOOL "Use the system version of Plustache (experimental)") # Distribution-specific settings SET(USE_GTEST_DEBIAN_SOURCE_PACKAGE OFF CACHE BOOL "Use the sources of Google Test shipped with libgtest-dev (Debian only)") @@ -187,7 +191,7 @@ UnitTestsSources/ImageProcessingTests.cpp UnitTestsSources/JpegLosslessTests.cpp UnitTestsSources/PluginsTests.cpp - UnitTestsSources/Plustache.cpp + UnitTestsSources/PlustacheTests.cpp ) diff -r 226cfef3822e -r a93867a94011 Resources/CMake/PlustacheConfiguration.cmake --- a/Resources/CMake/PlustacheConfiguration.cmake Thu Jul 10 11:42:32 2014 +0200 +++ b/Resources/CMake/PlustacheConfiguration.cmake Thu Jul 10 11:53:23 2014 +0200 @@ -1,21 +1,34 @@ -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}") +if (USE_PLUSTACHE) + add_definitions(-DORTHANC_PLUSTACHE_ENABLED=1) -list(APPEND THIRD_PARTY_SOURCES - ${PLUSTACHE_SOURCES_DIR}/src/context.cpp - ${PLUSTACHE_SOURCES_DIR}/src/template.cpp - ) + if (STATIC_BUILD OR NOT USE_SYSTEM_PLUSTACHE) + 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} - ) + include_directories( + ${PLUSTACHE_SOURCES_DIR} + ) + + execute_process( + COMMAND patch -p0 -i ${CMAKE_SOURCE_DIR}/Resources/CMake/PlustacheConfiguration.patch + WORKING_DIRECTORY ${CMAKE_BINARY_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}/.*) -source_group(ThirdParty\\Plustache REGULAR_EXPRESSION ${PLUSTACHE_SOURCES_DIR}/.*) + else() + message(FATAL_ERROR "Dynamic linking against plustache not implemented (a patch is required)") + endif() + +else() + add_definitions(-DORTHANC_PLUSTACHE_ENABLED=0) + +endif() diff -r 226cfef3822e -r a93867a94011 UnitTestsSources/Plustache.cpp --- a/UnitTestsSources/Plustache.cpp Thu Jul 10 11:42:32 2014 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,86 +0,0 @@ -#include "gtest/gtest.h" - -#include - - -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 "
  • {{name}}
  • "; - } -}; - - -TEST(Plustache, Basic1) -{ - PlustacheTypes::ObjectType ctx; - ctx["title"] = "About"; - - OrthancPlustache t; - ASSERT_EQ("

    About

    ", t.render("

    {{title}}

    ", ctx)); -} - - -TEST(Plustache, Basic2) -{ - Plustache::Context ctx; - ctx.add("title", "About"); - - OrthancPlustache t; - ASSERT_EQ("

    About

    ", t.render("

    {{title}}

    ", 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("", - t.render("", 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("", - t.render("", ctx)); -} - - diff -r 226cfef3822e -r a93867a94011 UnitTestsSources/PlustacheTests.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/UnitTestsSources/PlustacheTests.cpp Thu Jul 10 11:53:23 2014 +0200 @@ -0,0 +1,120 @@ +/** + * Orthanc - A Lightweight, RESTful DICOM Store + * Copyright (C) 2012-2014 Medical Physics Department, CHU of Liege, + * Belgium + * + * This program is free software: you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * In addition, as a special exception, the copyright holders of this + * program give permission to link the code of its release with the + * OpenSSL project's "OpenSSL" library (or with modified versions of it + * that use the same license as the "OpenSSL" library), and distribute + * the linked executables. You must obey the GNU General Public License + * in all respects for all of the code used other than "OpenSSL". If you + * modify file(s) with this exception, you may extend this exception to + * your version of the file(s), but you are not obligated to do so. If + * you do not wish to do so, delete this exception statement from your + * version. If you delete this exception statement from all source files + * in the program, then also delete it here. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + **/ + + +#include "PrecompiledHeadersUnitTests.h" +#include "gtest/gtest.h" + +#if ORTHANC_PLUSTACHE_ENABLED == 1 + +#include + +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 "
  • {{name}}
  • "; + } +}; + + +TEST(Plustache, Basic1) +{ + PlustacheTypes::ObjectType ctx; + ctx["title"] = "About"; + + OrthancPlustache t; + ASSERT_EQ("

    About

    ", t.render("

    {{title}}

    ", ctx)); +} + + +TEST(Plustache, Basic2) +{ + Plustache::Context ctx; + ctx.add("title", "About"); + + OrthancPlustache t; + ASSERT_EQ("

    About

    ", t.render("

    {{title}}

    ", 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("
    • Orthanc
    • Jodogne
    ", + t.render("
      {{#items}}
    • {{name}}
    • {{/items}}
    ", 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("
    • Orthanc
    • Jodogne
    ", + t.render("
      {{#items}}{{>partial}}{{/items}}
    ", ctx)); +} + +#endif