# HG changeset patch # User Laurent Peuch # Date 1574780586 -3600 # Node ID e6bf15a69ea01aab5ad85337fdd5c989db6ca143 # Parent 3a38f779bed5fa88eb8ae65dea07ca194783f572 [debug-toolbar/display_source_code] add function to generate html link to source code diff -r 3a38f779bed5 -r e6bf15a69ea0 cubicweb/pyramid/debug_source_code.py --- a/cubicweb/pyramid/debug_source_code.py Thu Sep 26 06:27:53 2019 +0200 +++ b/cubicweb/pyramid/debug_source_code.py Tue Nov 26 16:03:06 2019 +0100 @@ -36,6 +36,26 @@ FILES_WHITE_LIST = set() +def _generate_link_to_source(file_path, start=None, end=None, tag_body="<>"): + if start: + # step back a bit so we have a bit of top padding wen displaying the page + # and the highlighted line isn't glued to top of the browser window + line_anchor = max(0, start - 10) + + if end: + return '%s' % ( + DEBUG_DISPLAY_SOURCE_CODE_PATH, file_path, start, end, line_anchor, tag_body + ) + else: + return '%s' % ( + DEBUG_DISPLAY_SOURCE_CODE_PATH, file_path, start, line_anchor, tag_body + ) + + return '%s' % ( + DEBUG_DISPLAY_SOURCE_CODE_PATH, file_path, tag_body + ) + + def source_code_url(object_or_class): if object_or_class is None: return "" @@ -54,17 +74,9 @@ try: source_code, line = inspect.getsourcelines(object_or_class) except OSError: # when we couldn't read the source code/line - return '<>' % ( - DEBUG_DISPLAY_SOURCE_CODE_PATH, file_path - ) + return _generate_link_to_source(file_path) - # step back a bit so we have a bit of top padding wen displaying the page - # and the highlighted line isn't glued to top of the browser window - line_anchor = max(0, line - 10) - - return '<>' % ( - DEBUG_DISPLAY_SOURCE_CODE_PATH, file_path, line, line + len(source_code), line_anchor - ) + return _generate_link_to_source(file_path, line, line + len(source_code)) def debug_display_source_code(request):