From 0c5f66b53fbc118579339a154e45df58e078534f Mon Sep 17 00:00:00 2001 From: wjmcat <1435130236@qq.com> Date: Sat, 27 Jun 2020 13:53:02 +0800 Subject: [PATCH] add examples --- .gitignore | 3 +- README.md | 21 +++++-- examples/config/base_model.json | 16 +++-- examples/generate.sh | 5 ++ examples/plugins/base.plugin.jinja2 | 11 ++-- examples/templates/index.html.jinja2 | 15 ----- examples/templates/user_add.vue.jinja2 | 80 +++++++++++++++++++++++++ examples/templates/user_edit.vue.jinja2 | 80 +++++++++++++++++++++++++ src/code_generator/loader.py | 1 + src/code_generator/main.py | 2 +- 10 files changed, 202 insertions(+), 32 deletions(-) create mode 100755 examples/generate.sh delete mode 100644 examples/templates/index.html.jinja2 create mode 100644 examples/templates/user_add.vue.jinja2 create mode 100644 examples/templates/user_edit.vue.jinja2 diff --git a/.gitignore b/.gitignore index 997ec81..85d5a14 100644 --- a/.gitignore +++ b/.gitignore @@ -128,4 +128,5 @@ dmypy.json # Pyre type checker .pyre/ build.sh -.idea/ \ No newline at end of file +.idea/ +./src/code_generator.egg-info/ \ No newline at end of file diff --git a/README.md b/README.md index 821f3a4..170df39 100644 --- a/README.md +++ b/README.md @@ -16,17 +16,28 @@ ## quick start -1 . install command +1 . clone the repo ```shell script -pip install code-generator +git clone https://github.com/wj-Mcat/code-generator ``` -2 . prepare `templates`, `plugins`, `config` +2 . run the example generation -you should set the prepared +```shell script +./examples/generate.sh +``` + +3 . [Optional] change the template to generate your own code + +> you can change the code in `examples/config`, `examples/plugins`, `examples/templates` -3 . generate codes +## command description +> you don't need to write any code to run `code-generator`, only for configuration, templates, plugins + +```shell script + +``` ## changelog diff --git a/examples/config/base_model.json b/examples/config/base_model.json index b567319..50d68b6 100644 --- a/examples/config/base_model.json +++ b/examples/config/base_model.json @@ -1,10 +1,18 @@ { - "model": "基础模型", + "model": "user", + "description": "用户管理", "columns": [{ - "name": "1" + "field": "name", + "description": "姓名", + "type": "str" },{ - "name": "22" + "field": "sex", + "description": "性别", + "type": "int" },{ - "name": "33" + "field": "role_id", + "description": "角色", + "type": "str", + "plugin": "auto_complete" }] } \ No newline at end of file diff --git a/examples/generate.sh b/examples/generate.sh new file mode 100755 index 0000000..af1778d --- /dev/null +++ b/examples/generate.sh @@ -0,0 +1,5 @@ +pip install code-generator +code-gen render \ + --config=./config/base_model.json \ + --plugins=./plugins \ + --templates=./templates \ No newline at end of file diff --git a/examples/plugins/base.plugin.jinja2 b/examples/plugins/base.plugin.jinja2 index 075e8ac..7af784b 100644 --- a/examples/plugins/base.plugin.jinja2 +++ b/examples/plugins/base.plugin.jinja2 @@ -1,10 +1,9 @@ {%- macro number_input(column) -%} -