:toc:
:icon_image_rel_path: images/3.png
:icon_name: byCode
:read_more: #sec-byCode

[[sec-byCode]]
== Use by Code

image::{icon_image_rel_path}[The Icon 3s Alternative Text,160,160,float="right"]

=== a2dl as Module
:variable_name: short_description

The script comes as a python module and thus can be used in own programmes. It consists of Module a2dl with classes Diagicon and Diaglibrary.

WARNING:: Please note, that the module uses a logger "a2dl".

=== Examples

A basic example.

----

import a2dl.a2dl

# Overwrite some constants
a2dl.a2dl.ICON_STYLE = "rounded=1;whiteSpace=wrap;html=1;"
a2dl.a2dl.IMAGE_STYLE = 'fillColor=none;rounded=1;shape=image;verticalLabelPosition=bottom;labelBackgroundColor=default;verticalAlign=top;aspect=fixed;imageAspect=0;image=data:image/{},{};'

a2dl.a2dl.logging.getLogger('a2dl').addHandler(a2dl.a2dl.logging.NullHandler())

# create icon
DI = a2dl.a2dl.Diagicon()
DI.from_adoc('./data/exampleDocument.adoc')
# write the icon to a Diagram file
DI.write_diagram('./data/test-generated-icon-from-exampleDocument.drawio')

# create a library
DL = a2dl.a2dl.Diaglibrary()
DL.from_folder('./data')
DL.write('./data/test-generated-library.xml')

#  update a diagram
DG = a2dl.a2dl.Diagdiagram()
DG.from_file('./data/exampleDiagramFromLibrary-old.drawio')
DG.update(libraries=[DL])

----

=== Static Configuration

Overwrite to your own liking

----

# The following string determines the file search pattern:
GLOB_STRING = '**/*.adoc'  # Search for all adoc files recursively

# Detecting relevant lines in files can be customized with the following strings:
ADOC_VARIABLE_IDENTIFIER = [["==", "===", "====", "====="],
                            ":variable_name:"]  # Extract content afer each identifier until the next occurrence of i in [0]
ADOC_ICON_IDENTIFIER = ":icon_image_rel_path:"
ADOC_ICON_TITLE_IDENTIFIER = ":icon_name:"
ADOC_ICON_MORE_IDENTIFIER = ":read_more:"
LINES2SKIP = ['[quote', 'image::']  # skips lines starting with

# Formatting of the Tooltip can be customized with the following strings:
HTML_TOOLTIP = '<h1 class="dio_tooltip" >%name%</h1>'  # The HTML for each section will get appended to this string
HTML_SECTION = '<h2 class="dio_tooltip" >{}</h2>%{}%'  # variable['title'], variable['name']
HTML_WARNING = '<b class="dio_tooltip" >{}</b>'

# "read more" will be the last line in the html tooltip
HTML_MORE_BASEURL = '{}'  # 'or: use a base ur like https://example.com/{}
                          #      if articles details page share the same base url'
HTML_MORE = '<br> <a href="{}" target="_more">Image generated with Stable Diffusion</a>'

# Icon styling
ICON_STYLE = "rounded=1;whiteSpace=wrap;html=1;"

# If sections include images as .png, these will be encoded and included. The image styling can be modified:
IMAGE_STYLE = 'fillColor=none;rounded=1;shape=image;verticalLabelPosition=bottom;labelBackgroundColor=default;verticalAlign=top;aspect=fixed;imageAspect=0;image=data:image/{},{};'  # The type and image data are set from the file

----