Hello there! We are conducting a survey to better understand the user experience in making a first edit. If you have ever made an edit on Gamepedia, please fill out the survey. Thank you!

Module:NewsItem

From Leaguepedia | League of Legends Esports Wiki
Jump to: navigation, search

To edit the documentation or categories for this module, click here.


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

local s = {}
function s.LeagueSprite(id, link)
	return Sprite{
		id,
		type = 'League',
		link = link,
		nolink = 'No'
	}
end
local h = {}
local p = {}

function p.team(frame)
	local args = util_args.merge(true)
	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(true)
	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.makeNews(args)
	local region_image = m_region.onlyimage(args.region)
	local output = {
		'|-',
		'|class="news-region"|' .. region_image,
		'|class="news-subject"|' .. args.subject,
		'|class="news-text"|' .. (args.text or ''),
	}
	if args.cargo then
		h.storeCargo(args, region_image)
	end
	return table.concat(output,'\n')
end	

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

function h.tournamentSubject(tournament, link)
	local div = mw.html.create('div')
		:addClass('news-league-icon')
		:wikitext(s.LeagueSprite(tournament, link))
	return tostring(div) .. util_text.link(link, m_league.leagueshortname(tournament))
end

return p