Exemple #1
0
	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);
	}
Exemple #2
0
	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);
		}

	}
Exemple #3
0
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;
}