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();
|
||||
}
|
||||
|
||||
void onTextBodyFinished()
|
||||
void onTextBodyFinished(std::string working_string = {})
|
||||
{
|
||||
if (!working_string.empty())
|
||||
{
|
||||
mWorkingTextBody->addLine(working_string);
|
||||
}
|
||||
|
||||
if (mWorkingTextBody->hasContent())
|
||||
{
|
||||
mWorkingNode->addChild(std::move(mWorkingTextBody));
|
||||
|
@ -206,6 +211,7 @@ public:
|
|||
bool in_statement{ false };
|
||||
bool in_expression{ false };
|
||||
std::string working_string;
|
||||
std::string last_working_string;
|
||||
for (auto c : line)
|
||||
{
|
||||
if (c == '{')
|
||||
|
@ -225,6 +231,7 @@ public:
|
|||
{
|
||||
last_was_ldelimiter = false;
|
||||
in_statement = true;
|
||||
last_working_string = working_string;
|
||||
working_string = "";
|
||||
}
|
||||
else if (c == '%' && in_statement)
|
||||
|
@ -235,7 +242,7 @@ public:
|
|||
{
|
||||
if (last_was_statement_rdelimiter)
|
||||
{
|
||||
onTextBodyFinished();
|
||||
onTextBodyFinished(last_working_string);
|
||||
onFoundStatement(working_string);
|
||||
last_was_statement_rdelimiter = false;
|
||||
working_string = "";
|
||||
|
@ -253,6 +260,12 @@ public:
|
|||
working_string = "";
|
||||
}
|
||||
}
|
||||
else if (last_was_ldelimiter && (!in_statement && !in_expression))
|
||||
{
|
||||
last_was_ldelimiter = false;
|
||||
working_string += '{';
|
||||
working_string += c;
|
||||
}
|
||||
else
|
||||
{
|
||||
working_string += c;
|
||||
|
@ -267,7 +280,6 @@ public:
|
|||
|
||||
void onFoundStatement(const std::string& statement_string)
|
||||
{
|
||||
std::cout << "Got Statement: " << statement_string << std::endl;
|
||||
const auto statement_elements = StringUtils::split(statement_string);
|
||||
|
||||
if (statement_elements.size() == 0)
|
||||
|
@ -283,6 +295,10 @@ public:
|
|||
{
|
||||
onFoundEndBlock(statement_elements);
|
||||
}
|
||||
else if (statement_type == "extends")
|
||||
{
|
||||
onFoundExtends(statement_elements);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -10,6 +10,7 @@ int main()
|
|||
auto engine = TemplatingEngine(data_loc);
|
||||
engine.loadTemplateFiles();
|
||||
engine.processTemplate("index");
|
||||
engine.processTemplate("base");
|
||||
|
||||
|
||||
}
|
Loading…
Reference in a new issue