예제 #1
0
파일: listing.py 프로젝트: aashiquear/moose
 def extractContent(self, filename):
     """
     Extract content to display in listing code box.
     """
     content = common.read(filename)
     content, _ = common.extractContent(content, self.settings)
     return content
예제 #2
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))
예제 #3
0
def extractContent(filename, opts=dict()):
    """Helper for reading contents of a file in order to make assertions."""
    settings = common.get_settings_as_dict(common.extractContentSettings())
    settings.update(opts)
    content, _ = common.extractContent(common.read(MOOSE_DIR + '/' + filename),
                                       settings)
    return content
예제 #4
0
 def extractContent(self, filename):
     """
     Extract content to display in listing code box.
     """
     content = common.read(filename)
     content, _ = common.extractContent(content, self.settings)
     return content
예제 #5
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
예제 #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
예제 #7
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
예제 #8
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
예제 #9
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
예제 #10
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
예제 #11
0
파일: listing.py 프로젝트: aashiquear/moose
    def extractContent(self, filename):
        """Extract the file contents for display."""
        content = common.read(filename)
        if self.settings['block']:
            content = self.extractInputBlocks(content, self.settings['block'])

        content, _ = common.extractContent(content, self.settings)
        return content
예제 #12
0
파일: page.py 프로젝트: zhangsf2015/moose
 def read(self):
     """
     Read the content for conversion.
     """
     if self.source and os.path.exists(self.source):
         LOG.debug('READ %s', self.source)
         self._modified = os.path.getmtime(self.source)
         self.content = common.read(self.source).lstrip('\n') #pylint: disable=attribute-defined-outside-init
예제 #13
0
    def extractContent(self, filename):
        """Extract the file contents for display."""
        content = common.read(filename)
        if self.settings['block']:
            content = self.extractInputBlocks(content, self.settings['block'])

        content, _ = common.extractContent(content, self.settings)
        return content
예제 #14
0
 def read(self):
     """
     Read the content for conversion.
     """
     if self.source and os.path.exists(self.source):
         LOG.debug('READ %s', self.source)
         self._modified = os.path.getmtime(self.source)
         self.content = common.read(self.source)  #pylint: disable=attribute-defined-outside-init
예제 #15
0
    def testAlert(self):
        filename = os.path.join(MooseDocs.MOOSE_DIR, 'framework', 'doc', 'content', 'utilities', 'MooseDocs', 'extensions', 'alert.md')
        content = common.read(filename)
        ast = tokens.Token(None)
        self._reader.parse(ast, content)

        do_pickle(ast, timer=False)
        do_c_pickle(ast, timer=False)
예제 #16
0
파일: readers.py 프로젝트: jwpeterson/moose
    def read(self, page):
        """
        Read and return the content of the supplied page.

        This is called by the Translator object.
        """
        if isinstance(page, pages.Source) and page.source and os.path.exists(page.source):
            LOG.debug('READ %s', page.source)
            return common.read(page.source).lstrip('\n')
예제 #17
0
파일: readers.py 프로젝트: wesleyzzz/moose
    def read(self, page):
        """
        Read and return the content of the supplied page.

        This is called by the Translator object.
        """
        if isinstance(page, pages.Source) and page.source and os.path.exists(
                page.source):
            LOG.debug('READ %s', page.source)
            return common.read(page.source).lstrip('\n')
예제 #18
0
파일: template.py 프로젝트: crazy-ian/moose
    def createToken(self, parent, info, page):
        settings, t_args = common.match_settings(self.defaultSettings(),
                                                 info['settings'])

        location = self.translator.findPage(settings['file'])
        self.extension.addDependency(location)
        content = common.read(location.source)

        content = self.extension.applyTemplateArguments(content, **t_args)
        self.reader.tokenize(parent, content, page, line=info.line)
        return parent
예제 #19
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
예제 #20
0
파일: autolink.py 프로젝트: FHilty/moose
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
예제 #21
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
예제 #22
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
예제 #23
0
파일: include.py 프로젝트: real-THU/moose-1
    def createToken(self, info, parent):
        """
        NOTICE:
        Ideally, this method would create a connection between the two pages so that when you
        update the included page the livereload would run the including page. This doesn't work
        because of the multiprocessing, which would be making a connection between object that
        are on copies working on other processes from those that the livereload is watching.

        TODO: A possible fix would be to just hack in a regex for !include into the livereload
              watcher object itself, just need to implement it.
        """

        master_page = self.translator.current
        include_page = master_page.findall(info['subcommand'],
                                           exc=exceptions.TokenizeException)[0]

        content = common.read(
            include_page.source)  #TODO: copy existing tokens when not using re
        if self.settings['re']:
            content = common.regex(self.settings['re'], content,
                                   eval(self.settings['re-flags']))

        elif self.settings['start'] or self.settings['end']:
            lines = content.split('\n')
            start_idx = None
            end_idx = None
            start = self.settings['start']
            end = self.settings['end']

            for i, line in enumerate(lines):
                if (not start_idx) and (start in line):
                    start_idx = i
                if (not end_idx) and (end in line):
                    end_idx = i

            if start_idx is None:
                start_idx = 0
            if end_idx is None:
                end_idx = -1

            content = lines[start_idx:end_idx]

        self.translator.reader.parse(parent, content)
        return parent
