示例#1
0
    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))
示例#2
0
def builder(rows, headings=None, form=None):
    """Helper for creating tokens for a table."""
    node = Table(None)
    if headings:
        thead = TableHead(node)
        row = TableRow(thead)
        for h in headings:
            th = TableHeadItem(row, align='left')
            if isinstance(h, tokens.Token):
                h.parent = th
            else:
                tokens.String(th, content=str(h))

    tbody = TableBody(node)
    for data in rows:
        row = TableRow(tbody)
        for d in data:
            tr = TableItem(row, align='left')
            if isinstance(d, tokens.Token):
                d.parent = tr
            else:
                tokens.String(tr, content=str(d))

    if form is None:
        form = 'L'*len(rows[0])

    node['form'] = form
    return node
示例#3
0
文件: sqa.py 项目: real-THU/moose-1
    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))
示例#4
0
    def _addRequirement(self, parent, info, page, req):
        item = SQARequirementMatrixItem(parent, requirement=req)
        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)

        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,
                                     string=u"{}:{}".format(
                                         req.path, req.name),
                                     content=core.Code(None,
                                                       language=u'text',
                                                       content=content),
                                     title=unicode(req.filename))

        p = core.Paragraph(item)
        tokens.String(p, content=u'Details: ')
        filename = u'{}/{}.md'.format(req.path, req.name)
        autolink.AutoLink(p, page=unicode(filename))
示例#5
0
文件: sqa.py 项目: lszeng-hnu/moose
    def _addRequirement(self, parent, info, page, req):
        reqname = "{}:{}".format(req.path, req.name) if req.path != '.' else req.name
        item = SQARequirementMatrixItem(parent, label=req.label, reqname=reqname)
        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'],
                                          'SQA TOKENIZE ERROR')
                LOG.critical(msg)

        p = core.Paragraph(item)
        tokens.String(p, content='Specification: ')

        content = common.read(req.filename)
        floats.create_modal_link(p,
                                 string=reqname,
                                 content=core.Code(None, language='text', content=content),
                                 title=str(req.filename))

        p = core.Paragraph(item)
        tokens.String(p, content='Documentation: ')
        filename = getattr(req, info['subcommand'])
        autolink.AutoLink(p, page=str(filename))
示例#6
0
    def testString(self):
        token = tokens.String(content=u"content")
        self.assertEqual(token.content, "content")

        with self.assertRaises(exceptions.MooseDocsException) as e:
            token = tokens.String(content=1980)
        gold = "The supplied property 'content' must be of type 'unicode', but 'int' was provided."
        self.assertEqual(e.exception.message, gold)
示例#7
0
 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)
示例#8
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:
                    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)))
示例#9
0
 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
示例#10
0
    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
示例#11
0
 def _createOptionalContent(self, parent, token, page):
     """Renders text without link for optional link."""
     tok = tokens.Token(None)
     token.copyToToken(tok)
     if len(tok) == 0:  # Use filename if no children exist
         tokens.String(tok, content=page.local)
     self.renderer.render(parent, tok, page)
示例#12
0
    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
示例#13
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
示例#14
0
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
示例#15
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
示例#16
0
文件: sqa.py 项目: real-THU/moose-1
    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)
示例#17
0
def builder(rows, headings=None):
    node = Table()
    if headings:
        thead = TableHead(node)
        row = TableRow(thead)
        for h in headings:
            th = TableHeaderItem(row)
            tokens.String(th, content=unicode(h))

    tbody = TableBody(node)
    for data in rows:
        row = TableRow(tbody)
        for d in data:
            tr = TableItem(row)
            tokens.String(tr, content=unicode(d))

    return node
示例#18
0
def builder(rows, headings=None):
    """Helper for creating tokens for a table."""
    node = Table(None)
    if headings:
        thead = TableHead(node)
        row = TableRow(thead)
        for h in headings:
            th = TableHeadItem(row, align='left')
            tokens.String(th, content=unicode(h))

    tbody = TableBody(node)
    for data in rows:
        row = TableRow(tbody)
        for d in data:
            tr = TableItem(row, align='left')
            tokens.String(tr, content=unicode(d))

    return node
示例#19
0
    def createToken(self, info, parent):
        group_map = self.extension.get('requirement-groups')
        for group, requirements in self.extension.requirements.iteritems():
            group = group_map.get(group, group.replace('_', ' ').title())
            matrix = SQARequirementMatrix(parent,
                                          heading=tokens.String(None, content=unicode(group)))
            for req in requirements:
                self._addRequirement(matrix, req)

        return parent
