Пример #1
0
    def links(self):
        """Add a link from this file to another in the same folder with a
        matching extension, when such a file exists.
        """
        def dual_exts_for(ext):
            if ext in self.ext_pairings[0].exts:
                return self.ext_pairings[1]
            if ext in self.ext_pairings[1].exts:
                return self.ext_pairings[0]
            return _TitledExts((), '')

        def is_indexed(path):
            if any(fnmatchcase(basename(path), e)
                   for e in self.tree.ignore_filenames):
                return False
            if any(fnmatchcase('/' + path.replace(os.sep, '/'), e)
                   for e in self.tree.ignore_paths):
                return False
            return True

        path_no_ext, ext = splitext(self.path)
        dual_exts = dual_exts_for(ext)
        for dual_ext in dual_exts.exts:
            dual_path = path_no_ext + dual_ext
            if (isfile(join(self.tree.source_folder, dual_path)) and
                is_indexed(dual_path)):
                yield (4,
                       dual_exts.title,
                       [(icon(dual_path),
                        unicode_for_display(basename(dual_path)),
                        browse_file_url(self.tree.name,
                                        unicode_for_display(dual_path)))])
                # Todo? this 'break' breaks handling of multiple extension
                # pairings on the same basename.
                break
Пример #2
0
 def menu_items(self):
     # TODO: Check against the ignore patterns, and don't link to files we
     # won't build pages for.
     yield {'html': 'Jump to file',
            'title': 'Jump to what is included here.',
            'href': browse_file_url(self.tree.name, self.menu_data),
            'icon': 'jump'}
Пример #3
0
 def test_browse_file_url(self):
     """Test unicode of various widths, slashes, and spaces."""
     with self.app().test_request_context():
         eq_(
             browse_file_url(u'tr éé', u'ev il:päthß/ªre/bes†', _anchor=4),
             '/tr%20%C3%A9%C3%A9/source/ev%20il%3Ap%C3%A4th%C3%9F/%C2%AAre/bes%E2%80%A0#4'
         )
Пример #4
0
    def links(self):
        """Add a link from this file to another in the same folder with a
        matching extension, when such a file exists.
        """
        def dual_exts_for(ext):
            if ext in self.ext_pairings[0].exts:
                return self.ext_pairings[1]
            if ext in self.ext_pairings[1].exts:
                return self.ext_pairings[0]
            return _TitledExts((), '')

        def is_indexed(path):
            if any(fnmatchcase(basename(path), e)
                   for e in self.tree.ignore_filenames):
                return False
            if any(fnmatchcase('/' + path.replace(os.sep, '/'), e)
                   for e in self.tree.ignore_paths):
                return False
            return True

        path_no_ext, ext = splitext(self.path)
        dual_exts = dual_exts_for(ext)
        for dual_ext in dual_exts.exts:
            dual_path = path_no_ext + dual_ext
            if (isfile(join(self.tree.source_folder, dual_path)) and
                is_indexed(dual_path)):
                yield (4,
                       dual_exts.title,
                       [(icon(dual_path),
                        unicode_for_display(basename(dual_path)),
                        browse_file_url(self.tree.name,
                                        unicode_for_display(dual_path)))])
                # Todo? this 'break' breaks handling of multiple extension
                # pairings on the same basename.
                break
Пример #5
0
def jump_to_target_menu_item(tree_config, path, row, target_name):
    """Make a menu that jumps straight to a specific line of a file."""

    return {'html': 'Jump to %s' % target_name,
            'title': "Jump to %s in '%s'" % (target_name,
                                             os.path.basename(path)),
            'href': browse_file_url(tree_config.name, path, _anchor=int(row)),
            'icon': 'jump'}
Пример #6
0
 def menu_items(self):
     # TODO: Check against the ignore patterns, and don't link to files we
     # won't build pages for.
     yield {
         'html': 'Jump to file',
         'title': 'Jump to what is included here.',
         'href': browse_file_url(self.tree.name, self.menu_data),
         'icon': 'jump'
     }
Пример #7
0
def jump_to_target_menu_item(tree_config, path, row, target_name):
    """Make a menu that jumps straight to a specific line of a file."""

    return {
        'html': 'Jump to %s' % target_name,
        'title': "Jump to %s in '%s'" % (target_name, os.path.basename(path)),
        'href': browse_file_url(tree_config.name, path, _anchor=int(row)),
        'icon': 'jump'
    }
Пример #8
0
    def menu_items(self):
        """Return a jump-to-definition menu item along with whatever others
        _more_menu_items() returns.

        """
        path, row = self.menu_data[:2]
        if path is None:
            menu = []
        else:
            menu = [{'html': "Jump to definition",
                     'title': "Jump to the definition in '%s'" % basename(path),
                     'href': browse_file_url(self.tree.name, path, _anchor=row),
                     'icon': 'jump'}]
        menu.extend(self._more_menu_items(self.menu_data[2:]))
        return menu
Пример #9
0
    def menu_items(self):
        """Return a jump-to-definition menu item along with whatever others
        _more_menu_items() returns.

        """
        path, row = self.menu_data[:2]
        if path is None:
            menu = []
        else:
            menu = [{
                'html': "Jump to definition",
                'title': "Jump to the definition in '%s'" % basename(path),
                'href': browse_file_url(self.tree.name, path, _anchor=row),
                'icon': 'jump'
            }]
        menu.extend(self._more_menu_items(self.menu_data[2:]))
        return menu
Пример #10
0
 def test_browse_file_url(self):
     """Test unicode of various widths, slashes, and spaces."""
     with self.app().test_request_context():
         eq_(browse_file_url(u'tr éé', u'ev il:päthß/ªre/bes†', _anchor=4),
             '/tr%20%C3%A9%C3%A9/source/ev%20il%3Ap%C3%A4th%C3%9F/%C2%AAre/bes%E2%80%A0#4')