Skip to content

Add expand/collapse to all sections of dottydoc #2489

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 22, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions doc-tool/resources/_layouts/api-page.html
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
{% endif %}

<h1 class="section {% if entity.constructors == null or entity.constructors.size == 0 %}empty{% endif %}">
<span class="expand-button visible{% if entity.constructors == null or entity.constructors.size == 0 %}invisible{% endif %}" onclick="toggleMembersBody(this, 'constructors');">[-]</span>
Constructors
</h1>

Expand Down Expand Up @@ -97,14 +98,15 @@ <h1 class="section {% if entity.constructors == null or entity.constructors.size
</div>

<h1 class="section {% if entity.hasVisibleMembers == false %}empty{% endif %}">
<span class="expand-button visible" onclick="toggleMembersBody(this, 'members');">[-]</span>
Members
</h1>

<div id="entity-members" class="entity-section {% if entity.hasVisibleMembers == false %}empty{% endif %}">
{% for member in entity.members %}
<div id="{{ member.signature }}" class="member {% if member.isPrivate %}private{% elsif member.isProtected %}protected{% endif %}">
<div class="member-title">
<span class="expand-button {% if member.hasShortenedDocstring == false %}invisible{% endif %}" onclick="toggleMemberBody(this, '{{ member.signature }}');">[+]</span>
<span class="expand-button {% if member.comment.body %}visible{% endif %}" onclick="toggleMemberBody(this, '{{ member.signature }}');">[+]</span>
<span class="member-annotations">
{% for annot in member.annotations %}@{{ annot | split: '.' | last }} {% endfor %}
</span>
Expand Down Expand Up @@ -169,21 +171,21 @@ <h1 class="section {% if entity.hasVisibleMembers == false %}empty{% endif %}">
</div><!-- end member-title -->

<div class="member-body">
<div class="member-body-short" id="short-body-{{ member.signature }}">
{{ member.comment.short }}
</div>
<div class="member-body-long" id ="long-body-{{ member.signature }}">
{{ member.comment.body }}
</div>
</div>
<script>

function toggleMembersBody(span, arg){
var members = document.getElementById("entity-" + arg);
members.classList.toggle("toggled");
span.innerHTML = (span.innerHTML == "[-]") ? "[+]" : "[-]";
}

function toggleMemberBody(span, sig) {
var shortBody = document.getElementById("short-body-" + sig);
var longBody = document.getElementById("long-body-" + sig);

shortBody.classList.toggle("toggled")
longBody.classList.toggle("toggled")

span.innerHTML = (span.innerHTML == "[+]") ? "[-]" : "[+]";
}
</script>
Expand Down
4 changes: 4 additions & 0 deletions doc-tool/resources/_layouts/rand.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
currdate=$(date "+%Y-%m-%d\ %H:%M:%S")
currDateComment="<!-- Docs Last Generated On "$currdate"-->"
sed -i '.original' "1s/^/$currDateComment\\
/" main.html
Copy link
Contributor

Choose a reason for hiding this comment

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

This script should probably not be included in the PR

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah Sorry! Will fix it when I fix the commit history. Thanks!

29 changes: 25 additions & 4 deletions doc-tool/resources/css/api-page.css
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,23 @@ h1.section {
margin: 30px 0;
}

h1.section > span.expand-button.visible {
color: rgba(167, 161, 161, 0.5);
font-family: "Source Code Pro", sans-serif;
font-size: 25px;
}

h1.section > span.expand-button.visible:hover {
color: rgb(167, 161, 161);
cursor: pointer;
user-select: none;
}

h1.section > span.expand-button,
h1.section > span.expand-button.hover {
color: transparent;
}

.empty {
display: none;
}
Expand Down Expand Up @@ -112,18 +129,18 @@ div.entity-section > div.member > div.member-title span.no-right {
margin-right: -11px;
}

div.entity-section > div.member > div.member-title > span.expand-button {
div.entity-section > div.member > div.member-title > span.expand-button.visible {
color: rgba(167, 161, 161, 0.5);
}

div.entity-section > div.member > div.member-title > span.expand-button:hover {
div.entity-section > div.member > div.member-title > span.expand-button.visible:hover {
color: rgb(167, 161, 161);
cursor: pointer;
user-select: none;
}

div.entity-section > div.member > div.member-title > span.expand-button.invisible,
div.entity-section > div.member > div.member-title > span.expand-button.invisible:hover {
div.entity-section > div.member > div.member-title > span.expand-button,
div.entity-section > div.member > div.member-title > span.expand-button:hover {
color: transparent;
}

Expand All @@ -142,3 +159,7 @@ div.entity-section > div.member > div.member-body > div.member-body-long {
div.entity-section > div.member > div.member-body > div.member-body-long.toggled {
display: block;
}

div.entity-section.toggled {
display: none;
}
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,6 @@ object JavaConverters {
"path" -> ent.path.asJava,
"children" -> ent.children.map(_.asJava()).asJava,
"comment" -> ent.comment.map(_.asJava).asJava,
"hasShortenedDocstring" -> ent.hasShortenedDocstring,
"signature" -> ent.signature
)
val members = ent match {
Expand Down
3 changes: 0 additions & 3 deletions doc-tool/src/dotty/tools/dottydoc/model/entities.scala
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@ trait Entity { entity =>

def annotations: List[String]

def hasShortenedDocstring: Boolean =
comment.map(d => d.body.length > d.short.length).getOrElse(false)

def signature: String =
entity.name + (entity match {
case o: Object => "$"
Expand Down
1 change: 0 additions & 1 deletion doc-tool/test/JavaConverterTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,6 @@ class JavaConverterTest {
assertEquals(expected.kind, actual.get("kind"))
assertSameSeq(expected.annotations, actual.get("annotations"))
assertSameSeq(expected.path, actual.get("path"))
assertEquals(expected.hasShortenedDocstring, actual.get("hasShortenedDocstring"))
// Only test if a comment is present
expected.comment match {
case Some(c) => assertNotEquals(null, actual.get("comment"))
Expand Down