Skip to content
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

Provide a 'Create Badge' function for users #670

Merged
merged 5 commits into from
Jun 11, 2021
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
6 changes: 3 additions & 3 deletions README.MD
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,14 @@ read the [developer guide](/CONTRIBUTING.md)
You can add this badge to the README.MD of your own GitHub projects to show
the versions of Scala they support:

[![Scala version Badge](https://index.scala-lang.org/typelevel/cats/cats-core/latest-by-scala-version.svg)
[![cats-core Scala version support](https://index.scala-lang.org/typelevel/cats/cats-core/latest-by-scala-version.svg)](https://index.scala-lang.org/typelevel/cats/cats-core)

...the badge above only summarises latest JVM artifacts, if you'd like a badge
for Scala JS or Scala Native, add a `targetType=...` query-string parameter:

[![Scala version Badge](https://index.scala-lang.org/typelevel/cats/cats-core/latest-by-scala-version.svg?targetType=js)
[![cats-core Scala version support](https://index.scala-lang.org/typelevel/cats/cats-core/latest-by-scala-version.svg?targetType=js)](https://index.scala-lang.org/typelevel/cats/cats-core)

[![Scala version Badge](https://index.scala-lang.org/typelevel/cats/cats-core/latest-by-scala-version.svg?targetType=native)
[![cats-core Scala version support](https://index.scala-lang.org/typelevel/cats/cats-core/latest-by-scala-version.svg?targetType=native)](https://index.scala-lang.org/typelevel/cats/cats-core)

### Smaller, shorter badges

Expand Down
11 changes: 10 additions & 1 deletion model/src/main/scala/ch.epfl.scala.index.model/Release.scala
Original file line number Diff line number Diff line change
Expand Up @@ -227,10 +227,19 @@ object Release {

def projectReference = Project.Reference(organization, repository)
def name = s"$organization/$artifact"

def artifactHttpPath = s"/$organization/$repository/$artifact"
def artifactFullHttpUrl = s"https://index.scala-lang.org$artifactHttpPath"
private def nonDefaultTargetType = {
target.map(_.targetType).filter(_ != Jvm)
}
def badgeUrl: String =
s"$artifactFullHttpUrl/latest-by-scala-version.svg" +
nonDefaultTargetType.map("?targetType=" + _).mkString
def httpUrl = {
val targetQuery = target.map(t => s"?target=${t.encode}").getOrElse("")

s"/$organization/$repository/$artifact/$version$targetQuery"
s"$artifactHttpPath/$version$targetQuery"
}

def isScalaLib: Boolean = {
Expand Down
66 changes: 61 additions & 5 deletions server/src/main/assets/css/partials/_main.scss
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ main {
flex: 1;
}

.copyable-incantation {
user-select: all;
Copy link
Contributor Author

@rtyley rtyley May 28, 2021

Choose a reason for hiding this comment

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

This has the nice effect of the user selecting the entire text sample, rather just a word, when they click on it - at that point it's very easy to copy & paste the entire expression, so it's a nice complement (or possibly even replacement) to the Javascript 'Copy' button.

Copy link
Member

Choose a reason for hiding this comment

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

Nice trick!

}

.banner {
background: #0c353c;
text-align: center;
Expand Down Expand Up @@ -493,6 +497,11 @@ main {
margin-bottom: ($line-height-computed / 1.5);
}
.install {
.btn-copy {
position: absolute;
top: 50px;
right: 6px;
}
.nav-tabs > li:not(.active) > a {
color: white;
}
Expand Down Expand Up @@ -587,11 +596,6 @@ main {
.tab-pane {
height: 85px;
}
.btn-copy {
position: absolute;
top: 50px;
right: 6px;
}
}

.head-project {
Expand Down Expand Up @@ -676,6 +680,58 @@ main {
}
}

.badge-showcase {
.overlay {
position: fixed;
z-index: 10;
top: 0;
bottom: 0;
left: 0;
right: 0;
background: rgba(0, 0, 0, 0.7);
transition: opacity 500ms;
visibility: hidden;
opacity: 0;
}
.overlay:target {
visibility: visible;
opacity: 1;
}

.popup {
margin: 70px auto;
padding: 20px;
background: #fff;
border-radius: 5px;
width: 60%;
position: relative;
transition: all 5s ease-in-out;
}

.popup h2 {
margin-top: 0;
color: #333;
font-family: Tahoma, Arial, sans-serif;
}
.popup .close {
position: absolute;
top: 20px;
right: 30px;
transition: all 200ms;
font-size: 30px;
font-weight: bold;
text-decoration: none;
color: #333;
}
.popup .close:hover {
color: #06D85F;
}
.popup .content {
max-height: 30%;
overflow: auto;
}
}

.documentation-link {
ul {
padding-left: 0;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
@import ch.epfl.scala.index.model.Release
@(release: Release)
<div class="box badge-showcase">
<h4>Markdown Badge</h4>
<div style="overflow: hidden">
<a href="#badge-markdown">
<img src="@release.reference.badgeUrl" />
</a>
</div>
<div id="badge-markdown" class="overlay">
<div class="popup">
<h2>Create badge</h2>
<a class="close" href="#">&times;</a>

<div class="content">
<img src="@release.reference.badgeUrl" />
<div>
<h5>Markdown:</h5>
<pre
aria-label="Badge markdown"
id="copy-badge-markdown"
class="copyable-incantation"
>[![@release.reference.artifact Scala version support](@release.reference.badgeUrl)](@release.reference.artifactFullHttpUrl)</pre>
<button class="btn-copy btn btn-primary pull-right" data-clipboard-target="copy-badge-markdown">Copy Markdown</button>
</div>
</div>
</div>
</div>

</div>
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ <h1>
GitHub <i class="fa fa-github fa-lg"></i>
</a>
}

</div>
@for(github <- project.github) {
@if(!github.topics.isEmpty) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,32 +26,32 @@
</ul>
<div class="tab-content">
<div role="tabpanel" class="tab-pane active" id="sbt">
<pre id="copy-sbt">@release.sbtInstall</pre>
<pre id="copy-sbt" class="copyable-incantation">@release.sbtInstall</pre>
<button class="btn-copy" data-clipboard-target="copy-sbt">Copy</button>
</div>
<div role="tabpanel" class="tab-pane" id="ammonite">
<a href="http://www.lihaoyi.com/Ammonite/#Ammonite-REPL">Ammonite REPL</a>
<pre id="copy-amm">@release.ammInstall</pre>
<a href="https://ammonite.io/#Ammonite-REPL">Ammonite REPL</a>
<pre id="copy-amm" class="copyable-incantation">@release.ammInstall</pre>
<button class="btn-copy" data-clipboard-target="copy-amm">Copy</button>
</div>
@if(cliArtifacts.contains(release.reference.artifact)) {
<div role="tabpanel" class="tab-pane" id="coursier">
<a href="https://github.com/alexarchambault/coursier#command-line-1">Coursier</a>
<pre id="copy-coursier">./coursier launch @release.maven.groupId:@release.maven.artifactId:@release.maven.version</pre>
<a href="https://get-coursier.io/docs/cli-overview">Coursier</a>
<pre id="copy-coursier" class="copyable-incantation">cs launch @release.maven.groupId:@release.maven.artifactId:@release.maven.version</pre>
<button class="btn-copy" data-clipboard-target="copy-coursier">Copy</button>
</div>
}
<div role="tabpanel" class="tab-pane" id="maven">
<pre id="copy-maven">@release.mavenInstall</pre>
<pre id="copy-maven" class="copyable-incantation">@release.mavenInstall</pre>
<button class="btn-copy" data-clipboard-target="copy-maven">Copy</button>
</div>
<div role="tabpanel" class="tab-pane" id="gradle">
<pre id="copy-gradle">@release.gradleInstall</pre>
<pre id="copy-gradle" class="copyable-incantation">@release.gradleInstall</pre>
<button class="btn-copy" data-clipboard-target="copy-gradle">Copy</button>
</div>
<div role="tabpanel" class="tab-pane" id="mill">
<a href="https://www.lihaoyi.com/mill/">Mill build tool</a>
<pre id="copy-mill">@release.millInstall</pre>
<a href="https://com-lihaoyi.github.io/mill">Mill build tool</a>
<pre id="copy-mill" class="copyable-incantation">@release.millInstall</pre>
<button class="btn-copy" data-clipboard-target="copy-mill">Copy</button>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ <h1>[DEPRECATED]</h1>
</div>
}
@documentation(release, project)
@badges(release)
@install(release, project.cliArtifacts)
@release.scastieURL.map(url => scastie(url))
@project.github.map(gh => statistic(gh, project.githubRepo, project.releaseCount, allDeps.reverseDependencies.size))
Expand Down