コード例 #1
0
ファイル: graph.py プロジェクト: lszeng-hnu/moose
    def createToken(self, parent, info, page):

        # Build the JSON data for plotting
        data = self.settings['data']
        if data is None:
            raise common.exceptions.MooseDocsException("The 'data' setting is required.")
        data = eval(data)

        # Use Postprocessor file for data
        filename = self.settings['filename']
        if filename is not None:
            filename = common.check_filenames(filename)
            reader = mooseutils.PostprocessorReader(filename)

            for i, line in enumerate(data):
                data[i]['x'] = reader[line['x']].tolist()
                data[i]['y'] = reader[line['y']].tolist()

        flt = floats.create_float(parent, self.extension, self.reader, page, self.settings,
                                  bottom=True)
        scatter = ScatterToken(flt, data=data, layout=eval(self.settings['layout']))

        if flt is parent:
            scatter.attributes.update(**self.attributes)

        return parent
コード例 #2
0
ファイル: listing.py プロジェクト: real-THU/moose-1
    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
コード例 #3
0
    def createToken(self, parent, info, page):

        # Build the JSON data for plotting
        data = self.settings['data']
        if data is None:
            raise common.exceptions.MooseDocsException(
                "The 'data' setting is required.")
        data = eval(data)

        # Use Postprocessor file for data
        filename = self.settings['filename']
        if filename is not None:
            filename = common.check_filenames(filename)
            reader = mooseutils.PostprocessorReader(filename)

            for i, line in enumerate(data):
                data[i]['x'] = reader(line['x']).tolist()
                data[i]['y'] = reader(line['y']).tolist()

        flt = floats.create_float(parent, self.extension, self.reader, page,
                                  self.settings)
        ScatterToken(flt, data=data, layout=eval(self.settings['layout']))
        if flt.children[0].name == 'Caption':
            cap = flt.children[0]
            cap.parent = None
            cap.parent = flt

        return parent
コード例 #4
0
ファイル: listing.py プロジェクト: FHilty/moose
    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']:
            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
コード例 #5
0
ファイル: plotly.py プロジェクト: aashiquear/moose
    def createToken(self, parent, info, page):

        # Build the JSON data for plotting
        data = self.settings['data']
        if data is None:
            raise common.exceptions.MooseDocsException("The 'data' setting is required.")
        data = eval(data)

        # Use Postprocessor file for data
        filename = self.settings['filename']
        if filename is not None:
            filename = common.check_filenames(filename)
            reader = mooseutils.PostprocessorReader(filename)

            for i, line in enumerate(data):
                data[i]['x'] = reader(line['x']).tolist()
                data[i]['y'] = reader(line['y']).tolist()

        flt = floats.create_float(parent, self.extension, self.reader, page, self.settings)
        ScatterToken(flt, data=data, layout=eval(self.settings['layout']))
        if flt.children[0].name == 'Caption':
            cap = flt.children[0]
            cap.parent = None
            cap.parent = flt

        return parent
コード例 #6
0
    def createToken(self, parent, info, page):
        """
        Build the tokens needed for displaying code listing.
        """

        filename = common.check_filenames(info['subcommand'])
        flt = floats.create_float(parent,
                                  self.extension,
                                  self.reader,
                                  page,
                                  self.settings,
                                  token_type=Listing)
        # Create code token
        lang = self.settings.get('language')
        content = self.extractContent(filename)
        lang = lang if lang else common.get_language(filename)

        code = core.Code(flt,
                         style="max-height:{};".format(
                             self.settings['max-height']),
                         content=content,
                         language=lang)
        if flt is parent:
            code.attributes.update(**self.attributes)

        if flt is not parent:
            code.name = 'ListingCode'

        # Add bottom modal
        link = self.settings['link']
        link = link if link is not None else self.extension['modal-link']
        if link:
            rel_filename = os.path.relpath(filename, MooseDocs.ROOT_DIR)

            # Get the complete file
            content = common.read(filename)
            settings = common.get_settings_as_dict(
                common.extractContentSettings())
            settings['strip-header'] = False
            content, _ = common.extractContent(content, settings)

            # Create modal for display the files a popup
            code = core.Code(None, language=lang, content=content)
            link = floats.create_modal_link(
                flt,
                url=unicode(rel_filename),
                content=code,
                title=unicode(filename),
                string=u'({})'.format(rel_filename))
            link.name = 'ListingLink'
            link['data-tooltip'] = unicode(rel_filename)

        return parent
