Ejemplo n.º 1
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
Ejemplo n.º 2
0
    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))
Ejemplo n.º 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
Ejemplo n.º 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
Ejemplo n.º 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
Ejemplo 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
Ejemplo n.º 7
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
Ejemplo n.º 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
Ejemplo n.º 9
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']:
            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
Ejemplo n.º 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
Ejemplo n.º 11
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
Ejemplo n.º 12
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).lstrip('\n') #pylint: disable=attribute-defined-outside-init
Ejemplo n.º 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
Ejemplo n.º 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
Ejemplo n.º 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)
Ejemplo n.º 16
0
    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')
Ejemplo n.º 17
0
    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')
Ejemplo n.º 18
0
    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
Ejemplo n.º 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
Ejemplo n.º 20
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
Ejemplo n.º 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
Ejemplo n.º 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
Ejemplo n.º 23
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']))

        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
Ejemplo n.º 24
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
Ejemplo n.º 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
Ejemplo n.º 26
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']))

        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
Ejemplo n.º 27
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
Ejemplo n.º 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
Ejemplo n.º 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
Ejemplo n.º 30
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)
Ejemplo n.º 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)
Ejemplo n.º 32
0
 def __init__(self, name):
     self.__template = common.read(os.path.join(os.path.dirname(__file__),
                                                'templates',
                                                name))
Ejemplo n.º 33
0
 def __init__(self, name):
     self.__template = common.read(os.path.join(os.path.dirname(__file__),
                                                'templates',
                                                name))
Ejemplo n.º 34
0
 def content(self):
     """Return the markdown content."""
     return common.read(self._filename)
Ejemplo n.º 35
0
 def content(self):
     """Return the markdown content."""
     return common.read(self._filename)