Skip to content

Commit

Permalink
Refactored linker class
Browse files Browse the repository at this point in the history
  • Loading branch information
Justin-Byrne committed Oct 12, 2023
1 parent 6154c3e commit cd79df5
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 64 deletions.
34 changes: 20 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<img src=https://img.shields.io/badge/Python-3.11.2-blue />
<img src=https://img.shields.io/badge/PlantUML-1.2.023.4-purple />
<img src=https://img.shields.io/badge/Graphviz-8.0.5-gray />
<img src=https://img.shields.io/badge/Version-0.8.8-green />
<img src=https://img.shields.io/badge/Version-0.8.9-green />
<img src=https://img.shields.io/github/languages/code-size/Justin-Byrne/ClassGenerator />

PlantUML class generator for JavaScript
Expand Down Expand Up @@ -93,9 +93,9 @@ Configurations settings for each generated file can be set within `../app/config
```bash
#### FILE OMISSIONS
one
two
three
filename_one
filename_two
filename_three

#### SKIN PARAM
left to right direction
Expand Down Expand Up @@ -124,6 +124,12 @@ path=~/Programs/PlantUML

```

<b>Note:</b> for best results use the following skin-params:
```bash
skinparam DefaultFontSize 16
skinparam DefaultFontName Courier New
```

## Examples

> `python3 BuildClass.py ~/Programs/JavaScript/Classes/class.js -m "png"`
Expand Down Expand Up @@ -168,10 +174,10 @@ class ClassName
@startuml

class ClassName {
_prop0 <color:gray>{number}</color>
_prop1 <color:gray>{string}</color>
_prop2 <color:gray>{Object}</color>
_prop3 <color:gray>{Object}</color>
_prop0 {number}
_prop1 {string}
_prop2 {Object}
_prop3 {Object}
__ Setter __
prop0
prop1
Expand Down Expand Up @@ -244,8 +250,8 @@ class One
@startuml

class One {
prop0 <co..ay>{number}</co.or>
prop1 <co..ay>{string}</co.or>
prop0 {number}
prop1 {string}
prop2 {Two}
prop3 {Three}
__ Setter __
Expand All @@ -263,8 +269,8 @@ One *-- Three
One *-- Two

class Two {
prop0 <co..ay>{number}</co.or>
prop1 <co..ay>{string}</co.or>
prop0 {number}
prop1 {string}
prop2 {One}
prop3 {Three}
__ Setter __
Expand All @@ -280,8 +286,8 @@ prop3
}

class Three {
prop0 <co..ay>{number}</co.or>
prop1 <co..ay>{string}</co.or>
prop0 {number}
prop1 {string}
prop2 {One}
prop3 {Two}
__ Setter __
Expand Down
4 changes: 4 additions & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# Changelog
All notable changes to this project will be documented in this file.

## [0.8.9] - 2023-10-11
### Changed
- Refactored and cleaned `linker` class

## [0.8.8] - 2023-10-11
### Changed
- Refactored and cleaned entire `generator` class
Expand Down
6 changes: 3 additions & 3 deletions source/app/config/config.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#### FILE OMISSIONS
# one
# two
# three
# filename_one
# filename_two
# filename_three

#### SKIN PARAM
# left to right direction
Expand Down
2 changes: 0 additions & 2 deletions source/app/core/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@ def __init__( self, arguments ):

#### INITIALIZATION ##########################

# Util.view_arguments ( arguments )

self.init ( )

#### INITIATORS ########################################################
Expand Down
94 changes: 49 additions & 45 deletions source/app/core/linker.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,35 +10,46 @@ def __init__( self, arguments ):

#### GLOBALS ################################

self.arguments = arguments

self.file = ''

self.files = [ ]

self.files_linked = { }

self.arguments = arguments
########################################

self.classes = [ ]

self.objects = [ ]

self.regexes = [ ]

#### INITIALIZE ################################
#### INITIALIZATION ##########################

self.init ( )

#### INITIATORS ########################################
#### INITIATORS ########################################################

def init ( self ):
def init ( self ):

self.get_files ( )

self.process ( )

#### GETTERS ########################################

def get_files ( self ):
def process ( self ):

for file in self.files:

self.read_file ( file )

self.match_files ( )

#### GETTERS ########################################################

def get_files ( self ):

for ( root, dirs, file ) in os.walk ( self.arguments [ 'destination' ] ):

Expand All @@ -50,13 +61,7 @@ def get_files ( self ):

self.files.append ( f"{root}/{entry}" )

def process ( self ):

for file in self.files:

self.read_file ( file )

self.match_files ( )
#### UTILITIES ########################################################

def read_file ( self, file ):

Expand All @@ -66,6 +71,7 @@ def read_file ( self, file ):

self.objects = set ( re.findall ( r'(\w+)\s{2,}\{([^\}]+)\}', data ) )


def match_files ( self ):

self.find_files ( )
Expand All @@ -74,19 +80,21 @@ def match_files ( self ):

self.link_objects ( )


def find_files ( self ):

self.regexes = [ ]
self.regexes = [ ] # clear self.regexes


if self.objects:

for object in self.objects:

regex = ''
regex = ''

object = object [ 1 ]


object_lo, object_up = object.lower ( ), object.upper ( )


Expand All @@ -100,9 +108,10 @@ def find_files ( self ):

self.regexes.append ( regex )


def match_objects ( self ):

self.classes = [ ]
self.classes = [ ] # clear self.classes


if self.files:
Expand All @@ -123,9 +132,8 @@ def match_objects ( self ):

self.classes.append ( source )

def link_objects ( self ):

#### GLOBALS ################################
def link_objects ( self ):

links = [ ]

Expand All @@ -135,62 +143,58 @@ def link_objects ( self ):

header = re.findall ( r'class\s*([^\s]+)\s*', data ) [ 0 ]

#### FUNCTIONS ################################

def assemble_links ( data ):

for object in self.objects:
for object in self.objects:

links.append ( f"{header} *-- {object [ 1 ]}" )
links.append ( f"{header} *-- {object [ 1 ]}" )


links.append ( '@enduml\n' )
links.append ( '@enduml\n' )

data = data.replace ( '@enduml', '\n'.join ( links ) )
data = data.replace ( '@enduml', '\n'.join ( links ) )


for entry in self.classes:
for entry in self.classes:

CLASS_UML = open ( entry, 'r' ).read ( )
CLASS_UML = open ( entry, 'r' ).read ( )

data += f'\n{CLASS_UML}\n'
data += f'\n{CLASS_UML}\n'


data = re.sub ( r'@enduml\s*@startuml', '', data )
data = re.sub ( r'@enduml\s*@startuml', '', data )


with open ( file, 'w' ) as writer:
with open ( file, 'w' ) as writer:

writer.write ( data )
writer.write ( data )


print ( '>> [ output ]\n', file )
print ( '>> [ output ]\n', file )

def compose_image ( file ):

if 'plant_path' in self.arguments.keys ( ):
self.compose_image ( file )

for image_type in self.arguments [ 'make_image' ]:
#### RENDERERS ########################################################

output_path = f"{os.path.dirname ( file )}/images"
def compose_image ( self, file ):

command = f"java -jar {self.arguments [ 'plant_path' ]} \"{file}\" -o \"{output_path}\" -{image_type}"
if 'plant_path' in self.arguments.keys ( ):

filename = os.path.basename ( file ).replace ( 'txt', image_type )
for image_type in self.arguments [ 'make_image' ]:

output_path = f"{os.path.dirname ( file )}/images"

if Util.is_directory ( output_path ) is False:
command = f"java -jar {self.arguments [ 'plant_path' ]} \"{file}\" -o \"{output_path}\" -{image_type}"

os.makedirs ( output_path )
filename = os.path.basename ( file ).replace ( 'txt', image_type )


subprocess.run ( command, shell=True )
if Util.is_directory ( output_path ) is False:

os.makedirs ( output_path )

print ( f" {output_path}/{filename}\n" )

#### LOGIC ################################
subprocess.run ( command, shell=True )

assemble_links ( data )

compose_image ( file )
print ( f" {output_path}/{filename}\n" )

0 comments on commit cd79df5

Please sign in to comment.