Skip to content

Commit

Permalink
Merge pull request #45 from dwijnand/win-dows
Browse files Browse the repository at this point in the history
Workarounds for Windows FSs. Fixes #42
  • Loading branch information
eed3si9n authored Oct 26, 2016
2 parents 63775ff + 80a3d7a commit c7b716a
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 6 deletions.
19 changes: 19 additions & 0 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
os: Windows Server 2012
init:
- git config --global core.autocrlf input
install:
- ps: |
Add-Type -AssemblyName System.IO.Compression.FileSystem
if (!(Test-Path -Path "C:\sbt" )) {
(new-object System.Net.WebClient).DownloadFile(
'https://dl.bintray.com/sbt/native-packages/sbt/0.13.12/sbt-0.13.12.zip',
'C:\sbt-bin.zip'
)
[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
build_script:
- sbt clean compile
test_script:
- sbt test
33 changes: 28 additions & 5 deletions core/src/main/scala/com/lightbend/paradox/markdown/Page.scala
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@
package com.lightbend.paradox.markdown

import com.lightbend.paradox.tree.Tree.{ Forest, Location }
import com.lightbend.paradox.template.{ PageTemplate }
import com.lightbend.paradox.template.PageTemplate
import java.io.File
import java.net.URI
import java.nio.file.{ Path, Paths }
import org.pegdown.ast.{ Node, RootNode, SpecialTextNode, TextNode }
import scala.annotation.tailrec

Expand Down Expand Up @@ -182,20 +183,42 @@ object Path {
path.split('/').reverse.head
}

/**
* Normalize the path to Unix style root path. Removes drive letter and appends the "/" symbol.
* Also converts backslashes to slashes.
*/
def toUnixStyleRootPath(pathString: String): String = toUnixStyleRootPath(Paths.get(pathString))

/**
* Normalize the path to Unix style root path. Removes drive letter and appends the "/" symbol.
* Also converts backslashes to slashes.
*/
def toUnixStyleRootPath(path: Path): String = {
val fullPathWithDriveLetter = path.toAbsolutePath

val fullPathString =
if (fullPathWithDriveLetter.getRoot ne null)
File.separator + fullPathWithDriveLetter.getRoot.relativize(fullPathWithDriveLetter).toString
else
fullPathWithDriveLetter.toString

fullPathString.replace('\\', '/')
}

/**
* Provide the relative root path from a local path related to a full path
*/
def relativeRootPath(file: File, localPath: String): String = {
val fullPath = file.getAbsolutePath
if (fullPath.endsWith(localPath)) fullPath.dropRight(localPath.length) else fullPath
val pathString = toUnixStyleRootPath(file.toPath)
if (pathString.endsWith(localPath)) pathString.dropRight(localPath.length) else pathString
}

/**
* Provide the local path given the root path and the full path
*/
def relativeLocalPath(rootPath: String, fullPath: String): String = {
val root = new URI(rootPath)
val full = new URI(fullPath)
val root = new URI(toUnixStyleRootPath(rootPath))
val full = new URI(toUnixStyleRootPath(fullPath))
root.relativize(full).toString
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ object Snippet {
}

private def extract(file: File, blockStart: (String) => Boolean, blockEnd: (String) => Boolean, addLine: (String, Seq[String]) => Seq[String]): ExtractionState = {
val lines = Source.fromFile(file).getLines.toSeq
val lines = Source.fromFile(file)("UTF-8").getLines.toSeq
lines.foldLeft(ExtractionState(inBlock = false, snippetLines = Seq.empty)) {
case (es, l) =>
es.inBlock match {
Expand Down

0 comments on commit c7b716a

Please sign in to comment.