Skip to content

Commit

Permalink
Paths can be modified at construction time, not generate time
Browse files Browse the repository at this point in the history
  • Loading branch information
danakj committed Dec 12, 2023
1 parent 198e940 commit 4376854
Show file tree
Hide file tree
Showing 9 changed files with 38 additions and 46 deletions.
2 changes: 1 addition & 1 deletion subdoc/lib/gen/generate_concept.cc
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ void generate_concept_overview(HtmlWriter::OpenDiv& record_div,
auto type_sig_div = section_div.open_div(HtmlWriter::SingleLine);
type_sig_div.add_class("type-signature");

generate_source_link(type_sig_div, element, options);
generate_source_link(type_sig_div, element);

if (!element.template_params.is_empty()) {
auto template_pre = type_sig_div.open_pre();
Expand Down
15 changes: 7 additions & 8 deletions subdoc/lib/gen/generate_function.cc
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ void generate_function_extras(HtmlWriter::OpenDiv& div,

void generate_overload_set(HtmlWriter::OpenDiv& div,
const FunctionElement& element, Style style,
bool link_to_page, const Options& options) noexcept {
bool link_to_page) noexcept {
for (const FunctionOverload& overload : element.overloads) {
auto overload_div = div.open_div();
overload_div.add_class("overload");
Expand All @@ -115,7 +115,7 @@ void generate_overload_set(HtmlWriter::OpenDiv& div,
auto signature_div = overload_div.open_div(HtmlWriter::SingleLine);
signature_div.add_class("function-signature");

generate_source_link(signature_div, element, options);
generate_source_link(signature_div, element);

if (!link_to_page) {
// Only methods are not given their own page, and are just a named
Expand Down Expand Up @@ -301,7 +301,7 @@ sus::Result<void, MarkdownToHtmlError> generate_function(
auto signature_div = overload_div.open_div(HtmlWriter::SingleLine);
signature_div.add_class("function-signature");

generate_source_link(signature_div, element, options);
generate_source_link(signature_div, element);

if (!overload.template_params.is_empty()) {
auto template_div = signature_div.open_div(HtmlWriter::SingleLine);
Expand Down Expand Up @@ -353,7 +353,7 @@ sus::Result<void, MarkdownToHtmlError> generate_function(

sus::Result<void, MarkdownToHtmlError> generate_function_reference(
HtmlWriter::OpenUl& items_list, const FunctionElement& element,
ParseMarkdownPageState& page_state, const Options& options) noexcept {
ParseMarkdownPageState& page_state) noexcept {
auto item_li = items_list.open_li();
item_li.add_class("section-item");

Expand All @@ -365,7 +365,7 @@ sus::Result<void, MarkdownToHtmlError> generate_function_reference(
// Operator overloads can all have different parameters and return types, so
// we display them in long form.
generate_overload_set(overload_set_div, element, StyleShort,
/*link_to_page=*/true, options);
/*link_to_page=*/true);
}
{
auto desc_div = item_li.open_div();
Expand All @@ -386,8 +386,7 @@ sus::Result<void, MarkdownToHtmlError> generate_function_reference(

sus::Result<void, MarkdownToHtmlError> generate_function_method_reference(
HtmlWriter::OpenDiv& item_div, const FunctionElement& element,
bool with_constraints, ParseMarkdownPageState& page_state,
const Options& options) noexcept {
bool with_constraints, ParseMarkdownPageState& page_state) noexcept {
{
auto overload_set_div = item_div.open_div();
overload_set_div.add_class("overload-set");
Expand All @@ -396,7 +395,7 @@ sus::Result<void, MarkdownToHtmlError> generate_function_method_reference(
generate_overload_set(
overload_set_div, element,
with_constraints ? StyleLongWithConstraints : StyleLong,
/*link_to_page=*/false, options);
/*link_to_page=*/false);
}
{
auto desc_div = item_div.open_div();
Expand Down
5 changes: 2 additions & 3 deletions subdoc/lib/gen/generate_function.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,10 @@ sus::Result<void, MarkdownToHtmlError> generate_function(

sus::Result<void, MarkdownToHtmlError> generate_function_reference(
HtmlWriter::OpenUl& items_list, const FunctionElement& e,
ParseMarkdownPageState& page_state, const Options& options) noexcept;
ParseMarkdownPageState& page_state) noexcept;

sus::Result<void, MarkdownToHtmlError> generate_function_method_reference(
HtmlWriter::OpenDiv& items_list, const FunctionElement& e,
bool with_constraints, ParseMarkdownPageState& page_state,
const Options& options) noexcept;
bool with_constraints, ParseMarkdownPageState& page_state) noexcept;

} // namespace subdoc::gen
2 changes: 1 addition & 1 deletion subdoc/lib/gen/generate_macro.cc
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ sus::Result<void, MarkdownToHtmlError> generate_macro(
auto signature_div = overload_div.open_div(HtmlWriter::SingleLine);
signature_div.add_class("macro-signature");

generate_source_link(signature_div, element, options);
generate_source_link(signature_div, element);

{
auto auto_span = signature_div.open_span(HtmlWriter::SingleLine);
Expand Down
17 changes: 8 additions & 9 deletions subdoc/lib/gen/generate_namespace.cc
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ void generate_namespace_overview(HtmlWriter::OpenDiv& namespace_div,
auto header_div = section_div.open_div();
header_div.add_class("section-header");

generate_source_link(header_div, element, options);
generate_source_link(header_div, element);

if (element.namespace_name != Namespace::Tag::Global) {
auto span = header_div.open_span();
Expand Down Expand Up @@ -427,7 +427,7 @@ enum GenerateFunctionType {
sus::Result<void, MarkdownToHtmlError> generate_function_references(
HtmlWriter::OpenDiv& namespace_div, const NamespaceElement& element,
sus::Slice<SortedFunctionByName> functions, GenerateFunctionType type,
ParseMarkdownPageState& page_state, const Options& options) {
ParseMarkdownPageState& page_state) {
if (functions.is_empty()) return sus::ok();

auto section_div = namespace_div.open_div();
Expand Down Expand Up @@ -462,8 +462,7 @@ sus::Result<void, MarkdownToHtmlError> generate_function_references(
for (const SortedFunctionByName& sorted_fn : functions) {
const FunctionElement& fe =
function_element_from_sorted(element, sorted_fn);
if (auto result =
generate_function_reference(items_list, fe, page_state, options);
if (auto result = generate_function_reference(items_list, fe, page_state);
result.is_err()) {
return sus::err(sus::move(result).unwrap_err());
}
Expand Down Expand Up @@ -512,7 +511,7 @@ sus::Result<void, MarkdownToHtmlError> generate_macro_references(
sus::Result<void, MarkdownToHtmlError> generate_variable_references(
HtmlWriter::OpenDiv& namespace_div, const NamespaceElement& element,
sus::Slice<SortedVariableByName> variables,
ParseMarkdownPageState& page_state, const Options& options) {
ParseMarkdownPageState& page_state) {
if (variables.is_empty()) return sus::ok();

auto section_div = namespace_div.open_div();
Expand All @@ -535,7 +534,7 @@ sus::Result<void, MarkdownToHtmlError> generate_variable_references(
for (const SortedVariableByName& sorted_var : variables) {
const FieldElement& fe = field_element_from_sorted(element, sorted_var);
if (auto result = generate_field_reference(
items_div, fe, /*static_fields=*/false, page_state, options);
items_div, fe, /*static_fields=*/false, page_state);
result.is_err()) {
return sus::err(sus::move(result).unwrap_err());
}
Expand Down Expand Up @@ -880,23 +879,23 @@ sus::Result<void, MarkdownToHtmlError> generate_namespace(
if (!sorted_functions.is_empty()) {
if (auto result = generate_function_references(
namespace_div, element, sorted_functions, GenerateFunctions,
page_state, options);
page_state);
result.is_err()) {
return sus::err(sus::move(result).unwrap_err());
}
}
if (!sorted_operators.is_empty()) {
if (auto result = generate_function_references(
namespace_div, element, sorted_operators, GenerateOperators,
page_state, options);
page_state);
result.is_err()) {
return sus::err(sus::move(result).unwrap_err());
}
}

if (!sorted_variables.is_empty()) {
if (auto result = generate_variable_references(
namespace_div, element, sorted_variables, page_state, options);
namespace_div, element, sorted_variables, page_state);
result.is_err()) {
return sus::err(sus::move(result).unwrap_err());
}
Expand Down
33 changes: 16 additions & 17 deletions subdoc/lib/gen/generate_record.cc
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ void generate_record_overview(HtmlWriter::OpenDiv& record_div,
auto type_sig_div = section_div.open_div(HtmlWriter::SingleLine);
type_sig_div.add_class("type-signature");

generate_source_link(type_sig_div, element, options);
generate_source_link(type_sig_div, element);

if (!element.template_params.is_empty()) {
auto template_pre = type_sig_div.open_pre();
Expand Down Expand Up @@ -193,7 +193,7 @@ void generate_record_overview(HtmlWriter::OpenDiv& record_div,
sus::Result<void, MarkdownToHtmlError> generate_record_fields(
HtmlWriter::OpenDiv& record_div, const RecordElement& element,
bool static_fields, sus::Slice<SortedFieldByName> fields,
ParseMarkdownPageState& page_state, const Options& options) {
ParseMarkdownPageState& page_state) {
auto section_div = record_div.open_div();
section_div.add_class("section");
section_div.add_class("fields");
Expand Down Expand Up @@ -221,7 +221,7 @@ sus::Result<void, MarkdownToHtmlError> generate_record_fields(
for (auto&& [name, sort_key, field_unique_symbol] : fields) {
const FieldElement& fe = element.fields.at(field_unique_symbol);
if (auto result = generate_field_reference(items_div, fe, static_fields,
page_state, options);
page_state);
result.is_err()) {
return sus::err(sus::move(result).unwrap_err());
}
Expand All @@ -234,7 +234,7 @@ sus::Result<void, MarkdownToHtmlError> generate_record_fields(
sus::Result<void, MarkdownToHtmlError> generate_record_methods(
HtmlWriter::OpenDiv& record_div, const RecordElement& element,
MethodType type, sus::Slice<SortedFunctionByName> methods,
ParseMarkdownPageState& page_state, const Options& options) {
ParseMarkdownPageState& page_state) {
auto section_div = record_div.open_div();
section_div.add_class("section");
section_div.add_class("methods");
Expand Down Expand Up @@ -292,7 +292,7 @@ sus::Result<void, MarkdownToHtmlError> generate_record_methods(
function_element_from_sorted(element, type, sorted_fn);
if (auto result = generate_function_method_reference(
items_div, func,
/*with constraints=*/true, page_state, options);
/*with constraints=*/true, page_state);
result.is_err()) {
return sus::err(sus::move(result).unwrap_err());
}
Expand Down Expand Up @@ -484,9 +484,9 @@ sus::Result<void, MarkdownToHtmlError> generate_record(
md_html, options);

if (!sorted_static_fields.is_empty()) {
if (auto result = generate_record_fields(record_div, element, true,
sorted_static_fields.as_slice(),
page_state, options);
if (auto result =
generate_record_fields(record_div, element, true,
sorted_static_fields.as_slice(), page_state);
result.is_err()) {
return sus::err(sus::move(result).unwrap_err());
}
Expand All @@ -495,40 +495,39 @@ sus::Result<void, MarkdownToHtmlError> generate_record(
if (!sorted_static_methods.is_empty()) {
if (auto result = generate_record_methods(
record_div, element, MethodType::StaticMethods,
sorted_static_methods.as_slice(), page_state, options);
sorted_static_methods.as_slice(), page_state);
result.is_err()) {
return sus::err(sus::move(result).unwrap_err());
}
}
if (!sorted_methods.is_empty()) {
if (auto result = generate_record_methods(
record_div, element, MethodType::NonStaticMethods,
sorted_methods.as_slice(), page_state, options);
sorted_methods.as_slice(), page_state);
result.is_err()) {
return sus::err(sus::move(result).unwrap_err());
}
}
if (!sorted_conversions.is_empty()) {
if (auto result = generate_record_methods(
record_div, element, MethodType::Conversions,
sorted_conversions.as_slice(), page_state, options);
sorted_conversions.as_slice(), page_state);
result.is_err()) {
return sus::err(sus::move(result).unwrap_err());
}
}
if (!sorted_operators.is_empty()) {
if (auto result = generate_record_methods(
record_div, element, MethodType::NonStaticOperators,
sorted_operators.as_slice(), page_state, options);
sorted_operators.as_slice(), page_state);
result.is_err()) {
return sus::err(sus::move(result).unwrap_err());
}
}

if (!sorted_fields.is_empty()) {
if (auto result = generate_record_fields(record_div, element, false,
sorted_fields.as_slice(),
page_state, options);
if (auto result = generate_record_fields(
record_div, element, false, sorted_fields.as_slice(), page_state);
result.is_err()) {
return sus::err(sus::move(result).unwrap_err());
}
Expand Down Expand Up @@ -591,7 +590,7 @@ sus::Result<void, MarkdownToHtmlError> generate_record_reference(

sus::Result<void, MarkdownToHtmlError> generate_field_reference(
HtmlWriter::OpenDiv& div, const FieldElement& element, bool static_fields,
ParseMarkdownPageState& page_state, const Options& options) noexcept {
ParseMarkdownPageState& page_state) noexcept {
auto item_div = div.open_div();
item_div.add_class("section-item");

Expand All @@ -600,7 +599,7 @@ sus::Result<void, MarkdownToHtmlError> generate_field_reference(
sig_div.add_class("item-name");
sig_div.add_class("member-signature");

generate_source_link(sig_div, element, options);
generate_source_link(sig_div, element);

{
auto anchor = sig_div.open_a();
Expand Down
2 changes: 1 addition & 1 deletion subdoc/lib/gen/generate_record.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,6 @@ sus::Result<void, MarkdownToHtmlError> generate_record_reference(

sus::Result<void, MarkdownToHtmlError> generate_field_reference(
HtmlWriter::OpenDiv& div, const FieldElement& element, bool static_fields,
ParseMarkdownPageState& page_state, const Options& options) noexcept;
ParseMarkdownPageState& page_state) noexcept;

} // namespace subdoc::gen
5 changes: 1 addition & 4 deletions subdoc/lib/gen/generate_source_link.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@
namespace subdoc::gen {

void generate_source_link(HtmlWriter::OpenDiv& div,
const CommentElement& element,
const Options& options) {
const CommentElement& element) {
if (element.source_link.is_some()) {
const SourceLink& link = element.source_link.as_value();

Expand All @@ -29,8 +28,6 @@ void generate_source_link(HtmlWriter::OpenDiv& div,
auto a = source_link_div.open_a();
{
std::ostringstream str;
// TODO: URL prefix.
(void)options;
str << link.file_path << "#" << link.line;
a.add_href(sus::move(str).str());
}
Expand Down
3 changes: 1 addition & 2 deletions subdoc/lib/gen/generate_source_link.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
namespace subdoc::gen {

void generate_source_link(HtmlWriter::OpenDiv& div,
const CommentElement& element,
const Options& options);
const CommentElement& element);

} // namespace subdoc::gen

0 comments on commit 4376854

Please sign in to comment.