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

Add and apply scalafmt #40

Merged
merged 2 commits into from
Feb 5, 2024
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
23 changes: 23 additions & 0 deletions .github/workflows/format.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Scalafmt

permissions: {}

on:
pull_request:
branches: ['**']

jobs:
build:
name: Code is formatted
runs-on: ubuntu-latest
steps:
- name: Checkout current branch (full)
uses: actions/checkout@v4
with:
fetch-depth: 0
persist-credentials: false

- name: Check project is formatted
uses: jrouly/scalafmt-native-action@v3
with:
arguments: '--list --mode diff-ref=origin/main'
26 changes: 26 additions & 0 deletions .scalafmt.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
version = 3.7.17
runner.dialect = scala212
maxColumn = 120
project.git = true

# http://docs.scala-lang.org/style/scaladoc.html recommends the JavaDoc style.
# scala/scala is written that way too https://github.com/scala/scala/blob/v2.12.2/src/library/scala/Predef.scala
docstrings.style = Asterisk

# This also seems more idiomatic to include whitespace in import x.{ yyy }
spaces.inImportCurlyBraces = true

align.tokens."+" = [
{
code = "%"
owners = [
{ regex = "Term.ApplyInfix" }
]
},
{
code = "%%"
owners = [
{ regex = "Term.ApplyInfix" }
]
}
]
93 changes: 48 additions & 45 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -37,47 +37,47 @@ lazy val root = project("paradox-material-theme-parent", file("."))
"project.name" -> "Paradox Material Theme",
"github.base_url" -> "https://github.com/sbt/sbt-paradox-material-theme"
),
//#color
// #color
Compile / paradoxMaterialTheme ~= {
_.withColor("teal", "indigo")
}
//#color
// #color
,
//#repository
// #repository
Compile / paradoxMaterialTheme ~= {
_.withRepository(uri("https://github.com/sbt/sbt-paradox-material-theme"))
}
//#repository
// #repository
,
//#social
// #social
Compile / paradoxMaterialTheme ~= {
_.withSocial(
uri("https://github.com/jonas"),
uri("https://twitter.com/priorarts")
)
}
//#social
// #social
,
//#language
// #language
Compile / paradoxMaterialTheme ~= {
_.withLanguage(java.util.Locale.ENGLISH)
}
//#language
// #language
,
//#analytics
// #analytics
Compile / paradoxMaterialTheme ~= {
_.withGoogleAnalytics("UA-107934279-1") // Remember to change this!
}
//#analytics
// #analytics
,
//#copyright
// #copyright
Compile / paradoxMaterialTheme ~= {
_.withCopyright("""
Based on <a href="https://github.com/squidfunk/mkdocs-material">MkDocs Material</a>
by <a href="https://github.com/squidfunk">Martin Donath</a>
""")
}
//#copyright
// #copyright
)
.aggregate(theme, plugin)

