docs: def generate_doc_dict(module, user):
      """Compile a Pale module's documentation into a python dictionary.
  
      The returned dictionary is suitable to be rendered by a JSON formatter,
      or passed to a template engine, or manipulated in some other way.
      """
      from pale import extract_endpoints, extract_resources, is_pale_module
      if not is_pale_module(module):
          raise ValueError(
                  """The passed in `module` (%s) is not a pale module. `paledoc`
                  only works on modules with a `_module_type` set to equal
                  `pale.ImplementationModule`.""")
  
      module_endpoints = extract_endpoints(module)
      ep_doc = { ep._route_name: document_endpoint(ep) for ep \
              in module_endpoints }
  
      ep_doc_filtered = {}
  
      for endpoint in ep_doc:
          # check if user has permission to view this endpoint
          # this is currently an on/off switch: if any endpoint has a "@requires_permission"
          # decorator, user.is_admin must be True for the user to see documentation
          # @TODO - make this permission more granular if necessary
  
          if ep_doc[endpoint].get("requires_permission") != None and user != None and user.is_admin or \
              ep_doc[endpoint].get("requires_permission") == None:
              ep_doc_filtered[endpoint] = ep_doc[endpoint]
  
      module_resources = extract_resources(module)
      res_doc = { r._value_type: document_resource(r) for r \
              in module_resources }
  
      return {'endpoints': ep_doc_filtered,
              'resources': res_doc}