def createToken(self, match, parent): master = floats.Float(parent, **self.attributes) caption = floats.Caption(master, prefix=self.settings['prefix'], key=self.attributes['id']) grammar = self.reader.lexer.grammar('inline') self.reader.lexer.tokenize(caption, grammar, unicode(self.settings['caption']), match.line) data = match['block'] if 'block' in match else match['inline'] example = ExampleToken(master, data=data) return example
def createToken(self, match, parent): if self.settings['module'] is None: raise exceptions.TokenizeException( "The 'module' setting is required.") if self.settings['object'] is None: raise exceptions.TokenizeException( "The 'object' setting is required.") master = floats.Float(parent, **self.attributes) if self.settings['caption']: caption = floats.Caption(master, prefix=self.settings['prefix'], key=self.attributes['id']) grammar = self.reader.lexer.grammar('inline') self.reader.lexer.tokenize(caption, grammar, self.settings['caption'], match.line) try: mod = importlib.import_module(self.settings['module']) except ImportError: msg = "Unable to load the '{}' module." raise exceptions.TokenizeException(msg, self.settings['module']) try: obj = getattr(mod, self.settings['object']) except AttributeError: msg = "Unable to load the '{}' attribute from the '{}' module." raise exceptions.TokenizeException(msg, self.settings['object'], self.settings['module']) if hasattr(obj, 'defaultSettings'): settings = obj.defaultSettings() elif hasattr(obj, 'defaultConfig'): settings = obj.defaultConfig() else: msg = "The '{}' object in the '{}' module does not have a 'defaultSettings' or "\ "'defaultConfig' method." raise exceptions.TokenizeException(msg, mod, obj) rows = [[key, value[0], value[1]] for key, value in settings.iteritems()] tbl = table.builder(rows, headings=[u'Key', u'Default', u'Description']) tbl.parent = master return master
def createToken(self, info, parent): """ Build the tokens needed for displaying code listing. """ # Read filename filenames = common.project_find(info['subcommand']) if len(filenames) == 0: msg = "{} does not exist." raise exceptions.TokenizeException(msg, info['subcommand']) elif len(filenames) > 1: msg = "Multiple files located with matching name '{}':\n".format( info['subcommand']) for f in filenames: msg += ' {}\n'.format(f) raise exceptions.TokenizeException(msg) else: filename = filenames[0] # Listing container flt = floats.Float(parent) self.addCaption(flt) # Create code token lang = self.settings.get('language') lang = lang if lang else common.get_language(filename) tokens.Code(flt, style="max-height:{};".format(self.settings['max-height']), code=self.extractContent(filename, self.settings), language=lang) # Add bottom modal if self.settings['link']: code = tokens.Code(None, language=lang, code=common.read(filename)) floats.ModalLink(flt, url=unicode(filename), bottom=True, content=code, string=u'({})'.format( os.path.relpath(filename, MooseDocs.ROOT_DIR)), title=tokens.String(None, content=unicode(filename))) return parent
def testFloat(self): token = floats.Float(None) self.assertIsInstance(token, floats.Float)
def node(self, **kwargs): node = html.Tag(None, 'div') ast = floats.Float(None, **kwargs) self._translator.renderer.process(node, ast) return node