diff --git a/.gitignore b/.gitignore index 3de72ce..124464d 100644 --- a/.gitignore +++ b/.gitignore @@ -27,6 +27,7 @@ temp* dist test-output build.log +docs # other scm .svn diff --git a/README.md b/README.md index 7f57168..8bb7baa 100644 --- a/README.md +++ b/README.md @@ -19,17 +19,16 @@ Comments are passed through highlighted using [google-code-prettify](http://code.google.com/p/google-code-prettify/) syntax highlighting. -Currently, to build Scalocco, you'll need **maven** and **scala**. The project -depends on [scala-mustache](https://github.com/vspy/scala-mustache) and -[Markdown4j](https://code.google.com/p/markdown4j/) +Currently, to build Scalocco, you'll need [sbt](http://www.scala-sbt.org/release/docs/Getting-Started/Setup.html) and **scala**. The project +depends on [scala-mustache](https://github.com/vspy/scala-mustache) and [Markdown4j](https://code.google.com/p/markdown4j/) -To use Scalocco, build it using `maven` (no `sbt` for now) then run it from the command-line: +To run Scalocco, just use sbt: - java -jar scalocco.jar /path/to/scala/files + sbt "run /path/to/scala/files" ...will generate linked HTML documentation for the named source files, saving it into a `docs` folder. The visual style was borrowed from the .Net implementation of Docco: [Nocco](https://github.com/dontangg/nocco) -You can see the result of running Scalocco on its own source code here: [http://grison.me/scalocco/source](http://grison.me/scalocco/source) \ No newline at end of file +You can see the result of running Scalocco on its own source code here: [http://grison.me/scalocco/source](http://grison.me/scalocco/source) diff --git a/build.sbt b/build.sbt new file mode 100644 index 0000000..3847eb4 --- /dev/null +++ b/build.sbt @@ -0,0 +1,22 @@ +name := "scalocco" + +organization := "me.grison.scalocco" + +description := "Scalocco: A Docco implementation in Scala" + +homepage := Some(url("http://www.grison.me/scalocco/")) + +startYear := Some(2013) + +// licenses += ??? + +version := "1.1.0" + +scalaVersion := "2.10.1" + +scalacOptions ++= Seq( + "-unchecked" +, "-deprecation" +, "-feature" +, "-language:implicitConversions" +) diff --git a/lib/markdown4j-2.2.jar b/lib/markdown4j-2.2.jar new file mode 100644 index 0000000..65030fa Binary files /dev/null and b/lib/markdown4j-2.2.jar differ diff --git a/libs/markdown4j-1.1.jar b/libs/markdown4j-1.1.jar deleted file mode 100644 index f866453..0000000 Binary files a/libs/markdown4j-1.1.jar and /dev/null differ diff --git a/pom.xml b/pom.xml deleted file mode 100644 index 8027556..0000000 --- a/pom.xml +++ /dev/null @@ -1,144 +0,0 @@ - - 4.0.0 - me.grison.scalocco - scalocco - 1.0-SNAPSHOT - ${project.artifactId} - Scalocco: A Docco implementation in Scala - 2013 - http://www.grison.me/scalocco/ - - - 1.5 - 1.5 - UTF-8 - 2.8.0 - - - - - org.scala-lang - scala-library - ${scala.version} - - - - - junit - junit - 4.8.1 - test - - - org.scala-tools.testing - specs_${scala.version} - 1.6.5 - test - - - org.scalatest - scalatest - 1.2 - test - - - - - src/main/scala - src/test/scala - - - org.scala-tools - maven-scala-plugin - 2.15.0 - - - - compile - testCompile - - - - -make:transitive - -dependencyfile - ${project.build.directory}/.scala_dependencies - - - - - - - org.apache.maven.plugins - maven-surefire-plugin - 2.6 - - false - true - - - - **/*Test.* - **/*Suite.* - - - - - org.apache.maven.plugins - maven-shade-plugin - 1.6 - - true - - - *:* - - META-INF/*.SF - META-INF/*.DSA - META-INF/*.RSA - - - - - - - package - - shade - - - - - - me.grison.scalocco.Scalocco - - - - - - - - - com.googlecode.addjars-maven-plugin - addjars-maven-plugin - 1.0.5 - - - - add-jars - - - - - ${basedir}/libs - - - - - - - - - diff --git a/src/main/scala/me/grison/scalocco/Mustache.scala b/src/main/scala/me/grison/scalocco/Mustache.scala index f172e8f..9a249ab 100644 --- a/src/main/scala/me/grison/scalocco/Mustache.scala +++ b/src/main/scala/me/grison/scalocco/Mustache.scala @@ -413,7 +413,9 @@ case class MustacheParseException(line:Int, msg:String) value:Any , childrenString:String , render:(String)=>String - ):Any = + ):Any = { + type F1[t] = Function1[String, t] + type F2[t] = Function2[String, Function1[String,String], t] value match { case Some(someValue) => eval(someValue, childrenString, render) @@ -424,34 +426,37 @@ case class MustacheParseException(line:Int, msg:String) case m:MapLike[_, _, _] => m - case f:Function1[String, _] => + case f:F1[_] => eval(f(childrenString), childrenString, render) - case f:Function2[String, Function1[String,String], _] => + case f:F2[_] => eval(f(childrenString, render), childrenString, render) case other => other } + } @tailrec private def findInContext(stack:List[Any], key:String):Any = stack.headOption match { case None => None - case Some(head) => - (head match { - case null => None - case m : MapLike[String,_,_] => - m.get(key) match { - case Some(v) => v - case None => None - } - case m:Mustache => - m.globals.get(key) match { - case Some(v) => v - case None => None - } - case any => reflection(any, key) - }) match { + case Some(head) => { + type MapLikeString[a, b] = MapLike[String, a, b] + head match { + case null => None + case m:MapLikeString[_,_] => + m.get(key) match { + case Some(v) => v + case None => None + } + case m:Mustache => + m.globals.get(key) match { + case Some(v) => v + case None => None + } + case any => reflection(any, key) + } + } match { case None => findInContext(stack.tail, key) case x => x } diff --git a/src/main/scala/me/grison/scalocco/Scalocco.scala b/src/main/scala/me/grison/scalocco/Scalocco.scala index 3974578..678eddd 100644 --- a/src/main/scala/me/grison/scalocco/Scalocco.scala +++ b/src/main/scala/me/grison/scalocco/Scalocco.scala @@ -42,7 +42,7 @@ import io.Source import java.util.UUID //#### Import for processing Markdown #### -import com.petebevin.markdown.MarkdownProcessor; +import org.markdown4j.Markdown4jProcessor //### Section class### // The `Section` class is just an object having two fields to represent @@ -55,7 +55,7 @@ case class Section(doc: String, code: String) class Markdown { class MarkdownableString(s: String) { // *Markdownify* the given text. - def markdown = new MarkdownProcessor().markdown(s) + def markdown = new Markdown4jProcessor().process(s) // *Markdownify* the given text but removes the `

