Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
_小猫_
code-generator
提交
0c5f66b5
C
code-generator
项目概览
_小猫_
/
code-generator
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
2
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
C
code-generator
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
2
合并请求
2
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
0c5f66b5
编写于
6月 27, 2020
作者:
W
wjmcat
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add examples
上级
2d91eab4
变更
10
隐藏空白更改
内联
并排
Showing
10 changed file
with
202 addition
and
32 deletion
+202
-32
.gitignore
.gitignore
+2
-1
README.md
README.md
+16
-5
examples/config/base_model.json
examples/config/base_model.json
+12
-4
examples/generate.sh
examples/generate.sh
+5
-0
examples/plugins/base.plugin.jinja2
examples/plugins/base.plugin.jinja2
+5
-6
examples/templates/index.html.jinja2
examples/templates/index.html.jinja2
+0
-15
examples/templates/user_add.vue.jinja2
examples/templates/user_add.vue.jinja2
+80
-0
examples/templates/user_edit.vue.jinja2
examples/templates/user_edit.vue.jinja2
+80
-0
src/code_generator/loader.py
src/code_generator/loader.py
+1
-0
src/code_generator/main.py
src/code_generator/main.py
+1
-1
未找到文件。
.gitignore
浏览文件 @
0c5f66b5
...
...
@@ -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
README.md
浏览文件 @
0c5f66b5
...
...
@@ -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
...
...
examples/config/base_model.json
浏览文件 @
0c5f66b5
{
"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
examples/generate.sh
0 → 100755
浏览文件 @
0c5f66b5
pip
install
code-generator
code-gen render
\
--config
=
./config/base_model.json
\
--plugins
=
./plugins
\
--templates
=
./templates
\ No newline at end of file
examples/plugins/base.plugin.jinja2
浏览文件 @
0c5f66b5
{%- macro number_input(column) -%}
<h1>number_input</h1>
<h2>{{ column.name }}</h2>
<h1>number_input with {{ column.field }}</h1>
{% endmacro -%}
{%- macro date_input(column) -%}
<h1>date_input</h1>
<h3>{{ column.name }}</h3>
<h1>date_input with {{ column.field }}</h1>
{% endmacro -%}
{%- macro auto_complete(column) -%}
<h1>auto_complete plugin with {{ column.field }}</h1>
{% endmacro %}
\ No newline at end of file
examples/templates/index.html.jinja2
已删除
100644 → 0
浏览文件 @
2d91eab4
<h1>{{ model }}</h1>
<ul>
{%- for column in columns %}
<li>
{%- if column.name == "1" %}
{{ number_input(column) }}
{%- elif column.name == "22" %}
{{ date_input(column) }}
{%- else %}
<h1>ssss</h1>
{%- endif %}
</li>
{%- endfor %}
</ul>
\ No newline at end of file
examples/templates/user_add.vue.jinja2
0 → 100644
浏览文件 @
0c5f66b5
<template>
<div class="container">
<el-card class="box-card margin-space" style="margin:20px;">
<el-form :model="form" label-width="120px" :rules="rules" ref="form">
{%- for column in columns -%}
{% if column.type == "str" %}
<el-form-item label="{{ column.description }}" prop="{{ column.field }}">
<el-input v-model="form.{{ column.field }}" placeholder="请输入{{ column.description }}" />
</el-form-item>
{%- elif column.type == "int" %}
<el-input-number style="width:100%;" v-model="form.{{ column.field }}"
:min="0" :max="100" label="请输入{{ column.description }}">
</el-input-number>
{% else %}
{% endif %}
{%- endfor -%}
<el-form-item>
<el-button type="primary" @click="submit">提 交</el-button>
<el-button @click="reset_form">重 置</el-button>
<el-button @click="show=false">取 消</el-button>
</el-form-item>
</el-form>
</el-card>
</div>
</template>
<script>
import { add_news } from "./api_result";
import "quill/dist/quill.core.css";
import "quill/dist/quill.snow.css";
import "quill/dist/quill.bubble.css";
import { quillEditor } from "vue-quill-editor";
export default {
name: "add",
components: { quillEditor },
data() {
return {
loading: false,
show: false,
form: {},
rules: {
{% for column in columns %}
{{ column.field }}: [{ required: true, message: "请输入{{ column.description }}", trigger: ["blur"] }],
{% endfor %}
}
};
},
methods: {
show_dialog() {
this.show = true;
this.loading = false;
this.form = {
};
},
reset_form() {
this.form = {};
},
submit() {
this.$refs["form"].validate(valid => {
if (valid) {
this.loading = true;
let $this = this;
add_news(this.form).then(function(res) {
$this.loading = false;
if (res.code === 200) {
$this.show = false;
$this.$emit("fresh");
} else {
alert(res.message);
}
});
} else {
return false;
}
});
}
}
};
</script>
\ No newline at end of file
examples/templates/user_edit.vue.jinja2
0 → 100644
浏览文件 @
0c5f66b5
<template>
<div class="container">
<el-card class="box-card margin-space" style="margin:20px;">
<el-form :model="form" label-width="120px" :rules="rules" ref="form">
{%- for column in columns -%}
{% if column.type == "str" %}
<el-form-item label="{{ column.description }}" prop="{{ column.field }}">
<el-input v-model="form.{{ column.field }}" placeholder="请输入{{ column.description }}" />
</el-form-item>
{%- elif column.type == "int" %}
<el-input-number style="width:100%;" v-model="form.{{ column.field }}"
:min="0" :max="100" label="请输入{{ column.description }}">
</el-input-number>
{% else %}
{% endif %}
{%- endfor -%}
<el-form-item>
<el-button type="primary" @click="submit">提 交</el-button>
<el-button @click="reset_form">重 置</el-button>
<el-button @click="show=false">取 消</el-button>
</el-form-item>
</el-form>
</el-card>
</div>
</template>
<script>
import { add_news } from "./api_result";
import "quill/dist/quill.core.css";
import "quill/dist/quill.snow.css";
import "quill/dist/quill.bubble.css";
import { quillEditor } from "vue-quill-editor";
export default {
name: "edit",
components: { quillEditor },
data() {
return {
loading: false,
show: false,
form: {},
rules: {
{% for column in columns %}
{{ column.field }}: [{ required: true, message: "请输入{{ column.description }}", trigger: ["blur"] }],
{% endfor %}
}
};
},
methods: {
show_dialog() {
this.show = true;
this.loading = false;
this.form = {
};
},
reset_form() {
this.form = {};
},
submit() {
this.$refs["form"].validate(valid => {
if (valid) {
this.loading = true;
let $this = this;
add_news(this.form).then(function(res) {
$this.loading = false;
if (res.code === 200) {
$this.show = false;
$this.$emit("fresh");
} else {
alert(res.message);
}
});
} else {
return false;
}
});
}
}
};
</script>
\ No newline at end of file
src/code_generator/loader.py
浏览文件 @
0c5f66b5
...
...
@@ -39,6 +39,7 @@ class Loader(metaclass=ABCMeta):
init the plugin files path, not load the file content,
lazy load plugins
"""
log
.
info
(
'load file/dir <{%s}>'
,
file_or_dir
)
self
.
files
:
Dict
[
str
,
str
]
=
{}
log
.
info
(
'load the files from : %s'
,
file_or_dir
)
if
not
os
.
path
.
exists
(
file_or_dir
):
...
...
src/code_generator/main.py
浏览文件 @
0c5f66b5
...
...
@@ -62,7 +62,7 @@ def render_by_config():
log
.
info
(
plugins
)
templates
=
TemplateLoader
(
args
[
'templates'
]).
load_templates
(
plugins
)
for
name
,
template
in
templates
.
items
():
result
=
template
.
render
(
config
)
result
=
template
.
render
(
**
config
)
base_name
=
os
.
path
.
basename
(
args
[
'templates'
])
+
'_result'
_save_to_file
(
base_name
,
name
,
result
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录