~ubuntu-branches/ubuntu/vivid/kate/vivid-proposed

« back to all changes in this revision

Viewing changes to addons/kate/pate/src/plugins/js_utils/js_autocomplete.gen

  • Committer: Package Import Robot
  • Author(s): Jonathan Riddell
  • Date: 2014-12-04 16:49:41 UTC
  • mfrom: (1.6.6)
  • Revision ID: package-import@ubuntu.com-20141204164941-l3qbvsly83hhlw2v
Tags: 4:14.11.97-0ubuntu1
* New upstream release
* Update build-deps and use pkg-kde v3 for Qt 5 build
* kate-data now kate5-data for co-installability

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* js_autocomplete.json file was generated with this script: */
2
 
function kateGetCategory(child, childKey) {
3
 
    if (!child) {
4
 
        return "constant";
5
 
    }
6
 
    try {
7
 
        var repr = child.toString();
8
 
    } catch(e) {
9
 
        return "constant";
10
 
    }
11
 
    if (repr == "[object "+ childKey +"]" ) {
12
 
        return "class";
13
 
    } else if (repr.indexOf("[object ") != -1) {
14
 
        return "module";
15
 
    }
16
 
    if (typeof(child) == "function") {
17
 
        return "function";
18
 
    }
19
 
    return "constant";
20
 
}
21
 
 
22
 
function kateGetArgs(child) {
23
 
    var args = "";
24
 
    try {
25
 
        var firstLine = child.toString().split("\n")[0];
26
 
        var arg1 = firstLine.indexOf("(") + 1;
27
 
        var arg2 = firstLine.indexOf(")");
28
 
        args = firstLine.substring(arg1, arg2);
29
 
        if (args) {
30
 
            args = "(" + args + ")";
31
 
        }
32
 
    } catch(e) {
33
 
    }
34
 
    return args;
35
 
}
36
 
 
37
 
function kateGetJSAutocomplete(obj, levelmax, level, dict) {
38
 
    if (!dict) {
39
 
        dict = {}
40
 
    }
41
 
    if (level == undefined) {
42
 
        level = 0;
43
 
    } else {
44
 
        level++;
45
 
    }
46
 
    for (var childKey in obj){
47
 
        children = {};
48
 
        var child = null;
49
 
        var childKeyInt = parseInt(childKey);
50
 
 
51
 
        if (childKey != "window" && childKey.indexOf("kateGet") == -1 && !childKeyInt && childKeyInt!=0) {
52
 
            try {
53
 
                child = obj[childKey];
54
 
                if (level < levelmax) {
55
 
                    children = kateGetJSAutocomplete(child, levelmax, level, children);
56
 
                }
57
 
            } catch(e) {
58
 
            }
59
 
            dict[childKey] = {"children": children};
60
 
            if (child != undefined) {
61
 
                var category = kateGetCategory(child, childKey);
62
 
                dict[childKey]["category"] = category;
63
 
                if (category == "function") {
64
 
                    var args = kateGetArgs(child);
65
 
                    if (args) {
66
 
                        dict[childKey]["args"] = kateGetArgs(child);
67
 
                    }
68
 
                }
69
 
            } else {
70
 
                dict[childKey]["category"] = "constant";
71
 
            }
72
 
        }
73
 
    }
74
 
    return dict
75
 
}
76
 
 
77
 
result = JSON.stringify(kateGetJSAutocomplete(window, 2))
78
 
 
79
 
/* After in a python shell (pretty json): */
80
 
import simplejson
81
 
file_path = "./js_autocomplete.json"
82
 
json_text = open(file_path).read()
83
 
file = open(file_path, "w")
84
 
target = simplejson.dumps(simplejson.loads(json_text), indent=2)
85
 
file.write(target)
86
 
file.close()