From 55c49e5ce1d0db030e7c301957105de45109d42e Mon Sep 17 00:00:00 2001 From: Daniel Sipka Date: Fri, 24 Apr 2015 01:35:29 +0200 Subject: [PATCH 1/4] update readme --- README.md | 68 ++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 67 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 0cbc9de..a98bf5d 100644 --- a/README.md +++ b/README.md @@ -1 +1,67 @@ -# mstch [![Build Status](https://travis-ci.org/no1msd/mstch.svg?branch=master)](https://travis-ci.org/no1msd/mstch) +# mstch - {{mustache}} templates in C++11 + +mstch is a complete implementation of [{{mustache}}](http://mustache.github.io/) templates using modern C++. +[![Build Status](https://travis-ci.org/no1msd/mstch.svg?branch=master)](https://travis-ci.org/no1msd/mstch) + +## Basic usage + +```c++ +#include + +#include + +int main() { + std::string view{"{{#names}}Hi {{name}}!\n{{/names}}"}; + mstch::map context{ + {"names", mstch::array{ + mstch::map{{"name", std::string{"Chris"}}, + mstch::map{{"name", std::string{"Mark"}}, + mstch::map{{"name", std::string{"Scott"}}, + } + }; + + std::cout << mstch::render(view, context) << std::endl; + + return 0; +} + +``` + +The output of this example will be: + +``` +Hi chris! +Hi mark! +Hi scott! +``` + +## Requirements + + - A C++ compiler with decent C++11 support. Currently only tested with GCC 4.9. + - Boost 1.54 + - CMake for building + +## Building + +From the root of the source tree: + +```bash + $ mkdir build + $ cd build + $ cmake .. + $ make +``` + +Building with unit tests: + +```bash + $ mkdir build + $ cd build + $ cmake -DWITH_UNIT_TESTS=ON .. + $ make + $ make test +``` + +### Advanced usage + +TODO \ No newline at end of file From c4b5eb8664c6a9508cf30a261685437ba37a8629 Mon Sep 17 00:00:00 2001 From: Daniel Sipka Date: Fri, 24 Apr 2015 01:37:09 +0200 Subject: [PATCH 2/4] update readme --- README.md | 8 +++---- test/benchmark_main.cpp | 48 +++++++++++------------------------------ 2 files changed, 16 insertions(+), 40 deletions(-) diff --git a/README.md b/README.md index a98bf5d..326554f 100644 --- a/README.md +++ b/README.md @@ -14,10 +14,10 @@ int main() { std::string view{"{{#names}}Hi {{name}}!\n{{/names}}"}; mstch::map context{ {"names", mstch::array{ - mstch::map{{"name", std::string{"Chris"}}, - mstch::map{{"name", std::string{"Mark"}}, - mstch::map{{"name", std::string{"Scott"}}, - } + mstch::map{{"name", std::string{"Chris"}}}, + mstch::map{{"name", std::string{"Mark"}}}, + mstch::map{{"name", std::string{"Scott"}}}, + }} }; std::cout << mstch::render(view, context) << std::endl; diff --git a/test/benchmark_main.cpp b/test/benchmark_main.cpp index 412581b..550670d 100644 --- a/test/benchmark_main.cpp +++ b/test/benchmark_main.cpp @@ -1,42 +1,18 @@ -#include "mstch/mstch.hpp" - -#include #include -unsigned long current_msec() { - return std::chrono::system_clock::now().time_since_epoch() / - std::chrono::milliseconds(1); -} +#include int main() { - std::string comment_tmp{ - "

