stanch / reftree

Automatically generated diagrams and animations for Scala data structures
http://stanch.github.io/reftree/
GNU General Public License v3.0
587 stars 36 forks source link

Minimal example is not complete #18

Closed wsargent closed 1 month ago

wsargent commented 6 years ago

In https://stanch.github.io/reftree/#minimal-example the example uses ImagePath but does not define it.

It would be easier if a URL was provided:

import java.nio.file.Paths

import reftree.diagram.Diagram
import reftree.render.{Renderer, RenderingOptions}

object Main {
  def main(args: Array[String]): Unit = {
    val imagePath = Paths.get("images") // current relative path + "images"
    val renderer = Renderer(
      renderingOptions = RenderingOptions(density = 75),
      directory = imagePath.resolve("overview")
    )

    import renderer._

    case class Person(firstName: String, age: Int)

    Diagram.sourceCodeCaption(Person("Bob", 42)).render("example")
    val file = directory.resolve("example.png")

    println(s"Open with Browser ${file.toUri}")
    println(s"Open with IntelliJ IDEA http://localhost:63342/api/file/${file.toString}")
  }
}
stanch commented 6 years ago

Note that the code in the snippet is executed automatically by tut when the site is built. Therefore the snippet needs to generate the image in a predictable location, so that I can include the image on the site. If you take a look at the source, ImagePath is defined as "site/target/tut/images". My thought was that exposing that path to the reader of the site would be confusing. Therefore it’s defined in an invisible code block.

Now, regarding your suggestion, I am not sure I understand it. Could you elaborate on what you see as the end goal? My vision is that the user copies the code in the snippet, defines their desired file location and after running the code is able to find the resulting file there, as expected. But it seems that your scenario is different. What does the port 63342 stand for? And why do you prefer to open an image with a browser or IDEA, instead of an image viewer?

wsargent commented 6 years ago

No, I think it totally makes sense to show the path and where it's going. I'm not sure why a render returns Unit instead of a RenderResult, to be honest.

So port 63342 is a REST API that IntelliJ exposes that loops back to IDEA. http://develar.org/idea-rest-api/#api-Platform-file

It's useful because IDEA has a built in image viewer so I can see code and can open the image by clicking on it. You hit run in IDEA, it shows the URL already hyperlinked, and then opens the image.