diff --git a/crm/_gen.php b/crm/_gen.php new file mode 100755 index 000000000..67d36e671 --- /dev/null +++ b/crm/_gen.php @@ -0,0 +1,71 @@ +#!/usr/bin/env php +set_compile_location("/tmp", true); +$tpl->add_default("newline", "\n"); + +$api_files = glob("docs/src/spec/*.json"); +$apis = array_map(function($filename) { + return array_change_key_case_recursive(json_decode(file_get_contents($filename), true)); +}, $api_files); + +usort($apis, function($a, $b) { + return strcmp($a['interface'], $b['interface']); +}); + +foreach (array("structs", "handlers", "interfaces", "request", "") as $type) { + foreach ($apis as $api) { + if (!empty($api['struct'])) { + $name = ucfirst($api['interface']); + $filename = str_replace("..", ".", strtolower($name) . "." . $type . ".go"); + + $tpl->load("http_$type.tpl"); + $tpl->assign("parsers", array( + "uint64" => "parseUInt64" + )); + $tpl->assign("package", $api['package']); + $tpl->assign("name", $name); + $tpl->assign("self", strtolower(substr($name, 0, 1))); + $tpl->assign("api", $api); + $tpl->assign("fields", $api['struct']); + $tpl->assign("calls", $api['apis']); + $contents = $tpl->get(); + + $save = true; + if ($type === "" && file_exists($filename)) { + $save = false; + } + if ($save) { + file_put_contents($filename, $contents); + } + } + } +} + +foreach (array("routes") as $type) { + $name = ucfirst($api['interface']); + $filename = str_replace("..", ".", $type . ".go"); + + $tpl->load("http_$type.tpl"); + $tpl->assign("package", reset($apis)['package']); + $tpl->assign("apis", $apis); + $contents = $tpl->get(); + + file_put_contents($filename, $contents); +} + +passthru("go fmt"); \ No newline at end of file diff --git a/crm/docs/README.md b/crm/docs/README.md new file mode 100644 index 000000000..7fe802d6a --- /dev/null +++ b/crm/docs/README.md @@ -0,0 +1,30 @@ +# Types + +Types are building blocks for module forms + +## List available types + +#### Method + +| URI | Protocol | Method | Authentication | +| --- | -------- | ------ | -------------- | +| `/types/list` | HTTP/S | GET | | + +#### Request parameters + +| Parameter | Type | Method | Description | Default | Required? | +| --------- | ---- | ------ | ----------- | ------- | --------- | + +## Get type details + +#### Method + +| URI | Protocol | Method | Authentication | +| --- | -------- | ------ | -------------- | +| `/types/type/{id}` | HTTP/S | GET | | + +#### Request parameters + +| Parameter | Type | Method | Description | Default | Required? | +| --------- | ---- | ------ | ----------- | ------- | --------- | +| id | string | PATH | Type ID | N/A | YES | \ No newline at end of file diff --git a/crm/docs/README.php b/crm/docs/README.php new file mode 100755 index 000000000..269d69adc --- /dev/null +++ b/crm/docs/README.php @@ -0,0 +1,66 @@ +#!/usr/bin/php + $v) { + if ($v === "") { + if ($empty) { + unset($lines[$k]); + } + $empty = true; + continue; + } + $empty = false; + } + $contents = implode("\n", $lines); + $contents = str_replace("`\n|", "` |", $contents); + $contents = preg_replace("/^# /sm", "\n\n\n# ", $contents); + return trim($contents); +} + +$spec = json_decode(file_get_contents("src/spec.json"), true); + +$apis = array(); +foreach ($spec as $api) { + $entrypoint = $api['entrypoint']; + $filename = "src/spec/" . $entrypoint . ".json"; + $filename_md = "src/" . $entrypoint . "/index.md"; + $api = json_decode(file_get_contents($filename), true); + $api = array_change_key_case_recursive($api); + if (file_exists($filename_md)) { + $api['description'] = file_get_contents($filename_md); + } + $calls = array(); + foreach ($api['apis'] as $call) { + $name = $call['name']; + $filename_md = "src/" . $entrypoint . "/" . $name . ".md"; + if (file_exists($filename_md)) { + $call['description'] = file_get_contents($filename_md); + } + $calls[$name] = $call; + } + $api['apis'] = $calls; + $apis[] = $api; +} + +$tpl = new Monotek\MiniTPL\Template; +$tpl->set_compile_location("/tmp", true); +$tpl->set_paths("./"); +$tpl->load("README.tpl"); +$tpl->assign("apis", $apis); +file_put_contents("README.md", cleanUp($tpl->get())); \ No newline at end of file diff --git a/crm/docs/README.tpl b/crm/docs/README.tpl new file mode 100644 index 000000000..4960f1e1b --- /dev/null +++ b/crm/docs/README.tpl @@ -0,0 +1,31 @@ +{foreach $apis as $api} +# {api.title} + +{api.description} + +{foreach $api.apis as $name => $call} + ## {call.title} + + {call.description} + + #### Method + + | URI | Protocol | Method | Authentication | + | --- | -------- | ------ | -------------- | + | `{api.path}{call.path}` | {if $api.protocol}{api.protocol}{else}HTTP/S{/if} | {call.method} | {eval echo implode(", ", $api.authentication)} | + + #### Request parameters + + | Parameter | Type | Method | Description | Default | Required? | + | --------- | ---- | ------ | ----------- | ------- | --------- | + {foreach $call.parameters as $method => $params} + {foreach $params as $param} + | {param.name} | {param.type} | {method|toupper} | {param.title} | {if empty($param.default)}N/A{else}{param.default}{/if} +{if $param.values}

Values: