parameters: (features, app_name)
return_statement: return features
docstring: Convert a |feautres| dictionary, and all 'children' dictionaries, into
    lists recursively. Sort lists first by 'level' then by name.
docstring_summary: Convert a |feautres| dictionary, and all 'children' dictionaries, into
    lists recursively. Sort lists first by 'level' then by name.
docstring_tokens: Convert a |feautres| dictionary and all children dictionaries into lists recursively . Sort lists first by level then by name .
function: def _ListifyAndSortDocs(features, app_name):
    '''Convert a |feautres| dictionary, and all 'children' dictionaries, into
    lists recursively. Sort lists first by 'level' then by name.
    '''
    def sort_key(item):
      '''Key function to sort items primarily by level (according to index into
      levels) then subsort by name.
      '''
      levels = ('required', 'recommended', 'only_one', 'optional')
  
      return (levels.index(item.get('level', 'optional')), item['name'])
  
    def coerce_example_to_feature(feature):
      '''To display json in examples more clearly, convert the example of
      |feature| into the feature format, with a name and children, to be rendered
      by the templates. Only applicable to examples that are dictionaries.
      '''
      if not isinstance(feature.get('example'), dict):
        if 'example' in feature:
          feature['example'] = json.dumps(feature['example'])
        return
      # Add any keys/value pairs in the dict as children
      for key, value in feature['example'].iteritems():
        if not 'children' in feature:
          feature['children'] = {}
        feature['children'][key] = { 'name': key, 'example': value }
      del feature['example']
      del feature['has_example']
  
    def convert_and_sort(features):
      for key, value in features.items():
        if 'example' in value:
          value['has_example'] = True
          example = json.dumps(value['example'])
          if example == '{}':
            value['example'] = '{...}'
          elif example == '[]':
            value['example'] = '[...]'
          elif example == '[{}]':
            value['example'] = '[{...}]'
          else:
            coerce_example_to_feature(value)
        if 'children' in value:
          features[key]['children'] = convert_and_sort(value['children'])
      return sorted(features.values(), key=sort_key)
  
    # Replace {{platform}} in the 'name' manifest property example with
    # |app_name|, the convention that the normal template rendering uses.
    # TODO(kalman): Make the example a template and pass this through there.
    if 'name' in features:
      name = features['name']
      name['example'] = name['example'].replace('{{platform}}', app_name)
  
    features = convert_and_sort(features)
  
    return features
function_tokens: def _ListifyAndSortDocs ( features , app_name ) : def sort_key ( item ) : '''Key function to sort items primarily by level (according to index into
      levels) then subsort by name.
      ''' levels = ( 'required' , 'recommended' , 'only_one' , 'optional' ) return ( levels . index ( item . get ( 'level' , 'optional' ) ) , item [ 'name' ] ) def coerce_example_to_feature ( feature ) : '''To display json in examples more clearly, convert the example of
      |feature| into the feature format, with a name and children, to be rendered
      by the templates. Only applicable to examples that are dictionaries.
      ''' if not isinstance ( feature . get ( 'example' ) , dict ) : if 'example' in feature : feature [ 'example' ] = json . dumps ( feature [ 'example' ] ) return # Add any keys/value pairs in the dict as children for key , value in feature [ 'example' ] . iteritems ( ) : if not 'children' in feature : feature [ 'children' ] = { } feature [ 'children' ] [ key ] = { 'name' : key , 'example' : value } del feature [ 'example' ] del feature [ 'has_example' ] def convert_and_sort ( features ) : for key , value in features . items ( ) : if 'example' in value : value [ 'has_example' ] = True example = json . dumps ( value [ 'example' ] ) if example == '{}' : value [ 'example' ] = '{...}' elif example == '[]' : value [ 'example' ] = '[...]' elif example == '[{}]' : value [ 'example' ] = '[{...}]' else : coerce_example_to_feature ( value ) if 'children' in value : features [ key ] [ 'children' ] = convert_and_sort ( value [ 'children' ] ) return sorted ( features . values ( ) , key = sort_key ) # Replace {{platform}} in the 'name' manifest property example with # |app_name|, the convention that the normal template rendering uses. # TODO(kalman): Make the example a template and pass this through there. if 'name' in features : name = features [ 'name' ] name [ 'example' ] = name [ 'example' ] . replace ( '{{platform}}' , app_name ) features = convert_and_sort ( features ) return features