From 43d14a0f7a2d43c53266ad1cef502712f75c57ee Mon Sep 17 00:00:00 2001 From: Tit Petric Date: Sun, 1 Jul 2018 00:40:35 +0200 Subject: [PATCH] import docs gen, initial crm specs for types --- crm/_gen.php | 71 ++ crm/docs/README.md | 30 + crm/docs/README.php | 66 ++ crm/docs/README.tpl | 31 + crm/docs/composer.json | 5 + crm/docs/composer.lock | 67 ++ crm/docs/src/spec.json | 31 + crm/docs/src/spec/types.json | 40 + crm/docs/vendor/autoload.php | 7 + crm/docs/vendor/composer/ClassLoader.php | 413 +++++++++ crm/docs/vendor/composer/LICENSE | 21 + .../vendor/composer/autoload_classmap.php | 9 + .../vendor/composer/autoload_namespaces.php | 10 + crm/docs/vendor/composer/autoload_psr4.php | 9 + crm/docs/vendor/composer/autoload_real.php | 52 ++ crm/docs/vendor/composer/autoload_static.php | 26 + crm/docs/vendor/composer/installed.json | 52 ++ crm/docs/vendor/monotek/minitpl/.gitignore | 2 + crm/docs/vendor/monotek/minitpl/.gitmodules | 3 + .../vendor/monotek/minitpl/README.markdown | 37 + .../minitpl/code/Monotek/MiniTPL/Compiler.php | 345 ++++++++ .../minitpl/code/Monotek/MiniTPL/Template.php | 182 ++++ crm/docs/vendor/monotek/minitpl/composer.json | 34 + .../documentation/documentation_en.markdown | 783 ++++++++++++++++++ .../documentation/documentation_sl.markdown | 705 ++++++++++++++++ crm/docs/vendor/monotek/minitpl/phpunit.xml | 22 + .../vendor/monotek/minitpl/test/.gitignore | 1 + .../monotek/minitpl/test/TemplateTest.php | 128 +++ .../vendor/monotek/minitpl/test/bootstrap.php | 7 + .../minitpl/test/compiled/01_variable.tpl | 16 + .../minitpl/test/compiled/02_arrays.tpl | 18 + .../minitpl/test/compiled/03_modifiers.tpl | 44 + .../minitpl/test/compiled/04_objects.tpl | 56 ++ .../minitpl/test/compiled/05_constants.tpl | 15 + .../minitpl/test/compiled/06_includes.tpl | 17 + .../monotek/minitpl/test/compiled/07_eval.tpl | 12 + .../minitpl/test/compiled/08_utf8_bom.tpl | 8 + .../test/compiled/09_blocks_and_includes.tpl | 18 + .../test/compiled/10_literal_blocks.tpl | 23 + .../minitpl/test/compiled/11_expressions.tpl | 15 + .../test/compiled/12_global_objects.tpl | 9 + .../test/compiled/13_foreach_array.tpl | 7 + .../minitpl/test/templates/01_variable.tpl | 10 + .../minitpl/test/templates/02_arrays.tpl | 13 + .../minitpl/test/templates/03_modifiers.tpl | 43 + .../minitpl/test/templates/04_objects.tpl | 53 ++ .../minitpl/test/templates/05_constants.tpl | 13 + .../minitpl/test/templates/06_includes.tpl | 3 + .../minitpl/test/templates/07_eval.tpl | 12 + .../minitpl/test/templates/08_utf8_bom.tpl | 5 + .../test/templates/09_blocks_and_includes.tpl | 19 + .../test/templates/10_literal_blocks.tpl | 20 + .../minitpl/test/templates/11_expressions.tpl | 11 + .../test/templates/12_global_objects.tpl | 6 + .../test/templates/13_foreach_array.tpl | 13 + .../test/templates2/fail_to_compile.tpl | 0 crm/routes.go | 13 + crm/templates/http_.tpl | 11 + crm/templates/http_handlers.tpl | 14 + crm/templates/http_interfaces.tpl | 34 + crm/templates/http_request.tpl | 43 + crm/templates/http_routes.tpl | 18 + crm/templates/http_structs.tpl | 30 + crm/types.go | 12 + crm/types.handlers.go | 16 + crm/types.interfaces.go | 32 + crm/types.request.go | 56 ++ crm/types.structs.go | 19 + 68 files changed, 3966 insertions(+) create mode 100755 crm/_gen.php create mode 100644 crm/docs/README.md create mode 100755 crm/docs/README.php create mode 100644 crm/docs/README.tpl create mode 100644 crm/docs/composer.json create mode 100644 crm/docs/composer.lock create mode 100644 crm/docs/src/spec.json create mode 100644 crm/docs/src/spec/types.json create mode 100644 crm/docs/vendor/autoload.php create mode 100644 crm/docs/vendor/composer/ClassLoader.php create mode 100644 crm/docs/vendor/composer/LICENSE create mode 100644 crm/docs/vendor/composer/autoload_classmap.php create mode 100644 crm/docs/vendor/composer/autoload_namespaces.php create mode 100644 crm/docs/vendor/composer/autoload_psr4.php create mode 100644 crm/docs/vendor/composer/autoload_real.php create mode 100644 crm/docs/vendor/composer/autoload_static.php create mode 100644 crm/docs/vendor/composer/installed.json create mode 100644 crm/docs/vendor/monotek/minitpl/.gitignore create mode 100644 crm/docs/vendor/monotek/minitpl/.gitmodules create mode 100644 crm/docs/vendor/monotek/minitpl/README.markdown create mode 100644 crm/docs/vendor/monotek/minitpl/code/Monotek/MiniTPL/Compiler.php create mode 100644 crm/docs/vendor/monotek/minitpl/code/Monotek/MiniTPL/Template.php create mode 100644 crm/docs/vendor/monotek/minitpl/composer.json create mode 100644 crm/docs/vendor/monotek/minitpl/documentation/documentation_en.markdown create mode 100644 crm/docs/vendor/monotek/minitpl/documentation/documentation_sl.markdown create mode 100644 crm/docs/vendor/monotek/minitpl/phpunit.xml create mode 100644 crm/docs/vendor/monotek/minitpl/test/.gitignore create mode 100644 crm/docs/vendor/monotek/minitpl/test/TemplateTest.php create mode 100644 crm/docs/vendor/monotek/minitpl/test/bootstrap.php create mode 100644 crm/docs/vendor/monotek/minitpl/test/compiled/01_variable.tpl create mode 100644 crm/docs/vendor/monotek/minitpl/test/compiled/02_arrays.tpl create mode 100644 crm/docs/vendor/monotek/minitpl/test/compiled/03_modifiers.tpl create mode 100644 crm/docs/vendor/monotek/minitpl/test/compiled/04_objects.tpl create mode 100644 crm/docs/vendor/monotek/minitpl/test/compiled/05_constants.tpl create mode 100644 crm/docs/vendor/monotek/minitpl/test/compiled/06_includes.tpl create mode 100644 crm/docs/vendor/monotek/minitpl/test/compiled/07_eval.tpl create mode 100644 crm/docs/vendor/monotek/minitpl/test/compiled/08_utf8_bom.tpl create mode 100644 crm/docs/vendor/monotek/minitpl/test/compiled/09_blocks_and_includes.tpl create mode 100644 crm/docs/vendor/monotek/minitpl/test/compiled/10_literal_blocks.tpl create mode 100644 crm/docs/vendor/monotek/minitpl/test/compiled/11_expressions.tpl create mode 100644 crm/docs/vendor/monotek/minitpl/test/compiled/12_global_objects.tpl create mode 100644 crm/docs/vendor/monotek/minitpl/test/compiled/13_foreach_array.tpl create mode 100644 crm/docs/vendor/monotek/minitpl/test/templates/01_variable.tpl create mode 100644 crm/docs/vendor/monotek/minitpl/test/templates/02_arrays.tpl create mode 100644 crm/docs/vendor/monotek/minitpl/test/templates/03_modifiers.tpl create mode 100644 crm/docs/vendor/monotek/minitpl/test/templates/04_objects.tpl create mode 100644 crm/docs/vendor/monotek/minitpl/test/templates/05_constants.tpl create mode 100644 crm/docs/vendor/monotek/minitpl/test/templates/06_includes.tpl create mode 100644 crm/docs/vendor/monotek/minitpl/test/templates/07_eval.tpl create mode 100644 crm/docs/vendor/monotek/minitpl/test/templates/08_utf8_bom.tpl create mode 100644 crm/docs/vendor/monotek/minitpl/test/templates/09_blocks_and_includes.tpl create mode 100644 crm/docs/vendor/monotek/minitpl/test/templates/10_literal_blocks.tpl create mode 100644 crm/docs/vendor/monotek/minitpl/test/templates/11_expressions.tpl create mode 100644 crm/docs/vendor/monotek/minitpl/test/templates/12_global_objects.tpl create mode 100644 crm/docs/vendor/monotek/minitpl/test/templates/13_foreach_array.tpl create mode 100644 crm/docs/vendor/monotek/minitpl/test/templates2/fail_to_compile.tpl create mode 100644 crm/routes.go create mode 100644 crm/templates/http_.tpl create mode 100644 crm/templates/http_handlers.tpl create mode 100644 crm/templates/http_interfaces.tpl create mode 100644 crm/templates/http_request.tpl create mode 100644 crm/templates/http_routes.tpl create mode 100644 crm/templates/http_structs.tpl create mode 100644 crm/types.go create mode 100644 crm/types.handlers.go create mode 100644 crm/types.interfaces.go create mode 100644 crm/types.request.go create mode 100644 crm/types.structs.go 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: