Skip to content

Commit

Permalink
wire fragment resources; refactor fragment interface
Browse files Browse the repository at this point in the history
  • Loading branch information
andiwand committed Jan 5, 2025
1 parent f5f1d9a commit 234ee00
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 32 deletions.
11 changes: 3 additions & 8 deletions src/odr/html_service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,16 +48,11 @@ const HtmlResourceLocator &HtmlFragment::resource_locator() const {
return m_impl->resource_locator();
}

HtmlResources HtmlFragment::write_fragment(std::ostream &os) const {
void HtmlFragment::write_fragment(std::ostream &os,
HtmlResources &resources) const {
internal::html::HtmlWriter out(os, config());

auto internal_resources = m_impl->write_fragment(out);

HtmlResources resources;
for (const auto &[resource, location] : internal_resources) {
resources.emplace_back(HtmlResource(resource), location);
}
return resources;
m_impl->write_fragment(out, resources);
}

HtmlResources HtmlFragment::write_document(std::ostream &os) const {
Expand Down
2 changes: 1 addition & 1 deletion src/odr/html_service.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class HtmlFragment final {
[[nodiscard]] const HtmlConfig &config() const;
[[nodiscard]] const HtmlResourceLocator &resource_locator() const;

HtmlResources write_fragment(std::ostream &os) const;
void write_fragment(std::ostream &os, HtmlResources &resources) const;

HtmlResources write_document(std::ostream &os) const;

Expand Down
3 changes: 2 additions & 1 deletion src/odr/internal/abstract/html_service.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ class HtmlFragment {
[[nodiscard]] virtual const HtmlConfig &config() const = 0;
[[nodiscard]] virtual const HtmlResourceLocator &resource_locator() const = 0;

virtual HtmlResources write_fragment(html::HtmlWriter &out) const = 0;
virtual void write_fragment(html::HtmlWriter &out,
HtmlResources &resources) const = 0;

virtual HtmlResources write_document(html::HtmlWriter &out) const = 0;
};
Expand Down
28 changes: 6 additions & 22 deletions src/odr/internal/html/document.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ class HtmlServiceImpl : public HtmlService {

front(m_document, state);
for (const auto &fragment : fragments()) {
fragment->write_fragment(out);
fragment->write_fragment(out, resources);
}
back(m_document, state);

Expand All @@ -179,7 +179,7 @@ class HtmlFragmentBase : public HtmlFragment {
WritingState state(out, config(), resource_locator(), resources);

front(m_document, state);
write_fragment(out);
write_fragment(out, resources);
back(m_document, state);

return resources;
Expand All @@ -196,9 +196,7 @@ class TextHtmlFragment final : public HtmlFragmentBase {
: HtmlFragmentBase("document", std::move(document), std::move(config),
std::move(resource_locator)) {}

HtmlResources write_fragment(HtmlWriter &out) const final {
HtmlResources resources;

void write_fragment(HtmlWriter &out, HtmlResources &resources) const final {
WritingState state(out, config(), resource_locator(), resources);

auto root = m_document.root_element();
Expand All @@ -224,8 +222,6 @@ class TextHtmlFragment final : public HtmlFragmentBase {
translate_children(element.children(), state);
out.write_element_end("div");
}

return resources;
}
};

Expand All @@ -237,14 +233,10 @@ class SlideHtmlFragment final : public HtmlFragmentBase {
std::move(resource_locator)),
m_slide{slide} {}

HtmlResources write_fragment(HtmlWriter &out) const final {
HtmlResources resources;

void write_fragment(HtmlWriter &out, HtmlResources &resources) const final {
WritingState state(out, config(), resource_locator(), resources);

html::translate_slide(m_slide, state);

return resources;
}

private:
Expand All @@ -259,14 +251,10 @@ class SheetHtmlFragment final : public HtmlFragmentBase {
std::move(resource_locator)),
m_sheet{sheet} {}

HtmlResources write_fragment(HtmlWriter &out) const final {
HtmlResources resources;

void write_fragment(HtmlWriter &out, HtmlResources &resources) const final {
WritingState state(out, config(), resource_locator(), resources);

translate_sheet(m_sheet, state);

return resources;
}

private:
Expand All @@ -281,14 +269,10 @@ class PageHtmlFragment final : public HtmlFragmentBase {
std::move(resource_locator)),
m_page{page} {}

HtmlResources write_fragment(HtmlWriter &out) const final {
HtmlResources resources;

void write_fragment(HtmlWriter &out, HtmlResources &resources) const final {
WritingState state(out, config(), resource_locator(), resources);

html::translate_page(m_page, state);

return resources;
}

private:
Expand Down

0 comments on commit 234ee00

Please sign in to comment.