示例#20
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
示例#21
0
    def _addRequirement(self, parent, info, page, req):
        item = SQARequirementMatrixItem(parent,
                                        label=unicode(req.label),
                                        satisfied=req.satisfied,
                                        id_=req.path)
        self.reader.tokenize(item, req.text, page, line=info.line)

        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,
                tooltip=False,
                url=u"#",
                string=u"{}:{}".format(req.path, req.name),
                title=tokens.String(None, content=unicode(req.filename)),
                content=core.Code(None, language=u'text', code=content))

        p = core.Paragraph(item)
        tokens.String(p, content=u'Details: ')
        filename = u'{}/{}.md'.format(req.path, req.name)
        autolink.AutoLink(p, page=unicode(filename))
示例#22
0
    def testProcess(self):
        ast = tokens.Paragraph(None)
        tokens.String(ast, content=u'foo')

        renderer = renderers.HTMLRenderer()
        renderer.add(tokens.Paragraph, ParComponent())
        renderer.add(tokens.String, StringComponent())

        root = html.Tag(None, 'div')
        renderer.process(root, ast)

        self.assertIsInstance(root(0), html.Tag)
        self.assertEqual(root(0).name, 'p')
        self.assertIsInstance(root(0)(0), html.String)
        self.assertEqual(root(0)(0).content, u'foo')
示例#23
0
    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
示例#24
0
    def testRender(self):
        ast = tokens.Paragraph(None)
        tokens.String(ast, content=u'foo')
        content = page.PageNodeBase(None)
        renderer = renderers.HTMLRenderer()
        translator = Translator(content, MarkdownReader(), renderer, [])
        translator.init('')

        renderer.add(tokens.Paragraph, ParComponent())
        renderer.add(tokens.String, StringComponent())

        root = renderer.render(ast)
        self.assertIsInstance(root, html.Tag)
        self.assertEqual(root.name, 'body')
        self.assertIsInstance(root(0), html.Tag)
        self.assertEqual(root(0).name, 'p')
        self.assertIsInstance(root(0)(0), html.String)
        self.assertEqual(root(0)(0).content, u'foo')
示例#25
0
    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
示例#26
0
    def createToken(self, info, parent):

        # Markdown files
        match = LINK_RE.search(info['key'])
        #        if match and (parent.root.page is not None):
        if match and (self.translator.current is not None):
            return AutoShortcutLink(parent,
                                    key=match.group('filename'),
                                    bookmark=match.group('bookmark'),
                                    header=self.extension.get(
                                        'include-page-header', True))

        link = _source_token(parent, info['key'])
        if link:
            tokens.String(link, content=os.path.basename(info['key']))
            return parent

        return core.ShortcutLink.createToken(self, info, parent)
示例#27
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
示例#28
0
    def postTokenize(self, ast, page, meta, reader):
        """Set float number for each counter."""
        for node in moosetree.iterate(ast, lambda n: n.name == 'FloatCaption'):
            prefix = node.get('prefix', None)
            if prefix is not None:
                meta.getData('counts')[prefix] += 1
                node['number'] = meta.getData('counts')[prefix]
            key = node.get('key')
            if key:
                shortcut = core.Shortcut(ast.root,
                                         key=key,
                                         link='#{}'.format(key))

                # TODO: This is a bit of a hack to get Figure~\ref{} etc. working in general
                if isinstance(self.translator.renderer, LatexRenderer):
                    shortcut['prefix'] = prefix.title()
                else:
                    tokens.String(shortcut,
                                  content='{} {}'.format(
                                      prefix.title(), node['number']))
示例#29
0
    def _addItems(self, parent, info, page, group, objects, base=None):

        count = 0
        for obj in objects:
            if (group in obj.groups) and (not obj.removed):
                count += 1
                item = SyntaxListItem(parent, group=group, syntax=obj.name)
                if base:
                    item['base'] = base
                nodes = self.translator.findPages(obj.markdown())
                if len(nodes) == 0:
                    tokens.String(item, content=unicode(obj.name))
                else:
                    SyntaxLink(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
示例#30
0
文件: devel.py 项目: lszeng-hnu/moose
    def createLatex(self, parent, token, page):

        # Create label option and render caption text
        cap = token(0)
        cap.parent = None
        label = latex.create_settings(label=cap['key'])

        text = tokens.String(None)
        cap.copyToToken(text)
        title = latex.Brace()
        self.translator.renderer.render(title, text, page)

        # Create example environment with upper and lower part
        example = latex.Environment(parent, 'example', args=[label, title])

        code = token.children[0]
        code.parent = None
        self.translator.renderer.render(example, code, page)  # upper
        latex.Command(example, 'tcblower', start='\n')
        return example