diff --git a/drogon_ctl/CommandHandler.h b/drogon_ctl/CommandHandler.h index 89259f82..44fe61cb 100755 --- a/drogon_ctl/CommandHandler.h +++ b/drogon_ctl/CommandHandler.h @@ -8,6 +8,7 @@ class CommandHandler:public virtual drogon::DrObjectBase { public: virtual void handleCommand(std::vector ¶meters)=0; + virtual bool isTopCommand(){return false;} virtual std::string script(){return "";} virtual ~CommandHandler(){} }; \ No newline at end of file diff --git a/drogon_ctl/create.h b/drogon_ctl/create.h index 463cfa16..afc10cbd 100755 --- a/drogon_ctl/create.h +++ b/drogon_ctl/create.h @@ -15,6 +15,7 @@ namespace drogon_ctl { public: virtual void handleCommand(std::vector ¶meters) override; - std::string script(){return "create controller or view class files";} + virtual std::string script() override {return "create controller or view class files";} + virtual bool isTopCommand() override {return true;} }; } diff --git a/drogon_ctl/create_controller.h b/drogon_ctl/create_controller.h index 6742c2dc..70efb5e1 100755 --- a/drogon_ctl/create_controller.h +++ b/drogon_ctl/create_controller.h @@ -15,7 +15,7 @@ namespace drogon_ctl { public: virtual void handleCommand(std::vector ¶meters) override; - std::string script(){return "create controller or view class files";} + std::string script(){return "create controller files";} protected: enum ControllerType{ diff --git a/drogon_ctl/create_view.cc b/drogon_ctl/create_view.cc new file mode 100755 index 00000000..10612b26 --- /dev/null +++ b/drogon_ctl/create_view.cc @@ -0,0 +1,251 @@ +#include "create_view.h" +#include "cmd.h" +#include +#include +#include + +static const std::string cxx_include="<%inc"; +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="$$"; + +using namespace drogon_ctl; + +static std::string& replace_all(std::string& str,const std::string& old_value,const std::string& new_value) +{ + std::string::size_type pos(0); + while(true) { + + + //std::cout<0) + oSrcFile<<"\t"< ¶meters) +{ + for(auto file:parameters) + { + if(file[0]=='-') + { + std::cout< &cspFileNames) +{ + + for(auto file:cspFileNames) + { + std::cout<<"create view:"<\n"; + file<<"using namespace drogon;\n"; + file<<"class "<\n"; + file<<"{\npublic:\n\t"<\n"; + file <<"#include \n"; + file <<"#include \n"; + file <<"#include \n"; + file <<"#include \n"; + file <<"using namespace std;\n"; + std::string buffer; + char line[8192]; + int import_flag=0; + + + while(infile.getline(line,sizeof(line))) + { + buffer=line; + + std::string::size_type pos(0); + + + if(!import_flag) + { + std::string lowerBuffer=buffer; + std::transform(lowerBuffer.begin(), lowerBuffer.end(), lowerBuffer.begin(), ::tolower); + if((pos=lowerBuffer.find(cxx_include))!=std::string::npos) + { + //std::cout<<"haha find it!"<setStatusCode(HttpResponse::k200Ok);\n"; + file<<"#ifdef CONTENT_TYPE\n"; + file<<"\tres->setContentTypeCode(CONTENT_TYPE);\n"; + file<<"#else\n"; + file<<"\tres->setContentTypeCode(CT_TEXT_HTML);\n"; + file<<"#endif\n"; + file<<"\tres->setBody("< +#include "CommandHandler.h" +using namespace drogon; +namespace drogon_ctl +{ + class create_view:public DrObject,public CommandHandler + { + public: + virtual void handleCommand(std::vector ¶meters) override; + virtual std::string script() override {return "create view class files";} + + protected: + + void createViewFiles(std::vector &cspFileNames); + int createViewFile(const std::string &script_filename); + void newViewHeaderFile(std::ofstream &file,const std::string &className); + void newViewSourceFile(std::ofstream &file,const std::string &className,std::ifstream &infile); + }; +} \ No newline at end of file diff --git a/drogon_ctl/help.cc b/drogon_ctl/help.cc index 0f3d15b2..958d5c72 100755 --- a/drogon_ctl/help.cc +++ b/drogon_ctl/help.cc @@ -21,6 +21,8 @@ void help::handleCommand(std::vector ¶meters) auto cmdHdlPtr=std::dynamic_pointer_cast(classPtr); if(cmdHdlPtr) { + if(!cmdHdlPtr->isTopCommand()) + continue; auto pos=className.rfind("::"); if(pos!=std::string::npos) { diff --git a/drogon_ctl/help.h b/drogon_ctl/help.h index 5391b78a..fb603255 100755 --- a/drogon_ctl/help.h +++ b/drogon_ctl/help.h @@ -15,6 +15,7 @@ namespace drogon_ctl { public: virtual void handleCommand(std::vector ¶meters) override; - std::string script(){return "display this message";} + virtual std::string script() override {return "display this message";} + virtual bool isTopCommand() override {return true;} }; } diff --git a/drogon_ctl/version.h b/drogon_ctl/version.h index 6a06c136..1c6b4b3d 100755 --- a/drogon_ctl/version.h +++ b/drogon_ctl/version.h @@ -9,7 +9,8 @@ namespace drogon_ctl { public: virtual void handleCommand(std::vector ¶meters) override; - std::string script(){return "display version of this tool";} + virtual std::string script() override {return "display version of this tool";} + virtual bool isTopCommand() override {return true;} version(){} }; } diff --git a/examples/static_link_example/TestView.csp b/examples/static_link_example/TestView.csp new file mode 100755 index 00000000..6c24f561 --- /dev/null +++ b/examples/static_link_example/TestView.csp @@ -0,0 +1,13 @@ + + +<%c++ std::string title=@@.get("title");%> + + + <%c++ $$<<title;%> + + +
+ CopyRight@2017 All Rights Reserved +
+ + diff --git a/lib/inc/drogon/HttpView.h b/lib/inc/drogon/HttpView.h index c28613cb..77e30a89 100755 --- a/lib/inc/drogon/HttpView.h +++ b/lib/inc/drogon/HttpView.h @@ -1,8 +1,10 @@ #pragma once #include +#include +#include +#include namespace drogon { - class HttpViewBase; template class HttpView:public DrObject,public HttpViewBase { diff --git a/lib/src/HttpViewBase.h b/lib/inc/drogon/HttpViewBase.h similarity index 100% rename from lib/src/HttpViewBase.h rename to lib/inc/drogon/HttpViewBase.h diff --git a/lib/src/HttpResponseImpl.cc b/lib/src/HttpResponseImpl.cc index 90a51f4b..85842fb0 100755 --- a/lib/src/HttpResponseImpl.cc +++ b/lib/src/HttpResponseImpl.cc @@ -15,8 +15,8 @@ // that can be found in the License file. #include "HttpResponseImpl.h" -#include "HttpViewBase.h" +#include #include #include @@ -60,9 +60,9 @@ HttpResponse* HttpResponse::locationRedirectResponse(std::string path) return res; } -newHttpViewResponse(const std::string &viewName,const HttpViewData& data) +HttpResponse* HttpResponse::newHttpViewResponse(const std::string &viewName,const HttpViewData& data) { - + return HttpViewBase::genHttpResponse(viewName,data); } const std::string HttpResponseImpl::web_content_type_to_string(uint8_t contenttype) { diff --git a/lib/src/HttpViewBase.cc b/lib/src/HttpViewBase.cc index aa5e7a62..594317c9 100755 --- a/lib/src/HttpViewBase.cc +++ b/lib/src/HttpViewBase.cc @@ -1,4 +1,10 @@ -#include "HttpViewBase.h" +// +// Copyright 2018, An Tao. All rights reserved. +// +// Use of this source code is governed by a MIT license +// that can be found in the License file. + +#include #include #include #include