پودمان:AlborzInfoBox
ظاهر
توضیحات این پودمان میتواند در پودمان:AlborzInfoBox/توضیحات قرار گیرد.
local p = {}
local data = mw.loadData('Module:AlborzInfoBox/Data/Geography')
--------------------------------------------------------------------------------
-- DEBUG TOGGLE
--------------------------------------------------------------------------------
local DEBUG = true
local function log(t)
if DEBUG then
mw.logObject(t)
end
end
--------------------------------------------------------------------------------
-- Render
--------------------------------------------------------------------------------
local function render(args)
log(args)
local layoutName = args["نوع"] or "city"
local layout = data.layouts[layoutName]
if not layout then
layout = data.layouts.city
log("Fallback to city layout")
else
log("Layout: " .. layoutName)
end
local root = mw.html.create("table")
:addClass("infobox alborz-infobox")
--------------------------------------------------------------------------
-- Title
--------------------------------------------------------------------------
local title = args["نام"] or mw.title.getCurrentTitle().text
root:tag("tr")
:tag("th")
:attr("colspan","2")
:wikitext(title)
--------------------------------------------------------------------------
-- Image
--------------------------------------------------------------------------
if args["تصویر"] and args["تصویر"] ~= "" then
root:tag("tr")
:tag("td")
:attr("colspan","2")
:wikitext("[[پرونده:" .. args["تصویر"] .. "|250px]]")
if args["توضیح تصویر"] and args["توضیح تصویر"] ~= "" then
root:tag("tr")
:tag("td")
:attr("colspan","2")
:wikitext(args["توضیح تصویر"])
end
end
--------------------------------------------------------------------------
-- Rows DEBUG MODE
--------------------------------------------------------------------------
for i = 1, #layout do
local key = layout[i]
local field = data.fields[key]
if not field then
log("Missing field: " .. tostring(key))
else
log("Checking field: " .. key)
local value = nil
if field.arg then
value = args[field.arg]
end
if value and value ~= "" then
log("FOUND VALUE: " .. key .. " = " .. value)
local tr = root:tag("tr")
tr:tag("th"):wikitext(field.label)
tr:tag("td"):wikitext(value)
else
log("EMPTY: " .. key .. " (arg=" .. tostring(field.arg) .. ")")
end
end
end
return tostring(root)
end
--------------------------------------------------------------------------------
-- Main
--------------------------------------------------------------------------------
function p.main(frame)
local args = {}
local parent = frame:getParent() or frame
for k, v in pairs(parent.args or {}) do
if v and v ~= "" then
args[k] = mw.text.trim(v)
end
end
for k, v in pairs(frame.args or {}) do
if v and v ~= "" then
args[k] = mw.text.trim(v)
end
end
return render(args)
end
return p