Skip to content

Instantly share code, notes, and snippets.

@Timshel
Last active December 28, 2015 23:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Timshel/7580837 to your computer and use it in GitHub Desktop.
Save Timshel/7580837 to your computer and use it in GitHub Desktop.
Play215 with scalariform formatting before compilation
# Control the activation of the scalariform plugin (default false).
application.scalariform.enable=true
# Path to the configuration properties :
#application.scalariform.config.path="conf/scalariform.properties"
import sbt._
import Keys._
import play.Project._
import com.typesafe.config._
object ApplicationBuild extends Build {
val conf = ConfigFactory.parseFile(new File("conf/application.conf")).resolve()
val appName = "play215"
val appVersion = "1.0-SNAPSHOT"
val appDependencies = Seq(
// Add your project dependencies here,
jdbc,
anorm
)
lazy val scalariformConf: Seq[Setting[_]] = {
import scala.util.control.Exception._
val useScalariform = (catching(classOf[ConfigException]) opt conf.getBoolean("application.scalariform.enable")).getOrElse(false)
if( useScalariform ){
import com.typesafe.sbt.SbtScalariform.ScalariformKeys
import scalariform.formatter.preferences._
val confPath = ( catching(classOf[ConfigException]) opt
conf.getString("application.scalariform.config.path") ).getOrElse("conf/scalariform.properties")
val formattingPreferences = PreferencesImporterExporter.loadPreferences(confPath)
com.typesafe.sbt.SbtScalariform.scalariformSettings ++ Seq( ScalariformKeys.preferences := formattingPreferences )
} else { Nil }
}
val main = play.Project(appName, appVersion, appDependencies).settings(scalariformConf:_*)
}
// Comment to get more information during initialization
logLevel := Level.Warn
// The Typesafe repository
resolvers += "Typesafe repository" at "http://repo.typesafe.com/typesafe/releases/"
// Scalariform formatting
addSbtPlugin("com.typesafe.sbt" % "sbt-scalariform" % "1.0.1")
// Use the Play sbt plugin for Play projects
addSbtPlugin("play" % "sbt-plugin" % "2.1.5")
alignSingleLineCaseStatements=true
compactControlReadability=true
compactStringConcatenation=true
doubleIndentClassDeclaration=true
formatXml=true
indentLocalDefs=true
indentPackageBlocks=true
indentSpaces=2
multilineScaladocCommentsStartOnFirstLine=true
preserveSpaceBeforeArguments=false
preserveDanglingCloseParenthesis=false
rewriteArrowSymbols=false
spaceBeforeColon=false
spaceInsideBrackets=false
spacesWithinPatternBinders=true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment