Skip to content

Latest commit

 

History

History
278 lines (170 loc) · 7.12 KB

dbpp.kroki.krokiencoder.md

File metadata and controls

278 lines (170 loc) · 7.12 KB

dbpp.widgets package: GuiBaseClass - AutoScrollbar - Balloon - Ctext - LabEntry - RoText - Scrolled - SqlText - StatusBar - TableView - TextMixins - XTableView - XTreeView

dbpp.kroki - dbpp.kroki.KrokiEncoder - dbpp.utils - dbpp.utils.SqlUtils -

apps: dbpp.peditor

module kroki.krokiencoder

dbpp.kroki.KrokiEncoder - class to encode diagram code as krokio.io URL's and to decode them back to text.

This class provides methods to convert diagram code for tools like PlantUML, GraphViz or Ditaa to base64 encoded URL's ready to display them as web images using the https://kroki.io and ready to edit them online using the Niolesk web editor.

Examples:

from dbpp.kroki.KrokiEncoder import KrokiEncoder
kroki = KrokiEncoder()
kroki.text2kroki("A --> B")
kroki.text2kroki("class A { }",dia='plantuml',ext='svg')  
kroki.dia2kroki('input.pml',dia='plantuml',ext='png')

Classes:

@startuml
class A
class B

A ->  B
@enduml
     >>> x = 1
     >>> x + 1
     2
     >>> from dbpp.kroki.KrokiEncoder import KrokiEncoder
     >>> kroki = KrokiEncoder()
     >>> kroki.text2kroki("class A { }",dia='plantuml',ext='svg')  
     'https://kroki.io/plantuml/svg/eNpLzkksLlZwVKhWqAUAF10DsA=='

DOCUMENTATION


function usage

usage(args)

Usage information for the KrokiEncoder as a standalone application."

Args:

  • args (list): argument list in order: appname, filename, dia, ext

function main

main(args)

Starting the KrokiEncoder as standalone application using command line options. Can be directly called programatically like this:

Args:

  • args (list): argument list in order: appname, filename, dia, ext
import KrokiEncoder
KrokiEncoder.main([None,'diagram.pml','plantuml','png'])

Here an example for converting a PlantUML file into a PNG image using the command line application interface:

$ KrokiEncoder.py diagram.pml plantuml png

Thereafter the file diagram.png should be in parallel to the file diagram.pml.

here a file diagram.pml with the following content and below the output:

@startuml
class A {
    var1
    method1()
}
class B {
    var2
    method2()
}
A -> B
@enduml

class KrokiEncoder

Class to encode and decode diagram code using the https://kroki.io web service.

Here the methods of the class:

@startuml
class KrokiEncoder { 
     dia2file()
     dia2kroki()
     kroki2dia()
     text2kroki()
}
@enduml

method dia2file

dia2file(diafile, dia='ditaa', ext='png', imagefile='')

Converts a diagram file to an image file.

Args:

  • diafile (string): a diagram file, for instance with the pml extension for PlantUML code, defaults to None
  • dia (string): diagram type, either 'ditaa', 'plantuml', 'erd' or 'graphviz', defaults to 'ditaa'
  • ext (string): file extension, either 'png', 'svg' or 'pdf', not all extensions are supported for all diagram types, defaults to 'png'
  • imagefile (string): a output filename for the image file, if not given the diagram imagefile will have the basename of the diagram file nut with the image extension.

Returns: None


method dia2kroki

dia2kroki(filename, dia='ditaa', ext='png')

Converts a diagram file to a Kroki URL

Args:

  • filename (string): a diagram file, for instance with the pml extension for PlantUML code, defaults to None
  • dia (string): diagram type, either 'ditaa', 'plantuml', 'erd' or 'graphviz', defaults to 'ditaa'
  • ext (string): file extension, either 'png', 'svg' or 'pdf', not all extensions are supported for all diagram types, defaults to 'png'

Returns: Kroki-URL (string)


method kroki2dia

kroki2dia(url)

Converts a Kroki URL back to diagram code.

Args:

Returns: diagram code (string)

Examples:

import sys, os
sys.path.append(os.path.join(os.getcwd(),".."))
from KrokiEncoder import KrokiEncoder
kroki=KrokiEncoder()
text=kroki.kroki2dia('https://kroki.io/plantuml/svg/eNpLzkksLlZwVKhWqOXiSgZznCAcRwVdLQUnAJ-uCKI=')
print(text)

method text2kroki

text2kroki(text, dia='ditaa', ext='png')

Converts a given diagram text to a Kroki URL.

Args:

  • text (string): diagram text as string, for instance PlantUML code, defaults to None
  • dia (string): diagram type, either 'ditaa', 'plantuml', 'erd' or 'graphviz', defaults to 'ditaa'
  • ext (string): file extension, either 'png', 'svg' or 'pdf', not all extensions are supported for all diagram types, defaults to 'png'

Returns: Kroki-URL (string)


This file was automatically generated via lazydocs.