Marvel Database
Advertisement
Marvel Database

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

-- module to form Marvel Database:Event Template
local p = {}
local h = require("Module:HF")
local getArgs = require('Dev:Arguments').getArgs


function p.event_parts(frame)
	local args = getArgs (frame)
	local function div_row(row)
		local output = mw.html.create( 'div' )
					:css( 'display', 'table' )
					:css( 'margin', '0 auto' )
					:wikitext( row )
					:done()
		return tostring(output)
	end
	local div_clear = tostring(mw.html.create( 'div' ):css( 'clear', 'left' ):done() )
	local parts = {}
	local part
	local i
	local row4 = {}
	local output = {}
	
	for i = 1,50 do
		part = args['Part'..i]
		if not h.isempty(part)
			then table.insert(parts, p.lua_event_part(part, i) )
			else break
		end
	end
	
	for i = 1, #parts do
		if #row4 < 4
			then table.insert(row4, parts[i])
		end
		
		if #row4 == 4 or i == #parts
			then 
				--table.insert( output, div_row(table.concat(row4)) )
				table.insert( output, table.concat(row4) )
				table.insert( output, div_clear )
				row4 = {}
		end	
	end
 
	output = table.concat(output)
	
	return frame:preprocess(output)
end

--------------------------------------------------------
function p.lua_event_part(pagename, part_number)
	local page_content
	local cover
	local story_title
	local synopsis
	local no_issue = ''
	local output = ''
	
	cover = mw.html.create('div')
			:css('height', '224px')
			:css('overflow', 'hidden')
			:wikitext('[[File:No Image Cover.jpg|150px|center|link='..pagename..']]')
			:done()
	cover = tostring(cover)
	
	no_issue = mw.html.create('div')
				:css('font-size', '0.8em')
				:css('font-weight', 'bold')
				:wikitext('Part '..part_number..':<br>No Issue Supplied')
				:done()
	no_issue = cover..tostring(no_issue)
	
	pagename = h.break_link(pagename, 1)
	
	if not h.isempty(pagename)
		then
			page_content = h.get_content(pagename)
			if page_content == ''
				then output = no_issue
				else
					cover = h.get_field_value(page_content, 'Image')
					if h.isempty(cover)
						then cover = 'No Image Cover.jpg'
					end
					cover = mw.html.create('div')
							:css('height', '224px')
							:css('overflow', 'hidden')
							:wikitext('[[File:'..cover..'|150px|center|link='..pagename..']]')
							:done()
					cover = tostring(cover)

					story_title = h.get_field_value(page_content, 'StoryTitle1')
					if h.isempty(story_title)
						then story_title = ''
						else 
							story_title = '"'..string.gsub(story_title,'"','')..'"'
							story_title = ':<br>'..h.Link(pagename, story_title)
					end
					story_title = mw.html.create('th')
									:css('font-size', '0.8em')
									:css('font-weight', 'bold')
									:wikitext('Part '..part_number..story_title)
									:done()
					story_title = tostring(story_title)
					story_title = mw.html.create('tr'):wikitext(story_title):done()
					story_title = tostring(story_title)

					synopsis = h.get_field_value(page_content, 'Synopsis1')
					if h.isempty(synopsis)
						then synopsis = ''
						else synopsis = string.sub(synopsis, 1, 150)..h.Link(pagename, '..more..')
					end
					synopsis = mw.html.create('td')
								:css('margin', '0.5em')
								:css('font-size', '1em')
								:wikitext(synopsis)
								:done()
					synopsis = tostring(synopsis)
					synopsis = mw.html.create('tr'):wikitext(synopsis):done()
					synopsis = tostring(synopsis)
					

					output = mw.html.create('table')
								:attr('class', 'collapsible collapsed')
								:attr('width', '100%')
								:css('clear', 'both')
								:wikitext(story_title..synopsis)
								:done()
					output = cover..tostring(output)
			end
		else output = no_issue
	end
	
	output = mw.html.create('div')
				:attr('align', 'center')
				:css('float', 'left')
				:css('width', '150px')
				:css('text-align', 'center')
				:css('padding', '2px')
				:wikitext(output)
				:done()
	output = tostring(output)
	
	return output
end

return p