Skip to content

Commit

Permalink
shrink public API surface in laika.rewrite.*
Browse files Browse the repository at this point in the history
  • Loading branch information
jenshalm committed Jul 14, 2023
1 parent f2ffad0 commit d6bf9e8
Show file tree
Hide file tree
Showing 13 changed files with 36 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ object DefaultTemplatePath {

private val base: Path = Root / "default"

def forSuffix(suffix: String): Path = base.withSuffix(s"template.$suffix")
private[laika] def forSuffix(suffix: String): Path = base.withSuffix(s"template.$suffix")

def forHTML: Path = forSuffix("html")
def forEPUB: Path = forSuffix("epub.xhtml")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,9 @@ case class ReferenceResolver(config: Config) {

}

/** Companion for constructing ReferenceResolvers for a particular
* target Document.
/** Companion for constructing ReferenceResolvers for a particular target Document.
*/
object ReferenceResolver {
private[laika] object ReferenceResolver {

object CursorKeys {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import scala.annotation.tailrec
*
* @author Jens Halm
*/
case class DocumentTargets(document: Document, slugBuilder: String => String) {
private[link] class DocumentTargets(document: Document, slugBuilder: String => String) {

/** Generates symbol identifiers.
* Contains a predefined list of ten symbols to generate.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import laika.config.{ ConfigEncoder, DefaultKey, LaikaKeys }

/** Registers Icon AST elements for use with the `@:icon` directive and the `IconReference` AST element.
*/
case class IconRegistry(icons: Map[String, Icon])
case class IconRegistry private (icons: Map[String, Icon])

object IconRegistry {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ import scala.annotation.tailrec
*
* @author Jens Halm
*/
class LinkResolver(root: DocumentTreeRoot, slugBuilder: String => String)
private[laika] class LinkResolver(root: DocumentTreeRoot, slugBuilder: String => String)
extends RewriteRulesBuilder {

val targets = new TreeTargets(root, slugBuilder)
Expand Down
18 changes: 9 additions & 9 deletions core/shared/src/main/scala/laika/rewrite/link/Selector.scala
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import laika.ast.Path
* from both, the ids rendered in the final document
* and the ids used for display.
*/
sealed trait Selector {
private[link] sealed trait Selector {

/** Indicates whether this selector is applicable
* beyond the boundaries of a single document.
Expand All @@ -43,45 +43,45 @@ sealed trait Selector {

/** A selector that can be used for a sequence of targets.
*/
sealed trait SequenceSelector extends Selector {
private[link] sealed trait SequenceSelector extends Selector {
val global = false
val unique = false
}

/** A selector that can is a globally unique identifier.
*/
sealed trait UniqueSelector extends Selector {
private[link] sealed trait UniqueSelector extends Selector {
val global = true
val unique = true
def description: String
}

/** A selector for a rendered target in a document.
*/
case class TargetIdSelector(id: String) extends UniqueSelector {
private[link] case class TargetIdSelector(id: String) extends UniqueSelector {
val description = s"link target with id '$id'"
}

/** A selector for a definition for an internal or external link.
*/
case class LinkDefinitionSelector(id: String) extends UniqueSelector {
private[link] case class LinkDefinitionSelector(id: String) extends UniqueSelector {
val description = s"link definition with id '$id'"
}

/** A selector based on a path, optionally including a fragment component.
*/
case class PathSelector(path: Path) extends UniqueSelector {
private[link] case class PathSelector(path: Path) extends UniqueSelector {
val description = s"link target with path '$path'"
}

/** An anonymous selector (usually matched by position).
*/
case object AnonymousSelector extends SequenceSelector
private[link] case object AnonymousSelector extends SequenceSelector

/** An auto-number selector (usually matched by position).
*/
case object AutonumberSelector extends SequenceSelector
private[link] case object AutonumberSelector extends SequenceSelector

/** An auto-symbol selector (usually matched by position).
*/
case object AutosymbolSelector extends SequenceSelector
private[link] case object AutosymbolSelector extends SequenceSelector
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@ import laika.rewrite.nav.TargetFormats
/** Represents the source of a link, its document path
* and the actual inline span that is representing the link.
*/
case class LinkSource(span: Span, path: Path)
private[link] case class LinkSource(span: Span, path: Path)

/** Represents a resolver for a target that has its final identifier generated
* (if necessary) and can be used to resolve matching reference nodes.
*
* @param selector the selector to use to identify reference nodes matching this target
* @param precedence the precedence in comparison to other resolvers with the same selector
*/
abstract sealed class TargetResolver(
private[link] abstract sealed class TargetResolver(
val selector: Selector,
val targetFormats: TargetFormats = TargetFormats.All,
val precedence: Int = 0
Expand All @@ -53,7 +53,7 @@ abstract sealed class TargetResolver(

}

object ReferenceResolver {
private[link] object ReferenceResolver {
def lift(f: PartialFunction[LinkSource, Span]): LinkSource => Option[Span] = f.lift

def internalLink(target: Path): LinkSource => Option[Span] = lift {
Expand All @@ -78,14 +78,13 @@ object ReferenceResolver {

}

object TargetReplacer {
private[link] object TargetReplacer {
def lift(f: PartialFunction[Block, Block]): Block => Option[Block] = f.lift
def addId(id: String): Block => Option[Block] = block => Some(block.withId(id))
val removeId: Block => Option[Block] = block => Some(block.withoutId)
val removeTarget: Block => Option[Block] = Function.const(None)
}

object TargetResolver {
private[link] object TargetResolver {

def create(
selector: Selector,
Expand Down Expand Up @@ -201,7 +200,7 @@ object TargetResolver {
/** Represents a resolver for a sequence of targets where matching reference nodes get determined by position.
* The `resolveReference` and `resolveTarget` methods can be invoked as many times as this sequence contains elements.
*/
case class TargetSequenceResolver(targets: Seq[TargetResolver], sel: Selector)
private[link] case class TargetSequenceResolver(targets: Seq[TargetResolver], sel: Selector)
extends TargetResolver(sel) {
private val refIt = targets.iterator
private val targetIt = targets.iterator
Expand All @@ -216,7 +215,7 @@ case class TargetSequenceResolver(targets: Seq[TargetResolver], sel: Selector)

}

case class LinkAliasResolver(
private[link] case class LinkAliasResolver(
sourceSelector: TargetIdSelector,
targetSelector: TargetIdSelector,
referenceResolver: LinkSource => Option[Span],
Expand All @@ -241,7 +240,7 @@ case class LinkAliasResolver(

}

object LinkAliasResolver {
private[link] object LinkAliasResolver {

def unresolved(
sourceSelector: TargetIdSelector,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import laika.ast.{ DocumentTreeRoot, Path, StaticDocument }
*
* @author Jens Halm
*/
class TreeTargets(root: DocumentTreeRoot, slugBuilder: String => String) {
private[link] class TreeTargets(root: DocumentTreeRoot, slugBuilder: String => String) {

private val targetMap: Map[(Path, Selector), TargetResolver] = {

Expand All @@ -42,7 +42,7 @@ class TreeTargets(root: DocumentTreeRoot, slugBuilder: String => String) {
} yield ((path, target.selector), target)

val targets = root.allDocuments.flatMap { doc =>
val targets = DocumentTargets(doc, slugBuilder).targets
val targets = new DocumentTargets(doc, slugBuilder).targets
val global =
if (doc.path == Root) Nil
else mapToKeys(allPaths(doc.path.parent), targets.filter(_.selector.global))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,9 @@ case class AutonumberConfig(
maxDepth: Int = Int.MaxValue
)

case class ConfigurationException(msg: String) extends RuntimeException(msg)
private[nav] sealed trait Scope

sealed trait Scope

object Scope {
private[nav] object Scope {
case object Documents extends Scope
case object Sections extends Scope
case object All extends Scope
Expand Down
4 changes: 2 additions & 2 deletions core/shared/src/main/scala/laika/rewrite/nav/CoverImage.scala
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ object CoverImage {

}

case class CoverImages(default: Option[Path], classified: Map[String, Path]) {
private[laika] case class CoverImages(default: Option[Path], classified: Map[String, Path]) {

def getImageFor(classifier: String): Option[Path] = classified.get(classifier).orElse(default)

Expand All @@ -63,7 +63,7 @@ case class CoverImages(default: Option[Path], classified: Map[String, Path]) {

}

object CoverImages {
private[laika] object CoverImages {

def forPDF(config: Config): ConfigResult[CoverImages] =
extract(config, LaikaKeys.root.child("pdf"), LaikaKeys.root)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,13 @@ import laika.config.{ Config, LaikaKeys }
import laika.ast._
import laika.config.Config.ConfigResult

/** Responsible for applying the navigation order to the
* contents of a document tree, either based on user-specified
* configuration or by the alphabetical order of the names of
* the documents and subtrees.
/** Responsible for applying the navigation order to the contents of a document tree,
* either based on user-specified configuration
* or by the alphabetical order of the names of the documents and subtrees.
*
* @author Jens Halm
* @author Jens Halm
*/
object NavigationOrder {
private[laika] object NavigationOrder {

def applyTo(
content: Seq[Cursor],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import scala.collection.mutable.ListBuffer
*
* @author Jens Halm
*/
object SectionBuilder extends RewriteRulesBuilder {
private[laika] object SectionBuilder extends RewriteRulesBuilder {

private class DefaultRule(
autonumberConfig: AutonumberConfig,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import laika.config.{ Config, LaikaKeys }
*
* @author Jens Halm
*/
object TitleDocumentConfig {
private[laika] object TitleDocumentConfig {

val defaultInputName: String = "README"
val defaultOutputName: String = "index"
Expand Down

0 comments on commit d6bf9e8

Please sign in to comment.