def createTokenFromSyntax(self, info, parent, obj): item = self.extension.database.get(obj.name, None) if item and hasattr(item, self.SUBCOMMAND): attr = getattr(item, self.SUBCOMMAND) self.createHeading(parent) ul = tokens.UnorderedList(parent) for filename in attr: filename = unicode(filename) li = tokens.ListItem(ul) lang = common.get_language(filename) code = tokens.Code(None, language=lang, code=common.read(filename)) floats.ModalLink(li, url=filename, bottom=True, content=code, string=u'({})'.format( os.path.relpath(filename, MooseDocs.ROOT_DIR)), title=tokens.String(None, content=filename)) return parent
def createTokenFromSyntax(self, info, parent, obj): item = self.extension.database.get(obj.name, None) attr = getattr(item, self.SUBCOMMAND, None) if item and attr: db = DatabaseListToken(parent) self.createHeading(db) ul = tokens.UnorderedList(db, class_='moose-list-{}'.format( self.SUBCOMMAND)) for filename in attr: filename = unicode(filename) li = tokens.ListItem(ul) lang = common.get_language(filename) code = tokens.Code(None, language=lang, code=common.read( os.path.join(MooseDocs.ROOT_DIR, filename))) floats.ModalLink(li, url=filename, bottom=True, content=code, string=filename, title=tokens.String(None, content=filename)) return parent
def _addRequirement(self, parent, req): item = SQARequirementMatrixItem(parent, label=unicode(req.label), satisfied=req.satisfied, id_=req.path) self.translator.reader.parse(item, req.text) p = tokens.Paragraph(item, 'p') tokens.String(p, content=u'Specification: ') with codecs.open(req.filename, encoding='utf-8') as fid: content = fid.read() floats.ModalLink(p, 'a', tooltip=False, url=u"#", string=u"{}:{}".format(req.path, req.name), title=tokens.String(None, content=unicode( req.filename)), content=tokens.Code(None, language=u'text', code=content)) p = tokens.Paragraph(item, 'p') tokens.String(p, content=u'Details: ') filename = u'{}/{}.md'.format(req.path, req.name) autolink.AutoShortcutLink(p, key=unicode(filename))
def createToken(self, info, parent): """ Build the tokens needed for displaying code listing. """ # Locate filename filename = common.check_filenames(info['subcommand']) # 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']: rel_filename = os.path.relpath(filename, MooseDocs.ROOT_DIR) code = tokens.Code(None, language=lang, code=common.read(filename)) floats.ModalLink(flt, url=unicode(rel_filename), bottom=True, content=code, string=u'({})'.format(rel_filename), title=tokens.String(None, content=unicode(filename))) return parent
def _addRequirement(self, parent, req): item = SQARequirementMatrixItem(parent, label=unicode(req.label), id_=req.path) self.translator.reader.parse(item, req.text) if self.settings['link']: if self.settings['link-spec']: p = tokens.Paragraph(item, 'p') tokens.String(p, content=u'Specification: ') with codecs.open(req.filename, encoding='utf-8') as fid: content = fid.read() floats.ModalLink(p, 'a', tooltip=False, url=u"#", string=u"{}:{}".format(req.path, req.name), title=tokens.String(None, content=unicode(req.filename)), content=tokens.Code(None, language=u'text', code=content)) if self.settings['link-design'] and req.design: p = tokens.Paragraph(item, 'p') tokens.String(p, content=u'Design: ') for design in req.design: autolink.AutoShortcutLink(p, key=unicode(design)) if self.settings['link-issues'] and req.issues: p = tokens.Paragraph(item, 'p') tokens.String(p, content=u'Issues: ') for issue in req.issues: url = u"https://github.com/idaholab/moose/issues/{}".format(issue[1:]) tokens.Link(p, url=url, string=unicode(issue))
def testModalLink(self): token = floats.ModalLink(None, url=u'foo', bottom=True, content=tokens.String(None, content=u''), title=tokens.String(None, content=u'')) self.assertIsInstance(token.title, tokens.Token) self.assertTrue(token.bottom)
def _addRequirement(self, parent, req, requirements): item = SQARequirementMatrixItem(parent, label=unicode(req.label), satisfied=req.satisfied, id_=req.path) self.translator.reader.parse(item, req.text) if self.settings['link']: if self.settings['link-spec']: p = tokens.Paragraph(item, 'p') tokens.String(p, content=u'Specification: ') with codecs.open(req.filename, encoding='utf-8') as fid: content = fid.read() floats.ModalLink(p, 'a', tooltip=False, url=u"#", string=u"{}:{}".format(req.path, req.name), title=tokens.String(None, content=unicode( req.filename)), content=tokens.Code(None, language=u'text', code=content)) if self.settings['link-design'] and req.design: p = tokens.Paragraph(item, 'p') tokens.String(p, content=u'Design: ') for design in req.design: autolink.AutoShortcutLink(p, key=unicode(design)) if self.settings['link-issues'] and req.issues: p = tokens.Paragraph(item, 'p') tokens.String(p, content=u'Issues: ') for issue in req.issues: if issue.startswith('#'): url = u"https://github.com/idaholab/moose/issues/{}".format( issue[1:]) else: url = u"https://github.com/idaholab/moose/commit/{}".format( issue[1:]) tokens.Link(p, url=url, string=unicode(issue)) tokens.Space(p) if self.settings['link-prerequisites'] and req.prerequisites: labels = [] for prereq in req.prerequisites: for other in requirements: if other.name == prereq: labels.append(other.label) p = tokens.Paragraph(item, 'p') tokens.String(p, content=u'Prerequisites: {}'.format( ' '.join(labels)))
def node(self, **kwargs): root = html.Tag(None, 'body') ast = floats.ModalLink(None, url=u'foo', string=u'link', content=tokens.String(None, content=u'content'), title=tokens.String(None, content=u'title'), **kwargs) self._translator.renderer.process(root, ast) return root
def createMaterialize(self, token, parent): key = token.key func = lambda n: isinstance(n, SQADocumentItem) and (n.key == key) replacement = anytree.search.find(token.root, filter_=func, maxlevel=2) if replacement: if token.heading is not None: self.translator.renderer.process(parent, token.heading) self.translator.renderer.process(parent, replacement) # Remove item so it doesn't render again replacement.parent = None for child in replacement: child.parent = None # else: filename = self.translator.current.local content = tokens.Token(None) self.translator.reader.parse(content, ERROR_CONTENT.format(key, filename)) modal_title = tokens.String( None, content=u'Missing Template Item "{}"'.format(key)) alert_title = tokens.Token(None) tokens.String(alert_title, content=u'Missing Template Item "{}"'.format(key)) h_token = floats.ModalLink(alert_title, url=unicode(filename), content=content, title=modal_title, class_='moose-help') materialicon.IconToken(h_token, icon=u'help_outline') err = alert.AlertToken(token.parent, brand=u'error', title=alert_title) for child in token.children: child.parent = err self.translator.renderer.process(parent, err)
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): matrix = SQARequirementMatrix(parent) for req in self.extension.requirements: item = SQARequirementMatrixItem(matrix) self.translator.reader.parse(item, unicode(req.requirement)) #TODO: Make option p = tokens.Paragraph(item, 'p') tokens.String(p, content=u'Specification: ') with codecs.open(req.filename, encoding='utf-8') as fid: content = fid.read() floats.ModalLink(p, 'a', tooltip=False, url=u"#", string=u"{}:{}".format(req.path, req.name), title=tokens.String(None, content=unicode( req.filename)), content=tokens.Code(None, language=u'text', code=content)) #TODO: Make option if req.design: p = tokens.Paragraph(item, 'p') tokens.String(p, content=u'Design: ') for design in req.design.split(): autolink.AutoShortcutLink(p, key=unicode(design)) #TODO: Make option if req.issues: p = tokens.Paragraph(item, 'p') tokens.String(p, content=u'Issues: ') for issue in req.issues.split(): url = u"https://github.com/idaholab/moose/issues/{}".format( issue[1:]) tokens.Link(p, url=url, string=unicode(issue)) return parent