-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Add browsable versions extension for scaladoc #12596
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
Add browsable versions extension for scaladoc #12596
Conversation
468fe96
to
c46d686
Compare
document.onclick = (e: Event) => { | ||
if e.target.asInstanceOf[html.Element].id != "dropdown-button" then | ||
document.getElementById("dropdown-content").classList.remove("show") | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use document.addEventListener('click', (Event) => Unit)
instead. onclick
allows to attach only one handler per event so if anybody somewhere else did document.onclick
, this handler would get overriden.
document is frequently used and it's very likely that somebody overrides it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will change
@JSExportTopLevel("dropdownHandler") | ||
def dropdownHandler() = | ||
if document.getElementById("dropdown-content").getElementsByTagName("a").size > 0 && | ||
window.getSelection.toString.length == 0 then |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why do you need to check for selection?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To let people copy the version without clicking the button
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that's a good point. It didn't occur to me.
for i <- 0 until a.length do | ||
val txtValue = a(i).innerText | ||
val disp = if txtValue.toUpperCase.indexOf(filter) > -1 then | ||
"" | ||
else | ||
"none" | ||
a(i).asInstanceOf[html.Anchor].style.display = disp |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems that in Scala.js you can use HTMLCollection just like Seq, so you could just do a.foreach
scala-js/scala-js-dom#194
https://github.com/scala-js/scala-js-dom/blob/master/src/main/scala/org/scalajs/dom/ext/Extensions.scala
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok
for i <- 0 until a.length do | ||
val txtValue = a(i).innerText | ||
val disp = if txtValue.toUpperCase.indexOf(filter) > -1 then | ||
"" | ||
else | ||
"none" | ||
a(i).asInstanceOf[html.Anchor].style.display = disp |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's better to use css class instead of inline style
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok
b396d86
to
d165021
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting! Do you mind adding more comments to the implementation class DropdownHandler
, and also user documentation on how to use this feature? The most important thing is that we never document the expected format of the JSON document that provides the versions. An example would be welcome.
I’m curious to see how you eventually build the documentation for several versions. Did you experiment with some solutions already? It seems tempting to leave the content in the Git history, at specific tags, but then it means that to build the documentation you would have to perform multiple Git commands, and also sometimes you want to be able to keep improving the documentation even after a release. I think the other alternative would be to keep every version of the documentation in subdirectories? Then the process for creating a new version of the documentation would be to copy the current docs into a new subdirectory and update the JSON dictionary accordingly.
window.sessionStorage.setItem(KEY, UNDEFINED_VERSIONS) | ||
disableButton() | ||
} | ||
catch // Globals.versionDictionaruUrl is undefined |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not check if versionsDictionaryUrl
is set before calling getURLContent
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The exception is not thrown by getUrlContent
but by accessing versionsDictionaryUrl
itself.
When I want to access the js proprty that actually does not exists (because not always we want to have more docs linked) we do not append js property to html header properties, thus when we want to access it we get and exception at js runtime. I don't know if I can handle this one better, I did it after inspecting the transpiled js code and it's the only solution I could come up with.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would a if Globals.versionDictionaryUrl == js.undefined
work?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will confirm that, but if I recall correctly calling Globals.versionDictionaryUrl
throws the exception, not the comparison
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In addition to changing it to js.UndefOr[String]
, use
if (js.typeOf(Globals.versionDictionaryUrl) != "undefined") {
// it's defined
} else {
// it's not
}
js.typeOf
is magical, like JavaScript's typeof
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, will try out
Hi @julienrf I know I haven't provided yet any documentation, I was about to as soon as we implement it for When it comes to the deploy, we provide dynamic interface for injecting dictionary of versions with url locations and it's up to user to manage the releases. User can keep them as he wish as long as they are available at their url path. For dotty, we will probably manage it with github actions by checking out git tree at provided list of tags, then getting tasty files, at last we will generate all the html docs using the newest scaladoc (for keeping the UI interface concise). |
d165021
to
84feae8
Compare
No description provided.