Module:Sidebar: Difference between revisions

Ganaram inukshuk (talk | contribs)
Created page with "local getArgs = require("Module:Arguments").getArgs local p = {} -- Not to be confused with the infobox; the sidebar only has one column and is a -- different color. Some infobox-ish templates use that style -- Not to be confused with the sidebox either. -- TODO: add float option? -- "Main" function function p._sidebar(args) local title = args["Title" ] local header = args["Header"] local rows = args["Rows" ] local footer = args["Footer"] -- Helper functi..."
 
Ganaram inukshuk (talk | contribs)
m add name, pulled from args
 
(11 intermediate revisions by the same user not shown)
Line 1: Line 1:
-- This module follows [[User:Ganaram inukshuk/Provisional style guide for Lua]]
local getArgs = require("Module:Arguments").getArgs
local getArgs = require("Module:Arguments").getArgs
local navbar  = require("Module:Navbar")._navbar
local tiu    = require("Module:Template input utils")


local p = {}
local p = {}
Line 8: Line 11:
-- Not to be confused with the sidebox either.
-- Not to be confused with the sidebox either.


-- TODO: add float option?
-- TODO: use templatestyles


-- "Main" function
-- "Main" function
function p._sidebar(args)
function p._sidebar(args)
local title  = args["Title" ]
local title  = args["Title"] or "Sidebar Title"
local header = args["Header"]
local header = args["Header Row"]
local rows  = args["Rows" ]
local rows  = args["Rows"]
local footer = args["Footer"]
local footer = args["Footer Row"]
local float  = args["float"] or "right"
local name  = args["name"]
-- Helper function; title
-- Helper function; title
function sidebar_title()
function sidebar_title()
local lines = {}
local lines = {}
table.insert("|-")
table.insert(lines, "|-")
table.insert(string.format("! %s", title))
table.insert(lines, string.format("! %s", title))
return table.concat(lines, "\n")
return table.concat(lines, "\n")
end
end
Line 28: Line 33:
function sidebar_row(row_content)
function sidebar_row(row_content)
local lines = {}
local lines = {}
table.insert("|-")
table.insert(lines, "|-")
table.insert(string.format("| %s", row_content))
table.insert(lines, string.format("| %s", row_content))
return table.concat(lines, "\n")
return table.concat(lines, "\n")
end
end
Line 36: Line 41:
function header_footer_row(row_content)
function header_footer_row(row_content)
local lines = {}
local lines = {}
table.insert("|-")
table.insert(lines, "|-")
table.insert(string.format('| style="font-size: 80%;" | %s', row_content))
table.insert(lines, string.format('| style="font-size: 80%%;" | %s', row_content))
return table.concat(lines, "\n")
end
-- Helper function; navbar row
function navbar_row()
local lines = {}
table.insert(lines, '|-')
table.insert(lines, '| style="text-align: center;" | ' .. navbar(name, "mini", ""))
return table.concat(lines, "\n")
return table.concat(lines, "\n")
end
end
Line 43: Line 57:
-- Boilerplate and start of table
-- Boilerplate and start of table
local lines = {}
local lines = {}
table.insert(lines, '<div class="toccolours" style="float: right; margin: 0px 0px 4px 4px; text-align: center">')
table.insert(lines, string.format('<div class="toccolours" style="float: %s; margin: 0px 0px 4px 4px; text-align: center">', float))
table.insert(lines, '{| class="none"')
table.insert(lines, '{| class="none"')
table.insert(lines, "|-")
table.insert(lines, "|-")
Line 58: Line 72:
-- Footer
-- Footer
if footer then table.insert(lines, header_footer_row(footer)) end
if footer then table.insert(lines, header_footer_row(footer)) end
if name then table.insert(lines, navbar_row()) end
-- End of table
-- End of table
table.insert(lines, "|}")
table.insert(lines, "|}")
table.insert(lines, "</div>")
return table.concat(lines, "\n")
return table.concat(lines, "\n")
Line 70: Line 87:
-- Preprocess rows
-- Preprocess rows
local rows = {}
args["Rows"] = tiu.numbered_args_to_table(args, 20, "Row %d")
for i = 1, 20 do
local key = string.format("Row %d")
local row = args[key]
if row then table.insert(rows, row) end
args[key] = nil
end
args["Rows"] = rows
return frame:preprocess(p._sidebar(args))
return frame:preprocess(p._sidebar(args))