Skip to content

Commit

Permalink
优化web页面生成
Browse files Browse the repository at this point in the history
  • Loading branch information
xiyoo0812 committed Oct 7, 2023
2 parents 3243202 + 41d1fea commit 79bf934
Show file tree
Hide file tree
Showing 17 changed files with 655 additions and 560 deletions.
26 changes: 11 additions & 15 deletions .luacheckrc
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,20 @@ max_cyclomatic_complexity = 13
max_code_line_length = 160
max_comment_line_length = 160
exclude_files = {
"script/luabt/*.*",
"script/luaoop/*.*",
"script/luabt/luaoop/*.*",
"script/luabt/LICENSE",
"script/luaoop/LICENSE",
"script/luabt/luaoop/LICENSE",
"server/robot/accord/page/*",
"extend/lmake/share.lua"
"extend/lmake/share.lua",
"server/robot/accord/page/*"
}
include_files = {
"script/*",
"server/*",
"worker/*",
"bin/proto/*.lua",
"tools/encrypt/*",
"tools/excel2lua/*",
"script/*.lua",
"server/*.lua",
"script/*/*.lua",
"server/*/*.lua",
"script/*/*/*.lua",
"server/*/*/*.lua",
"script/*/*/*/*.lua",
"server/*/*/*/*.lua",
"extend/lmake/*.lua",
"extend/lmake/ltemplate/*.lua",
"tools/*/*.lua",
}
ignore = {"212", "213", "512"}

2 changes: 1 addition & 1 deletion bin/database.conf
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ set_env("QUANTA_MONGO_URLS", [[
]])
--redis
set_env("QUANTA_REDIS_URLS", [[
redis://root:123456@127.0.0.1:6379;
redis://root:123456@10.96.8.100:6379;
]])
--mysql
set_env("QUANTA_MYSQL_URLS", [[
Expand Down
3 changes: 2 additions & 1 deletion bin/share.conf
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,9 @@ set_env("QUANTA_DB_CACHE_FLUSH", "10")
--webhook设置
-----------------------------------------------------
--log: 日志采集
--httphttp发送
--http: http发送
set_env("QUANTA_WEBHOOK_MODE", "log")
--webhook地址设置
--set_env("QUANTA_LARK_URL", "https://open.feishu.cn/open-apis/bot/v2/hook/9a6565bf-51b4-48ab-80f0-64caf4d58ab8")
--set_env("QUANTA_DING_URL", "https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=a4c64781-adad-4ddc-a615-6bc232ce71ef")
set_env("QUANTA_WECHAT_URL", "https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=d7cd918c-f608-4762-87af-bb8c7fc51074")
Expand Down
61 changes: 43 additions & 18 deletions extend/lmake/ltemplate.lua
Original file line number Diff line number Diff line change
Expand Up @@ -164,12 +164,11 @@ local function render(content, env)
return nil, chunk
end

--导出文件模板
--根据配置导出文件模板
--tpl_f: 文件模板
--tpl_out_f: 输出文件
--tpl_env: 环境变量
--tpl_var_f: 环境变量文件
local function render_file(tpl_f, tpl_out_f, tpl_env, tpl_var_f)
local function render_file(tpl_f, tpl_out_f, tpl_env)
if not tpl_f or not tpl_out_f or not tpl_env then
error("render template file params error!")
return
Expand All @@ -182,19 +181,6 @@ local function render_file(tpl_f, tpl_out_f, tpl_env, tpl_var_f)
tpl_env.NAME = tpl_f
local content = template_file:read("*all")
template_file:close()
if tpl_var_f then
setmetatable(tpl_env, { __index = function(t, k) return _G[k] end })
local func, err = loadfile(tpl_var_f, "bt", tpl_env)
if not func then
error(sformat("open template variable file %s failed :%s", tpl_var_f, err))
return
end
local ok, res = pcall(func)
if not ok then
error(sformat("load template variable file %s failed :%s", tpl_var_f, res))
return
end
end
local out_file = iopen(tpl_out_f, "w")
if not out_file then
error(sformat("open template out file %s failed!", tpl_out_f))
Expand All @@ -214,13 +200,52 @@ local function render_file(tpl_f, tpl_out_f, tpl_env, tpl_var_f)
print(sformat("render template file %s to %s success!", tpl_f, tpl_out_f))
end

--输入参数
local arg_num = select("#", ...)

--工具用法
--tpl_f: 模板文件路径
--tpl_out_f:输出文件路径
--tpl_var_f:环境变量配置文件
if select("#", ...) == 3 then
if arg_num == 3 then
local tpl_env = {}
local tpl_f, tpl_out_f, tpl_var_f = select(1, ...)
render_file(tpl_f, tpl_out_f, {}, tpl_var_f)
if tpl_var_f then
setmetatable(tpl_env, { __index = function(t, k) return _G[k] end })
local func, err = loadfile(tpl_var_f, "bt", tpl_env)
if not func then
error(sformat("open template variable file %s failed :%s", tpl_var_f, err))
return
end
local ok, res = pcall(func)
if not ok then
error(sformat("load template variable file %s failed :%s", tpl_var_f, res))
return
end
end
render_file(tpl_f, tpl_out_f, tpl_env)
end

--工具用法
--tpl_f: 模板文件路径
--tpl_out_f:输出文件路径
--key:文件索引, filename:文件名, ...
if arg_num > 3 then
local tpl_env = {}
local args = { ... }
local filenum = (arg_num - 2) // 2
for i = 1, filenum do
local key = args[2 + i * 2 - 1]
local filename = args[2 + i * 2]
local args_file = iopen(filename, "r")
if not args_file then
error(sformat("open args file %s failed!", filename))
return
end
tpl_env[key] = args_file:read("*all")
args_file:close()
end
render_file(args[1], args[2], tpl_env)
end

return {
Expand Down
Loading

0 comments on commit 79bf934

Please sign in to comment.