Module:Infobox: Difference between revisions

ArrowHead294 (talk | contribs)
mNo edit summary
Ganaram inukshuk (talk | contribs)
complete infobox function
Line 63: Line 63:
-- Infobox is set up as a Mediawiki table with two cols.
-- Infobox is set up as a Mediawiki table with two cols.
function p.infobox_row(row_content)
function p.infobox_row(row_content)
local row = ""
if #row_content > 1 then
local caption = row_content[1]
local text    = row_content[2]
row = row
.. '|-\n'
.. '| style="text-align: right; padding-right: 0.25em;" | ' .. caption .. '\n'
.. '| style="background-color: white; padding-left: 0.25em; font-weight: bold;" | ' .. text '\n'
elseif #row_content == 1 then
local text = row_content[1]
row = row
.. '|-\n'
.. '| colspan="2" style="text-align: center;" | ' .. text .. '\n'
end
return row
end
end


Line 72: Line 86:
-- Function to be called by other modules; also called by wrapper function
-- Function to be called by other modules; also called by wrapper function
function p._infobox(args)
function p._infobox(args)
local title = args["Title"] or "Infobox Title"
local adjacent_links = args["Adjacent Links"]
local rows = args["Rows"]
-- Start of infobox; outer div and start of table
-- Start of infobox; outer div and start of table
local s = '<div style="'
local infobox = '<div style="'
.. 'border: 1px solid #999; '
.. 'border: 1px solid #999; '
.. 'margin: 0; '
.. 'margin: 0; '
Line 91: Line 108:
-- For loop for populating entries
-- For loop for populating entries
-- wip
for i = 1, #rows do
infobox = infobox .. p.infobox_row(rows[i])
end
infobox = infobox .. "|}</div>"
return s
return s
Line 103: Line 123:
-- Preprocess adjacent links
-- Preprocess adjacent links
-- If there are two adjacent links (such as with edos), then links
-- will be placed on the left and right of the title
-- [Link 1] Title [Link 2]
-- - Link 1 is previous, link 2 is next
-- If there are eight adjacent links (such as with mosses), then
-- links surround the title, forming a 3x3 grid as such:
-- [Link 1] [Link 2] [Link 3]
-- [Link 4]  Title  [Link 5]
-- [Link 6] [Link 7] [Link 8]
-- - 1: prev_A, prev_B
-- - 2: prev_B
-- - 3: next_A, prev_B
-- - 4: prev_A, 
-- - 5: next_A, 
-- - 6: prev_A, next_B
-- - 7: next_B, 
-- - 8: next_A, next_B
-- Leaving this field nil defaults to only having the title; individual
-- links, as with "border" cases (eg, nothing comes before 0edo), can be
-- left blank.
local adjacent_links = {}
local adjacent_links = {}
local link_count = args["Link Count"] -- This is 0, 2, or 8
local link_count = args["Link Count"] -- This is 0, 2, or 8
if link_count == 2 then
table.insert(adjacent_links, args["Left Link" ])
table.insert(adjacent_links, args["Right Link"])
elseif link_count == 8 then
table.insert(adjacent_links, args["Upper Left Link" ])
table.insert(adjacent_links, args["Upper Link"      ])
table.insert(adjacent_links, args["Upper Right Link"])
table.insert(adjacent_links, args["Left Link"      ])
table.insert(adjacent_links, args["Right Link"      ])
table.insert(adjacent_links, args["Lower Left Link" ])
table.insert(adjacent_links, args["Lower Link"      ])
table.insert(adjacent_links, args["Lower Right Link"])
end
args["Upper Left Link" ] = nil
args["Upper Link"      ] = nil
args["Upper Right Link"] = nil
args["Left Link"      ] = nil
args["Right Link"      ] = nil
args["Lower Left Link" ] = nil
args["Lower Link"      ] = nil
args["Lower Right Link"] = nil
-- Preprocess rows
-- Preprocess rows