Permalink
Browse files

back to simple parser; package extension example

  • Loading branch information...
1 parent 79edb6a commit 8b8cc330146c38baab6d0840df41c2faf7b16be7 jto committed Jul 9, 2012
@@ -56,7 +56,7 @@ class Giter8 extends xsbti.AppMain with Apply {
| Resolves a template within a given branch
| --paramname=paramvalue
| Set given parameter value and bypass interaction.
- |
+ |
|
|Apply template and interactively fulfill parameters.
| g8 n8han/giter8
@@ -0,0 +1,15 @@
+package $package$
+
+import play.api._
+
+object $className$ extends GlobalSettings {
+
+ override def onStart(app: Application) {
+ Logger.info("Application has started")
+ }
+
+ override def onStop(app: Application) {
+ Logger.info("Application shutdown...")
+ }
+
+}
@@ -0,0 +1,2 @@
+className=Global
+package=global
@@ -1,2 +1 @@
-className=Application
-package=models
+className=User
@@ -13,70 +13,30 @@ object ScaffoldPlugin extends sbt.Plugin {
import ScaffoldingKeys._
import complete._
+ import complete.DefaultParsers._
- val parser: sbt.Project.Initialize[State => Parser[(File, Map[String, String])]] =
+ val parser: sbt.Project.Initialize[State => Parser[String]] =
(baseDirectory, templatesPath) { (b, t) =>
-
- import complete.DefaultParsers._
- import java.io.FileInputStream
-
(state: State) =>
- val folder = b / t
-
- val folders = folder.listFiles.filter(f => f.isDirectory && !f.isHidden)
- val templatesParsers = folders
- .map(_.getName: Parser[String])
- .reduceLeft(_ | _)
-
-
- val ex = for(
- f <- folders;
- k <- GIO.readProps(new FileInputStream(f / "default.properties")).keys.toList
- ) yield (k)
-
- val eq: Parser[String] = "="
-
- Space ~> templatesParsers.map(folder / _).flatMap { root =>
+ val folder = b / t
+ val templates = folder.listFiles
+ .filter(f => f.isDirectory && !f.isHidden)
+ .map(_.getName: Parser[String])
- val params = GIO.readProps(new FileInputStream(root / "default.properties"))
- val validParam = params
- .keys
- .map(x => x: Parser[String])
- .reduceLeft(_ | _)
-
- val p = ((validParam <~ eq): Parser[String]) ~ NotSpace
-
- def filtered(consumed: List[String]): Parser[Map[String, String]] = (Space ~> p).map(Map(_))
- .filter(
- parsed => !consumed.contains(parsed.head._1),
- c => "PAF" // ??
- ).flatMap { case parsed =>
- (filtered(consumed :+ parsed.head._1) ?).map{
- case Some(m) => m ++ parsed
- case None => parsed
- }
- }
-
- filtered(Nil).map{ (root, _) }.examples(ex:_*)
-
- // Space ~> (p?) map { param =>
- // (root, param.map(Map(_)).getOrElse(Map.empty))
- // }
- }
+ Space ~> templates.reduceLeft(_ | _)
}
- val scafffoldTask = scaffold <<= InputTask(parser){ (templateData: TaskKey[(File, Map[String, String])]) =>
- (baseDirectory, templateData) map { (b, data) =>
- val (t, param) = data
- // TODO: how to handle packages names in java (folder structure)
- // Template hooks? package(toto.tutu) like ls(,,)
- // G8Helpers.applyRaw(t, b, param).fold(
- // e => error(e),
- // r => println("Success :)")
- // )
+ val scafffoldTask = scaffold <<= InputTask(parser){ (argTask: TaskKey[String]) =>
+ (baseDirectory, templatesPath, argTask) map { (b, t, name) =>
+ val folder = b / t
+ G8Helpers.applyRaw(folder / name, b, Nil).fold(
+ e => error(e),
+ r => println("Success :)")
+ )
}
}
+
lazy val scaffoldSettings: Seq[sbt.Project.Setting[_]] = Seq(
templatesPath := ".g8",
scafffoldTask

0 comments on commit 8b8cc33

Please sign in to comment.