#NEWLINE# def new_bootstrap_tabs( visitor , block ) : #NEWLINE# #INDENT# '\n    Render text as bootstrap tabs, for example:\n        \n        {% tabs %}\n        -- name --\n        ...\n        ...\n        -- name --\n        ...\n        ...\n        {% endtabs %}\n    ' #NEWLINE# import re #NEWLINE# global __section__ #NEWLINE# if ( 'new' in block ) : #NEWLINE# #INDENT# __section__ += 1 #NEWLINE# r_name = re . compile ( '(^-- [^-]+ --$)' , re . M ) #NEWLINE# def get_id( ) : #NEWLINE# #INDENT# global __seq__ #NEWLINE# __seq__ += 1 #NEWLINE# return ( 'tab_item_%d_%d' % ( __section__ , __seq__ ) ) #NEWLINE# #UNINDENT# txt = [ ] #NEWLINE# txt . append ( '<div class="tabbable">' ) #NEWLINE# txt . append ( '<ul class="nav nav-tabs">' ) #NEWLINE# body = block [ 'body' ] #NEWLINE# i = 0 #NEWLINE# items = r_name . split ( body ) #NEWLINE# first = True #NEWLINE# entries = [ ] #NEWLINE# in_tab = False #NEWLINE# ids = [ ] #NEWLINE# while ( i < len ( items ) ) : #NEWLINE# #INDENT# if in_tab : #NEWLINE# #INDENT# entries . append ( items [ i ] ) #NEWLINE# in_tab = False #NEWLINE# #UNINDENT# if ( items [ i ] . startswith ( '-- ' ) and items [ i ] . endswith ( ' --' ) ) : #NEWLINE# #INDENT# if first : #NEWLINE# #INDENT# cls = ' class="active"' #NEWLINE# first = False #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# cls = '' #NEWLINE# #UNINDENT# _id = get_id ( ) #NEWLINE# ids . append ( _id ) #NEWLINE# txt . append ( ( '<li%s><a href="#%s" data-toggle="tab">%s</a></li>' % ( cls , _id , items [ i ] [ 3 : ( - 3 ) ] ) ) ) #NEWLINE# in_tab = True #NEWLINE# #UNINDENT# i += 1 #NEWLINE# #UNINDENT# txt . append ( '</ul>' ) #NEWLINE# txt . append ( '<div class="tab-content">' ) #NEWLINE# for ( i , x ) in enumerate ( entries ) : #NEWLINE# #INDENT# if ( i == 0 ) : #NEWLINE# #INDENT# cls = ' active' #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# cls = '' #NEWLINE# #UNINDENT# txt . append ( ( '<div class="tab-pane%s" id="%s">' % ( cls , ids [ i ] ) ) ) #NEWLINE# txt . append ( visitor . parse_text ( x , 'article' ) ) #NEWLINE# txt . append ( '</div>' ) #NEWLINE# #UNINDENT# txt . append ( '</div>' ) #NEWLINE# txt . append ( '</div>' ) #NEWLINE# return '\n' . join ( txt ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# return bootstrap_tabs ( visitor , block )