1010--=
1111--==============================================================
1212
13- assert, assertArg
13+ assert
1414 attributeWith, attributeWithAny
1515 cleanupPath
1616 countStrings, countSubStrings
@@ -1465,8 +1465,7 @@ end
14651465
14661466
14671467function _G.getProtectionWrapper(obj, objName)
1468- assertArg(1, obj, "table")
1469- assertArg(2, objName, "string")
1468+ !ARGS "obj:table objName:string"
14701469
14711470 local wrapper = protectionWrappers[obj]
14721471 if wrapper then return wrapper end
@@ -1630,8 +1629,7 @@ function _G.generateFromTemplateFile(page)
16301629end
16311630
16321631function _G.generateRedirection(url, targetUrl, sourcePath)
1633- assertArg(1, url, "string")
1634- assertArg(2, targetUrl, "string")
1632+ !ARGS "url,targetUrl,sourcePath:string"
16351633
16361634 if not url:find"^/" then
16371635 errorLine("Redirection URLs must begin with '/'. (%s)", url)
@@ -1699,8 +1697,8 @@ function _G.generateRedirection(url, targetUrl, sourcePath)
16991697 </body>
17001698 </html>
17011699 ]=], {
1702- url = encodeHtmlEntities( toUrlAbsolute( targetUrl) ),
1703- urlAbsPercent = encodeHtmlEntities(toUrlAbsolute(toUrlAbsolute( targetUrl) )),
1700+ url = encodeHtmlEntities( targetUrl ),
1701+ urlAbsPercent = encodeHtmlEntities(toUrlAbsolute(targetUrl)),
17041702 }
17051703 )
17061704
@@ -1722,39 +1720,6 @@ function _G.assert(v, ...)
17221720 _error(message, 2)
17231721end
17241722
1725- -- value = assertArg( [ functionName=auto, ] argumentNumber, value, expectedValueType1, ... [, depth=2 ] )
1726- do
1727- local function _assertArg(fName, n, v, ...)
1728- local vType = type(v)
1729- local varargCount = select("#", ...)
1730- local lastArg = select(varargCount, ...)
1731- local hasDepthArg = (type(lastArg) == "number")
1732- local typeCount = varargCount+(hasDepthArg and -1 or 0)
1733-
1734- for i = 1, typeCount do
1735- if vType == select(i, ...) then return v end
1736- end
1737-
1738- local depth = 2 + (hasDepthArg and lastArg or 2)
1739-
1740- if not fName then
1741- fName = debug.traceback("", depth-1):match": in function '(.-)'" or "?"
1742- end
1743-
1744- local expects = table.concat({...}, " or ", 1, typeCount)
1745-
1746- errorf(depth, "bad argument #%d to '%s' (%s expected, got %s)", n, fName, expects, vType)
1747- end
1748-
1749- function _G.assertArg(fNameOrArgNum, ...)
1750- if type(fNameOrArgNum) == "string" then
1751- return (_assertArg(fNameOrArgNum, ...))
1752- else
1753- return (_assertArg(nil, fNameOrArgNum, ...))
1754- end
1755- end
1756- end
1757-
17581723
17591724
17601725function _G.indexOf(t, v)
@@ -1846,7 +1811,7 @@ end
18461811
18471812
18481813function _G.datetimeToTime(datetime)
1849- assertArg(1, datetime, " string")
1814+ !ARGS "datetime: string"
18501815
18511816 local date = dateLib(datetime)
18521817 local time = (date-dateLib.epoch()):spanseconds()
@@ -1856,7 +1821,7 @@ end
18561821
18571822-- datetime = getDatetime( [ time=now ] )
18581823function _G.getDatetime(time)
1859- assertArg(1, time, " number","nil")
1824+ !ARGS "? time: number"
18601825
18611826 local date = dateLib(time or os.time()):tolocal()
18621827 local datetime = date:fmt"${iso}%z" :gsub("..$", ":%0") :gsub("%+00:00$", "Z")
20562021 end
20572022
20582023 function _G.newPage(pathRel, isRedirection)
2059- assertArg(1, pathRel, "string")
2060- assertArg(2, isRedirection, "boolean")
2024+ !ARGS "pathRel:string isRedirection:boolean"
20612025
20622026 local filename = getFilename(pathRel)
20632027 local ext = getExtension(filename)
21452109 g = function(field) return field.v ~= "" and field.v or page.date.v end,
21462110 s = function(field, datetime)
21472111 assertContext("template", "publishDate", 3)
2148- assertArg(1, datetime, " string")
2112+ !ARGS "datetime: string"
21492113 field.v = datetime
21502114 end,
21512115 },
24432407 end
24442408
24452409 function _G.makeError(message, level)
2446- assertArg(1, message, "string")
2447- assertArg(2, level, "number","nil")
2410+ !ARGS "message:string ? level:number"
24482411
24492412 level = (level == 0) and 0 or (level or 1)
24502413 local stack = {}
@@ -2523,7 +2486,7 @@ end
25232486
25242487
25252488function _G.ipairsr(t)
2526- assertArg(1, t, " table")
2489+ !ARGS "t: table"
25272490 return iprev, t, #t+1
25282491end
25292492
0 commit comments