Documentation for this module may be created at Module:Design/doc

local p = {}
local h = require("Module:HF")
local getArgs = require('Dev:Arguments').getArgs


--------------------------------------------------------------------------------
function p.get_main_border_color()
	return '#B5B7CF'
end

function p.get_main_background_color()
	return '#EFF0FF'
end

--------------------------------------------------------------------------------
function p.green(text)
	local output = ''
	if not h.isempty(text)
		then 
			output = mw.html.create( 'span' )
				:css( 'color', 'darkgreen' )
				:css( 'font-weight', 'bold' )
				:css( 'font-style', 'italic' )
				:css( 'font-size', 'smaller' )
				:wikitext('('..text..')')
				:done()
			output = tostring(output)
	end
	return output
end


--------------------------------------------------------------------------------
function p.span(text)
	local italic = mw.html.create( 'span' ):css( 'font-style', 'italic' )
	local bold = mw.html.create( 'span' ):css( 'font-weight', 'bold' )
	local both = mw.html.create( 'span' ):css( 'font-weight', 'bold' ):css( 'font-style', 'italic' )
	local output = { italic = '', bold = '', both = '' }
	
	if not h.isempty(text)
		then
			output = {
				italic  = tostring(italic:wikitext(text):done()),
				bold	= tostring(bold:wikitext(text):done()),
				both	= tostring(both:wikitext(text):done()),
			}
	end

	return output
end


--------------------------------------------------------------------------------
-- creates message box
function p.messagebox(frame)
	local args = getArgs (frame)
	local width = args['width'] or '95%'
	local textalign = args['text-align'] or 'center'
	local fontsize = args['font-size'] or '100%'
	local border = args['border'] or p.get_main_border_color()
	local background = args['background'] or p.get_main_background_color()
	local margin = args['margin'] or '1em'
	local clear = args['clear'] or 'none'
	local padding = args['padding'] or '5px'
	local extrastyle = args['extrastyle'] or ''
	local message = args[1] or args['Message'] or ''
	
	local tag = mw.html.create( 'div' )
				:attr( 'id', 'messageBox' )
				:attr( 'align', 'center' )
				:css( 'width', width )
				:css( 'text-align', textalign )
				:css( 'font-size', fontsize )
				:css( 'border', '1px solid '..border )
				:css( 'background', background )
				:css( 'border-radius', '10px' )
				:css( 'margin', margin )
				:css( 'clear', clear )
				:css( 'padding', padding )
				:wikitext( message )
				:done()
	if not h.isempty(extrastyle)
		then tag:cssText (extrastyle):done()
	end
	
	return tostring(tag)
end


--------------------------------------------------------------------------------
-- adds a header
function p.add_header(text, level, align)
	local output = ''
	level = level or '2'
	align = align or 'left'
	
	if not h.isempty(text)
		then output = '\n'..tostring( mw.html.create( 'h'..level ):css('text-align', align):wikitext( text ) )
	end
	
	return output
end


