forked from lamdor/coffee-script-sbt-plugin
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Mustache templating as an optional step in the
Javascript compilation process. See the README for details. Implementation notes: - Add some more tests. - Refactored code to move URL and file handling into ManifestObjects. - Removed complex download tasks and do the downloads whenever we compile. - Update buid.properties to the next snapshot version.
- Loading branch information
Showing
11 changed files
with
270 additions
and
94 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
;; This config was generated using ensime-config-gen. Feel free to customize its contents manually. | ||
|
||
( | ||
|
||
:project-package "untyped" | ||
|
||
:use-sbt t | ||
|
||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package untyped | ||
|
||
import com.google.javascript.jscomp._ | ||
|
||
import sbt._ | ||
|
||
trait ClosureCompilerConfig extends MavenStyleWebScalaPaths { | ||
|
||
// Configuration ------------------------------ | ||
|
||
// This is a convenience method from Project. | ||
def descendents(parent: PathFinder, include: FileFilter): PathFinder | ||
|
||
/** | ||
* Returns true if the path refers to a file that should be templated | ||
* | ||
* It is templated if the file name contains .template. E.g. foo.template.js | ||
*/ | ||
def closureJsIsTemplated(path: Path): Boolean = path.name.contains(".template") | ||
|
||
/** | ||
* Where we should look to find properties files that supply values we use when templating | ||
*/ | ||
def closurePropertiesPath: Path = mainResourcesPath | ||
|
||
def closureSourcePath: Path = webappPath | ||
|
||
def closureJsSourceFilter: NameFilter = GlobFilter("*.js") | ||
def closureJsSources: PathFinder = descendents(closureSourcePath, closureJsSourceFilter) | ||
|
||
def closureManifestSourceFilter: NameFilter = GlobFilter("*.jsm") | "*.jsmanifest" | ||
def closureManifestSources: PathFinder = descendents(closureSourcePath, closureManifestSourceFilter) | ||
|
||
def closureOutputPath: Path = (outputPath / "sbt-closure-temp") ## | ||
|
||
var _closurePrettyPrint = false | ||
def closurePrettyPrint = _closurePrettyPrint | ||
|
||
var _closureVariableRenamingPolicy = VariableRenamingPolicy.LOCAL | ||
def closureVariableRenamingPolicy = _closureVariableRenamingPolicy | ||
|
||
def closureCompilerOptions = { | ||
val options = new CompilerOptions | ||
options.variableRenaming = closureVariableRenamingPolicy | ||
options.prettyPrint = closurePrettyPrint | ||
options | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package untyped | ||
|
||
import java.net.URL | ||
import scala.io.Source | ||
import sbt._ | ||
|
||
sealed abstract class ManifestObject { | ||
def filename: String | ||
def path(parent: Path): Path = | ||
filename.split("""[/\\]""").foldLeft(parent)(_ / _) | ||
} | ||
|
||
case class ManifestFile(val filename: String) extends ManifestObject | ||
|
||
case class ManifestUrl(val url: String) extends ManifestObject { | ||
lazy val filename: String = """[^A-Za-z0-9.]""".r.replaceAllIn(url, "_") | ||
|
||
def content: String = Source.fromInputStream(new URL(url).openStream).mkString | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package untyped | ||
|
||
import java.io.File | ||
|
||
object ManifestOps { | ||
def stripComments(line: String) = "#.*$".r.replaceAllIn(line, "").trim | ||
def isSkippable(line: String): Boolean = stripComments(line) == "" | ||
def isUrl(line: String): Boolean = stripComments(line).matches("^https?:.*") | ||
|
||
def parse(manifest: String): List[ManifestObject] = | ||
manifest.split("[\r\n]+"). | ||
map(stripComments _). | ||
filter(item => !isSkippable(item)). | ||
map(line => if(isUrl(line)) ManifestUrl(line) else ManifestFile(line)). | ||
toList | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.