Skip to content

Commit

Permalink
closes #1
Browse files Browse the repository at this point in the history
added output directory customization
  • Loading branch information
ShaggyYeti committed Jun 24, 2014
1 parent ece0111 commit 7c5bcfd
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 17 deletions.
22 changes: 19 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
sbt-sass for play framework 2.3
========

Plugin based on [play-sass][play-sass] for Play Framework 2.2.x

## ver 0.1.1 [24-06-2014]
* Added output directory customization
* Fix for windows using
* Sass sources directory changed from `app/assets/*` to `app/public/*`

# Prerequisites
[Sass][sass] compiler needs to be installed for plugin to work. This means that `sass` executable
needs to be found in path. Sass can be installed by by installing `sass` gem.
Expand All @@ -24,7 +28,7 @@ gem install compass
```
resolvers += Resolver.url("GitHub repository", url("http://shaggyyeti.github.io/releases"))(Resolver.ivyStylePatterns)
addSbtPlugin("default" % "sbt-sass" % "0.1")
addSbtPlugin("default" % "sbt-sass" % "0.1.1")
```
2. Run `activator`

Expand All @@ -42,8 +46,20 @@ gem install compass
5. Run `activator`

# Usage
* `*.sass` and `*.scss` files in `app/assets/*` directories will be automatically compiled to `*.css` files.
* `*.sass` and `*.scss` files in `app/public/*` directories will be automatically compiled to `*.css` files.
* Files starting with `_`-character will be left out from compilation as per Play convention.
* By default output directory is sass:
```
<link rel="stylesheet" media="screen" href="@routes.Assets.at("sass/test.css")">
```
* If you want to set output directory = `css`, then add to `build.sbt` next line:
```
sassPublicDir in Assets := "css"
```
and include in templates:
```
<link rel="stylesheet" media="screen" href="@routes.Assets.at("sass/test.css")">
```

Example of play-project: [example][example]

Expand Down
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ sbtPlugin := true

name := "sbt-sass"

version := "0.1"
version := "0.1.1"

scalaVersion := "2.10.4"

Expand Down
22 changes: 9 additions & 13 deletions src/main/scala/sass/SbtSass.scala
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ object Import {
val sass = TaskKey[Seq[File]]("sass", "Generate css files from scss and sass")
val sassEntryPoints = SettingKey[PathFinder]("Finder for sass and scss files")
val sassOptions = SettingKey[Seq[String]]("sassOptions", "Additional sass options")
val sassPublicDir = SettingKey[String]("sassPublicDir", "Directory name for storing published css files. Default: sass")
}


Expand All @@ -25,23 +26,15 @@ object SbtSass extends AutoPlugin {
import autoImport._

val baseSbtSassSettings = Seq(
sassEntryPoints <<= (sourceDirectory in Compile)(base => ((base / "assets" ** "*.sass") +++ (base / "assets" ** "*.scss") --- base / "assets" ** "_*")),
sassEntryPoints <<= (sourceDirectory in Compile)(srcPath => ((srcPath / "public" ** "*.sass") +++ (srcPath / "public" ** "*.scss") --- srcPath / "public" ** "_*")),
sassOptions := Seq.empty[String],
moduleName in sass := "sass",
sassPublicDir := (moduleName in sass).value,

sass := {
val targetDir = webTarget.value / (moduleName in sass).value / "main"

// val targetDir = webTarget.value / sourceFileTask.key.label / "main"

def paths = sassEntryPoints.value.get
paths.map(file => {
val z = resourceManaged.value
val x = targetDir
val c = target.value
val v = (public in Assets).value
val b = streams.value.cacheDirectory
println(resourceManaged.value)
val fileName = (file.getName).replace(".sass", "").replace(".scss", "")
val targetFileCss = targetDir / fileName.concat(".css")
val targetFileCssMin = targetDir / fileName.concat(".min.css")
Expand All @@ -51,24 +44,27 @@ object SbtSass extends AutoPlugin {
IO.write(targetFileCss, css)
IO.write(targetFileCssMin, cssMin)

SbtWeb.copyResourceTo(
(public in Assets).value / (moduleName in sass).value,
val f = SbtWeb.copyResourceTo(
(public in Assets).value / sassPublicDir.value,
targetFileCss.toURI().toURL(),
streams.value.cacheDirectory / "copy-resource"
)

SbtWeb.copyResourceTo(
(public in Assets).value / (moduleName in sass).value,
(public in Assets).value / sassPublicDir.value,
targetFileCssMin.toURI().toURL(),
streams.value.cacheDirectory / "copy-resource"
)
(public in Assets).value / sassPublicDir.value

targetFileCss
})
Seq(targetDir)
},
resourceGenerators <+= sass
)


override def projectSettings: Seq[Setting[_]] = inConfig(Assets)(baseSbtSassSettings)

}

0 comments on commit 7c5bcfd

Please sign in to comment.