Module:Issue banner

From Wikisource
Jump to navigation Jump to search

--[=[
Implements issue banner templates
]=]
require('strict')

local getArgs = require('Module:Arguments').getArgs
local yesno = require('Module:Yesno')
local make_style_string = require('Module:Optional style').make_style_string

local p = {}

local function div_with_style(class, style_args)
	local class = ''
	if args.class then
		class = 'class:' .. args.class .. ';'
	end
	return '<div ' .. table.concat({class, make_style_string(style_args)}, ' ') .. '>'
end

function p._issue_banner(args)
	local style_args = {
		['border-top'] = args['border-top'] or args.border,
		['border-bottom'] = args['border-bottom'] or args.border,
		['style'] = args.style
	}
	local main_div = div_with_style('issue-banner', style_args)
	
	-- left
	local left_cell = div_with_style(nil, {['style'] = args.lstyle}) .. (args.left or args[1] or '{{{1}}}') .. '</div>'
	
	local lbrace_cell = ''
	if yesno(args.lbrace) then
		lbrace_cell = div_with_style('brace', {['font-size'] = args['lbrace-size'] or args['brace-size']}) .. '}</div>'
	end
	
	local center_left_cell = ''
	if args['center-left'] then
		center_left_cell = div_with_style(nil, {['style'] = args.cstyle}) .. args['center-left'] .. '</div>'
	end
	
	local left_content = '<div>' .. left_cell .. lbrace_cell .. center_left_cell .. '</div>'
	
	-- center
	local center_content = ''
	local center = args.center or args[2]
	if center then
		center_content = div_with_style(nil, {['style'] = args.cstyle})  .. center .. '</div>'
	end
	
	-- right
	local center_right_cell = ''
	if args['center-right'] then
		center_right_cell = div_with_style(nil, {['style'] = args.cstyle}) .. args['center-right'] .. '</div>'
	end
	
	local rbrace_cell = ''
	if yesno(args.rbrace) then
		rbrace_cell = div_with_style('brace', {['font-size'] = args['rbrace-size'] or args['brace-size']}) .. '{</div>'
	end
	
	local right_cell = div_with_style(nil, {['style'] = args.rstyle}) .. (args.right or args[3] or '{{{3}}}') .. '</div>'
	
	local right_content = '<div>' .. center_right_cell .. rbrace_cell .. right_cell .. '</div>'
	
	return main_div .. left_content .. center_content .. right_content .. '</div>'
end

function p.issue_banner(frame)
	return p._issue_banner(getArgs(frame))
end

return p