From cd79df53f26fceb306f7281e91b79db957045b0c Mon Sep 17 00:00:00 2001 From: Justin Don Byrne Date: Wed, 11 Oct 2023 19:13:55 -0700 Subject: [PATCH] Refactored linker class --- README.md | 34 +++++++------ docs/CHANGELOG.md | 4 ++ source/app/config/config.txt | 6 +-- source/app/core/generator.py | 2 - source/app/core/linker.py | 94 +++++++++++++++++++----------------- 5 files changed, 76 insertions(+), 64 deletions(-) diff --git a/README.md b/README.md index a862fec..032b293 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ - + PlantUML class generator for JavaScript @@ -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 @@ -124,6 +124,12 @@ path=~/Programs/PlantUML ``` +Note: 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"` @@ -168,10 +174,10 @@ class ClassName @startuml class ClassName { -_prop0 {number} -_prop1 {string} -_prop2 {Object} -_prop3 {Object} +_prop0 {number} +_prop1 {string} +_prop2 {Object} +_prop3 {Object} __ Setter __ prop0 prop1 @@ -244,8 +250,8 @@ class One @startuml class One { -prop0 {number} -prop1 {string} +prop0 {number} +prop1 {string} prop2 {Two} prop3 {Three} __ Setter __ @@ -263,8 +269,8 @@ One *-- Three One *-- Two class Two { -prop0 {number} -prop1 {string} +prop0 {number} +prop1 {string} prop2 {One} prop3 {Three} __ Setter __ @@ -280,8 +286,8 @@ prop3 } class Three { -prop0 {number} -prop1 {string} +prop0 {number} +prop1 {string} prop2 {One} prop3 {Two} __ Setter __ diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 133df0e..adb5d85 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -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 diff --git a/source/app/config/config.txt b/source/app/config/config.txt index a53e592..11b1d28 100644 --- a/source/app/config/config.txt +++ b/source/app/config/config.txt @@ -1,7 +1,7 @@ #### FILE OMISSIONS -# one -# two -# three +# filename_one +# filename_two +# filename_three #### SKIN PARAM # left to right direction diff --git a/source/app/core/generator.py b/source/app/core/generator.py index 1198b8c..e4b1b1a 100644 --- a/source/app/core/generator.py +++ b/source/app/core/generator.py @@ -35,8 +35,6 @@ def __init__( self, arguments ): #### INITIALIZATION ########################## - # Util.view_arguments ( arguments ) - self.init ( ) #### INITIATORS ######################################################## diff --git a/source/app/core/linker.py b/source/app/core/linker.py index 04b28e6..993cb4c 100644 --- a/source/app/core/linker.py +++ b/source/app/core/linker.py @@ -10,13 +10,15 @@ def __init__( self, arguments ): #### GLOBALS ################################ + self.arguments = arguments + self.file = '' self.files = [ ] self.files_linked = { } - self.arguments = arguments + ######################################## self.classes = [ ] @@ -24,21 +26,30 @@ def __init__( self, arguments ): 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' ] ): @@ -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 ): @@ -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 ( ) @@ -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 ( ) @@ -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: @@ -123,9 +132,8 @@ def match_objects ( self ): self.classes.append ( source ) - def link_objects ( self ): - #### GLOBALS ################################ + def link_objects ( self ): links = [ ] @@ -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" )