From 5e0afb2c9239fd8695ff338f92fe113d593b2bf0 Mon Sep 17 00:00:00 2001 From: Bent Bisballe Nyeng Date: Mon, 5 Dec 2011 15:46:44 +0100 Subject: Prepare for template scripts. --- server/src/template.h | 2 ++ server/src/templateparser.cc | 49 ++++++++++++++++++++++++++++++++++++++++++++ server/src/templateparser.h | 3 +++ 3 files changed, 54 insertions(+) (limited to 'server') diff --git a/server/src/template.h b/server/src/template.h index a069cff..e549ef3 100644 --- a/server/src/template.h +++ b/server/src/template.h @@ -84,6 +84,8 @@ public: class Template { public: + std::vector< Script > scripts; + std::vector< Macro > macros; std::string name; diff --git a/server/src/templateparser.cc b/server/src/templateparser.cc index b9c65f5..704b215 100644 --- a/server/src/templateparser.cc +++ b/server/src/templateparser.cc @@ -81,6 +81,10 @@ TemplateParser::~TemplateParser() void TemplateParser::characterData(std::string &data) { + if(state == SCRIPT) { + assert(current_script); // No script present! + current_script->code.append(data); + } } void TemplateParser::startTag(std::string name, attributes_t &attr) @@ -127,6 +131,39 @@ void TemplateParser::startTag(std::string name, attributes_t &attr) return; } + // Enable script parsing + if(name == "scripts") { + if(state != MACRO) error("scripts found outside macro."); + state = SCRIPTS; + + assert(t); // No template is currently available, cannot create maps! + + return; + } + + // Create script + if(name == "script") { + + assert(t); // No template is currently available, cannot create script! + + switch(state) { + case SCRIPTS: + { + state = SCRIPT; + + Script s; + s.attributes = attr; + t->scripts.push_back(s); + current_script = &(t->scripts.back()); + } + break; + default: + error("