Content deleted Content added
simplify removing dependency on Module:Redirect |
fix indentation to adhere to mw:Manual:Coding conventions/Lua |
||
Line 3:
function p.main(frame)
--Get input arguments
local args = require('Module:Arguments').getArgs(frame,{valueFunc =
})
--Call main function
return p.luaMain(frame,args)
end
Line 24:
function p.luaMain(frame,args)
function emp2nil(x)
end
function space2emp(x)
end
function nopx(x)
end
--Country & mode parameters
local mode = string.lower(args[1] or "usc")
local mi = string.sub(mode,1,1)
local ms = string.sub(mode,2,2)
local mn = string.sub(mode,3,3)
local me = string.sub(mode,4,-1)
local country = args[2] or ""
local avar = args["avar"] or args["altvar"]
local clink = args["clink"] or args["link"]
--Get country data & altvar data
local data, alink, amap, asuf
if avar then
else
end
--Name and link parameters
clink = clink or data.alias or country
local pref = args["pref"]
local suff = args["suff"] or asuf
if not pref and not suff then --Default prefix
end
local yn_map = {[""]=0; ["0"]=0; ["no"]=0; ["n"]=0; ["1"]=1; ["yes"]=1; ["y"]=1}
local fthe = (args["pthe"] and yn_map[args["pthe"]]~=0) or (args["the"] and yn_map[args["the"]]~=0)
local nthe = (args["nthe"] and yn_map[args["nthe"]]~=0) or (args["the"] and yn_map[args["the"]]~=0)
fthe = fthe and (pref and "t" or "T").."he " or ""
nthe = nthe and (pref and "t" or "T").."he " or ""
local flink = args["plink"] or args["flink"] or alink
or clink=="" and "" or space2emp((pref or "").." ")..fthe..clink..space2emp(" "..(suff or ""))
local fsec = args["psection"] or args["section"]
local csec = args["csection"] or args["section"]
fsec = fsec and "#"..fsec or ""
csec = csec and "#"..csec or ""
if string.find(me,"f") then
flink = clink
end▼
end
▲end
local name = args["name"]
if not name then
end
--Image parameters
local pimage = args["image"]
local placeholder = "Flag placeholder.svg"
local variant = args["variant"] or args[3] or ""
local image_map = {[""]=placeholder; ["none"]=placeholder; ["blank"]=placeholder}
if pimage then --Remove namespace
end
local iname = image_map[pimage] or pimage
local size = args["size"] or args["sz"]
local size_map = {xs="12x8px"; s="17x11px"; m="23x15px"; l="32x21px"; xl="46x30px"}
if size==nil or string.find(size,"^%d*x?%d+px$") then
elseif string.find(size,"^%d*x?%d+$") then --EIS size without "px" suffix
else --size from map, or invalid value
end
local border = args["border"]
if iname then
else
end
local am = ""
if args["alt"] or string.find(me,"a") then
end
--Build display name
local text = args["text"]
if not text then
end
--Build image
local ilink = args["ilink"]
if not ilink then
end
if am == "" and string.find(me,"l") then
end
local image = "[[File:"..iname.."|"..size..border..ilink.."|alt="..am.."]]"
if iname==placeholder then
iname = ''
image = "[[:Template:Country data "..country.."]]"
end▼
image = image..args["missingcategory"]▼
text = ''▼
end
▲ if (args["missingcategory"] or '') ~= '' then
--Combine image and name with separator▼
▲ image = image..args["missingcategory"]
local nalign = args["nalign"] or args["nal"]
local align_map = {left="left", l="left", center="center", centre="center", c="center", middle="center", m="center", right="right", r="right"}▼
local out▼
end▼
else --image left of name▼
end▼
end
if string.find(me,"
▲ text = ''
end
▲end
--Tracking categories▼
▲--Combine image and name with separator
local
if pimage and not image_map[pimage] and country~="" and data["flag alias"] and not args.demo then▼
▲local nalign = args["nalign"] or args["nal"]
▲local align_map = {left="left", l="left", center="center", centre="center", c="center", middle="center", m="center", right="right", r="right"}
end▼
▲local out
▲if string.find(me,"r") then
▲ --image right of name
▲ if (ms=="x" and mi=="x") or (string.find(me,"o") and iname==placeholder and pimage~=placeholder) then --name only
▲ out = text
▲ elseif ms=="x" then --no separator
▲ out = text.."<span class=\"flagicon\">"..image.."</span>"
▲ elseif ms=="n" then --non-breaking space
▲ out = text.."<span class=\"flagicon\"> "..image.."</span>"
▲ elseif ms=="l" then --line break
▲ out = text.."<span class=\"flagicon\"><br/>"..image.."</span>"
▲ elseif ms=="t" then --table cell
▲ out = "style=\"text-align:"..(align_map[nalign] or "left").."\"|"..text.."||style=\"text-align:"..(align_map[align] or "center")..";\"|<span class=\"flagicon\">"..image.."</span>"
▲ else --fixed-width span box (default)
▲ local width = args["width"] or args["w"] or require("Module:Flaglist").luawidth(size)
▲ out = text.." <span class=\"flagicon\" style=\"display:inline-block;width:"..width.."px;text-align:"..(align_map[align] or "right")..";\">"..image.."</span>"
▲ end
▲ else --image left of name
▲ if (ms=="x" and mi=="x") or (string.find(me,"o") and iname==placeholder and pimage~=placeholder) then --name only
▲ out = text
▲ elseif ms=="x" then --no separator
▲ out = "<span class=\"flagicon\">"..image.."</span>"..text
▲ elseif ms=="n" then --non-breaking space
▲ out = "<span class=\"flagicon\">"..image.." </span>"..text
▲ elseif ms=="l" then --line break
▲ out = "<span class=\"flagicon\">"..image.."<br/></span>"..text
▲ elseif ms=="t" then --table cell
▲ out = "style=\"text-align:"..(align_map[align] or "center")..";\"|<span class=\"flagicon\">"..image.."</span>||style=\"text-align:"..(align_map[nalign] or "left").."\"|"..text
▲ else --fixed-width span box (default)
▲ local width = nopx(args["width"] or args["w"]) or require("Module:Flaglist").luawidth(size)
▲ out = "<span class=\"flagicon\" style=\"display:inline-block;width:"..width.."px;text-align:"..(align_map[align] or "left")..";\">"..image.."</span> "..text
▲ end
▲end
▲if string.find(me,"w") then --avoid wrapping
▲ out = "<span class=\"nowrap\">"..out.."</span>"
▲end
▲--Tracking categories
▲if pimage and not image_map[pimage] and country~="" and data["flag alias"] and not args.demo then
▲ cat = "[[Category:Pages using Flagg with specified image instead of data template image]]"
▲end
return out..cat
end
|