void create(std::string filename){ cerr << "Compiling " << filename << endl; TiObj objs; objs.loadFile(filename); if ( objs.has("template") ){ TiVar& var_tmpl = objs["template"]; if ( var_tmpl.isObj() ){ this->db = var_tmpl.atObj(); } else { db.loadFile( objs.atStr("template") ); if ( db.is("Error") ){ cerr << objs; return; } } } else { if ( objs.is("Error") ){ cerr << objs; } else cerr << "Nao existe template configurado\n"; return; } this->root = objs.atStr("root","."); // Reopen cout int pos = filename.find_last_of('.'); string outfile = Join("%s.html").at(filename.substr(0,pos)).ok; freopen (outfile.c_str(),"w",stdout); // Create the response cout << "<html><head>\n"; cout << "\t<meta charset=\"utf-8\">\n"; for (int i=0; i<objs.size(); i++){ TiObj& node = objs.box[i]; if ( node.is("Css") ){ cout << Join("\t<link href=\"%s\" rel=\"stylesheet\">\n").at(node.atStr("url")).ok; }/* else if ( node.is("Js") ){ cout << Join("\t<link href=\"%s\" rel=\"stylesheet\">\n").at(node.atStr("url")).ok(); }*/ } if ( objs.has("title") ){ cout << Join("\t<title>%s</title>").at(objs.atStr("title")).ok; } cout << "</head><body>\n"; for (int i=0; i<objs.size(); i++){ this->process( objs.box[i] ); } cout << "</body></html>\n"; // Close the file fclose(stdout); }
std::string path_context (std::string classe, std::string _url){ string url; if ( _url == "" ) url = path_absolute("."); else url = path_absolute(_url); Filesystem fs; TiObj aux; while (true){ if ( url.size() == 0 ) return ""; aux.set( "class", fs.folder_type(url) ); if ( aux.is(classe) ){ break; } if ( url == "/" ){ return ""; } else { int i; for ( i=url.size()-1; i>0; i--){ if ( url[i] == '/' ){ break; } } if ( i == 0 ) url.resize(1); else url.resize(i); } } return url; }
void Filesystem::folder_sysobj(TiObj& out, std::string url){ out.clear(); string descfile = path_add(url,".sysobj.ti"); if ( this->exists(descfile) ){ out.load(descfile); } if ( out.classe() == "" ){ out.set("class", "Folder"); } else if ( !out.is("Folder") ){ out.set("class", "Folder:"+out.classe()); } }
bool Filesystem::ls_r( TiObj out, std::string url ){ TiObj buffer = this->ls(url); for ( int i=0; i<buffer.size(); i++){ TiObj node = buffer.box(i); if ( node.is("Folder") ){ this->ls_r( out, node.atStr("url") ); } else { out.box() += node; } } return true; }
int main(int argc, char** argv){ TiObj obj; TiStream stream(stdin); if ( argc > 1 ){ while ( stream.next(obj) ){ if ( obj->is(argv[1]) ) cout << obj->encode(1) << endl; } } else { while ( stream.next(obj) ){ cout << obj->encode(1) << endl; } } return 0; }
int main(){ string nom = getenv("nom"); string akk = getenv("_Akk"); TiObj buf; if ( nom == "." ){ buf.loadFile(stdin); } else { buf.loadFile(nom); if ( buf.is("ERROR") ){ cerr << buf; return 1; } } cout << buf.atStr(akk) << endl; return 0; }