def Global(self, **kwargs): """Sets global metadata, like plugin author.""" self.SetType(True) for key, value in kwargs.items(): if key in self.globals: raise error.RedundantControl(key) self.globals[key] = value
def ConsumeMetadata(self, block): assert block.locals.get('type') in [vimdoc.SECTION, vimdoc.BACKMATTER] # Error out for deprecated controls. if 'author' in block.globals: raise error.InvalidBlock( 'Invalid directive @author.' ' Specify author field in addon-info.json instead.') if 'tagline' in block.globals: raise error.InvalidBlock( 'Invalid directive @tagline.' ' Specify description field in addon-info.json instead.') for control in ['stylization', 'library']: if control in block.globals: if getattr(self, control) is not None: raise error.RedundantControl(control) setattr(self, control, block.globals[control])
def Merge(self, block, namespace=None): """Merges a block with the module.""" typ = block.locals.get('type') # This block doesn't want to be spoken to. if not typ: return # If the type still hasn't been set, it never will be. if typ is True: raise error.AmbiguousBlock block.Local(namespace=namespace) # Consume module-level metadata if 'order' in block.globals: if self.order is not None: raise error.RedundantControl('order') self.order = block.globals['order'] self.plugin.Merge(block) # Sections and Backmatter are specially treated. block_id = block.locals.get('id') if typ == vimdoc.SECTION: # Overwrite existing section if it's a default. if block_id not in self.sections or self.sections[ block_id].IsDefault(): self.sections[block_id] = block elif not block.IsDefault(): # Tried to overwrite explicit section with explicit section. raise error.DuplicateSection(block_id) elif typ == vimdoc.BACKMATTER: # Overwrite existing section backmatter if it's a default. if (block_id not in self.backmatters or self.backmatters[block_id].IsDefault()): self.backmatters[block_id] = block elif not block.IsDefault(): # Tried to overwrite explicit backmatter with explicit backmatter. raise error.DuplicateBackmatter(block_id) else: collection_type = self.plugin.GetCollectionType(block) if collection_type is not None: self.collections.setdefault(collection_type, []).append(block)