예제 #1
0
def ProcessSchema(path, file_data):
  '''Parses |file_data| using a method determined by checking the
  extension of the file at the given |path|. Then, trims 'nodoc' and handles
  inlineable types from the parsed schema data.
  '''
  def trim_and_inline(schema, is_idl=False):
    '''Modifies an API schema in place by removing nodes that shouldn't be
    documented and inlining schema types that are only referenced once.
    '''
    if RemoveNoDocs(schema):
      # A return of True signifies that the entire schema should not be
      # documented. Otherwise, only nodes that request 'nodoc' are removed.
      return None
    if is_idl:
      DetectInlineableTypes(schema)
    InlineDocs(schema)
    return schema

  if path.endswith('.idl'):
    idl = idl_schema.IDLSchema(idl_parser.IDLParser().ParseData(file_data))
    return trim_and_inline(idl.process()[0], is_idl=True)

  schemas = json_parse.Parse(file_data)
  for schema in schemas:
    # Schemas could consist of one API schema (data for a specific API file)
    # or multiple (data from extension_api.json).
    trim_and_inline(schema)
  return schemas
예제 #2
0
 def _LoadIdlAPI(self, api, disable_refs):
     idl = idl_parser.IDLParser().ParseData(api)
     return _JSCModel(idl_schema.IDLSchema(idl).process()[0],
                      self._ref_resolver_factory.Create()
                      if not disable_refs else None,
                      disable_refs,
                      idl=True).ToDict()
예제 #3
0
    def Process(self, path, file_data):
        '''Parses |file_data| using a method determined by checking the
    extension of the file at the given |path|. Then, trims 'nodoc' and if
    |self.retain_inlined_types| is given and False, removes inlineable types
    from the parsed schema data.
    '''
        def trim_and_inline(schema, is_idl=False):
            '''Modifies an API schema in place by removing nodes that shouldn't be
      documented and inlining schema types that are only referenced once.
      '''
            if self._RemoveNoDocs(schema):
                # A return of True signifies that the entire schema should not be
                # documented. Otherwise, only nodes that request 'nodoc' are removed.
                return None
            if is_idl:
                self._DetectInlineableTypes(schema)
            self._InlineDocs(schema)
            return schema

        if path.endswith('.idl'):
            idl = idl_schema.IDLSchema(
                idl_parser.IDLParser().ParseData(file_data))
            # Wrap the result in a list so that it behaves like JSON API data.
            return [trim_and_inline(idl.process()[0], is_idl=True)]

        try:
            schemas = json_parse.Parse(file_data)
        except:
            raise ValueError('Cannot parse "%s" as JSON:\n%s' %
                             (path, traceback.format_exc()))
        for schema in schemas:
            # Schemas could consist of one API schema (data for a specific API file)
            # or multiple (data from extension_api.json).
            trim_and_inline(schema)
        return schemas
예제 #4
0
 def Process(self, path, file_data):
     if path.endswith('.idl'):
         idl = idl_schema.IDLSchema(
             idl_parser.IDLParser().ParseData(file_data))
         # Wrap the result in a list so that it behaves like JSON API data.
         return [idl.process()[0]]
     return json_parse.Parse(file_data)
 def _LoadIdlAPI(self, api, disable_refs):
     idl = idl_parser.IDLParser().ParseData(api)
     return _JSCModel(idl_schema.IDLSchema(idl).process()[0],
                      self._ref_resolver_factory.Create()
                      if not disable_refs else None,
                      disable_refs,
                      self._availability_finder,
                      self._parse_cache,
                      self._template_data_source,
                      idl=True).ToDict()
예제 #6
0
 def _LoadIdlAPI(self, api):
     idl = idl_parser.IDLParser().ParseData(api)
     generator = HandlebarDictGenerator(
         idl_schema.IDLSchema(idl).process()[0])
     return generator.Generate()
예제 #7
0
 def _LoadIdlAPI(self, api):
   idl = idl_parser.IDLParser().ParseData(api)
   return _JscModel(idl_schema.IDLSchema(idl).process()[0])