Skip to content

Commit

Permalink
Turn off not checked and failing snippets
Browse files Browse the repository at this point in the history
  • Loading branch information
pikinier20 committed Mar 14, 2022
1 parent b47994f commit 06d6152
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
2 changes: 1 addition & 1 deletion scaladoc-js/common/src/code-snippets/CodeSnippets.scala
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ class CodeSnippets:
val buttonsSection = getButtonsSection(snippet)
buttonsSection.foreach(s =>
s.appendChild(copyButton)
if !snippet.hasAttribute("hasContext") then {
if snippet.hasAttribute("runnable") then {
s.appendChild(toScastieButton)
s.appendChild(runButton)
s.appendChild(exitButton)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import com.vladsch.flexmark.html._
import util.HTML._

import dotty.tools.scaladoc.snippets._
import dotty.tools.scaladoc.util.HTML._

case class SnippetLine(content: String, lineNo: Int, classes: Set[String] = Set.empty, messages: Seq[String] = Seq.empty, attributes: Map[String, String] = Map.empty):
def withClass(cls: String) = this.copy(classes = classes + cls)
Expand Down Expand Up @@ -134,15 +133,26 @@ object SnippetRenderer:
div(cls := "snippet-label")(name)
).toString

def renderSnippetWithMessages(snippetName: Option[String], codeLines: Seq[String], messages: Seq[SnippetCompilerMessage], hasContext: Boolean): String =
def renderSnippetWithMessages(snippetName: Option[String], codeLines: Seq[String], messages: Seq[SnippetCompilerMessage], hasContext: Boolean, success: Boolean): String =
val transformedLines = wrapCodeLines.andThen(addCompileMessages(messages)).apply(codeLines).map(_.toHTML)
val codeHTML = s"""<code class="language-scala">${transformedLines.mkString("")}</code>"""
s"""<div class="snippet" scala-snippet ${if hasContext then "hasContext" else ""}><div class="buttons"></div><pre>$codeHTML</pre>${snippetName.fold("")(snippetLabel(_))}</div>"""
val isRunnable = !hasContext && success
val attrs = Seq(
Option.when(isRunnable)(Attr("runnable") := "")
).flatten
div(cls := "snippet", Attr("scala-snippet") := "", attrs)(
div(cls := "buttons")(),
pre(
raw(codeHTML)
),
raw(snippetName.fold("")(snippetLabel(_)))
).toString

def renderSnippetWithMessages(node: ExtendedFencedCodeBlock): String =
renderSnippetWithMessages(
node.name,
node.codeBlock.getContentChars.toString.split("\n").map(_ + "\n").toSeq,
node.compilationResult.toSeq.flatMap(_.messages),
node.hasContext
node.hasContext,
node.compilationResult.fold(false)(_.isSuccessful)
)

0 comments on commit 06d6152

Please sign in to comment.