#NEWLINE# def view( request , app , path ) : #NEWLINE# #INDENT# "\n  Views and renders a file at a given path.\n\n  Markdown files are parsed through markdown; others\n  are just pasted in <pre>'s.\n\n  TODO: Expose a way to do images.\n  " #NEWLINE# path = _unquote_path ( path ) #NEWLINE# fs = get_help_fs ( app ) #NEWLINE# if fs . isdir ( path ) : #NEWLINE# #INDENT# for i in INDEX_FILENAMES : #NEWLINE# #INDENT# tmp_path = os . path . join ( path , i ) #NEWLINE# if fs . isfile ( tmp_path ) : #NEWLINE# #INDENT# path = tmp_path #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# if ( not fs . isfile ( path ) ) : #NEWLINE# #INDENT# raise PopupException ( ( 'Could not find or read the file: %s (app %s)' % ( path , app ) ) ) #NEWLINE# #UNINDENT# content = fs . open ( path , 'r' ) . read ( ) #NEWLINE# content = unicode ( content , 'utf-8' , errors = 'replace' ) #NEWLINE# if path . lower ( ) . endswith ( '.md' ) : #NEWLINE# #INDENT# content = ( ( '<div class="print rendered-markdown">' + markdown . markdown ( content , [ 'extra' ] ) ) + '</div>' ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if path . lower ( ) . endswith ( '.html' ) : #NEWLINE# #INDENT# content = ( '<div class="print">%s</div>' % ( content , ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# content = ( ( '<pre>' + app ) + '</pre>' ) #NEWLINE# #UNINDENT# #UNINDENT# data = { #NEWLINE# #INDENT# 'content' : content , #NEWLINE# 'apps' : sorted ( [ x for x in appmanager . DESKTOP_MODULES if x . help_dir ] , key = ( lambda app : app . menu_index ) ) , #NEWLINE# 'title' : appmanager . get_desktop_module ( app ) . nice_name , #NEWLINE# 'current' : app , #NEWLINE# #UNINDENT# } #NEWLINE# return render ( 'display.mako' , request , data )