# HG changeset patch # User Sebastien Jodogne # Date 1401292499 -7200 # Node ID d8f5de5b9517c8512a249bffdc3a83ab24b7a809 # Parent da4c30a8bcdd549b27ce59f71cb2a26c6f789cda partials diff -r da4c30a8bcdd -r d8f5de5b9517 Resources/CMake/PlustacheConfiguration.cmake --- a/Resources/CMake/PlustacheConfiguration.cmake Wed May 28 16:21:48 2014 +0200 +++ b/Resources/CMake/PlustacheConfiguration.cmake Wed May 28 17:54:59 2014 +0200 @@ -13,4 +13,9 @@ ${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}/.*) diff -r da4c30a8bcdd -r d8f5de5b9517 Resources/CMake/PlustacheConfiguration.patch --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Resources/CMake/PlustacheConfiguration.patch Wed May 28 17:54:59 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~ diff -r da4c30a8bcdd -r d8f5de5b9517 UnitTestsSources/Plustache.cpp --- a/UnitTestsSources/Plustache.cpp Wed May 28 16:21:48 2014 +0200 +++ b/UnitTestsSources/Plustache.cpp Wed May 28 17:54:59 2014 +0200 @@ -2,12 +2,85 @@ #include -TEST(Plustache, Basic) + +class OrthancPlustache : public Plustache::template_t { - std::map ctx; +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"; - Plustache::template_t t; + 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)); +} + +