Exemplo n.º 1
0
    def createToken(self, info, parent):
        content = info['inline'] if 'inline' in info else info['block']

        for package, version in self.extension.getConfig().iteritems():
            if package != 'moose_packages':
                content = content.replace('__' + package.upper() + '__',
                                          unicode(version))

        tokens.Code(parent,
                    style="max-height:{};".format(self.settings['max-height']),
                    language=self.settings['language'],
                    code=content)
        return parent
Exemplo n.º 2
0
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
Exemplo n.º 3
0
    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
Exemplo n.º 4
0
    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
Exemplo n.º 5
0
    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:
                    url = u"https://github.com/idaholab/moose/issues/{}".format(issue[1:])
                    tokens.Link(p, url=url, string=unicode(issue))

            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)))
Exemplo n.º 6
0
    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
Exemplo n.º 7
0
 def createHTML(self, token, parent):
     div = html.Tag(parent, 'div', class_='moose-example')
     left = html.Tag(div, 'div', class_='moose-example-code')
     ast = tokens.Code(left, code=token.data)
     self.translator.renderer.process(left, ast)
     html.Tag(div, 'div', class_='moose-example-rendered')
Exemplo n.º 8
0
 def testCode(self):
     token = tokens.Code(code=u"x+y=2;")
     self.assertEqual(token.code, "x+y=2;")