page.cpp 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #include <fstream>
  2. #include <string>
  3. #include <filesystem>
  4. #include "page.h"
  5. #include "exception.h"
  6. #include "subprojects/tedi2html/tedi2html.h"
  7. using namespace std;
  8. using namespace filesystem;
  9. page::~page(){}
  10. page::page(){}
  11. /*
  12. * part_path: part file with tedi code
  13. * header: complete header text from header file
  14. * end: complete header text from end file
  15. */
  16. page::page(string part_path, string header, string end){
  17. this->header = header;
  18. this->path = part_path;
  19. string part;
  20. ifstream reader(part_path);
  21. string line;
  22. while(getline(reader,line))
  23. part += line + "\n";
  24. reader.close();
  25. this->body = part;
  26. this->end = end;
  27. }
  28. page& page::operator =(const page& P)
  29. {
  30. if (this != &P) { // avoid self-allocation
  31. path = P.path;
  32. header = P.header;
  33. body = P.body;
  34. end = P.end;
  35. }
  36. return *this;
  37. }
  38. void page::save(){
  39. string current_folder = current_path();
  40. cout << current_folder + "/www" + path.substr(current_folder.size() + 6) + ".html" << endl;
  41. ofstream writer(current_folder + "/www" + path.substr(current_folder.size() + 6) + ".html");
  42. string text;
  43. try{
  44. text = tedi2html().convert(body, header, end);
  45. }catch(Invalid i){
  46. cout << i.line() << endl;
  47. cout << i.reason() << endl;
  48. }
  49. writer << text;
  50. writer.close();
  51. }