پودمان:WorkInfoBox: تفاوت میان نسخهها
ظاهر
جزبدون خلاصۀ ویرایش |
جزبدون خلاصۀ ویرایش |
||
| (۲ نسخهٔ میانیِ ایجادشده توسط همین کاربر نشان داده نشد) | |||
| خط ۳: | خط ۳: | ||
local getArgs = require('Module:Arguments').getArgs | local getArgs = require('Module:Arguments').getArgs | ||
local html = mw.html | local html = mw.html | ||
local Fields = require('Module:WorkInfoBox/Data/Fields') | local Fields = require('Module:WorkInfoBox/Data/Fields') | ||
| خط ۶۹: | خط ۶۷: | ||
local function getLabel(kind, field) | local function getLabel(kind, field) | ||
if Labels[kind] | if Labels[kind] | ||
and Labels[kind][field] then | and Labels[kind][field] then | ||
| خط ۱۰۱: | خط ۹۹: | ||
box:tag('tr') | |||
:tag('td') | |||
:attr('colspan', '2') | :attr('colspan', '2') | ||
:addClass('infobox-image') | :addClass('work-infobox-image') | ||
:wikitext( | |||
'[[File:' .. | |||
image .. | |||
'|' .. | |||
(getValue(args, 'image_size') or '250px') .. | |||
']]' | |||
) | |||
local caption = getValue(args, 'image_caption') | local caption = getValue(args, 'image_caption') | ||
if caption then | if caption then | ||
box:tag('tr') | |||
:addClass('infobox-caption') | :tag('td') | ||
:attr('colspan', '2') | |||
:addClass('work-infobox-caption') | |||
:wikitext(caption) | :wikitext(caption) | ||
| خط ۱۴۲: | خط ۱۴۱: | ||
box:tag('tr') | |||
:tag('th') | |||
:addClass('infobox-label') | :addClass('infobox-label') | ||
:wikitext(label) | :wikitext(label) | ||
:done() | |||
:tag('td') | |||
:addClass('infobox-data') | :addClass('infobox-data') | ||
:wikitext(value) | :wikitext(value) | ||
| خط ۱۶۷: | خط ۱۶۳: | ||
local kind = getValue(args, 'type') | |||
local kind = getValue(args, 'type') | |||
or 'default' | |||
-- تبدیل نوع فارسی به کلید داخلی | |||
kind = Types[kind] | |||
or kind | |||
local layout = Layouts[kind] | local layout = Layouts[kind] | ||
| خط ۱۸۱: | خط ۱۸۱: | ||
local box = html.create('table') | local box = html.create('table') | ||
:addClass('infobox') | :addClass('infobox') | ||
:addClass('work-infobox') | |||
| خط ۲۴۳: | خط ۲۴۴: | ||
end | end | ||
end | end | ||
نسخهٔ کنونی تا ۱۳ ژوئیهٔ ۲۰۲۶، ساعت ۲۳:۲۳
توضیحات این پودمان میتواند در پودمان:WorkInfoBox/توضیحات قرار گیرد.
local p = {}
local getArgs = require('Module:Arguments').getArgs
local html = mw.html
local Fields = require('Module:WorkInfoBox/Data/Fields')
local Layouts = require('Module:WorkInfoBox/Data/Layouts')
local Labels = require('Module:WorkInfoBox/Data/Labels')
local Aliases = require('Module:WorkInfoBox/Data/Aliases')
local Types = require('Module:WorkInfoBox/Data/Types')
----------------------------------------------------------
-- Helpers
----------------------------------------------------------
local function norm(value)
if not value then
return nil
end
value = mw.text.trim(tostring(value))
if value == '' then
return nil
end
return value
end
local function getValue(args, field)
local value = norm(args[field])
if value then
return value
end
local alias = Aliases[field]
if alias then
for _, name in ipairs(alias) do
value = norm(args[name])
if value then
return value
end
end
end
return nil
end
local function getLabel(kind, field)
if Labels[kind]
and Labels[kind][field] then
return Labels[kind][field]
end
if Fields[field] then
return Fields[field].label
end
return field
end
----------------------------------------------------------
-- Image
----------------------------------------------------------
local function addImage(box, args)
local image = getValue(args, 'image')
if not image then
return
end
box:tag('tr')
:tag('td')
:attr('colspan', '2')
:addClass('work-infobox-image')
:wikitext(
'[[File:' ..
image ..
'|' ..
(getValue(args, 'image_size') or '250px') ..
']]'
)
local caption = getValue(args, 'image_caption')
if caption then
box:tag('tr')
:tag('td')
:attr('colspan', '2')
:addClass('work-infobox-caption')
:wikitext(caption)
end
end
----------------------------------------------------------
-- Row
----------------------------------------------------------
local function addRow(box, label, value)
if not value then
return
end
box:tag('tr')
:tag('th')
:addClass('infobox-label')
:wikitext(label)
:done()
:tag('td')
:addClass('infobox-data')
:wikitext(value)
end
----------------------------------------------------------
-- Render
----------------------------------------------------------
local function render(frame)
local args = getArgs(frame)
local kind = getValue(args, 'type')
or 'default'
-- تبدیل نوع فارسی به کلید داخلی
kind = Types[kind]
or kind
local layout = Layouts[kind]
or Layouts.default
local box = html.create('table')
:addClass('infobox')
:addClass('work-infobox')
------------------------------------------------------
-- Title
------------------------------------------------------
local title = getValue(args, 'title')
if title then
box:tag('caption')
:addClass('infobox-title')
:wikitext(title)
end
------------------------------------------------------
-- Image
------------------------------------------------------
addImage(box, args)
------------------------------------------------------
-- Sections
------------------------------------------------------
for _, section in ipairs(layout) do
if section.title then
box:tag('tr')
:tag('th')
:attr('colspan', '2')
:addClass('infobox-header')
:wikitext(section.title)
end
for _, field in ipairs(section.fields) do
local value = getValue(args, field)
if value then
addRow(
box,
getLabel(kind, field),
value
)
end
end
end
return tostring(box)
end
----------------------------------------------------------
function p.main(frame)
return render(frame)
end
return p