Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: l3build add-contrib [ci skip] #130

Merged
merged 13 commits into from
Nov 2, 2022
2 changes: 1 addition & 1 deletion .github/workflows/contrib.yml
Original file line number Diff line number Diff line change
Expand Up @@ -99,4 +99,4 @@ jobs:
join(fromJSON(steps.contrib_png.outputs.markdown_urls), ' ')
)
}}
name: comment (push)
name: comment (push)
2 changes: 1 addition & 1 deletion contrib/minted/sjtubeamerthememinted.ltx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
%% ------------------------------------------------------------------------
%% Copyright (C) 2022 LogCreative
%% Copyright (C) 2022 LogCreative <[email protected]>
%%
%% Licensed under the Apache License, Version 2.0 (the "License");
%% you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion contrib/poster/sjtubeamerthemeposter.ltx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
%% ------------------------------------------------------------------------
%% Copyright (C) 2022 LogCreative
%% Copyright (C) 2022 LogCreative <[email protected]>
%%
%% Licensed under the Apache License, Version 2.0 (the "License");
%% you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion contrib/sjtug/sjtubeamerthemesjtug.ltx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
%% ------------------------------------------------------------------------
%% Copyright (C) 2022 LogCreative
%% Copyright (C) 2022 LogCreative <[email protected]>
%%
%% Licensed under the Apache License, Version 2.0 (the "License");
%% you may not use this file except in compliance with the License.
Expand Down
86 changes: 84 additions & 2 deletions src/build.lua
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,9 @@ if options["target"] == "add-demo" then

-- modify the number in usr doc content.
local cnt
usrdoccontent, cnt = string.gsub(usrdoccontent, "step" .. string.gsub(string.gsub(oldid,"%+","%%+"),"%-","%%-") .. "%.", "step" .. newid .. ".") -- avoid the magical character insertion
usrdoccontent, cnt = string.gsub(usrdoccontent, "step" ..
string.gsub(string.gsub(oldid,"%+","%%+"),"%-","%%-") ..
"%.", "step" .. newid .. ".") -- avoid the magical character insertion

print("step" .. oldid .. " -> " .. "step" .. newid .. " Doc replaced: " .. cnt)
end
Expand All @@ -435,4 +437,84 @@ if options["target"] == "add-demo" then

adddemo(demonum)
os.exit(0)
end
end

-- contrib directory
contribdir = "../contrib"

-- usage: l3build add-contrib [pluginname]
-- description: initialize a plugin called [pluginname].
if options["target"] == "add-contrib" then
if options["names"] == nil or #options["names"] > 1 then
print("Error: Please specify one and only one contrib name. (" .. module .. ")")
os.exit(1)
end

local pluginname = options["names"][1]

local function addcontrib(pluginname)
local plugindir = contribdir .. "/" .. pluginname
if not direxists(plugindir) then
-- make plugin directory
mkdir(plugindir)

-- generate plugin itself
cp("sjtubeamerthemenewcontrib.template.ltx", supportdir, plugindir)
ren(plugindir, "sjtubeamerthemenewcontrib.template.ltx", "sjtubeamertheme" .. pluginname .. ".ltx")
local pluginpath = plugindir .. "/" .. "sjtubeamertheme" .. pluginname .. ".ltx"
local pluginfile = io.open(pluginpath, 'r')
local pluginfilecontent = pluginfile:read('a')
pluginfile:close()
pluginfilecontent = string.gsub(
string.gsub(
string.gsub(pluginfilecontent, "<year>", os.date("%Y")),
"0000/00/00",os.date("%Y/%m/%d")),
"newcontrib", pluginname
)
-- get information from git
-- no swap when no git
print('Trying to get author and email information from:')
local errorlevel = os.execute("git --version")
if errorlevel == 0 then
local author = io.popen("git config --get user.name",'r') -- get author info
if author ~= nil then
pluginfilecontent = string.gsub(pluginfilecontent, '<author>', author:read('*l'))
end
author:close()
local email = io.popen("git config --get user.email",'r') -- get author email
if email ~= nil then
pluginfilecontent = string.gsub(pluginfilecontent, '<email>', '<' .. email:read('*l') .. '>')
end
email:close()
end
pluginfile = io.open(pluginpath, 'w')
pluginfile:write(pluginfilecontent)
pluginfile:close()

-- generate plugin documentation
cp("newcontrib.template.tex", supportdir, plugindir)
ren(plugindir, "newcontrib.template.tex", pluginname .. ".tex")
local plugindocpath = plugindir .. "/" .. pluginname .. ".tex"
local plugindocfile = io.open(plugindocpath, 'r')
local plugindoccontent = plugindocfile:read('a')
plugindocfile:close()
plugindoccontent = string.gsub(plugindoccontent, "newcontrib", pluginname)
plugindocfile = io.open(plugindocpath, 'w')
plugindocfile:write(plugindoccontent)
plugindocfile:close()

print(pluginname .. " plugin is created.")
print(" > Plugin itself: " .. pluginpath)
print(" > Plugin documentation: " ..plugindocpath)
print("To debug the plugin, install the current version of sjtubeamer globally first by:")
print(" l3build install")
print("Then compile the documentation in the contrib directory: " .. plugindir)
else
print("Error: " .. pluginname .. " has already existed.")
os.exit(1)
end
end

addcontrib(pluginname)
os.exit(0)
end
2 changes: 2 additions & 0 deletions src/doc/sjtubeamerdevguide.tex
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,8 @@ \subsubsection{Exclusive Commands}\label{sec:exclcmd}
\end{tabular}
\end{table}

\fcmd{l3build add-contrib test} This command will create a plugin called \texttt{test} in the directory \texttt{../contrib}. This command will grab the information from \texttt{git} to fill the blanks of ``author'' and ``email'' (left blank when no git is installed).

\subsection{Customize Generation}\label{sec:precompile}

In \verb"source/beamerthemesjtubeamer.ins", you could customize what templates you want to output on the line:
Expand Down
11 changes: 11 additions & 0 deletions src/support/newcontrib.template.tex
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
\documentclass{ctexbeamer}
\usetheme{sjtubeamer}
\usesjtutheme{newcontrib}
\begin{document}
\begin{frame}
\frametitle{newcontrib 插件}

% 插件文档...

\end{frame}
\end{document}
21 changes: 21 additions & 0 deletions src/support/sjtubeamerthemenewcontrib.template.ltx
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
%% ------------------------------------------------------------------------
%% Copyright (C) <year> <author> <email>
%%
%% Licensed under the Apache License, Version 2.0 (the "License");
%% you may not use this file except in compliance with the License.
%% You may obtain a copy of the License at
%%
%% http://www.apache.org/licenses/LICENSE-2.0
%%
%% Unless required by applicable law or agreed to in writing, software
%% distributed under the License is distributed on an "AS IS" BASIS,
%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
%% See the License for the specific language governing permissions and
%% limitations under the License.
%% ------------------------------------------------------------------------
% 文件元数据
\ProvidesFile{sjtubeamerthemenewcontrib.ltx}[0000/00/00 newcontrib for sjtubeamer]
% 传入选项的处理
\if\EqualOption{newcontrib}{debug}{true}
\PackageInfo{You are debugging newcontrib}
\fi