added a simple little site generator for the API docs

This commit is contained in:
James Strachan
2012-03-07 20:09:10 +00:00
parent a2b41a717e
commit 44b2fec726
9 changed files with 224 additions and 2 deletions
+1 -1
View File
@@ -56,7 +56,7 @@
<module>stdlib</module>
<module>kunit</module>
<module>kdoc</module>
<module>apidocs</module>
<module>website</module>
</modules>
<build>
@@ -4,10 +4,19 @@
<output url="file://$MODULE_DIR$/target/classes" />
<output-test url="file://$MODULE_DIR$/target/test-classes" />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src/main/kotlin" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/test/kotlin" isTestSource="true" />
<excludeFolder url="file://$MODULE_DIR$/target" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="Maven: org.pegdown:pegdown:1.1.0" level="project" />
<orderEntry type="library" name="Maven: org.parboiled:parboiled-core:1.0.2" level="project" />
<orderEntry type="library" name="Maven: org.parboiled:parboiled-java:1.0.2" level="project" />
<orderEntry type="library" name="Maven: asm:asm:3.3.1" level="project" />
<orderEntry type="library" name="Maven: asm:asm-util:3.3.1" level="project" />
<orderEntry type="library" name="Maven: asm:asm-tree:3.3.1" level="project" />
<orderEntry type="library" name="Maven: asm:asm-analysis:3.3.1" level="project" />
<orderEntry type="library" name="Maven: org.jetbrains.kotlin:kotlin-compiler:0.2.3.8" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: junit:junit:4.9" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.hamcrest:hamcrest-core:1.1" level="project" />
@@ -11,9 +11,14 @@
<version>1.0-SNAPSHOT</version>
</parent>
<artifactId>apidocs</artifactId>
<artifactId>website</artifactId>
<dependencies>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>stdlib</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.pegdown</groupId>
<artifactId>pegdown</artifactId>
@@ -0,0 +1,45 @@
package org.jetbrains.kotlin.site
import kotlin.io.*
import java.io.File
import org.pegdown.Extensions
import org.pegdown.PegDownProcessor
import org.pegdown.LinkRenderer
class SiteGenerator(val sourceDir: File, val outputDir: File) : Runnable {
public var markdownProcessor: PegDownProcessor = PegDownProcessor(Extensions.ALL)
public var linkRendered: LinkRenderer = LinkRenderer()
override fun run() {
println("Generating the site to $outputDir")
sourceDir.recurse {
if (it.isFile()) {
var relativePath = sourceDir.relativePath(it)
println("Processing ${relativePath}")
var text = it.readText()
if (it.extension == "md") {
text = markdownProcessor.markdownToHtml(text, linkRendered) ?: ""
relativePath = relativePath.trimTrailing(it.extension) + "html"
}
text = layout(relativePath, it, text)
val outFile = File(outputDir, relativePath)
outFile.directory.mkdirs()
outFile.writeText(text)
}
}
}
/**
* Applies a layout to the given file
*/
fun layout(uri: String, file: File, text: String): String {
return """<html>
<body>
$text
</body>
</html>
"""
}
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.8 KiB

@@ -0,0 +1,118 @@
/*
* Copyright 2009 Red Hat, Inc.
*
* Red Hat licenses this file to you under the Apache License, version 2.0
* (the "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*/
/* Javadoc style sheet */
/* Define colors, fonts and other style attributes here to override the defaults */
/* Page background color */
body {
background-color: #FFFFFF;
background-image:url(resources/gradient-sand-white.png);
background-repeat: repeat-x;
margin:0 auto;
font-family:'Lucida Grande', Geneva, Verdana, Arial, sans-serif;
font-size:12px;
padding:0em 1em;
color:#333;
}
/* Common elements */
font {
font-family: inherit;
font-size: inherit;
color: inherit;
font-weight: inherit; }
hr {
border-top: 1px solid #A9A89B;
border-bottom: 0 none;
}
tt, tt *, pre, pre *, code, code * {
font-family: "Liberation Mono", "DejaVu Sans Mono", Consolas, Monaco, "Vera Sans Mono", "Lucida Console", "Courier New", monospace !important;
}
a:link { color:#5d5c50; }
a:visited { color:#5d5c50; }
a:hover { color:#5d5c50; }
/* Headings */
h1 {
font-size: 145%;
border-top:1px dotted #CCCCCC;
line-height:1.2em;
color:#CC333A;
font-size:2em;
padding:1.5em;
margin-top: 0px;
text-align:left;
}
/* Default Table elements and colors */
th, table { border-collapse:collapse;border-color: #A9A89B; }
.TableHeadingColor {
background:#EBE7C4 url(resources/bkgheader.png) no-repeat right top;
color:#CC333A;
font-size:12px;
font-weight:bold;
height:31px;
text-align:left;
padding:1.5em;
}
.TableHeadingColor th {
padding-left: 10px;
}
.TableSubHeadingColor { background-color:#EBE7C4; }
.TableRowColor { background: white; border-color: #A9A89B;}
.TableRowColor td { line-height: 175%; padding-left: 10px;}
/* Font used in left-hand frame lists */
.FrameTitleFont { font-size: 125%; font-family: Helvetica, Arial, sans-serif; font-weight: bold; margin-top: 1em; display: block; }
.FrameHeadingFont { font-size: 125%; font-family: 'Lucida Grande', Geneva, Verdana, Arial, sans-serif; font-weight: bold; margin-top: 1em; display: block; }
.FrameItemFont { font-size: 100%; font-family: Helvetica, Arial, sans-serif }
/* Navigation bar fonts and colors */
.NavBarCell1 {
background:#EBE7C4;
line-height:2em;
padding-left:6px;
padding-right:6px;
}
.NavBarFont1 {
color: #CC333A;
}
.NavBarCell1 a {
color: #CC333A;
}
.NavBarCell1Rev { background:#EBE7C4; padding-left:6px; padding-right:6px;}
.NavBarFont1 { color:#CC333A;}
.NavBarFont1Rev { color:#243446;}
.NavBarCell2 { background-color:#FFFFFF;}
.NavBarCell3 { background-color:#FFFFFF;}
@@ -0,0 +1,20 @@
# Kotlin Programming Language
Welcome to [Kotlin](http://www.jetbrains.com/kotlin)!
Some handy links
* [API Docs](apidocs/index.html)
* [Kotlin Blog](http://blog.jetbrains.com/kotlin/)
* [Web Demo](http://kotlin-demo.jetbrains.com/)
* [Issue Tracker](http://youtrack.jetbrains.com/issues/KT)
* [follow Kotlin on twitter](http://twitter.com/#!/project_kotlin)
## Editing Kotlin
* [Kotlin IDEA Plugin](http://hadihariri.com/2012/02/17/the-kotlin-journey-part-i-getting-things-set-up/)
* [Kotlin TextMate Bundle](https://github.com/k33g/kotlin-textmate-bundle#readme)
## Kommitter links
* [TeamCity CI build](http://teamcity.jetbrains.com/project.html?projectId=project67&tab=projectOverview)
@@ -0,0 +1,25 @@
package org.jetbrains.kotlin.site
import junit.framework.TestCase
import java.io.File
import kotlin.util.arrayList
class GenerateSiteTest : TestCase() {
fun testGenerateSite(): Unit {
val srcDir = findTemplateDir()
val generator = SiteGenerator(srcDir, File(srcDir, "../../../target/site"))
generator.run()
}
fun findTemplateDir(): File {
val path = "src/main/templates"
for (p in arrayList(".", "apidocs", "library/apidocs")) {
val sourceDir = File(".", path)
if (sourceDir.exists()) {
return sourceDir
}
}
throw IllegalArgumentException("Could not find template directory: $path")
}
}