コード例 #7
0
    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(check_filenames('image1.png'), 'image1.png')
        self.assertEqual(check_filenames('another/file0.md'),
                         '/path/to/another/file0.md')

        with self.assertRaises(exceptions.MooseDocsException) as e:
            self.assertEqual(check_filenames('file0.md'),
                             ['file0.md', '/path/to/another/file0.md'])
        self.assertIn('Multiple files', str(e.exception))
        self.assertIn('another/file0.md', str(e.exception))

        with self.assertRaises(exceptions.MooseDocsException) as e:
            self.assertEqual(check_filenames('wrong'), [])
        self.assertIn('does not exist in the repository', str(e.exception))
        self.assertIn('git ls-files', str(e.exception))
コード例 #8
0
    def testSourceLink(self):
        ast = self.tokenize('[framework/Makefile]')
        self.assertSize(ast, 1)
        self.assertToken(ast(0), 'Paragraph', size=1)
        self.assertToken(ast(0)(0),
                         'ModalSourceLink',
                         size=0,
                         src=common.check_filenames('framework/Makefile'))

        # If a file is not given, it should fall through to a regular link
        ast = self.tokenize('[not_a_file]')
        self.assertSize(ast, 1)
        self.assertToken(ast(0), 'Paragraph', size=1)
        self.assertToken(ast(0)(0), 'ShortcutLink', size=0, key='not_a_file')
コード例 #9
0
    def testSourceLink(self):
        ast = self.tokenize('[make](framework/Makefile)')
        self.assertSize(ast, 1)
        self.assertToken(ast(0), 'Paragraph', size=1)
        self.assertToken(ast(0, 0),
                         'ModalSourceLink',
                         size=1,
                         src=common.check_filenames('framework/Makefile'))
        self.assertToken(ast(0, 0, 0), 'Word', size=0, content='make')

        # If a file is not given, it should fall through to a regular link
        ast = self.tokenize('[text](not_a_file)')
        self.assertSize(ast, 1)
        self.assertToken(ast(0), 'Paragraph', size=1)
        self.assertToken(ast(0)(0), 'Link', size=1, url='not_a_file')
        self.assertToken(ast(0)(0)(0), 'Word', size=0, content='text')
コード例 #10
0
ファイル: listing.py プロジェクト: jwpeterson/moose
    def createToken(self, parent, info, page):
        """
        Build the tokens needed for displaying code listing.
        """

        filename = common.check_filenames(info['subcommand'])
        flt = floats.create_float(parent, self.extension, self.reader, page, self.settings,
                                  token_type=Listing)
        # Create code token
        lang = self.settings.get('language')
        content = self.extractContent(filename)
        lang = lang if lang else common.get_language(filename)

        code = core.Code(flt, style="max-height:{};".format(self.settings['max-height']),
                         content=content, language=lang)
        if flt is parent:
            code.attributes.update(**self.attributes)

        if flt is not parent:
            code.name = 'ListingCode'

        # Add bottom modal
        link = self.settings['link']
        link = link if link is not None else self.extension['modal-link']
        if link:
            rel_filename = os.path.relpath(filename, MooseDocs.ROOT_DIR)

            # Get the complete file
            content = common.read(filename)
            settings = common.get_settings_as_dict(common.extractContentSettings())
            settings['strip-header'] = False
            content, _ = common.extractContent(content, settings)

            # Create modal for display the files a popup
            code = core.Code(None, language=lang, content=content)
            link = floats.create_modal_link(flt,
                                            url=unicode(rel_filename),
                                            content=code,
                                            title=unicode(filename),
                                            string=u'({})'.format(rel_filename))
            link.name = 'ListingLink'
            link['data-tooltip'] = unicode(rel_filename)

        return parent