--------------------------------------------------------------------------------
function p.show_hide(frame)
	local args = getArgs (frame)
	local title = args['title'] or args['header'] or ' '
	local body = args['body'] or args['text'] or ''
	local collapsed = args['collapsed']
	local clear = args['clear'] or 'both'
	local border = args['border'] or p.get_main_border_color()
	local extrastyle = args['extrastyle'] or ''
	local extrastyle2 = args['extrastyle2'] or ''
	local extrastyle3 = args['extrastyle3'] or ''
	local width = args['width'] or '100%'
	local background = args['background'] or p.get_main_background_color()
	local titlestyle = args['titlestyle'] or ''
	local expandtext = args['expandtext'] or 'Expand'
	local collapsetext = args['collapsetext'] or 'Collapse'

	if h.isempty(collapsed) or collapsed == 'true' or collapsed == true
		then collapsed = ' mw-collapsed'
		else collapsed = ''
	end

	local tag_td = mw.html.create( 'td' )
		:css( 'margin', '0.5em' )
		:css( 'font-size', '12px' )
		:wikitext(body)
		:done()
	if not h.isempty(extrastyle3)
		then tag_td:cssText (extrastyle3):done()
	end
	tag_td = '<tr>'..tostring(tag_td)..'</tr>'

	local tag_div = mw.html.create( 'div' )
		:css( 'font-weight', 'bold' )
		:wikitext(title)
		:done()
	if not h.isempty(titlestyle)
		then tag_div:cssText (titlestyle):done()
	end
	tag_div = tostring(tag_div)
	
	local tag_th = mw.html.create( 'th' )
		:attr('colspan', '1')
		:css( 'background-color', background )
		:css( 'font-size', '12px' )
		:wikitext(tag_div)
		:done()
	if not h.isempty(extrastyle2)
		then tag_th:cssText (extrastyle2):done()
	end
	tag_th = '<tr>'..tostring(tag_th)..'</tr>'
	
	local tag_table = mw.html.create( 'table' )
		:addClass('mw-collapsible'..collapsed)
		:attr('data-expandtext', expandtext)
		:attr('data-collapsetext', collapsetext)
		:css( 'clear', clear )
		:css( 'border', '1px solid '..border )
		:css( 'font-size', '12px' )
		:css( 'width', width )
		:wikitext(tag_th..tag_td)
		:done()
	if not h.isempty(extrastyle)
		then tag_table:cssText (extrastyle):done()
	end
	
	return tostring(tag_table) 
end


--*******************************************************************************************
-- ************* functions to create INFOBOX *************

--------------------------------------------------------------------------------
function p.create_infobox(text, width)
	width = width or '300px'
	text = text or ''

	return tostring( mw.html.create( 'div' )
		:attr('class', 'infobox')
		:css( 'width', width )
		:css( 'float', 'right' )
		:css( 'clear', 'none' )
		:css( 'margin', '0px 0px 1em 1em' )
		:css( 'border', '1px solid '..p.get_main_border_color() )
		:css( 'background', p.get_main_background_color() )
		:css( 'border-radius', '10px' )
		:css( 'padding', '10px' )
		:wikitext(text)
		:done() )
end


--------------------------------------------------------------------------------
function p.add_infobox_row(label, value)
	local width_l = '40%'
	local width_r = '60%'
	local tag_label
	local tag_value
	local output = ''
	
	if not h.isempty(value)
		then
			if string.find(value, '^\n') == nil
				then value = '\n'..value
			end
			
			tag_label = mw.html.create( 'div' )
				:css( 'width', width_l )
				:css( 'text-align', 'left' )
				:css( 'float', 'left' )
				:css( 'font-weight', 'bold')
				:wikitext(label)
				:done()
			tag_value = mw.html.create( 'div' )
				:css( 'width', width_r )
				:css( 'text-align', 'left' )
				:css( 'float', 'left' )
				:wikitext(value)
				:done()
				
			tag_label = tostring(tag_label)
			tag_value = tostring(tag_value)
			
			output = mw.html.create( 'div' )
				:css( 'border-top', '1px solid '..p.get_main_border_color() )
				--:css( 'padding', '10px')
				:css( 'height', '1.5em' )
				:css( 'text-align', 'center' )
				:css( 'clear', 'left' )
				:css( 'font-size', '10px' )
				:wikitext(tag_label..tag_value)
				:done()
			output = tostring(output)
	end

	return output
end


--------------------------------------------------------------------------------
function p.add_infobox_group(group, header)
	local output = ''
	
	if table.concat(group) ~= ''
		then
			header = mw.html.create( 'div' )
			:css( 'clear', 'both' )
				:css( 'text-align', 'center' )
				:css( 'font-weight', 'bold' )
				:css( 'padding', '10px' )
				:css( 'height', '1.5em' )
				:css( 'background', p.get_main_background_color())
				:css( 'font-size', '14px' )
				:wikitext(header)
				:done()
			output = tostring(header)..'\n'..table.concat(group)
	end
	
	return output
end


--------------------------------------------------------------------------------
function p.add_infobox_horizontal_group(frame)
	local args = getArgs (frame)
	local centralheader = args['central_header'] or ''
	local leftheader = args['left_header'] or ''
	local lefttext = args['left_text'] or ''
	local rightheader = args['right_header'] or ''
	local righttext = args['right_text'] or ''
	local totalwidth = args['total_width']
	local tag_centralheader
	local tag_leftheader
	local tag_rightheader
	local tag_lefttext
	local tag_righttext
	local output = ''
 
	if not h.isempty(righttext)
		then 
			if not h.isempty(totalwidth)
				then totalwidth = tostring(tonumber(totalwidth)/2)..'px' 
				else totalwidth = '50%'
			end
		else totalwidth = '100%'
	end

	if not h.isempty(centralheader)
		then
			tag_centralheader = mw.html.create( 'div' )
				:css( 'width', '100%' )
				:css( 'float', 'left' )
				:css( 'font-weight', 'bold')
				:css( 'font-size', '14px' )
				:wikitext(centralheader)
				:done()
			output = output..tostring(tag_centralheader)
		else
			tag_leftheader = mw.html.create( 'div' )
				:css( 'width', totalwidth )
				:css( 'float', 'left' )
				:css( 'font-weight', 'bold')
				:css( 'font-size', '14px' )
				:wikitext(leftheader)
				:done()
			output = output..tostring(tag_leftheader)
	end
 
	if not h.isempty(righttext) and h.isempty(centralheader)
		then
			tag_rightheader = mw.html.create( 'div' )
					:css( 'width', totalwidth )
					:css( 'float', 'left' )
					:css( 'clear', 'right' )
					:css( 'font-weight', 'bold')
					:css( 'font-size', '14px' )
					:wikitext(rightheader)
					:done()
			output = output..tostring(tag_rightheader)
	end
 
	tag_lefttext = mw.html.create( 'div' )
		:css( 'width', totalwidth )
		:css( 'float', 'left' )
		:css( 'clear', 'left' )
		:css( 'font-size', '10px' )
		:wikitext(lefttext)
		:done()
	output = output..tostring(tag_lefttext)
 
 
	if not h.isempty(righttext)
		then
			tag_righttext = mw.html.create( 'div' )
					:css( 'width', totalwidth )
					:css( 'float', 'left' )
					:css( 'text-align', 'center' )
					:css( 'font-size', '10px' )
					:wikitext(righttext)
					:done()
			output = output..tostring(tag_righttext)
	end
 
	return tostring( mw.html.create( 'div' )
		:css( 'border-top', '1px solid '..p.get_main_border_color() )
		:css( 'text-align', 'center' )
		:wikitext(output)
		:done() )
end 


--------------------------------------------------------------------------------
-- used to add sections like "Notes", "Trivia", etc.
function p.add_section(header, section, header_level)
	local output = ''
	
	header_level = header_level or 2
	
	if not h.isempty(section)
		then output = p.add_header(header, header_level)..'\n'..section
	end
	
	return output
end

--*******************************************************************************************


--*******************************************************************************************
-- ************* functions to create various message boxes

--------------------------------------------------------------------------------
-- used in Template:Members Category
function p.members_category(frame)
	local reality = require("Module:Reality")
	local pagename = mw.title.getCurrentTitle().text
	local message
	local name
	local category
	local reality_info
	local reality_number
	local link
	local output = ''
	
	if string.find(pagename, ' members') ~= nil
		then
			if string.find(pagename, ' members %(') == nil
				then pagename = pagename..' (Earth-616)'
			end
			name, reality_info = reality.lua_get_name_and_reality(pagename)
			link = string.gsub(pagename, ' members', '')
			message = p.messagebox({'Members of the '..h.Link(link, link)})
			reality_number = reality_info.number
			if not h.isempty(reality_number)
				then 
					if tonumber(reality_number) ~= nil
						then reality_number = string.rep('0', 15-#reality_number)..reality_number
					end
					reality_number = ' '..reality_number
				else reality_number = ''
			end
			category = h.Category('Member Lists', name..reality_number)
			if tonumber(reality_number) ~= 616
				then category = category..h.Category(name, reality_number)
			end
			output = message..category
	end
	
	return output
end

return p
Community content is available under CC-BY-SA unless otherwise noted.