1
0
Fork 0
mirror of https://github.com/ganelson/inform.git synced 2024-07-01 06:24:58 +03:00
inform7/inter/index-module/Chapter 3/Contents Element.w

181 lines
6.3 KiB
OpenEdge ABL
Raw Normal View History

2021-06-07 00:18:08 +03:00
[ContentsElement::] Contents Element.
To write the Contents element (C) in the index.
2021-07-25 00:04:35 +03:00
@ This is a hierarchical contents page.
2021-06-07 00:18:08 +03:00
=
void ContentsElement::render(OUTPUT_STREAM, localisation_dictionary *LD) {
inter_tree *I = InterpretIndex::get_tree();
2021-06-07 00:18:08 +03:00
tree_inventory *inv = Synoptic::inv(I);
TreeLists::sort(inv->extension_nodes, Synoptic::category_order);
TreeLists::sort(inv->heading_nodes, Synoptic::module_order);
2021-07-25 00:04:35 +03:00
@<Write a sort of half-title page@>;
@<Index the headings@>;
@<Index the extensions@>;
}
@<Write a sort of half-title page@> =
2021-06-07 00:18:08 +03:00
HTML_OPEN("p");
WRITE("<b>");
inter_package *pack = Inter::Packages::by_url(I, I"/main/completion/bibliographic");
text_stream *title = Metadata::read_optional_textual(pack, I"^title");
text_stream *author = Metadata::read_optional_textual(pack, I"^author");
2021-07-25 00:04:35 +03:00
if (Str::len(title) > 0) {
if (Str::len(author) > 0)
Localisation::write_2(OUT, LD, I"Index.Elements.C.Titling", title, author);
else
Localisation::write_1(OUT, LD, I"Index.Elements.C.AnonymousTitling", title);
}
2021-06-07 00:18:08 +03:00
WRITE("</b>");
HTML_CLOSE("p");
@<Index the headings@> =
2021-07-25 00:04:35 +03:00
HTML_OPEN("p");
Localisation::write_0(OUT, LD, I"Index.Elements.C.ContentsHeading");
HTML_CLOSE("p");
int min_positive_level = 10, entries_written = 0;
inter_package *heading_pack;
LOOP_OVER_INVENTORY_PACKAGES(heading_pack, i, inv->heading_nodes)
if (Metadata::read_numeric(heading_pack, I"^indexable")) {
int L = (int) Metadata::read_numeric(heading_pack, I"^level");
if ((L > 0) && (L < min_positive_level)) min_positive_level = L;
}
LOOP_OVER_INVENTORY_PACKAGES(heading_pack, i, inv->heading_nodes)
if (Metadata::read_numeric(heading_pack, I"^indexable")) {
@<Index this entry in the contents@>;
entries_written++;
}
2021-06-07 00:18:08 +03:00
2021-07-25 00:04:35 +03:00
if (entries_written == 0) {
HTML_OPEN("p");
WRITE("(");
Localisation::write_0(OUT, LD, I"Index.Elements.C.NoContents");
2021-06-07 00:18:08 +03:00
WRITE(")");
HTML_CLOSE("p");
WRITE("\n");
}
@<Index this entry in the contents@> =
2021-07-25 00:04:35 +03:00
int L = (int) Metadata::read_numeric(heading_pack, I"^level");
2021-06-07 00:18:08 +03:00
/* indent to correct tab position */
HTML_OPEN_WITH("ul", "class=\"leaders\""); WRITE("\n");
2021-07-25 00:04:35 +03:00
int ind_used = (int) Metadata::read_numeric(heading_pack, I"^indentation");
2021-06-07 00:18:08 +03:00
if (L == 0) ind_used = 1;
HTML_OPEN_WITH("li", "class=\"leaded indent%d\"", ind_used);
HTML_OPEN("span");
2021-07-25 00:04:35 +03:00
WRITE("%S", Metadata::read_textual(heading_pack, I"^text"));
2021-06-07 00:18:08 +03:00
HTML_CLOSE("span");
HTML_OPEN("span");
if (L > min_positive_level) HTML::begin_colour(OUT, I"808080");
2021-07-25 00:04:35 +03:00
ContentsElement::word_count(OUT, heading_pack, LD);
2021-06-07 00:18:08 +03:00
if (L > min_positive_level) HTML::end_colour(OUT);
/* place a link to the relevant line of the primary source text */
2021-07-25 00:04:35 +03:00
IndexUtilities::link_package(OUT, heading_pack);
2021-06-07 00:18:08 +03:00
HTML_CLOSE("span");
HTML_CLOSE("li");
HTML_CLOSE("ul");
WRITE("\n");
2021-07-25 00:04:35 +03:00
text_stream *summary = Metadata::read_optional_textual(heading_pack, I"^summary");
2021-06-07 00:18:08 +03:00
if (Str::len(summary) > 0) {
HTML::open_indented_p(OUT, ind_used+1, "hanging");
HTML::begin_colour(OUT, I"808080");
WRITE("<i>%S</i>", summary);
HTML::end_colour(OUT);
HTML_CLOSE("p");
}
@<Index the extensions@> =
2021-07-25 00:04:35 +03:00
HTML_OPEN("p");
Localisation::write_0(OUT, LD, I"Index.Elements.C.ExtensionsHeading");
HTML_CLOSE("p");
ContentsElement::index_extensions_included_by(OUT, inv, NULL, FALSE, LD);
inter_package *ext_pack;
LOOP_OVER_INVENTORY_PACKAGES(ext_pack, i, inv->extension_nodes) {
inter_symbol *by_id =
Metadata::read_optional_symbol(ext_pack, I"^included_by");
if (by_id) ContentsElement::index_extensions_included_by(OUT, inv, by_id,
NOT_APPLICABLE, LD);
2021-06-07 00:18:08 +03:00
}
2021-07-25 00:04:35 +03:00
ContentsElement::index_extensions_included_by(OUT, inv, NULL, TRUE, LD);
2021-06-07 00:18:08 +03:00
2021-07-25 00:04:35 +03:00
@ This is called recursively to show how extensions have included each other:
2021-06-07 00:18:08 +03:00
=
void ContentsElement::index_extensions_included_by(OUTPUT_STREAM, tree_inventory *inv,
2021-07-25 00:04:35 +03:00
inter_symbol *owner_id, int auto_included, localisation_dictionary *LD) {
2021-06-07 00:18:08 +03:00
int show_head = TRUE;
2021-07-25 00:04:35 +03:00
inter_package *pack;
LOOP_OVER_INVENTORY_PACKAGES(pack, i, inv->extension_nodes) {
2021-06-07 00:18:08 +03:00
inter_symbol *by_id = Metadata::read_optional_symbol(pack, I"^included_by");
if (by_id == owner_id) {
if ((auto_included != NOT_APPLICABLE) &&
((int) Metadata::read_optional_numeric(pack, I"^auto_included") != auto_included))
continue;
if (show_head) {
HTML::open_indented_p(OUT, 2, "hanging");
HTML::begin_colour(OUT, I"808080");
2021-07-25 00:04:35 +03:00
if (auto_included == TRUE)
Localisation::write_0(OUT, LD, I"Index.Elements.C.IncludedAutomatically");
else if (auto_included == FALSE)
Localisation::write_0(OUT, LD, I"Index.Elements.C.IncludedFromSource");
2021-06-07 00:18:08 +03:00
else {
inter_package *owner_pack = Inter::Packages::container(owner_id->definition);
2021-07-25 00:04:35 +03:00
Localisation::write_1(OUT, LD, I"Index.Elements.C.IncludedBy",
Metadata::read_optional_textual(owner_pack, I"^title"));
2021-06-07 00:18:08 +03:00
}
HTML::end_colour(OUT);
HTML_CLOSE("p");
show_head = FALSE;
}
@<Index this extension@>;
}
}
}
@<Index this extension@> =
inter_symbol *by_id = Metadata::read_optional_symbol(pack, I"^included_by");
HTML_OPEN_WITH("ul", "class=\"leaders\"");
HTML_OPEN_WITH("li", "class=\"leaded indent2\"");
HTML_OPEN("span");
WRITE("%S ", Metadata::read_textual(pack, I"^title"));
if (Metadata::read_optional_numeric(pack, I"^standard") == 0) {
2021-07-24 20:16:56 +03:00
IndexUtilities::link_package(OUT, pack); WRITE("&nbsp;&nbsp;");
2021-06-07 00:18:08 +03:00
}
if (auto_included != TRUE) WRITE("by %S ", Metadata::read_textual(pack, I"^author"));
text_stream *v = Metadata::read_textual(pack, I"^version");
if (Str::len(v) > 0) {
HTML_OPEN_WITH("span", "class=\"smaller\"");
2021-07-25 00:04:35 +03:00
Localisation::write_1(OUT, LD, I"Index.Elements.C.Version", v);
2021-06-07 00:18:08 +03:00
HTML_CLOSE("span");
2021-07-25 00:04:35 +03:00
WRITE(" ");
2021-06-07 00:18:08 +03:00
}
text_stream *ec = Metadata::read_optional_textual(pack, I"^extra_credit");
if (Str::len(ec) > 0) {
HTML_OPEN_WITH("span", "class=\"smaller\"");
WRITE("(%S) ", ec);
HTML_CLOSE("span");
}
HTML_CLOSE("span");
HTML_OPEN("span");
2021-07-25 00:04:35 +03:00
ContentsElement::word_count(OUT, pack, LD);
2021-06-07 00:18:08 +03:00
if (by_id == NULL) {
int at = (int) Metadata::read_optional_numeric(pack, I"^included_at");
2021-07-09 00:56:01 +03:00
if (at > 0) IndexUtilities::link(OUT, at);
2021-06-07 00:18:08 +03:00
}
HTML_CLOSE("span");
HTML_CLOSE("li");
HTML_CLOSE("ul");
WRITE("\n");
2021-07-25 00:04:35 +03:00
@ =
void ContentsElement::word_count(OUTPUT_STREAM, inter_package *pack,
localisation_dictionary *LD) {
TEMPORARY_TEXT(words)
WRITE_TO(words, "%d", Metadata::read_numeric(pack, I"^word_count"));
Localisation::write_1(OUT, LD, I"Index.Elements.C.Words", words);
DISCARD_TEXT(words)
}