Skip to content

Commit

Permalink
Added the Classy C4 library.
Browse files Browse the repository at this point in the history
  • Loading branch information
james-gadrow-kr committed Apr 11, 2022
1 parent 06ae8d0 commit eb894e7
Show file tree
Hide file tree
Showing 16 changed files with 1,393 additions and 0 deletions.
39 changes: 39 additions & 0 deletions README.md
Expand Up @@ -123,6 +123,44 @@ Example of usage:
This example renders the following image:
![Example](http://www.plantuml.com/plantuml/png/SoWkIImgAStDuNBAJrBGjLDmpCbCJbMmKl18pSd9LmZFByf9KKINCyfBKSXDBIvEJ4zLKEHoICrB0He00000)

## Classy C4 library

The Classy C4 library combines the Classy and C4 libraries by defining Classy
classes that wrap the C4 macros.

Example of usage:
```
@startuml
!include <classy-c4/container>
!include <classy-c4/person>
!include <classy-c4/system>
!$system = $new(System)
$call($system, 'setName', 'Label', $void=%true())
$call($system, 'setDescription', 'Optional Description', $void=%true())
!$person = $new(Person)
$call($person, 'setName', 'Label', $void=%true())
$call($person, 'setDescription', 'Optional Description', $void=%true())
!$container = $new(Container)
$call($container, 'setName', 'Label', $void=%true())
$call($container, 'setDescription', 'Optional Description', $void=%true())
$call($container, 'setTechnology', 'Technology', $void=%true())
!$personAlias = $call($person, 'render')
!$containerAlias = $call($container, 'render')
$call($system, 'render', $void=%true())
Rel($personAlias, $containerAlias, "Label", "Optional Technology")
@enduml
```

This example renders the following image:
![Example](http://www.plantuml.com/plantuml/png/ZOvFIyGm4CNl-HIrfowupMLFdbQgjnKN_vnbcWxRm6GICXDalxtPWaKHnTDxCypxpTkBGjOIg1bsR_U40Ld5N7bsL2PiPjKaDzPcUEzFNkSo5i7i8YkozYu6cmZuaj-AJkH7E-osnylgzU5W0uXYjfKyr0HunjodUclC4RD4xj8Yj-H1hfls02DIMyrZKXyPgBb3STalKxinAwHpd-v7z0NTp97YwVm7wFaiYg6JHVxxtJmXVI-yjlWTyQNEnkoHfnBe0m00)

## Elastic library

The Elastic library consists of [Elastic](https://www.elastic.co) icons.
Expand Down Expand Up @@ -248,6 +286,7 @@ This example renders the following image:

* **aws**: made by https://github.com/milo-minderbinder/AWS-PlantUML
* **classy**: made by https://github.com/james-gadrow-kr/classy-plantuml
* **classy-c4**: made by https://github.com/james-gadrow-kr/classy-c4
* **tupadr3**: made by https://github.com/tupadr3/plantuml-icon-font-sprites
* **Material Icons**: from https://github.com/Templarian/MaterialDesign
* **Elastic Icons**: from https://github.com/Crashedmind/PlantUML-Elastic-icons
Expand Down
3 changes: 3 additions & 0 deletions classy-c4/INFO
@@ -0,0 +1,3 @@
VERSION=1.0.0
SOURCE=https://github.com/james-gadrow-kr/classy-c4

126 changes: 126 additions & 0 deletions classy-c4/bidirectional-component.puml
@@ -0,0 +1,126 @@
!include <classy/types/map>
!include <classy/types/ported-interface-consumer>
!include <classy/types/ported-interface-provider>
!include <classy-c4/component>

$class(BidirectionalComponent)
$classImplements(Component)
$classImplements(PortedInterfaceConsumer, 'consumer')
$classImplements(PortedInterfaceProvider, 'provider')

!function BidirectionalComponent($this)
!$parent = $getInstanceVar($this, 'parent')
Component($parent)

!$consumer = $getInstanceVar($this, 'consumer')
PortedInterfaceConsumer($consumer)

!$provider = $getInstanceVar($this, 'provider')
PortedInterfaceProvider($provider)

!$cbElementContent = $new('Callback')
!$cbOutside = $new('Callback')
!$cbPreElement = $new('Callback')

$call($cbElementContent, 'setContext', $this)
$call($cbOutside, 'setContext', $this)
$call($cbPreElement, 'setContext', $this)

$call($cbElementContent, 'setMethod', 'BidirectionalComponent__renderContent')
$call($cbOutside, 'setMethod', 'BidirectionalComponent__renderConsumed')
$call($cbPreElement, 'setMethod', 'BidirectionalComponent__renderProvided')

$call($this, 'setElementContentRendererCallback', $cbElementContent)
$call($this, 'setOutsideRendererCallback', $cbOutside)
$call($this, 'setPreElementRendererCallback', $cbPreElement)

!return $this
!endfunction

!procedure BidirectionalComponent__connectProvidedInterfaces($this)
!$interfaces = $call($this, 'getInterfaces')

!if '' != $interfaces
!$interface = $call($interfaces, 'each')
!$provider = $getInstanceVar($this, 'provider')
!$map = $call($provider, 'getMap')

!while %false() != $interface
!$port = $call($map, 'get', $interface)
!$portAlias = $call($port, 'render')
!$interfaceAlias = $call($interface, 'render')
$interfaceAlias -- $portAlias
!$interface = $call($interfaces, 'each')
!endwhile
!endif
!endprocedure

!procedure BidirectionalComponent__renderConsumed($this, $alias)
!$interfaces = $call($this, 'getConsumedInterfaces')

!if '' != $interfaces
!$interface = $call($interfaces, 'each')
!$consumer = $getInstanceVar($this, 'consumer')
!$map = $call($consumer, 'getMap')

!while %false() != $interface
!$port = $call($map, 'get', $interface)
!$portAlias = $call($port, 'render')
!$interfaceAlias = $call($interface, 'render')
$interfaceAlias )-- $portAlias
!$interface = $call($interfaces, 'each')
!endwhile
!endif
!endprocedure

!procedure BidirectionalComponent__renderContent($this, $alias)
!$provider = $getInstanceVar($this, 'provider')
!$ports = $call($provider, 'getPorts')
BidirectionalComponent__renderPorts($ports)

!$consumer = $getInstanceVar($this, 'consumer')
!$ports = $call($consumer, 'getPorts')
BidirectionalComponent__renderPorts($ports)

BidirectionalComponent__connectProvidedInterfaces($this)
!endprocedure

!procedure BidirectionalComponent__renderPorts($ports)
!if '' != $ports
!$port = $call($ports, 'each')

!while %false() != $port
$call($port, 'render', $void=%true())
!$port = $call($ports, 'each')
!endwhile
!endif
!endprocedure

!procedure BidirectionalComponent__renderProvided($this, $alias)
!$interfaces = $call($this, 'getInterfaces')

!if '' != $interfaces
!$interface = $call($interfaces, 'each')

!while %false() != $interface
$call($interface, 'render', $void=%true())
!$interface = $call($interfaces, 'each')
!endwhile
!endif
!endprocedure

$classMethod(getInPort)
!function BidirectionalComponent__getInPort($this, $args='')
!$provider = $getInstanceVar($this, 'provider')
!return $call($provider, 'getPort', $args)
!endfunction
$endclassMethod(getInPort)

$classMethod(getOutPort)
!function BidirectionalComponent__getOutPort($this, $args='')
!$consumer = $getInstanceVar($this, 'consumer')
!return $call($consumer, 'getPort', $args)
!endfunction
$endclassMethod(getOutPort)
$endclass(BidirectionalComponent)

0 comments on commit eb894e7

Please sign in to comment.