Skip to content

Commit

Permalink
checkpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
TiarkRompf committed Jul 25, 2014
1 parent 80530c0 commit 3344655
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 24 deletions.
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ startYear := Some(2013)

version := "1.1.0"

scalaVersion := "2.10.1"
scalaVersion := "2.11.2"

scalacOptions ++= Seq(
"-unchecked"
Expand Down
18 changes: 9 additions & 9 deletions src/main/resources/template.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,29 +23,29 @@
}
h4, h5, h6 {
color: #333;
margin: 6px 0 6px 0;
padding: 6px 0 6px 0;
font-size: 13px;
}
h2, h3 {
margin-bottom: 0;
padding-bottom: 15px;
color: #000;
overflow: hidden;
}
h1 {
margin-top: 40px;
margin-bottom: 15px;
/*padding-top: 40px;*/
padding-bottom: 15px;
color: #000;
}
#container {
position: relative;
}
#background {
/*#background {
position: fixed;
top: 0; left: 525px; right: 0; bottom: 0;
background: #f5f5ff;
border-left: 1px solid #e5e5ee;
z-index: -1;
}
}*/
#jump_to, #jump_page {
background: white;
-webkit-box-shadow: 0 0 25px #777; -moz-box-shadow: 0 0 25px #777;
Expand Down Expand Up @@ -122,7 +122,7 @@
opacity: 1;
}
td.code, th.code {
padding: 14px 15px 16px 25px;
padding: 10px 10px 10px 50px;
width: 100%;
vertical-align: top;
background: #f5f5ff;
Expand Down Expand Up @@ -154,7 +154,7 @@
<div id="jump_wrapper">
<div id="jump_page">
{{#sources}}
<a class="source" href="{{.}}.html">
<a class="source" href="{{.}}">
{{.}}
</a>
{{/sources}}
Expand All @@ -179,7 +179,7 @@ <h1>{{title}}</h1>
<a class="pilcrow" href="#section_{{index}}">&#182;</a>
</div>
{{{doc}}}
</td>
</td></tr><tr>
<td class="code">
<pre><code class='prettyprint lang-scala'>{{code}}</code></pre>
</td>
Expand Down
3 changes: 1 addition & 2 deletions src/main/scala/me/grison/scalocco/Mustache.scala
Original file line number Diff line number Diff line change
Expand Up @@ -441,10 +441,9 @@ case class MustacheParseException(line:Int, msg:String)
stack.headOption match {
case None => None
case Some(head) => {
type MapLikeString[a, b] = MapLike[String, a, b]
head match {
case null => None
case m:MapLikeString[_,_] =>
case m:Map[String,Any] =>
m.get(key) match {
case Some(v) => v
case None => None
Expand Down
35 changes: 23 additions & 12 deletions src/main/scala/me/grison/scalocco/Scalocco.scala
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class Markdown {
//Scalocco
//---------------
object Scalocco extends Markdown {
// This value is used to differentiate normal comments from scaladoc style.
/* This value is used to differentiate normal comments from scaladoc style. */
val scaladoc = UUID.randomUUID().toString

//ScalaDoc Parsing
Expand Down Expand Up @@ -184,20 +184,23 @@ object Scalocco extends Markdown {
} else if (line.matches("[^*]*[*]/\\s*$")) {
inScalaDoc = false;
// Reading a comment line `//` or ` * ` if inside `Scaladoc`
} else if (line.matches("^\\s*//.*") || (inScalaDoc && line.matches("^\\s*[*].*"))) {
//} else if (line.matches("^\\s*//.*") || inScalaDoc) {
} else if (inScalaDoc) {
// if we did had code, store the code and documentation in the resulting section list
if (hasCode) {
val documentation = scaladocIfNeeded(doc)
sections ::= Section(documentation, code.toString)
hasCode = false
doc = new StringBuilder
if (inScalaDoc) doc.append(scaladoc)
//if (inScalaDoc) doc.append(scaladoc)
code = new StringBuilder
}
doc.append(line.replaceFirst("^\\s*//", "")).append("\n")
val cleaned = line.replaceFirst(if (inScalaDoc) "^\\s*[*]" else "^\\s*//", "")
doc.append(cleaned).append("\n")
} else {
hasCode = true
code.append(line).append("\n")
if (!code.isEmpty || !line.trim.isEmpty)
code.append(line).append("\n")
inScalaDoc = false
}
)
Expand All @@ -213,19 +216,26 @@ object Scalocco extends Markdown {
* @param path the Path of the original file.
* @param destPath the Path where to write the documentation file.
*/
def documentFile(source: File, path: String, destPath: String) = {
def documentFile(source: File, path: String, destPath: String, templateFile: String) = {
val sections = parseSections(source)
val mustache = new Mustache(Source.fromURL(getClass.getResource("/template.html")).mkString)
val template = if (templateFile == "default") Source.fromURL(getClass.getResource("/template.html")).mkString
else Source.fromFile(templateFile).mkString
val mustache = new Mustache(template)
def outFile(destPath: String)(source: File) = {
new File(source.getCanonicalPath.replace(path, destPath).replace(".scala",".html"))
}
val html = mustache.render(Map(
// This is the title of the Scala source file
"title" -> source.getName,
// The sources are available in the right-upper box on the generated documentation
"sources" -> sources,
"destPath" -> destPath,
"sources" -> sources.map(outFile("")),
// keep indexes for sections
"sections" -> sections.zipWithIndex.map(t =>
Map("index" -> t._2, "code" -> t._1.code, "doc" -> t._1.doc.markdown))
))
val outputFile = new File(source.getCanonicalPath.replace(path, destPath) + ".html")
val outputFile = outFile(destPath)(source)
(new File(outputFile.getParent)).mkdirs
println("Generating documentation: " + outputFile.getCanonicalPath)
// output the HTML rendered with Mustache into a file named `SOURCE_FILE.scala.html`
val p = new PrintWriter(outputFile)
Expand All @@ -237,7 +247,7 @@ object Scalocco extends Markdown {
* @param path the Path were we may find some scala files.
* @param destPath the Path were we should output the documentation.
*/
def generateDoc(path: String, destPath: String) = {
def generateDoc(path: String, destPath: String, template: String) = {
val files = scalaFiles(path)
sources = files.toList

Expand All @@ -249,7 +259,7 @@ object Scalocco extends Markdown {
val dest = new File(destPath)
if (!dest.exists()) dest.mkdirs()

files.foreach(documentFile(_, basePath, destPath))
files.foreach(documentFile(_, basePath, destPath, template))
}

/**
Expand All @@ -261,7 +271,8 @@ object Scalocco extends Markdown {
else {
val path = args(0)
val destPath = if (args.length > 1) args(1) else "./docs/"
generateDoc(path, destPath)
val template = if (args.length > 2) args(2) else "default"
generateDoc(path, destPath, template)
}
}
}

0 comments on commit 3344655

Please sign in to comment.