Exemple #1
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
Exemple #2
0
 def defaultSettings():
     settings = command.CommandComponent.defaultSettings()
     settings.update(floats.caption_settings())
     settings.update(common.extractContentSettings())
     settings['max-height'] = (u'350px', "The default height for listing content.")
     settings['language'] = (None, "The language to use for highlighting, if not supplied it " \
                                   "will be inferred from the extension (if possible).")
     return settings
Exemple #3
0
 def defaultSettings():
     settings = command.CommandComponent.defaultSettings()
     settings.update(floats.caption_settings())
     settings.update(common.extractContentSettings())
     settings['max-height'] = ('350px',
                               "The default height for listing content.")
     settings['language'] = (None, "The language to use for highlighting, if not supplied it " \
                                   "will be inferred from the extension (if possible).")
     return settings
Exemple #4
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
Exemple #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
Exemple #6
0
 def defaultSettings():
     settings = command.CommandComponent.defaultSettings()
     settings.update(common.extractContentSettings())
     return settings
Exemple #7
0
 def defaultSettings():
     settings = LocalListingCommand.defaultSettings()
     settings.update(common.extractContentSettings())
     settings['link'] = (
         None, "Include a link to the filename after the listing.")
     return settings
Exemple #8
0
 def defaultSettings():
     settings = LocalListingCommand.defaultSettings()
     settings.update(common.extractContentSettings())
     settings['link'] = (True, "Include a link to the filename after the listing.")
     return settings
Exemple #9
0
 def defaultSettings():
     settings = command.CommandComponent.defaultSettings()
     settings.update(common.extractContentSettings())
     return settings