XMLNodeHandlerTemplate.cpp 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. #include "XMLNodeHandlerTemplate.h"
  2. #include "../../Include/RmlUi/Core/Dictionary.h"
  3. #include "../../Include/RmlUi/Core/Element.h"
  4. #include "../../Include/RmlUi/Core/Factory.h"
  5. #include "../../Include/RmlUi/Core/XMLParser.h"
  6. #include "Template.h"
  7. #include "TemplateCache.h"
  8. #include "XMLParseTools.h"
  9. namespace Rml {
  10. XMLNodeHandlerTemplate::XMLNodeHandlerTemplate() {}
  11. XMLNodeHandlerTemplate::~XMLNodeHandlerTemplate() {}
  12. Element* XMLNodeHandlerTemplate::ElementStart(XMLParser* parser, const String& name, const XMLAttributes& attributes)
  13. {
  14. RMLUI_ASSERT(name == "template");
  15. (void)name;
  16. // Tell the parser to use the default handler for all child nodes
  17. parser->PushDefaultHandler();
  18. const String template_name = Get<String>(attributes, "src", "");
  19. Element* element = parser->GetParseFrame()->element;
  20. if (template_name.empty())
  21. {
  22. Log::Message(Log::LT_WARNING,
  23. "Inline template injection requires the 'src' attribute with the target template name, but none provided. In element %s",
  24. element->GetAddress().c_str());
  25. return element;
  26. }
  27. return XMLParseTools::ParseTemplate(element, template_name);
  28. }
  29. bool XMLNodeHandlerTemplate::ElementEnd(XMLParser* /*parser*/, const String& /*name*/)
  30. {
  31. return true;
  32. }
  33. bool XMLNodeHandlerTemplate::ElementData(XMLParser* parser, const String& data, XMLDataType /*type*/)
  34. {
  35. return Factory::InstanceElementText(parser->GetParseFrame()->element, data);
  36. }
  37. } // namespace Rml