Skip to content

Reduce redundancy in HTML output.#147

Merged
s-ludwig merged 1 commit intomasterfrom
reduce_redundancy
Mar 7, 2017
Merged

Reduce redundancy in HTML output.#147
s-ludwig merged 1 commit intomasterfrom
reduce_redundancy

Conversation

@s-ludwig
Copy link
Member

@s-ludwig s-ludwig commented Mar 5, 2017

This is a more complete approach for #146, combining all declarations in a doc group and removing several redundant sub headings. Most importantly, it behaves correctly for doc pages with multiple doc groups.

With these changes, it now looks like this:
ddox

Copy link
Contributor

@wilzbach wilzbach left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not very familiar with the DDox codebase, so my first review might not be that helpful..

ul
- foreach (i, dg; info.docGroups)
- auto itm = dg.members[0];
li: a(href="\##{i}") #{dg.kinds.joiner("/")} #{itm.nestedName}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about using itm.nestedName.slugify?
A not optimized, but nicely working slugify method that I copy/paste around from time to time:

string slugify(string target) {
    import std.regex;
    import std.string : toLower;
    static immutable slugR = ctRegex!(r"[^a-z]+", "g");
    auto ret = target.toLower.replaceAll(slugR, "-");
    if(ret[0] == '-') {
        ret = ret[1..$];
    }
    if(ret[$-1] == '-') {
        ret = ret[0..$-1];
    }
    return ret;
}

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That would possibly result in duplicate anchor names. Using the mangled name as a basis could work, but the question is if that would be much better, since any small change in a function or template signature would change the outcome (thus rendering permanent links nearly as useless as for simple indexes).

- foreach (i, dg; info.docGroups)
- bool got_function = false;
- int hlevel = 2 + multi_page;
- auto kinds = dg.kinds;
Copy link
Contributor

@wilzbach wilzbach Mar 5, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this really worth it?
(kinds is not used much below)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's used once in the beginning and once in each foreach iteration. Usually the number of elements that kinds operates on will be quite limited, but it performs a GC allocation and sorting, so it isn't really cheap. Especially the GC allocation can be significant (it should really be eliminated completely, but as long as there are others this doesn't have the highest priority).

This should be more obvious from the name, though. I'll rename kinds to collectKinds.

- if (info.docGroups.length > 1)
h2 #{item.kindCaption} #{item.nestedName}
- if (multi_page)
h2(id=i) #{kinds.joiner("/")} #{dg.members[0].nestedName}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you go down the slugify road it would be sth. like: h2(name=dg.members[0].nestedName.slugify)

- if (hlevel == 2)
h2 #{item.kindCaption} #{item.nestedName}
- else
h3 #{item.kindCaption} #{item.nestedName}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why don't you use the new heading function here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Forgot to change this when I introduced heading later in the process. Will fix.

@s-ludwig
Copy link
Member Author

s-ludwig commented Mar 7, 2017

Okay, I think I have everything and will squash and merge now.

Would still be interesting if there is a better (more stable) way to generate page anchors. Maybe something in-between mangled names and indexes, or maybe something that just involves the base kind (function/class/...), the case sensitive name and parameter names.

This is a more complete approach for #146, combining all declarations in a doc group and removing several redundant sub headings.

Also reduces the footprint of the legal footer.
@s-ludwig s-ludwig force-pushed the reduce_redundancy branch from 567956e to 5f7aef8 Compare March 7, 2017 09:29
@wilzbach
Copy link
Contributor

wilzbach commented Mar 7, 2017

Would still be interesting if there is a better (more stable) way to generate page anchors. Maybe something in-between mangled names and indexes, or maybe something that just involves the base kind (function/class/...), the case sensitive name and parameter names.

I highly doubt that it will matter much if the link is "broken" as the user is already on the single artifact page.
So imho while being interesting it won't have impact on real-world users.

@s-ludwig s-ludwig merged commit b69e2a3 into master Mar 7, 2017
@s-ludwig s-ludwig deleted the reduce_redundancy branch March 7, 2017 10:58
@s-ludwig
Copy link
Member Author

s-ludwig commented Mar 7, 2017

You are probably right. I'll still open a ticket, but leave that topic for later.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

Comments