#NEWLINE# def generate_map( map , name = 'url_map' ) : #NEWLINE# #INDENT# "\n    Generates a JavaScript function containing the rules defined in\n    this map, to be used with a MapAdapter's generate_javascript\n    method.  If you don't pass a name the returned JavaScript code is\n    an expression that returns a function.  Otherwise it's a standalone\n    script that assigns the function with that name.  Dotted names are\n    resolved (so you an use a name like 'obj.url_for')\n\n    In order to use JavaScript generation, simplejson must be installed.\n\n    Note that using this feature will expose the rules\n    defined in your map to users. If your rules contain sensitive\n    information, don't use JavaScript generation!\n    " #NEWLINE# map . update ( ) #NEWLINE# rules = [ ] #NEWLINE# converters = [ ] #NEWLINE# for rule in map . iter_rules ( ) : #NEWLINE# #INDENT# trace = [ { #NEWLINE# #INDENT# 'is_dynamic' : is_dynamic , #NEWLINE# 'data' : data , #NEWLINE# #UNINDENT# } for ( is_dynamic , data ) in rule . _trace ] #NEWLINE# rule_converters = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# for ( key , converter ) in rule . _converters . iteritems ( ) : #NEWLINE# #INDENT# js_func = js_to_url_function ( converter ) #NEWLINE# try : #NEWLINE# #INDENT# index = converters . index ( js_func ) #NEWLINE# #UNINDENT# except ValueError : #NEWLINE# #INDENT# converters . append ( js_func ) #NEWLINE# index = ( len ( converters ) - 1 ) #NEWLINE# #UNINDENT# rule_converters [ key ] = index #NEWLINE# #UNINDENT# rules . append ( { #NEWLINE# #INDENT# 'endpoint' : rule . endpoint , #NEWLINE# 'arguments' : list ( rule . arguments ) , #NEWLINE# 'converters' : rule_converters , #NEWLINE# 'trace' : rule , #NEWLINE# 'defaults' : rule . defaults , #NEWLINE# #UNINDENT# } ) #NEWLINE# #UNINDENT# return _javascript_routing_template . render ( { #NEWLINE# #INDENT# 'name_parts' : ( ( name and name . split ( '.' ) ) or [ ] ) , #NEWLINE# 'rules' : dumps ( rules ) , #NEWLINE# 'converters' : converters , #NEWLINE# #UNINDENT# } )