` tags from the result def mkdNoP = markdown.replaceAll("", "").trim() // Creates a *Mustache* object whose template is the given String @@ -78,7 +78,7 @@ object Scalocco extends Markdown { * Abstract class representing a Scaladoc item. * @param tpl the Mustache template to be used to render the Scaladoc. */ - abstract case class DocItem(tpl: Mustache) { + abstract class DocItem(tpl: Mustache) { // Render this Scaladoc item def render = tpl.render(this) } @@ -240,9 +240,16 @@ object Scalocco extends Markdown { def generateDoc(path: String, destPath: String) = { val files = scalaFiles(path) sources = files.toList - if (!new File(destPath).exists()) - new File(destPath).mkdirs() - files.foreach(documentFile(_, path, destPath)) + + // if the given path is just a file, split the base part of it + val pathFile = new File(path) + val basePath = if (pathFile.isDirectory) path else pathFile.getParent + + // create destination path, if it doesn't exist + val dest = new File(destPath) + if (!dest.exists()) dest.mkdirs() + + files.foreach(documentFile(_, basePath, destPath)) } /** @@ -250,6 +257,11 @@ object Scalocco extends Markdown { * @param args the arguments to the program */ def main(args: Array[String]) { - generateDoc(args(0), Option(args(1)).getOrElse("./docs/")) + if(args.length == 0) println("Need an argument: path with sources") + else { + val path = args(0) + val destPath = if (args.length > 1) args(1) else "./docs/" + generateDoc(path, destPath) + } } }