diff options
| author | Juan Linietsky | 2017-09-12 17:42:36 -0300 |
|---|---|---|
| committer | Juan Linietsky | 2017-09-12 17:45:41 -0300 |
| commit | 4f929a0fdfae24b1ca5acf0b732219119090ee43 (patch) | |
| tree | 730471182cae00f2e47c7430db441d057383d29b /editor | |
| parent | 175777596ec3521731665dd750fd7087793b10fc (diff) | |
| download | godot-4f929a0fdfae24b1ca5acf0b732219119090ee43.tar.gz godot-4f929a0fdfae24b1ca5acf0b732219119090ee43.tar.zst godot-4f929a0fdfae24b1ca5acf0b732219119090ee43.zip | |
Changed the doc class generation to individual files per class. It is also possible to save module files in module directories and the build system will
recognize them.
Diffstat (limited to 'editor')
| -rw-r--r-- | editor/SCsub | 35 | ||||
| -rw-r--r-- | editor/doc/doc_data.cpp | 126 | ||||
| -rw-r--r-- | editor/doc/doc_data.h | 7 |
3 files changed, 121 insertions, 47 deletions
diff --git a/editor/SCsub b/editor/SCsub index 0e690cf46..839d8e74c 100644 --- a/editor/SCsub +++ b/editor/SCsub @@ -41,11 +41,8 @@ def make_doc_header(target, source, env): src = s.srcnode().abspath f = open_utf8(src, "r") content = f.read() - buf += content[content.find("<class"): content.rfind("</doc>")] - if len(docbegin) == 0: - docbegin = content[0: content.find("<class")] - if len(docend) == 0: - docend = content[content.rfind("</doc>"): len(buf)] + buf+=content + buf = encode_utf8(docbegin + buf + docend) decomp_size = len(buf) import zlib @@ -60,6 +57,7 @@ def make_doc_header(target, source, env): for i in range(len(buf)): g.write(byte_to_str(buf[i]) + ",\n") g.write("};\n") + g.write("#endif") @@ -385,6 +383,18 @@ def make_license_header(target, source, env): g.write("#endif\n") + +def _make_doc_data_class_path(to_path): + g = open_utf8(os.path.join(to_path,"doc_data_class_path.gen.h"), "wb") + g.write("static const int _doc_data_class_path_count="+str(len(env.doc_class_path))+";\n") + g.write("struct _DocDataClassPath { const char* name; const char* path; };\n") + + g.write("static const _DocDataClassPath _doc_data_class_paths["+str(len(env.doc_class_path)+1)+"]={\n"); + for c in env.doc_class_path: + g.write("{\""+c+"\",\""+env.doc_class_path[c]+"\"},\n") + g.write("{NULL,NULL}\n") + g.write("};\n") + if (env["tools"] == "yes"): # Register exporters @@ -401,16 +411,15 @@ if (env["tools"] == "yes"): f.close() # API documentation - docs = ["#doc/base/classes.xml"] - moduledir = os.path.join(os.getcwd(), "..", "modules") - for m in os.listdir(moduledir): - curmodle = os.path.join(moduledir, m) - docfile = os.path.join(curmodle, "classes.xml") - if os.path.isdir(curmodle) and os.path.isfile(docfile): - docs.append(docfile) + docs=[] + print("cdir is: "+env.Dir('#').abspath) + for f in os.listdir(os.path.join(env.Dir('#').abspath,"doc/classes")): + docs.append("#doc/classes/"+f) + + _make_doc_data_class_path(os.path.join(env.Dir('#').abspath,"editor/doc")) + env.Depends("#editor/doc_data_compressed.gen.h", docs) env.Command("#editor/doc_data_compressed.gen.h", docs, make_doc_header) - # Certificates env.Depends("#editor/certs_compressed.gen.h", "#thirdparty/certs/ca-certificates.crt") env.Command("#editor/certs_compressed.gen.h", "#thirdparty/certs/ca-certificates.crt", make_certs_header) diff --git a/editor/doc/doc_data.cpp b/editor/doc/doc_data.cpp index 6848c43b6..dd2eeaa5c 100644 --- a/editor/doc/doc_data.cpp +++ b/editor/doc/doc_data.cpp @@ -32,6 +32,7 @@ #include "global_constants.h" #include "io/compression.h" #include "io/marshalls.h" +#include "os/dir_access.h" #include "project_settings.h" #include "scene/resources/theme.h" #include "script_language.h" @@ -50,6 +51,8 @@ void DocData::merge_from(const DocData &p_data) { c.description = cf.description; c.brief_description = cf.brief_description; + c.tutorials = cf.tutorials; + c.demos =cf.demos; for (int i = 0; i < c.methods.size(); i++) { @@ -675,36 +678,72 @@ static Error _parse_methods(Ref<XMLParser> &parser, Vector<DocData::MethodDoc> & return OK; } -Error DocData::load(const String &p_path) { +Error DocData::load_classes(const String &p_dir) { - Ref<XMLParser> parser = memnew(XMLParser); - Error err = parser->open(p_path); - if (err) + Error err; + DirAccessRef da = DirAccess::open(p_dir,&err); + if (!da) { return err; - return _load(parser); -} -Error DocData::_load(Ref<XMLParser> parser) { + } - Error err = OK; + da->list_dir_begin(); + String path; + bool isdir; + path=da->get_next(&isdir); + while(path!=String()) { + if (!isdir && path.ends_with("xml")) { + Ref<XMLParser> parser = memnew(XMLParser); + Error err = parser->open(p_dir.plus_file(path)); + if (err) + return err; - while ((err = parser->read()) == OK) { + _load(parser); + } + path=da->get_next(&isdir); + } - if (parser->get_node_type() == XMLParser::NODE_ELEMENT) { + da->list_dir_end(); - if (parser->get_node_name() == "doc") { - break; - } else if (!parser->is_empty()) - parser->skip_section(); // unknown section, likely headers + return OK; +} +Error DocData::erase_classes(const String &p_dir) { + + Error err; + DirAccessRef da = DirAccess::open(p_dir,&err); + if (!da) { + return err; + } + + List<String> to_erase; + + da->list_dir_begin(); + String path; + bool isdir; + path=da->get_next(&isdir); + while(path!=String()) { + if (!isdir && path.ends_with("xml")) { + to_erase.push_back(path); } + path=da->get_next(&isdir); } + da->list_dir_end(); - if (parser->has_attribute("version")) - version = parser->get_attribute_value("version"); + while(to_erase.size()) { + da->remove(to_erase.front()->get()); + to_erase.pop_front(); + } + + return OK; +} +Error DocData::_load(Ref<XMLParser> parser) { + + Error err = OK; while ((err = parser->read()) == OK) { - if (parser->get_node_type() == XMLParser::NODE_ELEMENT_END && parser->get_node_name() == "doc") - break; //end of <doc> + if (parser->get_node_type() == XMLParser::NODE_ELEMENT && parser->get_node_name() == "?xml") { + parser->skip_section(); + } if (parser->get_node_type() != XMLParser::NODE_ELEMENT) continue; //no idea what this may be, but skipping anyway @@ -739,6 +778,14 @@ Error DocData::_load(Ref<XMLParser> parser) { parser->read(); if (parser->get_node_type() == XMLParser::NODE_TEXT) c.description = parser->get_node_data().strip_edges(); + } else if (name == "tutorials") { + parser->read(); + if (parser->get_node_type() == XMLParser::NODE_TEXT) + c.tutorials = parser->get_node_data().strip_edges(); + } else if (name == "demos") { + parser->read(); + if (parser->get_node_type() == XMLParser::NODE_TEXT) + c.demos = parser->get_node_data().strip_edges(); } else if (name == "methods") { Error err = _parse_methods(parser, c.methods); @@ -867,24 +914,33 @@ static void _write_string(FileAccess *f, int p_tablevel, const String &p_string) f->store_string(tab + p_string + "\n"); } -Error DocData::save(const String &p_path) { +Error DocData::save_classes(const String &p_default_path, const Map<String,String>& p_class_path) { - Error err; - FileAccess *f = FileAccess::open(p_path, FileAccess::WRITE, &err); - if (err) { - ERR_EXPLAIN("Can't write doc file: " + p_path); + for (Map<String, ClassDoc>::Element *E = class_list.front(); E; E = E->next()) { - ERR_FAIL_V(err); - } - _write_string(f, 0, "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>"); - _write_string(f, 0, "<doc version=\"" + String(VERSION_MKSTRING) + "\" name=\"Engine Types\">"); - - for (Map<String, ClassDoc>::Element *E = class_list.front(); E; E = E->next()) { ClassDoc &c = E->get(); + String save_path; + if (p_class_path.has(c.name)) { + save_path=p_class_path[c.name]; + } else { + save_path=p_default_path; + } + + Error err; + String save_file = save_path.plus_file(c.name+".xml"); + FileAccessRef f = FileAccess::open(save_file, FileAccess::WRITE, &err); + if (err) { + ERR_EXPLAIN("Can't write doc file: " + save_file); + + ERR_FAIL_V(err); + } + + _write_string(f, 0, "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>"); + String header = "<class name=\"" + c.name + "\""; if (c.inherits != "") header += " inherits=\"" + c.inherits + "\""; @@ -893,6 +949,7 @@ Error DocData::save(const String &p_path) { if (c.category == "") category = "Core"; header += " category=\"" + category + "\""; + header+=" version=\"" + String(VERSION_MKSTRING) + "\""; header += ">"; _write_string(f, 0, header); _write_string(f, 1, "<brief_description>"); @@ -903,6 +960,14 @@ Error DocData::save(const String &p_path) { if (c.description != "") _write_string(f, 2, c.description.xml_escape()); _write_string(f, 1, "</description>"); + _write_string(f, 1, "<tutorials>"); + if (c.tutorials != "") + _write_string(f, 2, c.tutorials.xml_escape()); + _write_string(f, 1, "</tutorials>"); + _write_string(f, 1, "<demos>"); + if (c.demos != "") + _write_string(f, 2, c.demos.xml_escape()); + _write_string(f, 1, "</demos>"); _write_string(f, 1, "<methods>"); c.methods.sort(); @@ -1035,9 +1100,6 @@ Error DocData::save(const String &p_path) { _write_string(f, 0, "</class>"); } - _write_string(f, 0, "</doc>"); - f->close(); - memdelete(f); return OK; } diff --git a/editor/doc/doc_data.h b/editor/doc/doc_data.h index efb4ea304..5f94fe17f 100644 --- a/editor/doc/doc_data.h +++ b/editor/doc/doc_data.h @@ -85,6 +85,8 @@ public: String category; String brief_description; String description; + String tutorials; + String demos; Vector<MethodDoc> methods; Vector<MethodDoc> signals; Vector<ConstantDoc> constants; @@ -101,8 +103,9 @@ public: void merge_from(const DocData &p_data); void remove_from(const DocData &p_data); void generate(bool p_basic_types = false); - Error load(const String &p_path); - Error save(const String &p_path); + Error load_classes(const String &p_dir); + static Error erase_classes(const String &p_dir); + Error save_classes(const String &p_default_path,const Map<String,String>& p_class_path); Error load_compressed(const uint8_t *p_data, int p_compressed_size, int p_uncompressed_size); }; |