{{header}}

    " - "{{#comments}}
  • {{name}}
    " - "

    {{body}}

  • {{/comments}}
"}; + std::string view{"{{#names}}Hi {{name}}!\n{{/names}}"}; + mstch::map context{ + {"names", mstch::array{ + mstch::map{{"name", std::string{"Chris"}}}, + mstch::map{{"name", std::string{"Mark"}}}, + mstch::map{{"name", std::string{"Scott"}}}, + }} + }; - auto comment_view = mstch::map{ - {"header", std::string{"My Post Comments"}}, - {"comments", mstch::array{ - mstch::map{{"name", std::string{"Joe"}}, {"body", std::string{"Thanks for this post!"}}}, - mstch::map{{"name", std::string{"Sam"}}, {"body", std::string{"Thanks for this post!"}}}, - mstch::map{{"name", std::string{"Heather"}}, {"body", std::string{"Thanks for this post!"}}}, - mstch::map{{"name", std::string{"Kathy"}}, {"body", std::string{"Thanks for this post!"}}}, - mstch::map{{"name", std::string{"George"}}, {"body", std::string{"Thanks for this post!"}}}}}}; + std::cout << mstch::render(view, context) << std::endl; - std::vector times; - for (int j = 0; j < 10; j++) { - unsigned long start = current_msec(); - for (int i = 0; i < 5000; i++) - mstch::render(comment_tmp, comment_view); - times.push_back(current_msec() - start); - } - - float avg = 0; - for (auto i: times) - avg += i; - avg /= times.size(); - - std::cout << avg << std::endl; - - return 0; -} + return 0; + } \ No newline at end of file From 26aa05fccc206bddd05c004cc89f7a7d1f46eab3 Mon Sep 17 00:00:00 2001 From: Daniel Sipka Date: Fri, 24 Apr 2015 01:37:31 +0200 Subject: [PATCH 3/4] benchmark --- test/benchmark_main.cpp | 48 ++++++++++++++++++++++++++++++----------- 1 file changed, 36 insertions(+), 12 deletions(-) diff --git a/test/benchmark_main.cpp b/test/benchmark_main.cpp index 550670d..412581b 100644 --- a/test/benchmark_main.cpp +++ b/test/benchmark_main.cpp @@ -1,18 +1,42 @@ +#include "mstch/mstch.hpp" + +#include #include -#include +unsigned long current_msec() { + return std::chrono::system_clock::now().time_since_epoch() / + std::chrono::milliseconds(1); +} int main() { - std::string view{"{{#names}}Hi {{name}}!\n{{/names}}"}; - mstch::map context{ - {"names", mstch::array{ - mstch::map{{"name", std::string{"Chris"}}}, - mstch::map{{"name", std::string{"Mark"}}}, - mstch::map{{"name", std::string{"Scott"}}}, - }} - }; + std::string comment_tmp{ + "

{{header}}

    " + "{{#comments}}
  • {{name}}
    " + "

    {{body}}

  • {{/comments}}
"}; - std::cout << mstch::render(view, context) << std::endl; + auto comment_view = mstch::map{ + {"header", std::string{"My Post Comments"}}, + {"comments", mstch::array{ + mstch::map{{"name", std::string{"Joe"}}, {"body", std::string{"Thanks for this post!"}}}, + mstch::map{{"name", std::string{"Sam"}}, {"body", std::string{"Thanks for this post!"}}}, + mstch::map{{"name", std::string{"Heather"}}, {"body", std::string{"Thanks for this post!"}}}, + mstch::map{{"name", std::string{"Kathy"}}, {"body", std::string{"Thanks for this post!"}}}, + mstch::map{{"name", std::string{"George"}}, {"body", std::string{"Thanks for this post!"}}}}}}; - return 0; - } \ No newline at end of file + std::vector times; + for (int j = 0; j < 10; j++) { + unsigned long start = current_msec(); + for (int i = 0; i < 5000; i++) + mstch::render(comment_tmp, comment_view); + times.push_back(current_msec() - start); + } + + float avg = 0; + for (auto i: times) + avg += i; + avg /= times.size(); + + std::cout << avg << std::endl; + + return 0; +} From 876f982cde752a82bba62336f83e51bcaa9d21e2 Mon Sep 17 00:00:00 2001 From: Daniel Sipka Date: Fri, 24 Apr 2015 01:48:42 +0200 Subject: [PATCH 4/4] cmake install --- README.md | 15 ++++++++------- src/CMakeLists.txt | 3 +++ 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 326554f..8cbe0ff 100644 --- a/README.md +++ b/README.md @@ -1,13 +1,13 @@ # mstch - {{mustache}} templates in C++11 mstch is a complete implementation of [{{mustache}}](http://mustache.github.io/) templates using modern C++. + [![Build Status](https://travis-ci.org/no1msd/mstch.svg?branch=master)](https://travis-ci.org/no1msd/mstch) ## Basic usage ```c++ #include - #include int main() { @@ -30,9 +30,9 @@ int main() { The output of this example will be: ``` -Hi chris! -Hi mark! -Hi scott! +Hi Chris! +Hi Mark! +Hi Scott! ``` ## Requirements @@ -41,7 +41,7 @@ Hi scott! - Boost 1.54 - CMake for building -## Building +## Installing From the root of the source tree: @@ -50,9 +50,10 @@ From the root of the source tree: $ cd build $ cmake .. $ make + $ make install ``` -Building with unit tests: +### Running the unit tests ```bash $ mkdir build @@ -62,6 +63,6 @@ Building with unit tests: $ make test ``` -### Advanced usage +## Advanced usage TODO \ No newline at end of file diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index aa0d9f7..efdd89d 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -21,3 +21,6 @@ set(SRC utils.cpp) add_library(mstch STATIC ${SRC}) + +install(TARGETS mstch DESTINATION lib) +install(FILES ${CMAKE_SOURCE_DIR}/include/mstch/mstch.hpp DESTINATION include/mstch) \ No newline at end of file