All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.ossuminc.riddl.hugo.MessagesPass.scala Maven / Gradle / Ivy

package com.ossuminc.riddl.hugo

import com.ossuminc.riddl.hugo.themes.ThemeGenerator
import com.ossuminc.riddl.language.Messages
import com.ossuminc.riddl.language.AST.*
import com.ossuminc.riddl.passes.resolve.ResolutionPass
import com.ossuminc.riddl.passes.symbols.SymbolsPass
import com.ossuminc.riddl.passes.{CollectingPass, CollectingPassOutput, PassCreator, PassInfo, PassInput, PassesOutput}

import scala.collection.mutable

/** Information about message types collected by the MessagesPass
  *
  * @param message
  *   The type of the message - shows the fields of the message, with their brief descriptions if any
  * @param link
  *   The documentation link to the message type
  * @param users
  *   shows the places from which this message is used with full path identification, and each path component is a link
  *   to the documentation for that definition.
  * @param description
  *   Brief description of the message
  */
case class MessageInfo(
  kind: String,
  message: String,
  link: String,
  users: String,
  description: String
)

case class MessageOutput(
  root: Root, 
  messages: Messages.Messages,
  collected: Seq[MessageInfo]
) extends CollectingPassOutput[MessageInfo]

// This is a request to create a new section in the hugo translator's output that organizes information focusing on
// message types, how they are used, where they are defined, and where in the hierarchy they exist.
// Message types are the four DDD types: command, event, query, and result. The documentation for every leaf subdomain
// should have four pages added, one for each kind of message type. Those pages should list all the messages of their
// type that are USED by the subdomain (all contexts) but none that are merely accessible by the subdomain. Ideally,
// that wouldn't happen, but in practice, it will.
//
// Each page contains a list of relevant messages. Each row in that list starts with the name of the message and then
// a set of tabs:
//

case class MessagesPass(input: PassInput, outputs: PassesOutput, options: HugoPass.Options)
    extends CollectingPass[MessageInfo](input, outputs) {

  requires(SymbolsPass)
  requires(ResolutionPass)

  private val usages = outputs.usage

  private val generator = ThemeGenerator(options, input, outputs, messages)

  def name: String = MessagesPass.name

  protected def collect(definition: RiddlValue, parents: ParentStack): Seq[MessageInfo] = {
    definition match {
      case t: Type =>
        val result = t.typEx match {
          case _: AggregateUseCaseTypeExpression =>
            val pars = generator.makeStringParents(parents.toParents)
            val link = generator.makeDocLink(t, pars)
            val users = usages.getUsers(t)
            val userLinks = users
              .map { definition =>
                s"[${definition.id.value}](${generator.makeDocLink(definition, pars)})"
              }
              .mkString(" 
") val description: String = t.descriptives.filter[BriefDescription].map(_.brief.s).mkString("\n") val mi = MessageInfo(t.kind, t.id.value, link, userLinks, description) Seq(mi) case _ => Seq.empty[MessageInfo] } result case _ => Seq.empty[MessageInfo] } } override def result(root: Root): MessageOutput = { val sortedList = collectedValues.sortBy(_.message).toSeq MessageOutput(root, messages.toMessages, sortedList) } } object MessagesPass extends PassInfo[HugoPass.Options] { val name: String = "Messages" def creator(options: HugoPass.Options): PassCreator = { (in: PassInput, out: PassesOutput) => MessagesPass(in, out, options) } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy