def test(self): """ Test that class with h and C files are located. """ MooseDocs.PROJECT_FILES = [ 'file0.md', '/path/to/another/file0.md', 'image1.png' ] self.assertEqual(project_find('image1.png'), ['image1.png']) self.assertEqual(project_find('file0.md'), ['file0.md', '/path/to/another/file0.md']) self.assertEqual(project_find('e0.md'), ['file0.md', '/path/to/another/file0.md']) self.assertEqual(project_find('wrong'), [])
def createTokenHelper(key, parent, info, page, use_key_in_modal=False): match = PAGE_LINK_RE.search(info[key]) bookmark = match.group('bookmark')[1:] if match.group('bookmark') else u'' filename = match.group('filename') # The link is local (i.e., [#foo]), the heading will be gathered on render because it # could be after the current position. if (filename is None) and (bookmark != u''): return LocalLink(parent, bookmark=bookmark) elif filename is not None: return AutoLink(parent, page=filename, bookmark=bookmark) else: source = common.project_find(info[key]) if len(source) == 1: src = unicode(source[0]) content = common.fix_moose_header(common.read(os.path.join(MooseDocs.ROOT_DIR, src))) code = core.Code(None, language=common.get_language(src), content=content) local = src.replace(MooseDocs.ROOT_DIR, '') link = floats.create_modal_link(parent, content=code, title=local) if use_key_in_modal: tokens.String(link, content=os.path.basename(info[key])) return link return None
def createTokenHelper(key, parent, info, page, use_key_in_modal=False): match = PAGE_LINK_RE.search(info[key]) bookmark = match.group('bookmark')[1:] if match.group('bookmark') else u'' filename = match.group('filename') # The link is local (i.e., [#foo]), the heading will be gathered on render because it # could be after the current position. if (filename is None) and (bookmark != u''): return LocalLink(parent, bookmark=bookmark) elif filename is not None: return AutoLink(parent, page=filename, bookmark=bookmark) else: source = common.project_find(info[key]) if len(source) == 1: src = unicode(source[0]) content = common.fix_moose_header( common.read(os.path.join(MooseDocs.ROOT_DIR, src))) code = core.Code(None, language=common.get_language(src), content=content) local = src.replace(MooseDocs.ROOT_DIR, '') link = floats.create_modal_link(parent, content=code, title=local) if use_key_in_modal: tokens.String(link, content=os.path.basename(info[key])) return link return None
def _source_token(parent, key): #pylint """Helper for source code fallback.""" # TODO: This needs to get smarter, the ModalLink needs to cache content so that same # content is not include a too many times. # TODO: This does not work with both type of links, Link and ShortcutLink source = common.project_find(key) if len(source) == 1: src = unicode(source[0]) code = tokens.Code(None, language=common.get_language(src), code=common.read(os.path.join(MooseDocs.ROOT_DIR, src))) link = floats.ModalLink(parent, url=src, content=code, bottom=True, title=tokens.String(None, content=src)) return link
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 _source_token(parent, key): #pylint """Helper for source code fallback.""" # TODO: This needs to get smarter, the ModalLink needs to cache content so that same # content is not include a too many times. # TODO: This does not work with both type of links, Link and ShortcutLink source = common.project_find(key) if len(source) == 1: src = unicode(source[0]) code = tokens.Code(None, language=common.get_language(src), code=common.read( os.path.join(MooseDocs.ROOT_DIR, src))) link = floats.ModalLink(parent, url=src, content=code, bottom=True, title=tokens.String(None, content=src)) return link
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