Expand All @@ -90,7 +90,7 @@ lazy val plugin = project("sbt-paradox-material-theme", file("plugin"))
scriptedBufferLog := false,
publishLocal := publishLocal.dependsOn(theme / publishLocal).value,
addSbtPlugin("com.lightbend.paradox" % "sbt-paradox" % "0.4.4"),
libraryDependencies += "org.jsoup" % "jsoup" % "1.10.3",
libraryDependencies += "org.jsoup" % "jsoup" % "1.10.3",
libraryDependencies += "io.circe" %% "circe-core" % "0.9.3",
Compile / resourceGenerators += Def.task {
val file = (Compile / resourceManaged).value / "paradox-material-theme.properties"
Expand All @@ -105,96 +105,99 @@ lazy val theme = project("paradox-material-theme", file("theme"))
description := "Material Design theme for Paradox",
Assets / WebKeys.webJars := {
val out = (Assets / WebKeys.webJars).value
(Assets / WebKeys.webJarsDirectory).value.**(
"*.min.js" | "*.min.css" | "lang-*.js" | "prettify.css" | "prettify.js"
).get.filter(_.isFile)
(Assets / WebKeys.webJarsDirectory).value
.**(
"*.min.js" | "*.min.css" | "lang-*.js" | "prettify.css" | "prettify.js"
)
.get
.filter(_.isFile)
},
previewSite := {},
libraryDependencies += "org.webjars" % "prettify" % "4-Mar-2013-1" % Provided,
libraryDependencies +=
Seq("animation", "base", "ripple", "rtl", "theme", "typography")
.foldLeft("org.webjars.npm" % "material__tabs" % "0.3.1" % Provided) {
(lib, dep) => lib.exclude("org.webjars.npm", s"material__$dep")
.foldLeft("org.webjars.npm" % "material__tabs" % "0.3.1" % Provided) { (lib, dep) =>
lib.exclude("org.webjars.npm", s"material__$dep")
}
)

lazy val optionExamples = Def.settings(
//#builder-api
// #builder-api
Compile / paradoxMaterialTheme := {
ParadoxMaterialTheme()
.withColor("red", "orange")
.withLogoIcon("cloud")
.withCopyright("Copyleft © Jonas Fonseca")
}
//#builder-api
// #builder-api
,
//#builder-api-v2
// #builder-api-v2
Compile / paradoxMaterialTheme ~= {
_.withColor("red", "orange")
.withLogoIcon("cloud")
.withCopyright("Copyleft © Jonas Fonseca")
.withLogoIcon("cloud")
.withCopyright("Copyleft © Jonas Fonseca")
}
//#builder-api-v2
// #builder-api-v2
,
//#font
// #font
Compile / paradoxMaterialTheme ~= {
_.withFont("Ubuntu", "Ubuntu Mono")
}
//#font
// #font
,
//#font-disable
// #font-disable
Compile / paradoxMaterialTheme ~= {
_.withoutFont()
}
//#font-disable
// #font-disable
,
//#favicon
// #favicon
Compile / paradoxMaterialTheme ~= {
_.withFavicon("assets/images/favicon.png")
}
//#favicon
// #favicon
,
//#logo
// #logo
Compile / paradoxMaterialTheme ~= {
_.withLogo("assets/images/logo.png")
}
//#logo
// #logo
,
//#logo-icon
// #logo-icon
Compile / paradoxMaterialTheme ~= {
_.withLogoIcon("cloud")
}
//#logo-icon
// #logo-icon
,
//#logo-uri
// #logo-uri
Compile / paradoxMaterialTheme ~= {
_.withLogoUri(uri("https://example.org/logo.png"))
}
//#logo-uri
// #logo-uri
,
//#custom-stylesheet
// #custom-stylesheet
Compile / paradoxMaterialTheme ~= {
_.withCustomStylesheet("assets/custom.css")
}
//#custom-stylesheet
// #custom-stylesheet
,
//#custom-javascript
// #custom-javascript
Compile / paradoxMaterialTheme ~= {
_.withCustomJavaScript("assets/custom.js")
}
//#custom-javascript
// #custom-javascript
,
//#disable-search
// #disable-search
Compile / paradoxMaterialTheme ~= {
_.withoutSearch()
}
//#disable-search
// #disable-search
,
//#search-tokenizer
// #search-tokenizer
Compile / paradoxMaterialTheme ~= {
_.withSearch(tokenizer = "[\\s\\-\\.]+")
}
//#search-tokenizer
// #search-tokenizer
)

lazy val scala212 = "2.12.18"
Expand All @@ -204,5 +207,5 @@ def project(id: String, base: File): Project = {
.settings(
crossScalaVersions := Seq(scala212),
scalaVersion := scala212
)
)
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package io.github.jonas.paradox.material.theme

import java.net.{URI, URLEncoder}
import java.net.{ URI, URLEncoder }
import java.util.Locale
import org.stringtemplate.v4.StringRenderer

Expand Down Expand Up @@ -104,9 +104,10 @@ case class ParadoxMaterialTheme(properties: Map[String, String]) {
object ParadoxMaterialTheme {
val Tlds = List("com", "org")
def findSite(sites: String*): URI => Option[String] =
uri => sites.find { service =>
Tlds.exists(tld => uri.getHost.endsWith(service + "." + tld))
}
uri =>
sites.find { service =>
Tlds.exists(tld => uri.getHost.endsWith(service + "." + tld))
}

val SocialSite = findSite("bitbucket", "facebook", "github", "gitlab", "linkedin", "twitter")
val RepositoryType = findSite("bitbucket", "github", "gitlab")
Expand All @@ -121,42 +122,42 @@ object ParadoxMaterialTheme {

object Palette {
val Primary = Map(
"red" -> "#ef5350",
"pink" -> "#e91e63",
"purple" -> "#ab47bc",
"red" -> "#ef5350",
"pink" -> "#e91e63",
"purple" -> "#ab47bc",
"deep-purple" -> "#7e57c2",
"indigo" -> "#3f51b5",
"blue" -> "#2196f3",
"light-blue" -> "#03a9f4",
"cyan" -> "#00bcd4",
"teal" -> "#009688",
"green" -> "#4caf50",
"indigo" -> "#3f51b5",
"blue" -> "#2196f3",
"light-blue" -> "#03a9f4",
"cyan" -> "#00bcd4",
"teal" -> "#009688",
"green" -> "#4caf50",
"light-green" -> "#7cb342",
"lime" -> "#c0ca33",
"yellow" -> "#f9a825",
"amber" -> "#ffa000",
"orange" -> "#fb8c00",
"lime" -> "#c0ca33",
"yellow" -> "#f9a825",
"amber" -> "#ffa000",
"orange" -> "#fb8c00",
"deep-orange" -> "#ff7043",
"brown" -> "#795548",
"grey" -> "#757575",
"blue-grey" -> "#546e7a"
"brown" -> "#795548",
"grey" -> "#757575",
"blue-grey" -> "#546e7a"
)
val Accent = Map(
"red" -> "#ff1744",
"pink" -> "#f50057",
"purple" -> "#e040fb",
"red" -> "#ff1744",
"pink" -> "#f50057",
"purple" -> "#e040fb",
"deep-purple" -> "#7c4dff",
"indigo" -> "#536dfe",
"blue" -> "#448aff",
"light-blue" -> "#0091ea",
"cyan" -> "#00b8d4",
"teal" -> "#00bfa5",
"green" -> "#00c853",
"indigo" -> "#536dfe",
"blue" -> "#448aff",
"light-blue" -> "#0091ea",
"cyan" -> "#00b8d4",
"teal" -> "#00bfa5",
"green" -> "#00c853",
"light-green" -> "#64dd17",
"lime" -> "#aeea00",
"yellow" -> "#ffd600",
"amber" -> "#ffab00",
"orange" -> "#ff9100",
"lime" -> "#aeea00",
"yellow" -> "#ffd600",
"amber" -> "#ffab00",
"orange" -> "#ff9100",
"deep-orange" -> "#ff6e40"
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,19 @@ object ParadoxMaterialThemePlugin extends AutoPlugin {
)

def paradoxMaterialThemeSettings(config: Configuration): Seq[Setting[_]] =
inConfig(config)(Def.settings(
paradoxMaterialTheme := ParadoxMaterialTheme(),
paradoxProperties += ("material.theme.version" -> (paradoxMaterialTheme / version).value),
paradoxProperties ++= paradoxMaterialTheme.value.paradoxProperties,
paradoxMaterialTheme / mappings := Def.taskDyn {
if (paradoxProperties.value.contains("material.search"))
Def.task(Seq(SearchIndex.mapping(config).value))
else
Def.task(Seq.empty[(File, String)])
}.value,
paradox / mappings ++= (paradoxMaterialTheme / mappings).value
))
inConfig(config)(
Def.settings(
paradoxMaterialTheme := ParadoxMaterialTheme(),
paradoxProperties += ("material.theme.version" -> (paradoxMaterialTheme / version).value),
paradoxProperties ++= paradoxMaterialTheme.value.paradoxProperties,
paradoxMaterialTheme / mappings := Def.taskDyn {
if (paradoxProperties.value.contains("material.search"))
Def.task(Seq(SearchIndex.mapping(config).value))
else
Def.task(Seq.empty[(File, String)])
}.value,
paradox / mappings ++= (paradoxMaterialTheme / mappings).value
)
)

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ object SearchIndex {

case class Section(location: String, title: String, text: String)
object Section {
implicit val encoder: ObjectEncoder[Section] = Encoder.forProduct3("location", "text", "title")(
page => ("/" + page.location, page.text, page.title))
implicit val encoder: ObjectEncoder[Section] =
Encoder.forProduct3("location", "text", "title")(page => ("/" + page.location, page.text, page.title))
}

val Headers = Set("h1", "h2", "h3", "h4", "h5", "h6")
Expand Down
Loading
Loading