From 0c6f39c34dcd690581575b6926125368a6bb03c3 Mon Sep 17 00:00:00 2001 From: antao Date: Fri, 5 Oct 2018 19:17:12 +0800 Subject: [PATCH] Modify create view command of drogon_ctl --- drogon_ctl/create_view.cc | 53 +++++++++++++++++++++--- examples/simple_example/ListParaCtl.cc | 2 +- examples/simple_example/ListParaView.csp | 4 +- lib/inc/drogon/HttpViewData.h | 6 ++- 4 files changed, 55 insertions(+), 10 deletions(-) diff --git a/drogon_ctl/create_view.cc b/drogon_ctl/create_view.cc index 68873a7e..e8321343 100755 --- a/drogon_ctl/create_view.cc +++ b/drogon_ctl/create_view.cc @@ -23,6 +23,8 @@ static const std::string cxx_end="%>"; static const std::string cxx_lang="<%c++"; static const std::string cxx_view_data="@@"; static const std::string cxx_output="$$"; +static const std::string cxx_val_start="{{"; +static const std::string cxx_val_end="}}"; using namespace drogon_ctl; @@ -55,7 +57,17 @@ static void parseCxxLine(std::ofstream &oSrcFile,const std::string& line,const s } } - +static void outputVal(std::ofstream &oSrcFile,const std::string& streamName,const std::string& viewDataName,const std::string &keyName) +{ + oSrcFile<<"{\n"; + oSrcFile<<" auto & val="<(val);\n"; + oSrcFile<<" }else if(val.type()==typeid(std::string)||val.type()==typeid(const std::string)){\n"; + oSrcFile<<" "<(val);\n"; + oSrcFile<<" }\n"; + oSrcFile<<"}\n"; +} static void parseLine(std::ofstream &oSrcFile,std::string& line,const std::string& streamName,const std::string& viewDataName,int &cxx_flag,int returnFlag=1) { std::string::size_type pos(0); @@ -74,12 +86,41 @@ static void parseLine(std::ofstream &oSrcFile,std::string& line,const std::strin } else { - if(line.length()>0) - oSrcFile<<"\t"<0) + oSrcFile<<"\t"<getParameters()); auto res=drogon::HttpResponse::newHttpViewResponse("ListParaView.csp",data); callback(res); diff --git a/examples/simple_example/ListParaView.csp b/examples/simple_example/ListParaView.csp index ec9e3fde..599322c4 100755 --- a/examples/simple_example/ListParaView.csp +++ b/examples/simple_example/ListParaView.csp @@ -1,11 +1,11 @@ -<%c++ std::string title=@@.get("title"); +<%c++ auto para=@@.get>("parameters"); %> - <%c++ $$<<title;%> + {{ title }} <%c++ if(para.size()>0){%> diff --git a/lib/inc/drogon/HttpViewData.h b/lib/inc/drogon/HttpViewData.h index 58e3e5b2..31ea465d 100755 --- a/lib/inc/drogon/HttpViewData.h +++ b/lib/inc/drogon/HttpViewData.h @@ -52,7 +52,11 @@ public: { viewData_[key]=obj; } + any& operator [] (const std::string &key) const + { + return viewData_[key]; + } protected: - ViewDataMap viewData_; + mutable ViewDataMap viewData_; }; }