Skip to content

Commit

Permalink
html document service (#385)
Browse files Browse the repository at this point in the history
  • Loading branch information
andiwand authored Aug 18, 2024
1 parent 916ec72 commit c1482dd
Show file tree
Hide file tree
Showing 8 changed files with 219 additions and 164 deletions.
16 changes: 16 additions & 0 deletions src/odr/html_service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,14 @@ std::vector<HtmlFragment> HtmlService::fragments() const {
return result;
}

void HtmlService::write_html_document(
std::ostream &os, const odr::HtmlConfig &config,
const odr::HtmlResourceLocator &resourceLocator) const {
internal::html::HtmlWriter out(os, config);

m_impl->write_html_document(out, config, resourceLocator);
}

HtmlFragment::HtmlFragment(
std::shared_ptr<internal::abstract::HtmlFragment> impl)
: m_impl{std::move(impl)} {}
Expand All @@ -32,4 +40,12 @@ void HtmlFragment::write_html_fragment(
m_impl->write_html_fragment(out, config, resourceLocator);
}

void HtmlFragment::write_html_document(
std::ostream &os, const odr::HtmlConfig &config,
const odr::HtmlResourceLocator &resourceLocator) const {
internal::html::HtmlWriter out(os, config);

m_impl->write_html_document(out, config, resourceLocator);
}

} // namespace odr
6 changes: 6 additions & 0 deletions src/odr/html_service.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ class HtmlService final {

[[nodiscard]] std::vector<HtmlFragment> fragments() const;

void write_html_document(std::ostream &os, const HtmlConfig &config,
const HtmlResourceLocator &resourceLocator) const;

private:
std::shared_ptr<internal::abstract::HtmlService> m_impl;
};
Expand All @@ -50,6 +53,9 @@ class HtmlFragment final {
void write_html_fragment(std::ostream &os, const HtmlConfig &config,
const HtmlResourceLocator &resourceLocator) const;

void write_html_document(std::ostream &os, const HtmlConfig &config,
const HtmlResourceLocator &resourceLocator) const;

private:
std::shared_ptr<internal::abstract::HtmlFragment> m_impl;
};
Expand Down
8 changes: 8 additions & 0 deletions src/odr/internal/abstract/html_service.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ class HtmlService {

[[nodiscard]] virtual const std::vector<std::shared_ptr<HtmlFragment>> &
fragments() const = 0;

virtual void
write_html_document(html::HtmlWriter &out, const HtmlConfig &config,
const HtmlResourceLocator &resourceLocator) const = 0;
};

class HtmlFragment {
Expand All @@ -31,6 +35,10 @@ class HtmlFragment {
virtual void
write_html_fragment(html::HtmlWriter &out, const HtmlConfig &config,
const HtmlResourceLocator &resourceLocator) const = 0;

virtual void
write_html_document(html::HtmlWriter &out, const HtmlConfig &config,
const HtmlResourceLocator &resourceLocator) const = 0;
};

} // namespace odr::internal::abstract
Expand Down
15 changes: 0 additions & 15 deletions src/odr/internal/html/common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,21 +31,6 @@ std::string file_to_url(const abstract::File &file,
HtmlResourceLocator local_resource_locator(const std::string &output_path,
const HtmlConfig &config);

class StaticHtmlService : public abstract::HtmlService {
public:
explicit StaticHtmlService(
std::vector<std::shared_ptr<abstract::HtmlFragment>> fragments)
: m_fragments(std::move(fragments)) {}

[[nodiscard]] const std::vector<std::shared_ptr<abstract::HtmlFragment>> &
fragments() const override {
return m_fragments;
}

private:
const std::vector<std::shared_ptr<abstract::HtmlFragment>> m_fragments;
};

} // namespace odr::internal::html

#endif // ODR_INTERNAL_HTML_COMMON_HPP
Loading

0 comments on commit c1482dd

Please sign in to comment.