Skip to content

Commit

Permalink
Merge f71004d into 0ebbb2f
Browse files Browse the repository at this point in the history
  • Loading branch information
reid-spencer committed Oct 22, 2023
2 parents 0ebbb2f + f71004d commit 841b39b
Show file tree
Hide file tree
Showing 45 changed files with 1,092 additions and 743 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ trait TranslatingState[OF <: OutputFile] {
path.resolve(nm)
}

def close: Seq[Path] = {
def writeFiles: Seq[Path] = {
files.foreach(_.write())
files.map(_.filePath).toSeq
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ package com.reactific.riddl.diagrams.mermaid

import com.reactific.riddl.language.AST.*
import com.reactific.riddl.passes.PassesResult
import com.reactific.riddl.passes.resolve.ReferenceMap

class EntityRelationshipDiagram(passesResult: PassesResult ) {
class EntityRelationshipDiagram(refMap: ReferenceMap ) {

private def makeTypeName(
pid: PathIdentifier,
Expand All @@ -12,7 +13,7 @@ class EntityRelationshipDiagram(passesResult: PassesResult ) {
parents.headOption match
case None => s"unresolved path: ${pid.format}"
case Some(parent) =>
passesResult.refMap.definitionOf[Definition](pid, parent) match {
refMap.definitionOf[Definition](pid, parent) match {
case None => s"unresolved path: ${pid.format}"
case Some(defn: Definition) => defn.id.format
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ trait SequenceDiagramSupport {
def getDefinitionFor[T <: Definition: ClassTag](pathId: PathIdentifier, parent: Definition): Option[T] = {
passesResult.refMap.definitionOf[T](pathId, parent)
}
def makeLinkFor(definition: Definition): String
def makeDocLink(definition: Definition): String
}

/** A class to generate the sequence diagrams for an Epic
Expand Down Expand Up @@ -93,7 +93,7 @@ case class SequenceDiagram(sds: SequenceDiagramSupport, useCase: UseCase) extend
}
parts.foreach { (part: Definition) =>
val name = part.id.value
val link = sds.makeLinkFor(part)
val link = sds.makeDocLink(part)
part match
case _: User => sb.append(s"${ndnt()}link $name: User @ $link")
case i: Input => sb.append(s"${ndnt()}link $name: ${i.alias} @ $link")
Expand Down
74 changes: 74 additions & 0 deletions hugo/src/main/scala/com/reactific/riddl/hugo/GlossaryPass.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
package com.reactific.riddl.hugo
import com.reactific.riddl.language.AST.*
import com.reactific.riddl.language.Messages
import com.reactific.riddl.passes.{CollectingPass, CollectingPassOutput, PassInput, PassesOutput, PassesResult}

import java.nio.file.Path
import scala.collection.mutable

case class GlossaryEntry(
term: String,
kind: String,
brief: String,
path: Seq[String],
link: String = "",
sourceLink: String = ""
)

case class GlossaryOutput(
messages: Messages.Messages,
entries: Seq[GlossaryEntry]
) extends CollectingPassOutput[GlossaryEntry]

case class GlossaryPass(
input: PassInput,
outputs: PassesOutput,
options: HugoCommand.Options
) extends CollectingPass[GlossaryEntry](input, outputs)
with PassUtilities {

// Members declared in com.reactific.riddl.passes.CollectingPass
protected def collect(
definition: Definition,
parents: mutable.Stack[Definition]
): Option[GlossaryEntry] = {
definition match {
case _: OnMessageClause | _: OnOtherClause | _: OnInitClause | _: OnTerminationClause | _: RootContainer |
_: Include[Definition] @unchecked =>
// None of these kinds of definitions contribute to the glossary
None
case d: Definition =>
// everything else does
val stack = parents.toSeq
Some(makeGlossaryEntry(definition, stack))
}
}

def makeGlossaryEntry(
d: Definition,
stack: Seq[Definition]
): GlossaryEntry = {
val parents = makeStringParents(stack)
val entry = GlossaryEntry(
d.id.value,
d.kind,
d.brief.map(_.s).getOrElse("-- undefined --"),
parents :+ d.id.value,
makeDocLink(d, parents),
makeSourceLink(d)
)
entry
}

def result: GlossaryOutput = {
GlossaryOutput(messages.toMessages, collectedValues)
}

// Members declared in com.reactific.riddl.passes.Pass
def name: String = GlossaryPass.name
def postProcess(root: com.reactific.riddl.language.AST.RootContainer): Unit = ()
}

object GlossaryPass {
val name: String = "Glossary"
}
32 changes: 24 additions & 8 deletions hugo/src/main/scala/com/reactific/riddl/hugo/HugoCommand.scala
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import com.reactific.riddl.language.CommonOptions
import com.reactific.riddl.language.Messages
import com.reactific.riddl.language.Messages.Messages
import com.reactific.riddl.passes.Pass.{PassesCreator, standardPasses}
import com.reactific.riddl.passes.{PassInput, PassesOutput, PassesResult}
import com.reactific.riddl.passes.{Pass, PassInput, PassesOutput, PassesResult}
import com.reactific.riddl.utils.Logger
import com.reactific.riddl.stats.StatsPass
import pureconfig.ConfigCursor
Expand Down Expand Up @@ -43,7 +43,8 @@ object HugoCommand {
withGlossary: Boolean = true,
withTODOList: Boolean = true,
withGraphicalTOC: Boolean = false,
withStatistics: Boolean = true
withStatistics: Boolean = true,
withMessageSummary: Boolean = true
) extends CommandOptions
with TranslatingOptions {
def command: String = "hugo"
Expand All @@ -60,16 +61,31 @@ object HugoCommand {
}

def getPasses(
log: Logger,
commonOptions: CommonOptions,
options: Options
): PassesCreator = {
standardPasses ++ Seq(
{ (input: PassInput, outputs: PassesOutput) => StatsPass(input, outputs) },
val glossary: PassesCreator =
if options.withGlossary then
Seq({ (input: PassInput, outputs: PassesOutput) => GlossaryPass(input, outputs, options) })
else Seq.empty

val messages: PassesCreator =
if options.withMessageSummary then
Seq({ (input: PassInput, outputs: PassesOutput) => MessagesPass(input, outputs, options) })
else Seq.empty

val stats: PassesCreator =
if options.withStatistics then Seq({ (input: PassInput, outputs: PassesOutput) => StatsPass(input, outputs) })
else Seq.empty

val toDo: PassesCreator =
if options.withTODOList then Seq({ (input: PassInput, outputs: PassesOutput) => ToDoListPass(input, outputs, options)})
else Seq.empty

standardPasses ++ glossary ++ messages ++ stats ++ toDo ++ Seq(
{ (input: PassInput, outputs: PassesOutput) =>
val result = PassesResult(input, outputs, Messages.empty)
val state = HugoTranslatorState(result, options, commonOptions, log)
HugoPass(input, outputs, state)
HugoPass(input, outputs, options)
}
)
}
Expand Down Expand Up @@ -268,7 +284,7 @@ class HugoCommand extends PassCommand[HugoCommand.Options]("hugo") {
commonOptions: CommonOptions,
options: Options
): PassesCreator = {
HugoCommand.getPasses(log, commonOptions, options)
HugoCommand.getPasses(commonOptions, options)
}

override def replaceInputFile(
Expand Down
Loading

0 comments on commit 841b39b

Please sign in to comment.