initial commit

This commit is contained in:
2024-01-01 15:31:33 +01:00
commit 572fdbb5cc
6 changed files with 289 additions and 0 deletions

112
include/Lazy.h Normal file
View File

@@ -0,0 +1,112 @@
#pragma once
#include <string>
#include <vector>
#include <memory>
enum class LazyType
{
Title,
Text,
Image,
};
class LazyElement
{
public:
virtual LazyType GetType() const = 0;
};
class LazyTitle : public LazyElement
{
private:
std::string m_Title;
std::uint8_t m_TitleLevel;
public:
LazyTitle(const std::string &title, const std::uint8_t level) : m_Title(title), m_TitleLevel(level) {}
virtual LazyType GetType() const override
{
return LazyType::Title;
};
const std::string &GetTitle() const
{
return m_Title;
}
int GetTitleLevel() const
{
return m_TitleLevel;
}
};
class LazyText : public LazyElement
{
private:
std::string m_Text;
public:
LazyText(const std::string &text) : m_Text(text) {}
virtual LazyType GetType() const override
{
return LazyType::Text;
};
const std::string &GetText() const
{
return m_Text;
}
};
class LazyImage : public LazyElement
{
private:
std::string m_ImageLink;
std::string m_ImageAlt;
public:
LazyImage(const std::string &link, const std::string &alt) : m_ImageLink(link), m_ImageAlt(alt) {}
virtual LazyType GetType() const override
{
return LazyType::Image;
};
const std::string &GetAlt() const
{
return m_ImageAlt;
}
const std::string &GetLink() const
{
return m_ImageLink;
}
};
typedef std::vector<std::unique_ptr<LazyElement>> ElementList;
class LazyFile
{
private:
ElementList m_Elements;
public:
void AddImage(const std::string &link, const std::string &alt) {
m_Elements.push_back(std::make_unique<LazyImage>(link, alt));
}
void AddTitle(const std::string &title, const std::uint8_t level) {
m_Elements.push_back(std::make_unique<LazyTitle>(title, level));
}
void AddText(const std::string& text) {
m_Elements.push_back(std::make_unique<LazyText>(text));
}
const ElementList& GetElements() const {
return m_Elements;
}
};
std::string RenderHtml(const LazyFile& lazy);
LazyFile ReadLazyFile(const std::string& filePath);