Skip to content

Commit

Permalink
Merge pull request agrison#1 from laughedelic/updates
Browse files Browse the repository at this point in the history
Updates: sbt, scala, markdown4j
  • Loading branch information
laughedelic committed Jul 21, 2013
2 parents 48a4342 + 7b94112 commit 9d12102
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 169 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ temp*
dist
test-output
build.log
docs

# other scm
.svn
Expand Down
22 changes: 22 additions & 0 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -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-SNAPSHOT"

scalaVersion := "2.10.1"

scalacOptions ++= Seq(
"-unchecked"
, "-deprecation"
, "-feature"
, "-language:implicitConversions"
)
Binary file added lib/markdown4j-2.2.jar
Binary file not shown.
Binary file removed libs/markdown4j-1.1.jar
Binary file not shown.
144 changes: 0 additions & 144 deletions pom.xml

This file was deleted.

41 changes: 23 additions & 18 deletions src/main/scala/me/grison/scalocco/Mustache.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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
}
Expand Down
26 changes: 19 additions & 7 deletions src/main/scala/me/grison/scalocco/Scalocco.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 `<p/>` tags from the result
def mkdNoP = markdown.replaceAll("</?p>", "").trim()
// Creates a *Mustache* object whose template is the given String
Expand All @@ -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)
}
Expand Down Expand Up @@ -240,16 +240,28 @@ 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))
}

/**
* Simply run **`scalocco`**.
* @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)
}
}
}

0 comments on commit 9d12102

Please sign in to comment.