123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293 |
- #include <fstream>
- #include <string>
- #include "page.h"
- using namespace std;
- #define INDEX_FOOTER1 "\n\t<footer>\n\t<ul>\n\t<li>"
- #define INDEX_FOOTER2 "\n\t<li><a href=\"manifiesto.html\">Manifiesto</a>\n\t<li><a href=\"en/index.html\">English</a>\n\t</ul>\n\t</footer>\n\t</div>\n</body>\n</html>"
- #define INDEX_FOOTER2_EN "\n\t<li><a href=\"manifesto.html\">Manifesto</a>\n\t<li><a href=\"../index.html\">Español</a>\n\t</ul>\n\t</footer>\n\t</div>\n</body>\n</html>"
- page::~page(){}
- page::page(){}
- /*
- * This constructor done index pages. Index pages have a different
- * footer with the version.
- * root:
- * 0: root directory
- * 1: relative directories
- * language:
- * 0: spanish
- * 1: english
- */
- page::page(string name, int language, int root, string version){
- this->name=name;
- string aux;
- if(language == 1){
- aux="en/";
- this->footer=INDEX_FOOTER1 + version + INDEX_FOOTER2_EN;
- }else{
- this->footer=INDEX_FOOTER1 + version + INDEX_FOOTER2;
- }
- if(root == 0){
- aux+="relative";
- }else{
- aux+="root";
- }
- this->header=load(HEAD + aux);
-
- this->body=load(BODY + name);
- }
- /*
- *
- * Constructor for every page.
- * root:
- * 0: root directory
- * 1: relative directories
- * language:
- * 0: Spanish
- * 1: English
- */
- page::page(string name, int language, int root){
- this->name=name;
- string aux;
- if(language == 1){
- aux="en/";
- }
- if(root == 0){
- aux+="relative";
- }else{
- aux+="root";
- }
- this->header=load(HEAD + aux);
- this->footer=load(FOOT + aux);
- this->body=load(BODY + name);
- }
- page& page::operator =(const page& P)
- {
- if (this != &P) { // avoid avoid self-allocation
- name=P.name;
- header=P.header;
- body=P.body;
- footer=P.footer;
- }
- return *this;
- }
- /*
- * 1.- Check if string constructor doesn't set garbage
- * 2.- If fstream can use string variable
- */
- string page::load(string file){
- ifstream reader(file);
- string line;
- string loaded_text;
- while(getline(reader,line))
- loaded_text+=line + "\n";
- reader.close();
- return loaded_text;
- }
- void page::save(string text){
- ofstream writer(LASTFOLDER + this->name +".html");
- writer << text;
- writer.close();
- }
|