Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into switch-groups
Browse files Browse the repository at this point in the history
  • Loading branch information
raboof committed May 11, 2017
2 parents 0a01685 + 91f2a8c commit ab03fa8
Show file tree
Hide file tree
Showing 31 changed files with 119 additions and 37 deletions.
2 changes: 1 addition & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ install:
[System.IO.Compression.ZipFile]::ExtractToDirectory("C:\sbt-bin.zip", "C:\sbt")
}
- cmd: SET PATH=C:\sbt\sbt\bin;%JAVA_HOME%\bin;%PATH%
- cmd: SET SBT_OPTS=-XX:MaxPermSize=2g -Xmx4g
- cmd: SET SBT_OPTS=-XX:MaxPermSize=2g -Xmx4g -Dfile.encoding=UTF8
build_script:
- sbt clean compile
test_script:
Expand Down
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ lazy val plugin = project
scriptedSettings,
scriptedLaunchOpts += ("-Dproject.version=" + version.value),
scriptedLaunchOpts ++= sys.process.javaVmArguments.filter(
a => Seq("-Xmx", "-Xms", "-XX").exists(a.startsWith)
a => Seq("-Xmx", "-Xms", "-XX", "-Dfile").exists(a.startsWith)
),
scriptedDependencies := {
val p1 = (publishLocal in core).value
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@

package com.lightbend.paradox

import com.lightbend.paradox.template.PageTemplate
import com.lightbend.paradox.markdown.{ Breadcrumbs, Groups, Page, Path, Reader, TableOfContents, Writer, Frontin, PropertyUrl, Url }
import com.lightbend.paradox.template.{ CachedTemplates, PageTemplate }
import com.lightbend.paradox.tree.Tree.{ Forest, Location }
import java.io.File
import org.pegdown.ast.{ ActiveLinkNode, ExpLinkNode, RootNode }
Expand All @@ -41,7 +41,7 @@ class ParadoxProcessor(reader: Reader = new Reader, writer: Writer = new Writer)
groups: Map[String, Seq[String]],
properties: Map[String, String],
navigationDepth: Int,
themeDir: File,
pageTemplate: PageTemplate,
errorListener: STErrorListener): Seq[(File, String)] = {
val pages = parsePages(mappings, Path.replaceSuffix(sourceSuffix, targetSuffix))
val paths = Page.allPaths(pages).toSet
Expand All @@ -58,9 +58,8 @@ class ParadoxProcessor(reader: Reader = new Reader, writer: Writer = new Writer)
val headerToc = new TableOfContents(pages = false, headers = true, ordered = false, maxDepth = navigationDepth)
val pageContext = PageContents(leadingBreadcrumbs, groups, loc, writer, writerContext, pageToc, headerToc)
val outputFile = new File(outputDirectory, page.path)
val template = CachedTemplates(themeDir, page.properties(Page.Properties.DefaultLayoutMdIndicator, PageTemplate.DefaultName))
outputFile.getParentFile.mkdirs
template.write(pageContext, outputFile, errorListener)
pageTemplate.write(page.properties(Page.Properties.DefaultLayoutMdIndicator, pageTemplate.defaultName), pageContext, outputFile, errorListener)
render(loc.next, rendered :+ (outputFile, page.path))
case None => rendered
}
Expand All @@ -81,6 +80,7 @@ class ParadoxProcessor(reader: Reader = new Reader, writer: Writer = new Writer)
lazy val getBase = page.base
lazy val getHome = link(Some(loc.root))
lazy val getPrev = link(loc.prev)
lazy val getSelf = link(Some(loc))
lazy val getNext = link(loc.next)
lazy val getBreadcrumbs = writer.writeBreadcrumbs(Breadcrumbs.markdown(leadingBreadcrumbs, loc.path), context)
lazy val getNavigation = writer.writeNavigation(pageToc.root(loc), context)
Expand All @@ -102,6 +102,7 @@ class ParadoxProcessor(reader: Reader = new Reader, writer: Writer = new Writer)
lazy val getHref: String = location.map(href).orNull
lazy val getHtml: String = location.map(link).orNull
lazy val getTitle: String = location.map(title).orNull
lazy val getAbsolute: PageLink = PageLink(location, location.map(_.root.tree.label).getOrElse(current), writer, context)
lazy val isActive: Boolean = location.exists(active)

