「モジュール:Infobox/former」の版間の差分
ナビゲーションに移動
検索に移動
Module:Infobox/former/sandboxより全文転記. Template talk:Infobox#Subboxes, WP:AN/PEに基づく
template>Rxy (モジュール:Infobox/former/sandbox 2016-08-01T03:56:21 UTC の版より。 WP:AN/PE (差分), モジュール‐ノート:Infobox/former (固定リンク) に基づく。) |
template>Waiesu |
||
4行目: | 4行目: | ||
local args = require('Module:Arguments').getArgs(frame, {parentOnly = true}) --引数取得 | local args = require('Module:Arguments').getArgs(frame, {parentOnly = true}) --引数取得 | ||
local child = (args.child == 'yes') | local child = (args.child == 'yes') | ||
local subbox = (args.subbox == 'yes') | |||
local h = {subheader = {}, image = {{}}} --ヘッダー部(subheader, image)テーブル | local h = {subheader = {}, image = {{}}} --ヘッダー部(subheader, image)テーブル | ||
local body, sbody = {}, {} --本体部テーブル, ソート済み本体部テーブル | local body, sbody = {}, {} --本体部テーブル, ソート済み本体部テーブル | ||
59行目: | 60行目: | ||
local str, num = string.match(k, '^(%D+)(%d+)$') | local str, num = string.match(k, '^(%D+)(%d+)$') | ||
num = tonumber(num) | num = tonumber(num) | ||
body[num] = body[num] | if not body[num] then | ||
body[num][str] = v | local OddOrEven = (num % 2 ~= 0) and 'odd' or 'even' | ||
body[num] = { | |||
num, | |||
headerstyle = (args.headerstyle or '') .. (args[OddOrEven .. 'headerstyle'] or ''), | |||
labelstyle = (args.labelstyle or '') .. (args[OddOrEven .. 'labelstyle'] or ''), | |||
datastyle = (args.datastyle or '') .. (args[OddOrEven .. 'datastyle'] or '') | |||
} | |||
end | |||
body[num][str] = (body[num][str] or '') .. v | |||
end | end | ||
end | end | ||
67行目: | 76行目: | ||
Template:Infobox/row | Template:Infobox/row | ||
]] | ]] | ||
local function row(header, headerstyle, label, labelstyle, data, datastyle, class, rowclass, id, itemprop, rowitemprop, itemtype, rowitemtype, itemref, rowitemref) | local function row(header, headerstyle, label, labelstyle, data, datastyle, rowstyle, class, rowclass, id, itemprop, rowitemprop, itemtype, rowitemtype, itemref, rowitemref) | ||
local result ='' | local result ='' | ||
if header then | if header then | ||
result = '<tr | result = '<tr style="' .. (rowstyle or '') ..'"' .. (rowitemtype and (' itemscope itemtype="' .. rowitemtype .. '"') or '') .. ' itemref="' .. (rowitemref or '') .. '"><th scope="col" colspan="2" class="' .. (class or '') .. '" style="text-align:center; ' .. (headerstyle or '') .. '">' .. header .. '</th></tr>' | ||
elseif data then | elseif data then | ||
result = '<tr class="' .. (rowclass or '') .. '" itemprop="' .. (rowitemprop or '') .. '"' .. (rowitemtype and (' itemscope itemtype="' .. rowitemtype .. '"') or '') .. ' itemref="' .. (rowitemref or '') .. '">' | result = '<tr class="' .. (rowclass or '') .. '" style="' .. (rowstyle or '') .. '" itemprop="' .. (rowitemprop or '') .. '"' .. (rowitemtype and (' itemscope itemtype="' .. rowitemtype .. '"') or '') .. ' itemref="' .. (rowitemref or '') .. '">' | ||
if label then | if label then | ||
result = result .. '<th scope="row" style="text-align:left; white-space:nowrap; ' .. (labelstyle or '') .. '">' .. label .. '</th><td class="' .. (class or '') .. '" style="' .. (datastyle or '') .. '" itemprop="' .. (itemprop or '') .. '"' .. (itemtype and (' itemscope itemtype="' .. itemtype .. '"') or '') .. ' itemref="' .. (itemref or '') .. '">' | result = result .. '<th scope="row" style="text-align:left; white-space:nowrap; ' .. (labelstyle or '') .. '">' .. label .. '</th><td class="' .. (class or '') .. '" style="' .. (datastyle or '') .. '" itemprop="' .. (itemprop or '') .. '"' .. (itemtype and (' itemscope itemtype="' .. itemtype .. '"') or '') .. ' itemref="' .. (itemref or '') .. '">' | ||
89行目: | 98行目: | ||
if not child then | if not child then | ||
--tableタグ | --tableタグ | ||
result = '<table class="infobox ' .. (args.bodyclass or '') .. '" style="width:22em; ' .. (args.bodystyle or '') .. '"' .. (args.bodyitemtype and (' itemscope itemtype="' .. args.bodyitemtype .. '"') or '') .. ' itemref="' .. (args.bodyitemref or '') .. '">' | result = '<table class="' .. (subbox and '' or 'infobox ') .. (args.bodyclass or '') .. '" style="' .. (subbox and 'min-width:100%; width:calc(100% + 6px); margin:-3px; ' or 'width:22em; ') .. (args.bodystyle or '') .. '"' .. (args.bodyitemtype and (' itemscope itemtype="' .. args.bodyitemtype .. '"') or '') .. ' itemref="' .. (args.bodyitemref or '') .. '">' | ||
if args.title then | if args.title then | ||
--captionタグ | --captionタグ | ||
104行目: | 113行目: | ||
for k, v in pairs(h.subheader) do | for k, v in pairs(h.subheader) do | ||
result = result .. row(nil, nil, nil, nil, v[1], v.style or h.subheader.style, h.subheader.class, v.rowclass, nil, nil, nil, nil, nil, nil, nil) | result = result .. row(nil, nil, nil, nil, v[1], v.style or h.subheader.style, v.rowstyle, h.subheader.class, v.rowclass, nil, nil, nil, nil, nil, nil, nil) | ||
end | end | ||
for k, v in pairs(h.image) do | for k, v in pairs(h.image) do | ||
result = result .. row(nil, nil, nil, nil, v[1] and (v[1] .. (v.caption or '')), v.style or h.image.style, h.image.class, v.rowclass, nil, nil, nil, nil, nil, nil, nil) | result = result .. row(nil, nil, nil, nil, v[1] and (v[1] .. (v.caption or '')), v.style or h.image.style, v.rowstyle, h.image.class, v.rowclass, nil, nil, nil, nil, nil, nil, nil) | ||
end | end | ||
119行目: | 128行目: | ||
--本体部 | --本体部 | ||
for k, v in ipairs(sbody) do | for k, v in ipairs(sbody) do | ||
result = result .. row(v.header, | result = result .. row(v.header, v.headerstyle, v.label, v.labelstyle, v.data, v.datastyle, v.rowstyle, v.class, v.rowclass, v.id, v.itemprop, v.rowitemprop, v.itemtype, v.rowitemtype, v.itemref, v.rowitemref) | ||
end | end | ||