예제 #24
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
예제 #25
0
    def createTokenFromSyntax(self, parent, info, page, obj):

        item = self.extension.database.get(obj.name, None)
        attr = getattr(item, self.SUBCOMMAND, None)
        if item and attr:
            self.createHeading(parent, page)
            ul = core.UnorderedList(parent, class_='moose-list-{}'.format(self.SUBCOMMAND))
            for filename in attr:
                filename = unicode(filename)
                li = core.ListItem(ul)
                lang = common.get_language(filename)
                content = common.fix_moose_header(common.read(os.path.join(MooseDocs.ROOT_DIR,
                                                                           filename)))
                code = core.Code(None, language=lang, code=content)
                floats.create_modal_link(li,
                                         url=filename,
                                         content=code,
                                         title=filename,
                                         string=filename)
        return parent
예제 #26
0
파일: include.py 프로젝트: FHilty/moose
    def createToken(self, info, parent):
        """
        NOTICE:
        Ideally, this method would create a connection between the two pages so that when you
        update the included page the livereload would run the including page. This doesn't work
        because of the multiprocessing, which would be making a connection between object that
        are on copies working on other processes from those that the livereload is watching.

        TODO: A possible fix would be to just hack in a regex for !include into the livereload
              watcher object itself, just need to implement it.
        """

        master_page = self.translator.current
        include_page = master_page.findall(info['subcommand'], exc=exceptions.TokenizeException)[0]

        content = common.read(include_page.source) #TODO: copy existing tokens when not using re
        if self.settings['re']:
            content = common.regex(self.settings['re'], content, eval(self.settings['re-flags']))

        elif self.settings['start'] or self.settings['end']:
            lines = content.split('\n')
            start_idx = None
            end_idx = None
            start = self.settings['start']
            end = self.settings['end']

            for i, line in enumerate(lines):
                if (not start_idx) and (start in line):
                    start_idx = i
                if (not end_idx) and (end in line):
                    end_idx = i

            if start_idx is None:
                start_idx = 0
            if end_idx is None:
                end_idx = -1

            content = lines[start_idx:end_idx]

        self.translator.reader.parse(parent, content)
        return parent
예제 #27
0
파일: appsyntax.py 프로젝트: FHilty/moose
    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
예제 #28
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
예제 #29
0
    def createToken(self, info, parent):
        """
        NOTICE:
        Ideally, this method would create a connection between the two pages so that when you
        update the included page the livereload would run the including page. This doesn't work
        because of the multiprocessing, which would be making a connection between object that
        are on copies working on other processes from those that the livereload is watching.

        TODO: A possible fix would be to just hack in a regex for !include into the livereload
              watcher object itself, just need to implement it.
        """

        master_page = self.translator.current
        include_page = master_page.findall(info['subcommand'],
                                           exc=exceptions.TokenizeException)[0]

        content = common.read(
            include_page.source)  #TODO: copy existing tokens when not using re
        if self.settings['re']:
            content = common.regex(self.settings['re'], content,
                                   eval(self.settings['re-flags']))

        self.translator.reader.parse(parent, content)
        return parent
예제 #30
0
파일: listing.py 프로젝트: real-THU/moose-1
    def extractContent(self, filename, settings):
        """
        Extract the desired content from the supplied raw text from a file.

        Inputs:
            filename[unicode]: The file to read (known to exist already).
            settings[dict]: The setting from the createToken method.
        """

        content = common.read(filename)
        if settings['re']:
            content = common.regex(self.settings['re'], content,
                                   eval(self.settings['re-flags']))

        elif settings['line']:
            content = self.extractLine(content, settings["line"])

        elif settings['start'] or settings['end']:
            content = self.extractLineRange(content, settings['start'],
                                            settings['end'],
                                            settings['include-start'],
                                            settings['include-end'])

        return self.prepareContent(content, settings)
예제 #31
0
    def extractContent(self, filename, settings):
        """
        Extract the desired content from the supplied raw text from a file.

        Inputs:
            filename[unicode]: The file to read (known to exist already).
            settings[dict]: The setting from the createToken method.
        """

        content = common.read(filename)
        if settings['re']:
            content = common.regex(self.settings['re'], content, eval(self.settings['re-flags']))

        elif settings['line']:
            content = self.extractLine(content, settings["line"])

        elif settings['start'] or settings['end']:
            content = self.extractLineRange(content,
                                            settings['start'],
                                            settings['end'],
                                            settings['include-start'],
                                            settings['include-end'])

        return self.prepareContent(content, settings)
예제 #32
0
파일: plotly.py 프로젝트: aashiquear/moose
 def __init__(self, name):
     self.__template = common.read(os.path.join(os.path.dirname(__file__),
                                                'templates',
                                                name))
예제 #33
0
파일: graph.py 프로젝트: lszeng-hnu/moose
 def __init__(self, name):
     self.__template = common.read(os.path.join(os.path.dirname(__file__),
                                                'templates',
                                                name))
예제 #34
0
파일: syntax.py 프로젝트: huangh-inl/moose
 def content(self):
     """Return the markdown content."""
     return common.read(self._filename)
예제 #35
0
 def content(self):
     """Return the markdown content."""
     return common.read(self._filename)