Skip to content

Instantly share code, notes, and snippets.

@wudi
Last active June 14, 2016 07:22
Show Gist options
  • Save wudi/c920cad17de09f2d51bff0c45c3f2ecd to your computer and use it in GitHub Desktop.
Save wudi/c920cad17de09f2d51bff0c45c3f2ecd to your computer and use it in GitHub Desktop.
QingCloudDoc2ThriftIDL
var typeConvert = function(t){
switch(t) {
case "String":
case "TimeStamp":
return "string";
case "Integer":
return "i32";
case "Array":
return "list<string>";
default:
return "<unknown>";
}
};
$('h1').find("a").remove();
var structName = $('h1').text();
$('.docutils > tbody').each(function(k, v) {
var struct = "struct " + structName + "Request {\n";
$.each($(v).find("tr"), function(k, tr) {
tds = $(tr).find('td');
var name = $(tds).eq(0).text();
var type = $(tds).eq(1).text();
var required = $(tds).eq(3).text() == "Yes" ? "required " : "";
idx = k+1;
var t = typeConvert(type);
if (name.indexOf(".n") != -1){
t = "list<"+t+">";
name = name.replace(".n", "");
}
struct += "\t"+idx+": "+required+t+ " "+ name+"\n";
});
struct += "}";
console.log(struct);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment