| 126 | |
| 127 | |
| 128 | class DocumentStructure(ReSTDocument): |
| 129 | def __init__(self, name, section_names=None, target='man', context=None): |
| 130 | """Provides a Hierarichial structure to a ReSTDocument |
| 131 | |
| 132 | You can write to it similar to as you can to a ReSTDocument but |
| 133 | has an innate structure for more orginaztion and abstraction. |
| 134 | |
| 135 | :param name: The name of the document |
| 136 | :param section_names: A list of sections to be included |
| 137 | in the document. |
| 138 | :param target: The target documentation of the Document structure |
| 139 | :param context: A dictionary of data to store with the structure. These |
| 140 | are only stored per section not the entire structure. |
| 141 | """ |
| 142 | super(DocumentStructure, self).__init__(target=target) |
| 143 | self._name = name |
| 144 | self._structure = OrderedDict() |
| 145 | self._path = [self._name] |
| 146 | self._context = {} |
| 147 | if context is not None: |
| 148 | self._context = context |
| 149 | if section_names is not None: |
| 150 | self._generate_structure(section_names) |
| 151 | |
| 152 | @property |
| 153 | def name(self): |
| 154 | """The name of the document structure""" |
| 155 | return self._name |
| 156 | |
| 157 | @property |
| 158 | def path(self): |
| 159 | """ |
| 160 | A list of where to find a particular document structure in the |
| 161 | overlying document structure. |
| 162 | """ |
| 163 | return self._path |
| 164 | |
| 165 | @path.setter |
| 166 | def path(self, value): |
| 167 | self._path = value |
| 168 | |
| 169 | @property |
| 170 | def available_sections(self): |
| 171 | return list(self._structure) |
| 172 | |
| 173 | @property |
| 174 | def context(self): |
| 175 | return self._context |
| 176 | |
| 177 | def _generate_structure(self, section_names): |
| 178 | for section_name in section_names: |
| 179 | self.add_new_section(section_name) |
| 180 | |
| 181 | def add_new_section(self, name, context=None): |
| 182 | """Adds a new section to the current document structure |
| 183 | |
| 184 | This document structure will be considered a section to the |
| 185 | current document structure but will in itself be an entirely |
no outgoing calls