Adds beginnings of BlogPageBuilder and associated classes

This commit is contained in:
Rosia E Evans 2023-09-20 09:09:51 +01:00
parent 65aefe46ce
commit 1506f661c9
114 changed files with 4740 additions and 518 deletions

65
Src/Page.cpp Normal file
View file

@ -0,0 +1,65 @@
#include "Page.h"
// reads flags from fileContents, consumes and flag data found
void Page::calculatePageFlags()
{
int endOfFirstLine = fileContents.find_first_of("\n");
std::string tagLine = fileContents.substr(0, endOfFirstLine);
fileContents = fileContents.substr(endOfFirstLine, fileContents.length()-endOfFirstLine);
FlagReader* flagReader = new FlagReader();
flags = flagReader->readFlags(tagLine);
delete flagReader;
}
std::string readFile(std::string fileUrl)
{
std::ifstream file(fileUrl);
std::stringstream fileCache;
fileCache << file.rdbuf();
return fileCache.str();
}
Page::Page(std::string fileUrl)
{
this->fileUrl = fileUrl;
fileContents = readFile(this->fileUrl);
calculatePageFlags();
}
std::string Page::getPageContents()
{
return fileContents;
}
FileFlags Page::getPageFlags()
{
return flags;
}
std::string Page::getPageTitle()
{
return title;
}
FileFlags FlagReader::readFlags(std::string flagString)
{
FileFlags flags;
for (char c : flagString)
{
switch (c)
{
case 'p':
flags.hidden = true;
break;
}
}
return flags;
}