Пример #1
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
Пример #2
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
Пример #3
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
Пример #4
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
Пример #5
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
Пример #6
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', 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
Пример #7
0
def createTokenHelper(key,
                      parent,
                      info,
                      page,
                      use_key_in_modal=False,
                      optional=False,
                      exact=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'' or
                               (match.group('bookmark') == u'#')):
        return LocalLink(parent, bookmark=bookmark)

    elif filename is not None:
        return AutoLink(parent,
                        page=filename,
                        bookmark=bookmark,
                        optional=optional,
                        exact=exact)

    else:
        source = common.project_find(info[key])
        if len(source) == 1:
            src_link = SourceLink(parent)
            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(src_link,
                                            content=code,
                                            title=local)
            if use_key_in_modal:
                tokens.String(link, content=os.path.basename(info[key]))
            return link

    return None
Пример #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
    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
Пример #10
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)

        # Create code token
        lang = self.settings.get('language')
        content = self.extractContent(filename)
        lang = lang if lang else common.get_language(filename)
        core.Code(flt,
                  style="max-height:{};".format(self.settings['max-height']),
                  content=content,
                  language=lang)

        # Add bottom modal
        if self.settings['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['data-tooltip'] = unicode(rel_filename)

        return parent
Пример #11
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
Пример #12
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
Пример #13
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