-
-
Save jdlangs/c116f6e80db79d394e42 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
class_names = [ | |
("Foo", ["bar", "baz"]), | |
("RJ", ["eat", "praps", "f"]), | |
] | |
file_str = "class.js" | |
def writeclass(file, name, members): | |
class_str = "\nvar %s = blah" | |
member_str = """ | |
%s.%s = { | |
get: function() { | |
return this.d_%s; | |
}, | |
set: function(val) { | |
this.d_%s = val; | |
} | |
}; | |
""" | |
init_beg_str = "\n%s.init = function(val) {\n" | |
init_end_str = "};\n" | |
init_mem_str = " this.%s = new %s(val.%s);\n" | |
file.write(class_str % name) | |
file.write(init_beg_str % name) | |
for m in members: | |
strs = (m, m.capitalize(), m) | |
file.write(init_mem_str % strs) | |
file.write(init_end_str) | |
for m in members: | |
strs = (name, m, m, m) | |
file.write(member_str % strs) | |
def main(): | |
print("Writing: ") | |
for c in class_names: | |
print("\t" + str(c)) | |
print("to file: " + file_str) | |
file = open(file_str, "w") | |
for class_info in class_names: | |
writeclass(file, class_info[0], class_info[1]) | |
file.close() | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment