Module:Border
Jump to navigation
Jump to search
![]() | This module depends on the following other modules: |
Implements {{border}}.
require('strict')
local p = {} --p stands for package
local getArgs = require('Module:Arguments').getArgs
local make_style_string = require('Module:Optional style').make_style_string
local CSS_unit = require('Module:CSS unit')._CSS_unit
function p.border_start(frame)
local args = getArgs(frame)
local trackingCats = {}
-- style arg aliases
args['maxwidth'] = args['max-width'] or args.maxwidth or args[2]
args.bstyle = args.bstyle or args[3]
args.bthickness = args.bthickness or args[4]
args.color = args.color or args[5]
args.bgcolor = args.bgcolor or args[6]
args.align = args.align or args[7]
args.padding = args.padding or args[9]
args.position = args.position or args[8]
if args.position ~= 'left' and args.position ~= 'right' then
args.position = 'center'
end
if CSS_unit({args.maxwidth}) == 'px' then
table.insert(trackingCats, '[[Category:' .. 'Pages using pixel widths (border)' .. ']]')
end
for k, v in pairs({'maxwidth', 'bstyle', 'bthickness', 'color', 'bgcolor', 'align', 'padding', 'style'}) do
if args[v] then
table.insert(trackingCats, '[[Category:' .. 'Borders using ' .. v .. ' parameter' .. ']]')
end
end
for k, v in pairs(args) do
if tonumber(k) and tonumber(k) ~= 1 then
table.insert(trackingCats, '[[Category:' .. 'Borders with numerical arguments' .. ']]')
break
end
end
local styleArgs = {
['max-width'] = args.maxwidth,
['display'] = args.display,
['border-style'] = args.bstyle,
['border-width'] = args.bthickness,
['border-color'] = args.color,
['background-color'] = args.bgcolor,
['text-align'] = args.align,
['padding'] = args.padding,
['style'] = args.style
}
if styleArgs['background-color'] then
styleArgs['color'] = 'inherit'
end
local styleParam = make_style_string(styleArgs)
local stylesheet = mw.getCurrentFrame():extensionTag('templatestyles', '', {src = 'Template:Border/styles.css'})
local divOpen = '<div class="' .. table.concat({'wst-border', 'wst-border-' .. args.position}, ' ') .. '" ' .. styleParam .. '>'
return stylesheet .. divOpen .. table.concat(trackingCats)
end
local function border_end()
return '</div>'
end
function p.border(frame)
return p.border_start(frame) .. (getArgs(frame)[1] or '') .. border_end()
end
return p