add HttpView csp file in example

This commit is contained in:
an-tao 2018-05-30 13:23:59 +08:00
parent 30ab716c6b
commit 388f97d729
4 changed files with 53 additions and 1 deletions

View File

@ -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})

View File

@ -0,0 +1,13 @@
<!DOCTYPE html>
<html>
<%c++ std::string title=@@.get<std::string>("title");%>
<head>
<meta charset="UTF-8">
<title><%c++ $$<<title;%> clone</title>
</head>
<body>
<footer>
<span>CopyRight@2017 All Rights Reserved</span>
</footer>
</body>
</html>

View File

@ -0,0 +1,9 @@
#include "TestViewCtl.h"
void TestViewCtl::asyncHandleHttpRequest(const HttpRequest& req,std::function<void (HttpResponse &)>callback)
{
//write your application logic here
drogon::HttpViewData data;
data.insert("title",std::string("TestView"));
std::unique_ptr<HttpResponse> res=std::unique_ptr<HttpResponse>(drogon::HttpResponse::newHttpViewResponse("TestViewClone",data));
callback(*res);
}

View File

@ -0,0 +1,13 @@
#pragma once
#include <drogon/HttpSimpleController.h>
using namespace drogon;
class TestViewCtl:public drogon::HttpSimpleController<TestViewCtl>
{
public:
virtual void asyncHandleHttpRequest(const HttpRequest& req,std::function<void (HttpResponse &)>callback)override;
PATH_LIST_BEGIN
//list path definations here;
//PATH_ADD("/path","filter1","filter2",...);
PATH_ADD("/view");
PATH_LIST_END
};