private def link(location: Location[Page]): String = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,36 +16,22 @@

package com.lightbend.paradox.template

import java.io.File
import java.io.{ File, OutputStreamWriter, FileOutputStream }
import java.util.{ Map => JMap }
import org.stringtemplate.v4.misc.STMessage
import org.stringtemplate.v4.{ STErrorListener, STRawGroupDir, ST }
import org.stringtemplate.v4.{ STErrorListener, STRawGroupDir, ST, NoIndentWriter }
import collection.concurrent.TrieMap

object CachedTemplates {
def apply(dir: File, templateName: String = PageTemplate.DefaultName): PageTemplate = {
cache.get((dir, templateName)) match {
case Some(t) => t
case _ =>
val newTemplate = new PageTemplate(dir, templateName)
cache((dir, templateName)) = newTemplate
newTemplate
}
}

val cache: TrieMap[(File, String), PageTemplate] = TrieMap()
}

/**
* Page template writer.
*/
class PageTemplate(directory: File, name: String = PageTemplate.DefaultName, startDelimiter: Char = '$', stopDelimiter: Char = '$') {
class PageTemplate(directory: File, val defaultName: String = "page", startDelimiter: Char = '$', stopDelimiter: Char = '$') {
private val templates = new STRawGroupDir(directory.getAbsolutePath, startDelimiter, stopDelimiter)

/**
* Write a templated page to the target file.
*/
def write(contents: PageTemplate.Contents, target: File, errorListener: STErrorListener): File = {
def write(name: String, contents: PageTemplate.Contents, target: File, errorListener: STErrorListener): File = {
import scala.collection.JavaConverters._

val template = Option(templates.getInstanceOf(name)) match {
Expand All @@ -54,15 +40,16 @@ class PageTemplate(directory: File, name: String = PageTemplate.DefaultName, sta
t.add("page", contents)
case None => sys.error(s"StringTemplate '$name' was not found for '$target'. Create a template or set a theme that contains one.")
}
template.write(target, errorListener)
val osWriter = new OutputStreamWriter(new FileOutputStream(target))
val noIndentWriter = new NoIndentWriter(osWriter)
template.write(noIndentWriter) // does not take into account the errorListener any more...
osWriter.close
target
}

}

object PageTemplate {
val DefaultName = "page"

/**
* All page information to give to the template.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ package com.lightbend.paradox.markdown
import com.lightbend.paradox.tree.Tree.{ Forest, Location }
import java.io.{ File, PrintWriter }
import org.scalatest.{ FlatSpec, Matchers }
import com.lightbend.paradox.template.{ CachedTemplates, PageTemplate }
import com.lightbend.paradox.template.PageTemplate
import java.nio.file._

abstract class MarkdownBaseSpec extends FlatSpec with Matchers {
Expand Down Expand Up @@ -51,8 +51,8 @@ abstract class MarkdownBaseSpec extends FlatSpec with Matchers {
val html = normalize(markdownWriter.write(page.markdown, context(loc)))
val outputFile = new File(page.path)
val emptyPageContext = PartialPageContent(page.properties.get, html)
val template = CachedTemplates(new File(templateDirectory.toString), page.properties(Page.Properties.DefaultLayoutMdIndicator, PageTemplate.DefaultName))
template.write(emptyPageContext, outputFile, new PageTemplate.ErrorLogger(s => println("[error] " + s)))
val template = new PageTemplate(new File(templateDirectory.toString))
template.write(page.properties(Page.Properties.DefaultLayoutMdIndicator, template.defaultName), emptyPageContext, outputFile, new PageTemplate.ErrorLogger(s => println("[error] " + s)))
val fileContent = fileToContent(outputFile)
outputFile.delete
render(loc.next, rendered :+ (page.path, normalize(fileContent)))
Expand Down
4 changes: 3 additions & 1 deletion docs/src/main/paradox/features/linking.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,9 @@ URL templates can be configured via `extref.<scheme>.base_url` and the
template may contain one `%s` which is replaced with the scheme specific
part of the link URL. For example, given the property:

scaladoc.rfc.base_url=http://tools.ietf.org/html/rfc%s
```text
extref.rfc.base_url=http://tools.ietf.org/html/rfc%s
```

then `@extref[RFC 2119](rfc:2119)` will resolve to the URL
<http://tools.ietf.org/html/rfc2119>.
Expand Down
7 changes: 7 additions & 0 deletions notes/0.2.10.markdown
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
https://github.com/lightbend/paradox/compare/v0.2.9...v0.2.10

### Fixes and enhancements

- Fixes indentation in code snippets. #84/#86 by @gsechaud
- Fixes character encoding to use UTF-8. #99 by @kamijin-fanta
- Exposes page URL to template. #110 by @raboof
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ trait ParadoxKeys {
val paradoxTheme = settingKey[Option[ModuleID]]("Web module name of the paradox theme, otherwise local template.")
val paradoxThemeDirectory = taskKey[File]("Sync combined theme and local template to a directory.")
val paradoxOverlayDirectories = settingKey[Seq[File]]("Directory containing common source files for configuration.")
val paradoxDefaultTemplateName = settingKey[String]("Name of default template for generating pages.")
val paradoxTemplate = taskKey[PageTemplate]("PageTemplate to use when generating HTML pages.")
val paradoxVersion = settingKey[String]("Paradox plugin version.")
val paradoxGroups = settingKey[Map[String, Seq[String]]]("Paradox groups.")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import sbt._
import sbt.Keys._

import com.lightbend.paradox.ParadoxProcessor
import com.lightbend.paradox.template.{ PageTemplate, CachedTemplates }
import com.lightbend.paradox.template.PageTemplate
import com.typesafe.sbt.web.Import.{ Assets, WebKeys }
import com.typesafe.sbt.web.SbtWeb

Expand All @@ -45,6 +45,7 @@ object ParadoxPlugin extends AutoPlugin {
paradoxNavigationDepth := 2,
paradoxProperties := Map.empty,
paradoxTheme := Some(builtinParadoxTheme("generic")),
paradoxDefaultTemplateName := "page",
paradoxLeadingBreadcrumbs := Nil,
paradoxGroups := Map.empty,
libraryDependencies ++= paradoxTheme.value.toSeq
Expand Down Expand Up @@ -106,7 +107,7 @@ object ParadoxPlugin extends AutoPlugin {
if (!dir.exists) {
IO.createDirectory(dir)
}
CachedTemplates(dir)
new PageTemplate(dir, paradoxDefaultTemplateName.value)
},

sourceDirectory in paradoxTemplate := (target in paradoxTheme).value, // result of combining published theme and local theme template
Expand All @@ -129,7 +130,7 @@ object ParadoxPlugin extends AutoPlugin {
paradoxGroups.value,
paradoxProperties.value,
paradoxNavigationDepth.value,
paradoxThemeDirectory.value,
paradoxTemplate.value,
new PageTemplate.ErrorLogger(s => streams.value.log.error(s))
)
},
Expand Down
6 changes: 6 additions & 0 deletions plugin/src/sbt-test/paradox/snippet-noindent-writer/build.sbt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
lazy val root = (project in file(".")).
enablePlugins(ParadoxPlugin).
settings(
paradoxTheme := None,
name := "snippet-indent"
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<div>
<div>
<pre class="prettyprint"><code class="language-scala">object Hello extends App {
def say(str: String): Unit = {
println(str)
}

say(&quot;hello&quot;)
}</code></pre>
</div>
</div>

<pre class="prettyprint"><code class="language-scala">object Hello extends App {
def say(str: String): Unit = {
println(str)
}

say(&quot;hello&quot;)
}</code></pre>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
addSbtPlugin("com.lightbend.paradox" % "sbt-paradox" % sys.props("project.version"))
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<div>
<div>
$page.content$
</div>
</div>

$page.content$
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// #hello_example
object Hello extends App {
def say(str: String): Unit = {
println(str)
}

say("hello")
}
// #hello_example
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@@snip[Hello](code-samples/Hello.scala)
3 changes: 3 additions & 0 deletions plugin/src/sbt-test/paradox/snippet-noindent-writer/test
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
> paradox

$ must-mirror target/paradox/site/main/index.html expected/index.html
7 changes: 7 additions & 0 deletions plugin/src/sbt-test/paradox/template/build.sbt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
lazy val templateTest = project
.in(file("."))
.enablePlugins(ParadoxPlugin)
.settings(
// set the generic theme to test overriding page.st
paradoxTheme := Some(builtinParadoxTheme("generic"))
)
1 change: 1 addition & 0 deletions plugin/src/sbt-test/paradox/template/changes/alt2.st
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Modified alternative template
1 change: 1 addition & 0 deletions plugin/src/sbt-test/paradox/template/changes/page2.st
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Modified template
1 change: 1 addition & 0 deletions plugin/src/sbt-test/paradox/template/expected/page1.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Override generic template
1 change: 1 addition & 0 deletions plugin/src/sbt-test/paradox/template/expected/page2.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Modified template
1 change: 1 addition & 0 deletions plugin/src/sbt-test/paradox/template/expected/page3.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Alternative template
1 change: 1 addition & 0 deletions plugin/src/sbt-test/paradox/template/expected/page4.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Modified alternative template
1 change: 1 addition & 0 deletions plugin/src/sbt-test/paradox/template/project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
addSbtPlugin("com.lightbend.paradox" % "sbt-paradox" % sys.props("project.version"))
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Alternative template
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Override generic template
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Test page
20 changes: 20 additions & 0 deletions plugin/src/sbt-test/paradox/template/test
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# check that the page.st from generic theme has been overridden
> paradox
$ must-mirror target/paradox/site/main/page.html expected/page1.html

# make a change to page.st and check that the template has been updated
$ copy-file changes/page2.st src/main/paradox/_template/page.st
$ sleep 1000
> paradox
$ must-mirror target/paradox/site/main/page.html expected/page2.html

# switch to a different default template
> 'set paradoxDefaultTemplateName := "alt"'
> paradox
$ must-mirror target/paradox/site/main/page.html expected/page3.html

# make a change to alt.st and check that the template has been updated
$ copy-file changes/alt2.st src/main/paradox/_template/alt.st
$ sleep 1000
> paradox
$ must-mirror target/paradox/site/main/page.html expected/page4.html
2 changes: 1 addition & 1 deletion project/build.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
sbt.version=0.13.13
sbt.version=0.13.15
2 changes: 1 addition & 1 deletion project/plugins.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ addSbtPlugin("org.scalariform" % "sbt-scalariform" % "1.6.0")
addSbtPlugin("com.typesafe.tmp" % "sbt-header" % "1.5.0-JDK6-0.1")
addSbtPlugin("me.lessis" % "bintray-sbt" % "0.3.0")
addSbtPlugin("com.jsuereth" % "sbt-pgp" % "1.0.0")
addSbtPlugin("com.lightbend.paradox" % "sbt-paradox" % "0.2.7")
addSbtPlugin("com.lightbend.paradox" % "sbt-paradox" % "0.2.10")

libraryDependencies += "org.scala-sbt" % "scripted-plugin" % sbtVersion.value

Expand Down
2 changes: 1 addition & 1 deletion version.sbt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
version in ThisBuild := "0.2.10-SNAPSHOT"
version in ThisBuild := "0.2.11-SNAPSHOT"

0 comments on commit ab03fa8

Please sign in to comment.