From 286c802d1f45914db0a0c7a7c7f9d34592384764 Mon Sep 17 00:00:00 2001 From: Lucas Date: Thu, 13 Apr 2023 10:51:39 +0200 Subject: [PATCH 1/7] Feat: Add a custom icon - Add setting "custom" - Possible white icon with||without dark icon - Improve tap target --- .../theme/components/button/icon-button.css | 22 +++++++++++++++++++ .../dotty_res/styles/theme/layout/footer.css | 4 ++-- .../tools/scaladoc/ScaladocSettings.scala | 3 ++- .../dotty/tools/scaladoc/SocialLinks.scala | 18 ++++++++++----- .../scaladoc/renderers/HtmlRenderer.scala | 21 +++++++----------- 5 files changed, 47 insertions(+), 21 deletions(-) diff --git a/scaladoc/resources/dotty_res/styles/theme/components/button/icon-button.css b/scaladoc/resources/dotty_res/styles/theme/components/button/icon-button.css index a6450984131e..59d506c27fd9 100644 --- a/scaladoc/resources/dotty_res/styles/theme/components/button/icon-button.css +++ b/scaladoc/resources/dotty_res/styles/theme/components/button/icon-button.css @@ -533,6 +533,28 @@ content: url("../../../../images/icon-buttons/gitter/dark/selected.svg"); } +/* custom button */ + +.icon-button.custom-dark{ + display: none; +} + +.theme-dark .icon-button.custom-dark{ + display: unset; +} + +.theme-dark .icon-button.custom{ + display: none; +} + +.icon-button.custom:hover{ + opacity: 0.8; +} + +.icon-button.custom-dark:hover{ + opacity: 0.8; +} + /* copy button */ .icon-button.copy-button::after { diff --git a/scaladoc/resources/dotty_res/styles/theme/layout/footer.css b/scaladoc/resources/dotty_res/styles/theme/layout/footer.css index 7c169af00591..9178e4a01acc 100644 --- a/scaladoc/resources/dotty_res/styles/theme/layout/footer.css +++ b/scaladoc/resources/dotty_res/styles/theme/layout/footer.css @@ -64,7 +64,7 @@ display: none; } - #footer.mobile-footer .text-mobile { + #footer.mobile-footer .text-mobile { display: flex; width: 100%; justify-content: center; @@ -78,5 +78,5 @@ #footer.mobile-footer > .text-mobile { display: flex; } - + } \ No newline at end of file diff --git a/scaladoc/src/dotty/tools/scaladoc/ScaladocSettings.scala b/scaladoc/src/dotty/tools/scaladoc/ScaladocSettings.scala index 5f2faf6df4d5..6a72d3c33a04 100644 --- a/scaladoc/src/dotty/tools/scaladoc/ScaladocSettings.scala +++ b/scaladoc/src/dotty/tools/scaladoc/ScaladocSettings.scala @@ -43,7 +43,8 @@ class ScaladocSettings extends SettingGroup with AllScalaSettings: val socialLinks: Setting[List[String]] = MultiStringSetting("-social-links", "social-links", - "Links to social sites. '[github|twitter|gitter|discord]::link' syntax is used.") + "Links to social sites. '[github|twitter|gitter|discord]::link' syntax is used." + + "'custom::link::white_icon_name::black_icon_name' is also allowed, in this case icons must be present in 'images/'' directory.") val deprecatedSkipPackages: Setting[List[String]] = MultiStringSetting("-skip-packages", "packages", "Deprecated, please use `-skip-by-id` or `-skip-by-regex`") diff --git a/scaladoc/src/dotty/tools/scaladoc/SocialLinks.scala b/scaladoc/src/dotty/tools/scaladoc/SocialLinks.scala index a07029d06c50..a7efde9b8aec 100644 --- a/scaladoc/src/dotty/tools/scaladoc/SocialLinks.scala +++ b/scaladoc/src/dotty/tools/scaladoc/SocialLinks.scala @@ -1,10 +1,15 @@ package dotty.tools.scaladoc -enum SocialLinks(val url: String, val className: String): - case Github(ghUrl: String) extends SocialLinks(ghUrl, "gh") - case Twitter(tUrl: String) extends SocialLinks(tUrl, "twitter") - case Gitter(gUrl: String) extends SocialLinks(gUrl, "gitter") - case Discord(dUrl: String) extends SocialLinks(dUrl, "discord") +import java.nio.file.Path +import java.nio.file.Paths +import dotty.tools.dotc.core.Contexts.Context + +enum SocialLinks(val url: String, val whiteIcon: String, val darkIcon: String, val className: String): + case Github(ghUrl: String) extends SocialLinks(ghUrl, "", "", "gh") + case Twitter(tUrl: String) extends SocialLinks(tUrl, "", "", "twitter") + case Gitter(gUrl: String) extends SocialLinks(gUrl, "", "", "gitter") + case Discord(dUrl: String) extends SocialLinks(dUrl, "", "", "discord") + case Custom(cUrl: String, firstIcon: String, secondIcon: String) extends SocialLinks(cUrl, firstIcon, secondIcon, "custom") object SocialLinks: def parse(s: String): Either[String, SocialLinks] = @@ -19,5 +24,8 @@ object SocialLinks: case "gitter" => Left(errorPrefix + "For 'gitter' arg expected one argument: url") case "discord" if splitted.size == 2 => Right(Discord(splitted(1))) case "discord" => Left(errorPrefix + "For 'discord' arg expected one argument: url") + case "custom" if splitted.size == 4 => Right(Custom(splitted(1), splitted(2), splitted(3))) + case "custom" if splitted.size == 3 => Right(Custom(splitted(1), splitted(2), splitted(2))) + case "custom" => Left(errorPrefix + "For 'custom' arg expected three arguments: url, white icon name, black icon name") case _ => Left(errorPrefix) } diff --git a/scaladoc/src/dotty/tools/scaladoc/renderers/HtmlRenderer.scala b/scaladoc/src/dotty/tools/scaladoc/renderers/HtmlRenderer.scala index 93b86ce0bc51..59ae87b8f043 100644 --- a/scaladoc/src/dotty/tools/scaladoc/renderers/HtmlRenderer.scala +++ b/scaladoc/src/dotty/tools/scaladoc/renderers/HtmlRenderer.scala @@ -166,7 +166,13 @@ class HtmlRenderer(rootPackage: Member, members: Map[DRI, Member])(using ctx: Do def icon(link: SocialLinks) = link.className args.socialLinks.map { link => a(href := link.url) ( - button(cls := s"icon-button ${icon(link)}") + if icon(link) == "custom" then + Seq( + img(cls := s"icon-button ${icon(link)}", src := s"../../../../images/${link.whiteIcon}"), + img(cls := s"icon-button ${icon(link)}-dark", src := s"../../../../images/${link.darkIcon}") + ) + else + button(cls := s"icon-button ${icon(link)}") ) } @@ -308,18 +314,7 @@ class HtmlRenderer(rootPackage: Member, members: Map[DRI, Member])(using ctx: Do "Generated with" ), div(cls := "right-container")( - a(href := "https://github.com/lampepfl/dotty") ( - button(cls := "icon-button gh") - ), - a(href := "https://twitter.com/scala_lang") ( - button(cls := "icon-button twitter") - ), - a(href := "https://discord.com/invite/scala") ( - button(cls := "icon-button discord"), - ), - a(href := "https://gitter.im/scala/scala") ( - button(cls := "icon-button gitter"), - ), + socialLinks, div(cls := "text")(textFooter) ), div(cls := "text-mobile")(textFooter) From 1ac2066c6a898928327985121149a14dc3774df1 Mon Sep 17 00:00:00 2001 From: Lucas Date: Mon, 24 Apr 2023 11:21:04 +0200 Subject: [PATCH 2/7] Corrections - Change SocialLinks and do a match case - Rephrase ScaladocSetting for custom --- .../dotty/tools/scaladoc/ScaladocSettings.scala | 3 +-- .../src/dotty/tools/scaladoc/SocialLinks.scala | 12 ++++++------ .../tools/scaladoc/renderers/HtmlRenderer.scala | 15 ++++++++------- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/scaladoc/src/dotty/tools/scaladoc/ScaladocSettings.scala b/scaladoc/src/dotty/tools/scaladoc/ScaladocSettings.scala index 6a72d3c33a04..57c2b2910d6a 100644 --- a/scaladoc/src/dotty/tools/scaladoc/ScaladocSettings.scala +++ b/scaladoc/src/dotty/tools/scaladoc/ScaladocSettings.scala @@ -43,8 +43,7 @@ class ScaladocSettings extends SettingGroup with AllScalaSettings: val socialLinks: Setting[List[String]] = MultiStringSetting("-social-links", "social-links", - "Links to social sites. '[github|twitter|gitter|discord]::link' syntax is used." + - "'custom::link::white_icon_name::black_icon_name' is also allowed, in this case icons must be present in 'images/'' directory.") + "Links to social sites. '[github|twitter|gitter|discord]::link' or 'custom::link::light_icon_file_name[::dark_icon_file_name]' syntax is used. For custom links, the icons must be present in '_assets/images/'") val deprecatedSkipPackages: Setting[List[String]] = MultiStringSetting("-skip-packages", "packages", "Deprecated, please use `-skip-by-id` or `-skip-by-regex`") diff --git a/scaladoc/src/dotty/tools/scaladoc/SocialLinks.scala b/scaladoc/src/dotty/tools/scaladoc/SocialLinks.scala index a7efde9b8aec..a4fa519680b8 100644 --- a/scaladoc/src/dotty/tools/scaladoc/SocialLinks.scala +++ b/scaladoc/src/dotty/tools/scaladoc/SocialLinks.scala @@ -4,12 +4,12 @@ import java.nio.file.Path import java.nio.file.Paths import dotty.tools.dotc.core.Contexts.Context -enum SocialLinks(val url: String, val whiteIcon: String, val darkIcon: String, val className: String): - case Github(ghUrl: String) extends SocialLinks(ghUrl, "", "", "gh") - case Twitter(tUrl: String) extends SocialLinks(tUrl, "", "", "twitter") - case Gitter(gUrl: String) extends SocialLinks(gUrl, "", "", "gitter") - case Discord(dUrl: String) extends SocialLinks(dUrl, "", "", "discord") - case Custom(cUrl: String, firstIcon: String, secondIcon: String) extends SocialLinks(cUrl, firstIcon, secondIcon, "custom") +enum SocialLinks(val url: String, val className: String): + case Github(ghUrl: String) extends SocialLinks(ghUrl, "gh") + case Twitter(tUrl: String) extends SocialLinks(tUrl, "twitter") + case Gitter(gUrl: String) extends SocialLinks(gUrl, "gitter") + case Discord(dUrl: String) extends SocialLinks(dUrl, "discord") + case Custom(cUrl: String, lightIcon: String, darkIcon: String) extends SocialLinks(cUrl, "custom") object SocialLinks: def parse(s: String): Either[String, SocialLinks] = diff --git a/scaladoc/src/dotty/tools/scaladoc/renderers/HtmlRenderer.scala b/scaladoc/src/dotty/tools/scaladoc/renderers/HtmlRenderer.scala index 59ae87b8f043..dc8e71291a22 100644 --- a/scaladoc/src/dotty/tools/scaladoc/renderers/HtmlRenderer.scala +++ b/scaladoc/src/dotty/tools/scaladoc/renderers/HtmlRenderer.scala @@ -166,13 +166,14 @@ class HtmlRenderer(rootPackage: Member, members: Map[DRI, Member])(using ctx: Do def icon(link: SocialLinks) = link.className args.socialLinks.map { link => a(href := link.url) ( - if icon(link) == "custom" then - Seq( - img(cls := s"icon-button ${icon(link)}", src := s"../../../../images/${link.whiteIcon}"), - img(cls := s"icon-button ${icon(link)}-dark", src := s"../../../../images/${link.darkIcon}") - ) - else - button(cls := s"icon-button ${icon(link)}") + link match + case SocialLinks.Custom(_, lightIcon, darkIcon) => + Seq( + img(cls := s"icon-button ${icon(link)}", src := s"../../../../images/$lightIcon"), + img(cls := s"icon-button ${icon(link)}-dark", src := s"../../../images/$darkIcon") + ) + case _ => + button(cls := s"icon-button ${icon(link)}") ) } From 5911c9f8420cfe4898e9dbe563f27dbe59d25200 Mon Sep 17 00:00:00 2001 From: Lucas Leblanc Date: Fri, 23 Jun 2023 14:24:45 +0200 Subject: [PATCH 3/7] Add src from css --- .../theme/components/button/icon-button.css | 12 +++++++++++- .../tools/scaladoc/renderers/HtmlRenderer.scala | 15 ++++++++++++--- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/scaladoc/resources/dotty_res/styles/theme/components/button/icon-button.css b/scaladoc/resources/dotty_res/styles/theme/components/button/icon-button.css index 59d506c27fd9..a9de4fac1f73 100644 --- a/scaladoc/resources/dotty_res/styles/theme/components/button/icon-button.css +++ b/scaladoc/resources/dotty_res/styles/theme/components/button/icon-button.css @@ -539,10 +539,20 @@ display: none; } +.icon-button.custom::after{ + content: var(--bgimage); + max-width: fit-content; +} + .theme-dark .icon-button.custom-dark{ display: unset; } +.theme-dark .icon-button.custom-dark::after{ + content: var(--bgimage-dark); + max-width: fit-content; +} + .theme-dark .icon-button.custom{ display: none; } @@ -852,4 +862,4 @@ .theme-dark .documentableElement .ar.icon-button.expanded.selected::after { content: url("../../../../images/icon-buttons/arrow-down/dark/selected.svg"); -} \ No newline at end of file +} diff --git a/scaladoc/src/dotty/tools/scaladoc/renderers/HtmlRenderer.scala b/scaladoc/src/dotty/tools/scaladoc/renderers/HtmlRenderer.scala index dc8e71291a22..d44ad8cfcd2c 100644 --- a/scaladoc/src/dotty/tools/scaladoc/renderers/HtmlRenderer.scala +++ b/scaladoc/src/dotty/tools/scaladoc/renderers/HtmlRenderer.scala @@ -2,9 +2,18 @@ package dotty.tools.scaladoc package renderers import util.HTML._ +import scala.jdk.CollectionConverters._ +import java.net.URI +import java.net.URL import dotty.tools.scaladoc.site._ +import scala.util.Try import org.jsoup.Jsoup +import java.nio.file.Paths +import java.nio.file.Path import java.nio.file.Files +import java.nio.file.FileVisitOption +import java.io.File +import dotty.tools.scaladoc.staticFileSymbolUUID class HtmlRenderer(rootPackage: Member, members: Map[DRI, Member])(using ctx: DocContext) extends Renderer(rootPackage, members, extension = "html"): @@ -167,10 +176,10 @@ class HtmlRenderer(rootPackage: Member, members: Map[DRI, Member])(using ctx: Do args.socialLinks.map { link => a(href := link.url) ( link match - case SocialLinks.Custom(_, lightIcon, darkIcon) => + case SocialLinks.Custom(_, lightIcon, darkIcon) => Seq( - img(cls := s"icon-button ${icon(link)}", src := s"../../../../images/$lightIcon"), - img(cls := s"icon-button ${icon(link)}-dark", src := s"../../../images/$darkIcon") + button(cls := s"icon-button ${icon(link)}", style := s"--bgimage:url(../../../../images/$lightIcon)"), + button(cls := s"icon-button ${icon(link)}-dark", style := s"--bgimage-dark:url(../../../../images/$darkIcon)") ) case _ => button(cls := s"icon-button ${icon(link)}") From ead99fe40cf77e7601bb522275437705311173aa Mon Sep 17 00:00:00 2001 From: Lucas Leblanc Date: Thu, 29 Jun 2023 16:08:29 +0200 Subject: [PATCH 4/7] Add resizing to png images --- .../theme/components/button/icon-button.css | 22 ++++++++++++++----- .../dotty/tools/scaladoc/SocialLinks.scala | 4 ---- .../scaladoc/renderers/HtmlRenderer.scala | 9 -------- 3 files changed, 17 insertions(+), 18 deletions(-) diff --git a/scaladoc/resources/dotty_res/styles/theme/components/button/icon-button.css b/scaladoc/resources/dotty_res/styles/theme/components/button/icon-button.css index a9de4fac1f73..d0957691fb1e 100644 --- a/scaladoc/resources/dotty_res/styles/theme/components/button/icon-button.css +++ b/scaladoc/resources/dotty_res/styles/theme/components/button/icon-button.css @@ -539,9 +539,15 @@ display: none; } -.icon-button.custom::after{ - content: var(--bgimage); - max-width: fit-content; +.icon-button.custom::after { + content: ""; + background-image: var(--bgimage); + background-repeat: no-repeat; + background-position: center; + background-size: contain; + display: block; + max-width: 100%; + max-height: 100%; } .theme-dark .icon-button.custom-dark{ @@ -549,8 +555,14 @@ } .theme-dark .icon-button.custom-dark::after{ - content: var(--bgimage-dark); - max-width: fit-content; + content: ""; + background-image: var(--bgimage-dark); + background-repeat: no-repeat; + background-position: center; + background-size: contain; + display: block; + max-width: 100%; + max-height: 100%; } .theme-dark .icon-button.custom{ diff --git a/scaladoc/src/dotty/tools/scaladoc/SocialLinks.scala b/scaladoc/src/dotty/tools/scaladoc/SocialLinks.scala index a4fa519680b8..0df8b9eaabf0 100644 --- a/scaladoc/src/dotty/tools/scaladoc/SocialLinks.scala +++ b/scaladoc/src/dotty/tools/scaladoc/SocialLinks.scala @@ -1,9 +1,5 @@ package dotty.tools.scaladoc -import java.nio.file.Path -import java.nio.file.Paths -import dotty.tools.dotc.core.Contexts.Context - enum SocialLinks(val url: String, val className: String): case Github(ghUrl: String) extends SocialLinks(ghUrl, "gh") case Twitter(tUrl: String) extends SocialLinks(tUrl, "twitter") diff --git a/scaladoc/src/dotty/tools/scaladoc/renderers/HtmlRenderer.scala b/scaladoc/src/dotty/tools/scaladoc/renderers/HtmlRenderer.scala index d44ad8cfcd2c..872f8a4f09c9 100644 --- a/scaladoc/src/dotty/tools/scaladoc/renderers/HtmlRenderer.scala +++ b/scaladoc/src/dotty/tools/scaladoc/renderers/HtmlRenderer.scala @@ -2,18 +2,9 @@ package dotty.tools.scaladoc package renderers import util.HTML._ -import scala.jdk.CollectionConverters._ -import java.net.URI -import java.net.URL import dotty.tools.scaladoc.site._ -import scala.util.Try import org.jsoup.Jsoup -import java.nio.file.Paths -import java.nio.file.Path import java.nio.file.Files -import java.nio.file.FileVisitOption -import java.io.File -import dotty.tools.scaladoc.staticFileSymbolUUID class HtmlRenderer(rootPackage: Member, members: Map[DRI, Member])(using ctx: DocContext) extends Renderer(rootPackage, members, extension = "html"): From f9c9ca6e4e2b0025e32d10ec7093b1a1b7b8ec8a Mon Sep 17 00:00:00 2001 From: Lucas Leblanc Date: Mon, 10 Jul 2023 16:41:08 +0200 Subject: [PATCH 5/7] Add a regex to allow only names with lowercase for custom icons --- scaladoc/src/dotty/tools/scaladoc/SocialLinks.scala | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/scaladoc/src/dotty/tools/scaladoc/SocialLinks.scala b/scaladoc/src/dotty/tools/scaladoc/SocialLinks.scala index 0df8b9eaabf0..d36ff0ac0392 100644 --- a/scaladoc/src/dotty/tools/scaladoc/SocialLinks.scala +++ b/scaladoc/src/dotty/tools/scaladoc/SocialLinks.scala @@ -8,9 +8,12 @@ enum SocialLinks(val url: String, val className: String): case Custom(cUrl: String, lightIcon: String, darkIcon: String) extends SocialLinks(cUrl, "custom") object SocialLinks: + val LowercaseNamePattern = "^[a-z]+$".r + def parse(s: String): Either[String, SocialLinks] = val errorPrefix = s"Social links arg $s is invalid: " val splitted = s.split("::") + splitted.head match { case "github" if splitted.size == 2 => Right(Github(splitted(1))) case "github" => Left(errorPrefix + "For 'github' arg expected one argument: url") @@ -20,8 +23,8 @@ object SocialLinks: case "gitter" => Left(errorPrefix + "For 'gitter' arg expected one argument: url") case "discord" if splitted.size == 2 => Right(Discord(splitted(1))) case "discord" => Left(errorPrefix + "For 'discord' arg expected one argument: url") - case "custom" if splitted.size == 4 => Right(Custom(splitted(1), splitted(2), splitted(3))) - case "custom" if splitted.size == 3 => Right(Custom(splitted(1), splitted(2), splitted(2))) - case "custom" => Left(errorPrefix + "For 'custom' arg expected three arguments: url, white icon name, black icon name") + case LowercaseNamePattern() if splitted.size == 4 => Right(Custom(splitted(1), splitted(2), splitted(3))) + case LowercaseNamePattern() if splitted.size == 3 => Right(Custom(splitted(1), splitted(2), splitted(2))) + case LowercaseNamePattern() => Left(errorPrefix + "For 'custom' two minimum arguments are expected: url, white icon name, [dark icon name]") case _ => Left(errorPrefix) } From d2123e708780a7faf5417d862c8017c747608b10 Mon Sep 17 00:00:00 2001 From: Lucas Leblanc Date: Tue, 11 Jul 2023 17:57:34 +0200 Subject: [PATCH 6/7] Add tests for the parse method --- .../tools/scaladoc/SocialLinksTest.scala | 47 +++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 scaladoc/test/dotty/tools/scaladoc/SocialLinksTest.scala diff --git a/scaladoc/test/dotty/tools/scaladoc/SocialLinksTest.scala b/scaladoc/test/dotty/tools/scaladoc/SocialLinksTest.scala new file mode 100644 index 000000000000..3150761e6ea2 --- /dev/null +++ b/scaladoc/test/dotty/tools/scaladoc/SocialLinksTest.scala @@ -0,0 +1,47 @@ +package dotty.tools.scaladoc + +import org.junit.Test +import org.junit.Assert._ +import dotty.tools.scaladoc.SocialLinks + +class SocialLinksTest: + + @Test def githubLink(): Unit = + val githubLink = "github::https://github.com/test" + val expected = SocialLinks.Github("https://github.com/test") + assertEquals(expected, SocialLinks.parse(githubLink).getOrElse(null)) + + @Test def twitterLink(): Unit = + val twitterLink = "twitter::https://twitter.com/test" + val expected = SocialLinks.Twitter("https://twitter.com/test") + assertEquals(expected, SocialLinks.parse(twitterLink).getOrElse(null)) + + @Test def gitterLink(): Unit = + val gitterLink = "gitter::https://gitter.im/test" + val expected = SocialLinks.Gitter("https://gitter.im/test") + assertEquals(expected, SocialLinks.parse(gitterLink).getOrElse(null)) + + @Test def discordLink(): Unit = + val discordLink = "discord::https://discord.gg/test" + val expected = SocialLinks.Discord("https://discord.gg/test") + assertEquals(expected, SocialLinks.parse(discordLink).getOrElse(null)) + + @Test def customLinkLight(): Unit = + val customLink = "namecustom::https://custom.com/test::custom" + val expected = SocialLinks.Custom("https://custom.com/test", "custom", "custom") + assertEquals(expected, SocialLinks.parse(customLink).getOrElse(null)) + + @Test def customLinkLightAndDark(): Unit = + val customLink = "namecustom::https://custom.com/test::custom::custom-dark" + val expected = SocialLinks.Custom("https://custom.com/test", "custom", "custom-dark") + assertEquals(expected, SocialLinks.parse(customLink).getOrElse(null)) + + @Test def parseRegexError(): Unit = + val regexErrorLink = "nameCustom::https://custom.com/test::custom::custom-dark::custom" + val expected = s"Social links arg $regexErrorLink is invalid: " + assertEquals(expected, SocialLinks.parse(regexErrorLink).left.getOrElse(null)) + + @Test def parseLinkWithError(): Unit = + val errorLink = "namecustom::https://custom.com/test::custom::custom-dark::custom" + val expected = s"Social links arg $errorLink is invalid: For 'custom' two minimum arguments are expected: url, white icon name, [dark icon name]" + assertEquals(expected, SocialLinks.parse(errorLink).left.getOrElse(null)) From 2d9347f818c87f65d5d8bca52faab6beb2126cda Mon Sep 17 00:00:00 2001 From: Lucas Leblanc Date: Thu, 13 Jul 2023 09:52:33 +0200 Subject: [PATCH 7/7] Add toLowerCase to accept more unfortunate errors --- scaladoc/src/dotty/tools/scaladoc/SocialLinks.scala | 4 ++-- scaladoc/test/dotty/tools/scaladoc/SocialLinksTest.scala | 9 +++++++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/scaladoc/src/dotty/tools/scaladoc/SocialLinks.scala b/scaladoc/src/dotty/tools/scaladoc/SocialLinks.scala index d36ff0ac0392..545d9176675a 100644 --- a/scaladoc/src/dotty/tools/scaladoc/SocialLinks.scala +++ b/scaladoc/src/dotty/tools/scaladoc/SocialLinks.scala @@ -14,7 +14,7 @@ object SocialLinks: val errorPrefix = s"Social links arg $s is invalid: " val splitted = s.split("::") - splitted.head match { + splitted.head.toLowerCase match { case "github" if splitted.size == 2 => Right(Github(splitted(1))) case "github" => Left(errorPrefix + "For 'github' arg expected one argument: url") case "twitter" if splitted.size == 2 => Right(Twitter(splitted(1))) @@ -25,6 +25,6 @@ object SocialLinks: case "discord" => Left(errorPrefix + "For 'discord' arg expected one argument: url") case LowercaseNamePattern() if splitted.size == 4 => Right(Custom(splitted(1), splitted(2), splitted(3))) case LowercaseNamePattern() if splitted.size == 3 => Right(Custom(splitted(1), splitted(2), splitted(2))) - case LowercaseNamePattern() => Left(errorPrefix + "For 'custom' two minimum arguments are expected: url, white icon name, [dark icon name]") + case LowercaseNamePattern() => Left(errorPrefix + "For the 'custom' link, a minimum of two arguments is expected: URL, light icon file name, [dark icon file name]") case _ => Left(errorPrefix) } diff --git a/scaladoc/test/dotty/tools/scaladoc/SocialLinksTest.scala b/scaladoc/test/dotty/tools/scaladoc/SocialLinksTest.scala index 3150761e6ea2..ede928ff2a08 100644 --- a/scaladoc/test/dotty/tools/scaladoc/SocialLinksTest.scala +++ b/scaladoc/test/dotty/tools/scaladoc/SocialLinksTest.scala @@ -36,12 +36,17 @@ class SocialLinksTest: val expected = SocialLinks.Custom("https://custom.com/test", "custom", "custom-dark") assertEquals(expected, SocialLinks.parse(customLink).getOrElse(null)) + @Test def customLinkUpper(): Unit = + val customLink = "Namecustom::https://custom.com/test::custom" + val expected = SocialLinks.Custom("https://custom.com/test", "custom", "custom") + assertEquals(expected, SocialLinks.parse(customLink).getOrElse(null)) + @Test def parseRegexError(): Unit = - val regexErrorLink = "nameCustom::https://custom.com/test::custom::custom-dark::custom" + val regexErrorLink = "nameCustom3::https://custom.com/test::custom::custom-dark::custom" val expected = s"Social links arg $regexErrorLink is invalid: " assertEquals(expected, SocialLinks.parse(regexErrorLink).left.getOrElse(null)) @Test def parseLinkWithError(): Unit = val errorLink = "namecustom::https://custom.com/test::custom::custom-dark::custom" - val expected = s"Social links arg $errorLink is invalid: For 'custom' two minimum arguments are expected: url, white icon name, [dark icon name]" + val expected = s"Social links arg $errorLink is invalid: For the 'custom' link, a minimum of two arguments is expected: URL, light icon file name, [dark icon file name]" assertEquals(expected, SocialLinks.parse(errorLink).left.getOrElse(null))