پودمان:AlborzInfoBox: تفاوت میان نسخهها
ظاهر
صفحهای تازه حاوی «-------------------------------------------------------------------------------- -- Module:AlborzInfoBox -- Wiki Alborz -- Version 1.0 -------------------------------------------------------------------------------- local p = {} local data = mw.loadData('Module:AlborzInfoBox/Data/Geography') -------------------------------------------------------------------------------- -- Render ----------------------------------------------------...» ایجاد کرد |
جزبدون خلاصۀ ویرایش |
||
| خط ۱: | خط ۱: | ||
local p = {} | |||
local data = mw.loadData('Module:AlborzInfoBox/Data/Geography') | |||
-------------------------------------------------------------------------------- | -------------------------------------------------------------------------------- | ||
-- | -- DEBUG TOGGLE | ||
-------------------------------------------------------------------------------- | -------------------------------------------------------------------------------- | ||
local DEBUG = true | |||
local | local function log(t) | ||
if DEBUG then | |||
mw.logObject(t) | |||
end | |||
end | |||
-------------------------------------------------------------------------------- | -------------------------------------------------------------------------------- | ||
| خط ۱۵: | خط ۲۰: | ||
local function render(args) | local function render(args) | ||
local | log(args) | ||
local layoutName = args["نوع"] or "city" | |||
local layout = data.layouts[layoutName] | |||
if not layout then | if not layout then | ||
layout = data.layouts.city | layout = data.layouts.city | ||
log("Fallback to city layout") | |||
else | |||
log("Layout: " .. layoutName) | |||
end | end | ||
local root = mw.html.create("table") | local root = mw.html.create("table") | ||
:addClass("infobox | :addClass("infobox alborz-infobox") | ||
-------------------------------------------------------------------------- | -------------------------------------------------------------------------- | ||
| خط ۲۹: | خط ۳۹: | ||
-------------------------------------------------------------------------- | -------------------------------------------------------------------------- | ||
local title = args["نام"] | local title = args["نام"] or mw.title.getCurrentTitle().text | ||
root | root:tag("tr") | ||
:tag("th") | |||
:attr("colspan","2") | |||
:wikitext(title) | |||
-------------------------------------------------------------------------- | -------------------------------------------------------------------------- | ||
| خط ۴۸: | خط ۵۲: | ||
if args["تصویر"] and args["تصویر"] ~= "" then | if args["تصویر"] and args["تصویر"] ~= "" then | ||
root | root:tag("tr") | ||
:tag("td") | |||
:attr("colspan","2") | |||
:wikitext("[[پرونده:" .. args["تصویر"] .. "|250px]]") | |||
if args["توضیح تصویر"] and args["توضیح تصویر"] ~= "" then | if args["توضیح تصویر"] and args["توضیح تصویر"] ~= "" then | ||
root | root:tag("tr") | ||
:tag("td") | |||
:attr("colspan","2") | |||
:wikitext(args["توضیح تصویر"]) | |||
end | end | ||
end | end | ||
-------------------------------------------------------------------------- | -------------------------------------------------------------------------- | ||
-- Rows | -- 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 | |||
if field.arg | |||
value = args[field.arg] | value = args[field.arg] | ||
end | end | ||
if value and value ~= "" then | 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 | end | ||
end | end | ||
| خط ۱۵۴: | خط ۱۱۵: | ||
local args = {} | local args = {} | ||
local parent = frame:getParent() | 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 | ||
end | end | ||
for k, v in pairs(frame.args) do | for k, v in pairs(frame.args or {}) do | ||
if v and v ~= "" then | if v and v ~= "" then | ||
args[k] = mw.text.trim(v) | args[k] = mw.text.trim(v) | ||
نسخهٔ ۳ ژوئیهٔ ۲۰۲۶، ساعت ۱۵:۵۲
توضیحات این پودمان میتواند در پودمان: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