def createToken(self, parent, info, page): owner = self.settings['owner'] or self.extension.get('owner') repo = self.settings['repo'] or self.extension.get('repo') sha = mooseutils.git_commit() url = u'https://civet.inl.gov/sha_events/{}/{}/{}'.format( owner, repo, sha) return core.Link(parent, url=url)
def testMinimalLatex(self): """The link and floats stuff is dropped by the LaTeX renderer""" link = autolink.SourceLink(None) core.Link(link, string='Content', url='something') res = self.render(link, renderer=base.LatexRenderer()) self.assertSize(res, 1) self.assertLatexString(res(0), 'Content')
def createHTMLHelper(self, parent, token, page, desired): bookmark = token['bookmark'] # Handle 'optional' linking if desired is None: tok = tokens.Token(None) for child in token.copy(): child.parent = tok self.renderer.render(parent, tok, page) return None url = unicode(desired.relativeDestination(page)) if bookmark: url += '#{}'.format(bookmark) link = core.Link(None, url=url, info=token.info) if len(token.children) == 0: head = heading.find_heading(self.translator, desired, bookmark) if head is not None: for child in head: child.parent = link else: tokens.String(link, content=url) else: for child in token.copy(): child.parent = link self.renderer.render(parent, link, page) return None
def createToken(self, parent, info, page): owner = self.settings['owner'] or self.extension.get('owner') repo = self.settings['repo'] or self.extension.get('repo') rows = [] for sha in mooseutils.git_merge_commits(): url = 'https://civet.inl.gov/sha_events/{}/{}/{}'.format(owner, repo, sha) link = core.Link(parent, url=url, string=sha) core.LineBreak(parent) return parent
def createToken(self, parent, info, page): arch = self.settings['arch'] packages = self.extension.get('moose_packages', dict()) if arch not in packages: msg = "The supplied value for the 'arch' settings, {}, was not found." raise exceptions.MooseDocsException(msg, arch) href = os.path.join(self.extension.get('link'), packages[arch]) core.Link(parent, url=unicode(href), string=unicode(packages[arch])) return parent
def create_modal_link(parent, title=None, content=None, string=None, **kwargs): """ Create the necessary tokens to create a link to a modal window with materialize. """ kwargs.setdefault('bookmark', unicode(uuid.uuid4())) link = core.Link(parent, url=u'#{}'.format(kwargs['bookmark']), class_='modal-trigger', string=string) create_modal(parent, title, content, **kwargs) return link
def _addRequirement(self, parent, info, page, req, requirements): item = SQARequirementMatrixItem(parent, label=unicode(req.label), satisfied=req.satisfied, id_=req.path) self.reader.tokenize(item, req.text, page) if self.settings['link']: if self.settings['link-spec']: p = core.Paragraph(item) tokens.String(p, content=u'Specification: ') with codecs.open(req.filename, encoding='utf-8') as fid: content = fid.read() floats.create_modal_link( p, url=u"#", title=tokens.String(None, content=unicode(req.filename)), content=core.Code(None, language=u'text', code=content), string=u"{}:{}".format(req.path, req.name), tooltip=False) if self.settings['link-design'] and req.design: p = core.Paragraph(item) tokens.String(p, content=u'Design: ') for design in req.design: autolink.AutoLink(p, page=unicode(design)) if self.settings['link-issues'] and req.issues: p = core.Paragraph(item) 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:]) core.Link(p, url=url, string=unicode(issue)) core.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 = core.Paragraph(item) tokens.String(p, content=u'Prerequisites: {}'.format( ' '.join(labels)))
def createHTML(self, parent, token, page): hide = token['hide'] levels = token['levels'] func = lambda n: (n.name == 'Heading') and (n['level'] in levels) and (n is not token) \ and (n['id'] not in hide) toks = anytree.search.findall(token.root, filter_=func) div = html.Tag(parent, 'div', class_='moose-table-of-contents') div.addStyle('column-count:{}'.format(token['columns'])) for tok in toks: id_ = tok['id'] bookmark = id_ if id_ else tok.text(u'-').lower() link = core.Link(None, url='#{}'.format(bookmark)) tok.copyToToken(link) core.LineBreak(link) self.renderer.render(div, link, page)
def _addItems(self, parent, info, page, group, objects): count = 0 for obj in objects: if group in obj.groups: count += 1 item = SyntaxListItem(parent) nodes = self.translator.findPages(obj.markdown()) if len(nodes) == 0: tokens.String(item, content=unicode(obj.name)) else: core.Link(item, string=unicode(obj.name), url=unicode(nodes[0].relativeDestination(page))) if obj.description: self.reader.tokenize(item, obj.description, page, MooseDocs.INLINE, info.line) return count
def createHTML(self, parent, token, page): levels = token['levels'] toks = [] children = token.parent.parent.children index = children.index(token.parent) func = lambda n: n.name == 'Heading' and n['level'] in levels for sibling in children[index + 1:]: toks += anytree.search.findall(sibling, filter_=func) div = html.Tag(parent, 'div', class_='moose-table-of-contents') div.addStyle('column-count:{}'.format(token['columns'])) for tok in toks: id_ = tok['id'] bookmark = id_ if id_ else tok.text(u'-').lower() link = core.Link(None, url='#{}'.format(bookmark)) tok.copyToToken(link) core.LineBreak(link) self.renderer.render(div, link, page)
def createHTMLHelper(self, parent, token, page, desired): bookmark = token['bookmark'] # Handle 'optional' linking if desired is None: self._createOptionalContent(parent, token, page) return None if desired is page: url = '#{}'.format(bookmark) if bookmark else '#' else: url = unicode(desired.relativeDestination(page)) if bookmark: url += '#{}'.format(bookmark) link = core.Link(None, url=url, info=token.info) if len(token.children) == 0: head = None if desired is page: for n in anytree.PreOrderIter( token.root, filter_=lambda n: bookmark == n.get('id', None)): head = n break else: head = heading.find_heading(self.translator, desired, bookmark) if head is not None: head.copyToToken(link) else: link['class'] = 'moose-error' tokens.String(link, content=url) else: token.copyToToken(link) self.renderer.render(parent, link, page) return None
def createToken(self, parent, info, page): tree = dict() tree[(u'', )] = core.UnorderedList(parent, browser_default=False) location = self.settings['location'] func = lambda p: p.local.startswith(location) and isinstance( p, pages.Source) nodes = self.translator.findPages(func) for node in nodes: key = tuple( node.local.strip(os.sep).replace(location, '').split(os.sep))[:-1] for i in xrange(1, len(key) + 1): k = key[:i] if k not in tree: col = Collapsible(tree[k[:-1]], summary=k[-1]) li = core.ListItem(col, class_='moose-source-item', tooltip=False) tree[k] = core.UnorderedList(li, browser_default=False) for node in nodes: key = tuple( node.local.strip(os.sep).replace(location, '').split(os.sep))[:-1] loc = node.relativeDestination(page) li = core.ListItem(tree[key]) core.Link(li, url=loc, string=node.name, class_='moose-source-item', tooltip=False) return parent
def _addRequirement(self, parent, info, page, req, requirements): item = SQARequirementMatrixItem(parent, label=unicode(req.label), satisfied=req.satisfied, id_=req.path) self.reader.tokenize(item, req.text, page, MooseDocs.INLINE, info.line, report=False) for token in anytree.PreOrderIter(item): if token.name == 'ErrorToken': msg = common.report_error( "Failed to tokenize SQA requirement.", req.filename, req.text_line, req.text, token['traceback'], u'SQA TOKENIZE ERROR') LOG.critical(msg) if self.settings['link']: if self.settings['link-spec']: p = core.Paragraph(item) tokens.String(p, content=u'Specification: ') with codecs.open(req.filename, encoding='utf-8') as fid: content = fid.read() floats.create_modal_link(p, title=req.filename, content=core.Code(None, language=u'text', content=content), string=u"{}:{}".format( req.path, req.name)) if self.settings['link-design'] and req.design: p = core.Paragraph(item) tokens.String(p, content=u'Design: ') for design in req.design: autolink.AutoLink(p, page=unicode(design)) if self.settings['link-issues'] and req.issues: p = core.Paragraph(item) tokens.String(p, content=u'Issue(s): ') 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:]) core.Link(p, url=url, string=unicode(issue)) core.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 = core.Paragraph(item) tokens.String(p, content=u'Prerequisites: {}'.format( ' '.join(labels)))