Modul:TemplUtl: Unterschied zwischen den Versionen
update
(Setup) |
(update) |
||
Zeile 1: | Zeile 1: | ||
--[=[ 2014-11- | --[=[ 2014-11-24 | ||
TemplUtl | TemplUtl | ||
]=] | ]=] | ||
Zeile 39: | Zeile 39: | ||
-- Does this describe an URL beginning? | -- Does this describe an URL beginning? | ||
-- Precondition: | -- Precondition: | ||
-- address -- string; | -- address -- string; what to inspect, URL presumed | ||
-- Postcondition: | -- Postcondition: | ||
-- Returns true, if URL beginning | -- Returns true, if URL beginning | ||
Zeile 177: | Zeile 177: | ||
if s and TemplUtl.feasible( s ) then | if s and TemplUtl.feasible( s ) then | ||
s = area .. " "; | s = area .. " "; | ||
s = s:match( "(% | s = s:match( "([^%s|]+)%s", j ); | ||
if s then | if s then | ||
k = s:find( "}}" ); | k = s:find( "}}" ); | ||
Zeile 199: | Zeile 199: | ||
return r, loop; | return r, loop; | ||
end -- TemplUtl.feed() | end -- TemplUtl.feed() | ||
TemplUtl.feeder = function ( area, at ) | |||
-- Retrieve all parameters | |||
-- Precondition: | |||
-- area -- string; template transclusion | |||
-- at -- optional number; byte position in area of "{{" | |||
-- Postcondition: | |||
-- Returns table | |||
-- [0] template, page, parser function name | |||
local n = 0; | |||
local j, k, p, r, r2, s, v; | |||
if type( at ) == "number" then | |||
j = at + 2; | |||
else | |||
j = 3; | |||
end | |||
while true do | |||
k = TemplUtl.feed( area, false, j ); | |||
s = area:sub( j, k ); | |||
s = s:gsub( "<!--.*-->", "" ); | |||
if n == 0 then | |||
r = { [ 0 ] = s }; | |||
n = 1; | |||
else | |||
p, v = s:match( "^([^=]*)=(.*)$" ); | |||
if p then | |||
if p:match( "^%s*%d+%s*$" ) then | |||
p = tonumber( p ); | |||
else | |||
p = mw.text.trim( p ); | |||
end | |||
v = mw.text.trim( v ); | |||
else | |||
p = n; | |||
v = s; | |||
n = n + 1; | |||
end | |||
if r[ p ] then | |||
if r2 then | |||
r2 = r2 .. " * "; | |||
else | |||
r2 = ""; | |||
end | |||
r2 = string.format( "%s%s '%s'", | |||
r2, | |||
"duplicated parameter", | |||
tostring( p ) ); | |||
end | |||
r[ p ] = v; | |||
end | |||
s = area:sub( k + 1, k + 2 ); | |||
if s == "}}" then | |||
break; -- while true | |||
elseif s == "" then | |||
r2 = "template not closed"; | |||
break; -- while true | |||
end | |||
j = k + 2; | |||
end -- while true | |||
return r, r2; | |||
end -- TemplUtl.feeder() | |||
Zeile 237: | Zeile 300: | ||
-- alter -- optional string; lowercase namespace pattern | -- alter -- optional string; lowercase namespace pattern | ||
-- "" for article | -- "" for article | ||
-- no colon (:) | |||
-- Postcondition: | -- Postcondition: | ||
-- Returns ustring position of "{{" in area, or false | -- Returns ustring position of "{{" in area, or false |