Esempio n. 1
0
def build(project_path, document_path, root):
    dirhtml = htmlldr.load_part('dir')
    dirlinkshtml = u''
    if not root:
        dirlinkhtml = htmlldr.load_part('dirlink')
        dirlinkhtml = dirlinkhtml.replace(u'{{{{Link}}}}', u'../__dir__.html')
        dirlinkhtml = dirlinkhtml.replace(u'{{{{Name}}}}', u'..')
        dirlinkshtml = dirlinkshtml + dirlinkhtml
    if not os.path.exists(document_path):
        os.mkdir(document_path)
    dir_list = sorted(os.listdir(project_path))
    for item in dir_list:
        if item == '.' or item == '..' or item[0] == '.':
            continue
        full_path = os.path.join(project_path, item)
        if os.path.isfile(full_path) and (os.path.splitext(item)[1] == '.c' or
                                          os.path.splitext(item)[1] == '.h'):
            process(full_path, document_path)
            filelinkhtml = htmlldr.load_part('filelink')
            filelinkhtml = filelinkhtml.replace('{{{{Link}}}}', item + '.html')
            filelinkhtml = filelinkhtml.replace('{{{{FuncLink}}}}',
                                                '__func__%s.html' % item)
            filelinkhtml = filelinkhtml.replace('{{{{Name}}}}', item)
            dirlinkshtml = dirlinkshtml + filelinkhtml
        if os.path.isdir(full_path):
            build(os.path.join(project_path, item),
                  os.path.join(document_path, item), False)
            dirlinkhtml = htmlldr.load_part('dirlink')
            dirlinkhtml = dirlinkhtml.replace(u'{{{{Link}}}}',
                                              item + '/__dir__.html')
            dirlinkhtml = dirlinkhtml.replace(u'{{{{Name}}}}', item)
            dirlinkshtml = dirlinkshtml + dirlinkhtml
    indexhtml = htmlldr.load_part('index')
    of = codecs.open(os.path.join(document_path, 'index.html'), 'w', 'utf8')
    of.write(indexhtml)
    of.close()
    # 把目录信息写入文件
    dirhtml = dirhtml.replace(u'{{{{Links}}}}', dirlinkshtml)
    of = codecs.open(os.path.join(document_path, '__dir__.html'), 'w', 'utf8')
    of.write(dirhtml)
    of.close()
Esempio n. 2
0
 def get_html(self):
     fhtml = htmlldr.load_part(u'file')
     fhtml = fhtml.replace(u'{{{{Name}}}}', self.name)
     fhtml = fhtml.replace(u'{{{{Author}}}}', self.author)
     fhtml = fhtml.replace(u'{{{{Date}}}}', self.date)
     fhtml = fhtml.replace(u'{{{{Desc}}}}',
                           self.desc.replace('\n', '<br />'))
     funchtml = u''
     for func in self.funcs:
         funchtml = funchtml + func.get_html()
     fhtml = fhtml.replace(u'{{{{Functions}}}}', funchtml)
     return fhtml
Esempio n. 3
0
	def get_html(self):
		fhtml = htmlldr.load_part(u'function')
		fhtml = fhtml.replace(u'{{{{Name}}}}', self.name.strip())
		fhtml = fhtml.replace(u'{{{{Access}}}}', self.access)
		fhtml = fhtml.replace(u'{{{{Desc}}}}', self.desc.replace('\n', '<br />'))
		pshtml = u''
		for param in self.params:
			phtml = htmlldr.load_part(u'param')
			phtml = phtml.replace(u'{{{{Name}}}}', param['name'])
			phtml = phtml.replace(u'{{{{Type}}}}', param['type'])
			phtml = phtml.replace(u'{{{{InOut}}}}', param['inout'])
			phtml = phtml.replace(u'{{{{Desc}}}}', param['desc'])
			pshtml = pshtml + phtml
		fhtml = fhtml.replace(u'{{{{Params}}}}', pshtml)
		if self.ret != None:
			fhtml = fhtml.replace(u'{{{{RetType}}}}', self.ret['type'])
			fhtml = fhtml.replace(u'{{{{RetDesc}}}}', self.ret['desc'])
		else:
			fhtml = fhtml.replace(u'{{{{RetType}}}}', u'')
			fhtml = fhtml.replace(u'{{{{RetDesc}}}}', u'')
		return fhtml
Esempio n. 4
0
def process(path, document_path):
    STATE_NONE = 0
    STATE_FILE = 1
    STATE_FUNC = 2
    source_file = os.path.split(path)[1]
    target_file = source_file + '.html'
    funchtml = htmlldr.load_part('func')
    funclinkshtml = u''
    f = codecs.open(path, 'r', 'utf8')
    lines = []
    try:
        for line in f:
            lines.append(line.rstrip())
    except Exception, e:
        process_die(path, len(lines) + 1, "Invalid line")
        f.close()
Esempio n. 5
0
     comment = True
 # 处理 */。
 elif is_comment_end(line):
     if comment:
         if state == STATE_FILE:
             file_doc = filedoc.FileDoc(file_name, file_author,
                                        file_date, file_desc)
             file_name = u''
             file_author = u''
             file_date = u''
             file_desc = u''
         elif state == STATE_FUNC:
             if file_doc == None:
                 process_die(path, ln, 'Expect file comment')
             else:
                 funclinkhtml = htmlldr.load_part('funclink')
                 funclinkhtml = funclinkhtml.replace(
                     '{{{{File}}}}',
                     os.path.split(target_file)[1])
                 funclinkhtml = funclinkhtml.replace(
                     '{{{{Name}}}}', func_name.strip())
                 funclinkshtml = funclinkshtml + funclinkhtml
                 func_doc = funcdoc.FuncDoc(func_name, func_access,
                                            func_desc)
                 for func_param in func_params:
                     func_doc.add_param(func_param['arr'][0],
                                        func_param['arr'][1],
                                        func_param['arr'][2],
                                        func_param['desc'])
                 if func_ret_type != u'':
                     func_doc.set_ret(func_ret_type, func_ret_desc)