From 388f97d72933e1ab286ee1b02d4d05d2cfebb0a9 Mon Sep 17 00:00:00 2001 From: an-tao <20741618@qq.com> Date: Wed, 30 May 2018 13:23:59 +0800 Subject: [PATCH] add HttpView csp file in example --- examples/CMakeLists.txt | 19 ++++++++++++++++++- .../static_link_example/TestViewClone.csp | 13 +++++++++++++ examples/static_link_example/TestViewCtl.cc | 9 +++++++++ examples/static_link_example/TestViewCtl.h | 13 +++++++++++++ 4 files changed, 53 insertions(+), 1 deletion(-) create mode 100755 examples/static_link_example/TestViewClone.csp create mode 100755 examples/static_link_example/TestViewCtl.cc create mode 100755 examples/static_link_example/TestViewCtl.h diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index 01e28c40..5ceea3ed 100755 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -1,3 +1,20 @@ link_libraries(drogon trantor uuid pthread jsoncpp) + +FILE(GLOB SCP_LIST ${CMAKE_CURRENT_SOURCE_DIR}/static_link_example/*.csp) +foreach(cspFile ${SCP_LIST}) + message(STATUS "cspFile:" ${cspFile}) + EXEC_PROGRAM(basename ARGS "-s .csp ${cspFile}" OUTPUT_VARIABLE classname) + message(STATUS "view classname:" ${classname}) + add_custom_command(OUTPUT ${classname}.h ${classname}.cc + COMMAND drogon_ctl + ARGS create view ${cspFile} + DEPENDS ${cspFile} + VERBATIM ) + set(VIEWSRC ${VIEWSRC} ${classname}.cc) +endforeach() + + AUX_SOURCE_DIRECTORY(static_link_example DIR_STATIC) -add_executable(webapp ${DIR_STATIC}) + +add_executable(webapp ${DIR_STATIC} ${VIEWSRC}) + diff --git a/examples/static_link_example/TestViewClone.csp b/examples/static_link_example/TestViewClone.csp new file mode 100755 index 00000000..2afb92bc --- /dev/null +++ b/examples/static_link_example/TestViewClone.csp @@ -0,0 +1,13 @@ + + +<%c++ std::string title=@@.get("title");%> + + + <%c++ $$<<title;%> clone + + + + + diff --git a/examples/static_link_example/TestViewCtl.cc b/examples/static_link_example/TestViewCtl.cc new file mode 100755 index 00000000..11b8f77c --- /dev/null +++ b/examples/static_link_example/TestViewCtl.cc @@ -0,0 +1,9 @@ +#include "TestViewCtl.h" +void TestViewCtl::asyncHandleHttpRequest(const HttpRequest& req,std::functioncallback) +{ + //write your application logic here + drogon::HttpViewData data; + data.insert("title",std::string("TestView")); + std::unique_ptr res=std::unique_ptr(drogon::HttpResponse::newHttpViewResponse("TestViewClone",data)); + callback(*res); +} \ No newline at end of file diff --git a/examples/static_link_example/TestViewCtl.h b/examples/static_link_example/TestViewCtl.h new file mode 100755 index 00000000..449ead0c --- /dev/null +++ b/examples/static_link_example/TestViewCtl.h @@ -0,0 +1,13 @@ +#pragma once +#include +using namespace drogon; +class TestViewCtl:public drogon::HttpSimpleController +{ +public: + virtual void asyncHandleHttpRequest(const HttpRequest& req,std::functioncallback)override; + PATH_LIST_BEGIN + //list path definations here; + //PATH_ADD("/path","filter1","filter2",...); + PATH_ADD("/view"); + PATH_LIST_END +};