void process(TiObj& obj){ bool error = false; if ( obj.classe == "" ){ if ( this->stack.size() == 0 ){ if ( obj.has("html") ){ cout << obj.atStr("html"); return; } } else { TiObj& parent = *this->stack[ this->stack.size()-1 ]; if ( parent.hasnt("default") ){ cerr << "Default do item nao encontrado\n"; error = true; } } } else if ( obj.classe != "Css" ){ if ( this->db.hasnt( obj.classe ) ){ cerr << Join("Item nao encontrado %s\n").at(obj.classe).ok; error = true; } } if ( error ) return; // Get Template TiObj* tempalte; if ( obj.classe == "" ){ if ( this->stack.size() > 0 ){ TiObj* parent = this->stack.back(); if ( parent->has("default") ){ tempalte = this->getObject(parent->at("default")); } } else cerr << "Pilha desbalanceada\n"; } else tempalte = &getTemplate(obj); assert(tempalte!=nullptr); // Process the template with the variable if ( tempalte->has("ini") || tempalte->has("end") ){ this->stack.push_back( &this->db.atObj(obj.classe) ); std::string ini = tempalte->atStr("ini"); std::string end = tempalte->atStr("end"); cout << this->parseTmpl(ini,obj); for (int i=0; i<obj.size(); i++){ this->process( obj.box[i] ); } cout << this->parseTmpl(end,obj); this->stack.pop_back(); } else { cout << this->parseTmpl(tempalte->atStr("txt"),obj); } }
std::string getHtmlFromClass(std::string class_name){ if ( class_name == "Css" ) return ""; TiVar& var = db.at(class_name); if ( var.isObj() ) return var.atObj().atStr("html"); else if ( var.isStr() ) return var.atStr(); else{ cerr << " Error in " << class_name << endl; return ""; } }
inline TiObj& getTemplate( TiObj& node ){ TiVar& var = db.at(node.classe); return *this->getObject(var); }