diff options
author | deva <deva> | 2010-08-03 12:29:39 +0000 |
---|---|---|
committer | deva <deva> | 2010-08-03 12:29:39 +0000 |
commit | d285c1bdb79752ef23a7252c9c2d9f408f0c9f49 (patch) | |
tree | 7c65185cdddb37dc99cccca6c5b89a9799add6a9 | |
parent | 726742e53bcbb3fa31bcd55e6e7fe305da225455 (diff) |
New script-tag attribute that includes lua code from a file.
-rw-r--r-- | server/src/macroparser.cc | 2 | ||||
-rw-r--r-- | server/src/macroparser.h | 1 | ||||
-rw-r--r-- | server/src/resumeparser.cc | 37 | ||||
-rw-r--r-- | server/src/resumeparser.h | 2 | ||||
-rw-r--r-- | server/src/transactionhandler.cc | 31 |
5 files changed, 58 insertions, 15 deletions
diff --git a/server/src/macroparser.cc b/server/src/macroparser.cc index eca189e..fe7f6e3 100644 --- a/server/src/macroparser.cc +++ b/server/src/macroparser.cc @@ -139,7 +139,7 @@ void MacroParser::startTag(std::string name, std::map< std::string, std::string> m->resume.attributes = attributes; - assert(m); // No macro is currently available, cannot create queries! + assert(m); // No macro is currently available, cannot create resume! return; } diff --git a/server/src/macroparser.h b/server/src/macroparser.h index a2a144c..86a1487 100644 --- a/server/src/macroparser.h +++ b/server/src/macroparser.h @@ -41,6 +41,7 @@ class MacroParser : public SAXParser { MAP, WIDGETS, SCRIPTS, + SCRIPT_INCLUDE, SCRIPT } ParserState; diff --git a/server/src/resumeparser.cc b/server/src/resumeparser.cc index 4d514ac..37b36f4 100644 --- a/server/src/resumeparser.cc +++ b/server/src/resumeparser.cc @@ -29,6 +29,7 @@ #include <string.h> #include "luaresume.h" +#include "configuration.h" static std::string resume_parser_format(Resume &r, Commit &commit) { @@ -100,18 +101,40 @@ static std::string resume_parser_format(Resume &r, Commit &commit) return resume; } -static std::string resume_parser_lua(Resume &resume, Commit &commit) +static std::string resume_parser_lua(Macro ¯o, Commit &commit) { LUAResume luaresume(commit); - - return luaresume.run(resume.attributes["format"]); + std::string lua; + /* + std::vector< ScriptInclude >::iterator spii = + macro.script_includes.begin(); + while(spii != macro.script_includes.end()) { + std::string file = + Conf::xml_basedir + "/include/" + spii->attributes["file"]; + FILE *fp = fopen(file.c_str(), "r"); + if(fp) { + char buf[64]; + size_t sz; + std::string inc; + while((sz = fread(buf, 1, sizeof(buf), fp)) != 0) { + lua.append(buf, sz); + } + fclose(fp); + } + spii++; + } + */ + lua += macro.resume.attributes["format"]; + + return luaresume.run(lua); } -std::string resume_parser(Resume &resume, Commit &commit) +std::string resume_parser(Macro ¯o, Commit &commit) { - if(resume.attributes["language"] == "lua") - return resume_parser_lua(resume, commit); + if(macro.resume.attributes["language"] == "lua") { + return resume_parser_lua(macro, commit); + } // Default to pracro format language. - return resume_parser_format(resume, commit); + return resume_parser_format(macro.resume, commit); } diff --git a/server/src/resumeparser.h b/server/src/resumeparser.h index 0d3ff0c..381e7c6 100644 --- a/server/src/resumeparser.h +++ b/server/src/resumeparser.h @@ -31,6 +31,6 @@ #include "transaction.h" #include "template.h" -std::string resume_parser(Resume &resume, Commit &commit); +std::string resume_parser(Macro ¯o, Commit &commit); #endif/*__PRACRO_RESUMEPARSER_H__*/ diff --git a/server/src/transactionhandler.cc b/server/src/transactionhandler.cc index f549192..86f7853 100644 --- a/server/src/transactionhandler.cc +++ b/server/src/transactionhandler.cc @@ -66,11 +66,11 @@ static std::string handleCommits(Transaction &transaction, Environment &env, mp.parse(); Macro *macro = mp.getMacro(); - std::string resume = resume_parser(macro->resume, commit); + std::string resume = resume_parser(*macro, commit); commit.fields["journal.resume"] = resume; db->commitTransaction(transaction.user, transaction.cpr, *macro, commit.fields); - + if(resume != "") { TemplateParser tp(env.templatelist.getLatestVersion(commit.templ)); @@ -199,12 +199,31 @@ static std::string handleRequest(Transaction &transaction, Environment &env, std::vector< Script >::iterator spi = m->scripts.begin(); while(spi != m->scripts.end()) { answer += " <script language=\"" + - spi->attributes["language"] - + "\" name=\"" + spi->attributes["name"] + "\">\n"; - answer += xml_encode(spi->attributes["code"]); - answer += "\n </script>\n"; + spi->attributes["language"] + "\">"; + + if(spi->attributes.find("src") != spi->attributes.end()) { + std::string file = + Conf::xml_basedir + "/include/" + spi->attributes["src"]; + FILE *fp = fopen(file.c_str(), "r"); + if(fp) { + char buf[64]; + size_t sz; + std::string inc; + while((sz = fread(buf, 1, sizeof(buf), fp)) != 0) { + inc.append(buf, sz); + } + fclose(fp); + answer += "\n-- BEGIN INCLUDE: '" + spi->attributes["src"] + "'\n"; + answer += xml_encode(inc); + answer += "\n-- END INCLUDE: '" + spi->attributes["src"] + "'\n"; + } + } else { + answer += xml_encode(spi->attributes["code"]); + } + answer += "</script>\n"; spi++; } + answer += " </scripts>\n"; } |