#NEWLINE# def build_settings_docs( docs_path , prefix = None ) : #NEWLINE# #INDENT# '\n    Converts names, descriptions and defaults for settings in\n    ``mezzanine.conf.registry`` into RST format for use in docs,\n    optionally filtered by setting names with the given prefix.\n    ' #NEWLINE# dynamic = '[dynamic]' #NEWLINE# lines = [ '.. THIS DOCUMENT IS AUTO GENERATED VIA conf.py' ] #NEWLINE# for name in sorted ( registry . keys ( ) ) : #NEWLINE# #INDENT# if ( prefix and ( not name . startswith ( prefix ) ) ) : #NEWLINE# #INDENT# continue #NEWLINE# #UNINDENT# setting = registry [ name ] #NEWLINE# settings_name = ( '``%s``' % settings_label ) #NEWLINE# settings_label = ( '.. _%s:' % name ) #NEWLINE# setting_default = setting [ 'default' ] #NEWLINE# if isinstance ( setting_default , str ) : #NEWLINE# #INDENT# if ( ( gethostname ( ) in setting_default ) or ( setting_default . startswith ( '/' ) and os . path . exists ( setting_default ) ) ) : #NEWLINE# #INDENT# setting_default = dynamic #NEWLINE# #UNINDENT# #UNINDENT# if ( setting_default != dynamic ) : #NEWLINE# #INDENT# setting_default = repr ( deep_force_unicode ( setting_default ) ) #NEWLINE# #UNINDENT# lines . extend ( [ '' , settings_label ] ) #NEWLINE# lines . extend ( [ '' , settings_name , ( '-' * len ( settings_name ) ) ] ) #NEWLINE# lines . extend ( [ '' , urlize ( ( setting [ 'description' ] or '' ) ) . replace ( '<a href="' , '`' ) . replace ( '" rel="nofollow">' , ' <' ) . replace ( '</a>' , '>`_' ) ] ) #NEWLINE# if setting [ 'choices' ] : #NEWLINE# #INDENT# choices = ', ' . join ( [ ( '%s: ``%s``' % ( str ( v ) , force_text ( k ) ) ) for ( k , v ) in setting [ 'choices' ] ] ) #NEWLINE# lines . extend ( [ '' , ( 'Choices: %s' % choices ) , '' ] ) #NEWLINE# #UNINDENT# lines . extend ( [ '' , ( 'Default: ``%s``' % setting_default ) ] ) #NEWLINE# #UNINDENT# with open ( os . path . join ( docs_path , 'settings.rst' ) , 'w' ) as f : #NEWLINE# #INDENT# f . write ( '\n' . join ( lines ) . replace ( "u'" , "'" ) . replace ( "yo'" , "you'" ) . replace ( '&#39;' , "'" ) )