paul@101 | 1 | #!/usr/bin/env python |
paul@101 | 2 | |
paul@101 | 3 | """ |
paul@101 | 4 | Graphviz document tree nodes. |
paul@101 | 5 | |
paul@101 | 6 | Copyright (C) 2018 Paul Boddie <paul@boddie.org.uk> |
paul@101 | 7 | |
paul@101 | 8 | This program is free software; you can redistribute it and/or modify it under |
paul@101 | 9 | the terms of the GNU General Public License as published by the Free Software |
paul@101 | 10 | Foundation; either version 3 of the License, or (at your option) any later |
paul@101 | 11 | version. |
paul@101 | 12 | |
paul@101 | 13 | This program is distributed in the hope that it will be useful, but WITHOUT |
paul@101 | 14 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
paul@101 | 15 | FOR A PARTICULAR PURPOSE. See the GNU General Public License for more |
paul@101 | 16 | details. |
paul@101 | 17 | |
paul@101 | 18 | You should have received a copy of the GNU General Public License along with |
paul@101 | 19 | this program. If not, see <http://www.gnu.org/licenses/>. |
paul@101 | 20 | """ |
paul@101 | 21 | |
paul@101 | 22 | from moinformat.tree.moin import Node |
paul@101 | 23 | |
paul@101 | 24 | class Directive(Node): |
paul@101 | 25 | |
paul@101 | 26 | "Format directive for Graphviz output." |
paul@101 | 27 | |
paul@188 | 28 | def __init__(self, key=None, value=None, directive=None): |
paul@188 | 29 | self.directive = directive |
paul@188 | 30 | |
paul@188 | 31 | if key or value: |
paul@188 | 32 | self.key = key |
paul@188 | 33 | self.value = value |
paul@188 | 34 | else: |
paul@188 | 35 | t = directive.split(None, 1) |
paul@188 | 36 | self.key = t[0] |
paul@188 | 37 | self.value = len(t) > 1 and t[1] or None |
paul@101 | 38 | |
paul@101 | 39 | def __repr__(self): |
paul@188 | 40 | return "Directive(%r, %r, %r)" % (self.key, self.value, self.directive) |
paul@101 | 41 | |
paul@101 | 42 | def prettyprint(self, indent=""): |
paul@188 | 43 | return "%sDirective: key=%r value=%r directive=%r" % (indent, self.key, self.value, self.directive) |
paul@101 | 44 | |
paul@101 | 45 | def to_string(self, out): |
paul@188 | 46 | out.directive(self.key, self.value, self.directive) |
paul@101 | 47 | |
paul@101 | 48 | # vim: tabstop=4 expandtab shiftwidth=4 |