Template engine tree building on sample data.
This commit is contained in:
parent
dbd7591dc5
commit
eb3b394bdf
2 changed files with 20 additions and 3 deletions
|
@ -189,8 +189,13 @@ public:
|
||||||
onTextBodyFinished();
|
onTextBodyFinished();
|
||||||
}
|
}
|
||||||
|
|
||||||
void onTextBodyFinished()
|
void onTextBodyFinished(std::string working_string = {})
|
||||||
{
|
{
|
||||||
|
if (!working_string.empty())
|
||||||
|
{
|
||||||
|
mWorkingTextBody->addLine(working_string);
|
||||||
|
}
|
||||||
|
|
||||||
if (mWorkingTextBody->hasContent())
|
if (mWorkingTextBody->hasContent())
|
||||||
{
|
{
|
||||||
mWorkingNode->addChild(std::move(mWorkingTextBody));
|
mWorkingNode->addChild(std::move(mWorkingTextBody));
|
||||||
|
@ -206,6 +211,7 @@ public:
|
||||||
bool in_statement{ false };
|
bool in_statement{ false };
|
||||||
bool in_expression{ false };
|
bool in_expression{ false };
|
||||||
std::string working_string;
|
std::string working_string;
|
||||||
|
std::string last_working_string;
|
||||||
for (auto c : line)
|
for (auto c : line)
|
||||||
{
|
{
|
||||||
if (c == '{')
|
if (c == '{')
|
||||||
|
@ -225,6 +231,7 @@ public:
|
||||||
{
|
{
|
||||||
last_was_ldelimiter = false;
|
last_was_ldelimiter = false;
|
||||||
in_statement = true;
|
in_statement = true;
|
||||||
|
last_working_string = working_string;
|
||||||
working_string = "";
|
working_string = "";
|
||||||
}
|
}
|
||||||
else if (c == '%' && in_statement)
|
else if (c == '%' && in_statement)
|
||||||
|
@ -235,7 +242,7 @@ public:
|
||||||
{
|
{
|
||||||
if (last_was_statement_rdelimiter)
|
if (last_was_statement_rdelimiter)
|
||||||
{
|
{
|
||||||
onTextBodyFinished();
|
onTextBodyFinished(last_working_string);
|
||||||
onFoundStatement(working_string);
|
onFoundStatement(working_string);
|
||||||
last_was_statement_rdelimiter = false;
|
last_was_statement_rdelimiter = false;
|
||||||
working_string = "";
|
working_string = "";
|
||||||
|
@ -253,6 +260,12 @@ public:
|
||||||
working_string = "";
|
working_string = "";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else if (last_was_ldelimiter && (!in_statement && !in_expression))
|
||||||
|
{
|
||||||
|
last_was_ldelimiter = false;
|
||||||
|
working_string += '{';
|
||||||
|
working_string += c;
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
working_string += c;
|
working_string += c;
|
||||||
|
@ -267,7 +280,6 @@ public:
|
||||||
|
|
||||||
void onFoundStatement(const std::string& statement_string)
|
void onFoundStatement(const std::string& statement_string)
|
||||||
{
|
{
|
||||||
std::cout << "Got Statement: " << statement_string << std::endl;
|
|
||||||
const auto statement_elements = StringUtils::split(statement_string);
|
const auto statement_elements = StringUtils::split(statement_string);
|
||||||
|
|
||||||
if (statement_elements.size() == 0)
|
if (statement_elements.size() == 0)
|
||||||
|
@ -283,6 +295,10 @@ public:
|
||||||
{
|
{
|
||||||
onFoundEndBlock(statement_elements);
|
onFoundEndBlock(statement_elements);
|
||||||
}
|
}
|
||||||
|
else if (statement_type == "extends")
|
||||||
|
{
|
||||||
|
onFoundExtends(statement_elements);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -10,6 +10,7 @@ int main()
|
||||||
auto engine = TemplatingEngine(data_loc);
|
auto engine = TemplatingEngine(data_loc);
|
||||||
engine.loadTemplateFiles();
|
engine.loadTemplateFiles();
|
||||||
engine.processTemplate("index");
|
engine.processTemplate("index");
|
||||||
|
engine.processTemplate("base");
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
Loading…
Reference in a new issue