Module:NewsItem

local util_args = require('Module:ArgsUtil') local util_cargo = require('Module:CargoUtil') local m_team = require('Module:Team') local util_vars = require('Module:VarsUtil') local util_table = require('Module:TableUtil') local util_text = require('Module:TextUtil') local Region = require('Module:Region') local League = require('Module:League')

local h = {} local p = {}

function p.team(frame) local args = util_args.merge h.castArgs(args) args.subject = m_team.rightshortlinked(args.team, {size=60}) if util_vars.getVar('newsCargo') and not args.nocargo then args.cargo = { Type = 'Team', Team = m_team.teamlinkname(args.team), Team_Markup = m_team.rightmediumlinked(args.team), }		args.cargo.Subject = args.cargo.Team args.cargo.Subject_Markup = args.cargo.Team_Markup end return h.makeNews(args) end

function p.tournament(frame) local args = util_args.merge h.castArgs(args) args.subject = h.tournamentSubject(args.tournament, args.link) if util_vars.getVar('newsCargo') and not args.nocargo then args.cargo = { _table = 'News', Type = 'Tournament', Tournament = args.link, Tournament_Markup = args.subject, Subject = args.link, Subject_Markup = args.subject }	end return h.makeNews(args) end

function h.castArgs(args) args.region = Region(args.region) end

function h.makeNews(args) local output = { '|-',		'|class="news-region"|' .. args.region:image, '|class="news-subject"|' .. args.subject, '|class="news-text"|' .. (args.text or ''), }	if args.cargo then h.storeCargo(args) end return table.concat(output,'\n') end

function h.storeCargo(args) local tbl = { _table = 'News', Date = util_vars.getVar('date', frame), ItemNo = util_vars.setGlobalIndex('NewsItem'), Region = args.region, Region_Markup = args.region:flair, Region_Image = args.region:image, Text = args.text }	tbl.UniqueLine = mw.title.getCurrentTitle.text .. '_' .. tbl.ItemNo util_table.merge(tbl, args.cargo) return end

function h.tournamentSubject(tournament, link) local league = League(tournament) local div = mw.html.create('div') :addClass('news-league-icon') :wikitext(league:imagelink{link = link}) return tostring(div) .. league:link{link = link, len = 'short'} end

return p