Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding additional UML options #853

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 18 additions & 4 deletions pyang/plugins/uml.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,14 @@ def add_opts(self, optparser):
optparse.make_option("--uml-filter-file",
dest="uml_filter_file",
help="NOT IMPLEMENTED: Only paths in the filter file will be included in the diagram"),
optparse.make_option("--uml-leafref-color",
dest="uml_leafref_color",
default = "",
help="sets the color of leafref links\nExample --uml-leafref-color='[#red]'"),
optparse.make_option("--uml-skinparams",
dest="uml_skinparams",
default = "",
help="Adds general UML skinparams. The values \nExample --uml-skinparams=ArrowColor:blue,FileFontColor:red"),
]
if hasattr(optparser, 'uml_opts'):
g = optparser.uml_opts
Expand Down Expand Up @@ -150,6 +158,7 @@ class uml_emitter:
ctx_truncate_augments = False
ctx_inline_augments = False
ctx_no_module = False
ctx_leafref_color = ''

ctx_filterfile = False
ctx_usefilterfile = None
Expand Down Expand Up @@ -211,6 +220,10 @@ def __init__(self, ctx):
self.ctx_truncate_augments = "augment" in ctx.opts.uml_truncate.split(",")
self.ctx_truncate_leafrefs = "leafref" in ctx.opts.uml_truncate.split(",")
self.ctx_no_module = "module" in no
self.ctx_leafref_color = ctx.opts.uml_leafref_color
self.ctx_skinparams = {}
if ctx.opts.uml_skinparams:
self.ctx_skinparams = dict(s.split(':', 1) for s in ctx.opts.uml_skinparams.split(","))

truncatestrings = ("augment", "leafref")
if ctx.opts.uml_truncate != "":
Expand Down Expand Up @@ -292,7 +305,7 @@ def emit_stmt(self, mod, stmt, fd):
node = statements.find_target_node(self._ctx, stmt, True)
if node is not None and prefix in self.module_prefixes and not self.ctx_inline_augments:
# sys.stderr.write("Found augment target : %s , %s \n" %(stmt.arg, self.full_path(node)))
self.augments.append(self.full_path(stmt) + '-->' + self.full_path(node) + ' : augments' + '\n')
self.augments.append(self.full_path(stmt) + '-' + + '->' + self.full_path(node) + ' : augments' + '\n')
else:
# sys.stderr.write("Not Found augment target : %s \n" %(stmt.arg))
pass
Expand Down Expand Up @@ -493,7 +506,8 @@ def emit_uml_header(self, title, fd):
if not self.ctx_stereotypes:
fd.write('hide stereotypes \n')


for k in self.ctx_skinparams:
fd.write('skinparam %s %s\n' %(k, self.ctx_skinparams[k]))

# split into pages ? option -s
fd.write('page %s \n' %self.ctx_pagelayout)
Expand Down Expand Up @@ -841,9 +855,9 @@ def typestring(self, node):

if n is not None:
if node.keyword == 'typedef':
self.leafrefs.append(self.make_plantuml_keyword(node.arg) + '-->' + '"' + leafrefkey + '"' + self.full_path(n.parent) + ': ' + node.arg + '\n')
self.leafrefs.append(self.make_plantuml_keyword(node.arg) + '-' + self.ctx_leafref_color + '->' + '"' + leafrefkey + '"' + self.full_path(n.parent) + ': ' + node.arg + '\n')
else:
self.leafrefs.append(self.full_path(node.parent) + '-->' + '"' + leafrefkey + '"' + self.full_path(n.parent) + ': ' + node.arg + '\n')
self.leafrefs.append(self.full_path(node.parent) + '-' + self.ctx_leafref_color + '->' + '"' + leafrefkey + '"' + self.full_path(n.parent) + ': ' + node.arg + '\n')
if prefix not in self.module_prefixes:
self.post_strings.append('class \"%s\" as %s <<leafref>> \n' %(leafrefparent, self.full_path(n.parent)))
# self.post_strings.append('%s : %s\n' %(self.full_path(n.parent), leafrefkey))
Expand Down