Difference between revisions of "Module:Data/Templates"

From Yugipedia
Jump to: navigation, search
(Get vg info.)
m (Correct parameter name.)
 
(4 intermediate revisions by the same user not shown)
Line 8: Line 8:
  
 
local DATA = require( 'Module:Data' )
 
local DATA = require( 'Module:Data' )
 +
local UTIL = require( 'Module:Util' )
  
local D = {}
+
local function getArg( frame, index )
 
+
return frame:getParent().args[ index ]
local function getLanguage( frame )
 
local v = frame:getParent().args[ 1 ]
 
 
 
return DATA.getLanguage( v ) or {}
 
 
end
 
end
  
 
local function getRegion( frame )
 
local function getRegion( frame )
local v = frame:getParent().args[ 1 ]
+
return DATA.getRegion( getArg( frame, 1 ) ) or {}
 +
end
  
return DATA.getRegion( v ) or {}
+
local function getLanguage( frame )
 +
return DATA.getLanguage( getArg( frame, 1 ) ) or {}
 
end
 
end
  
 
local function getMedium( frame )
 
local function getMedium( frame )
local v = frame:getParent().args[ 1 ]
+
return DATA.getMedium( getArg( frame, 1 ) ) or {}
 +
end
  
return DATA.getMedium( v ) or {}
+
local function getVideoGameName( frame )
 +
return DATA.videoGames.getName( getArg( frame, 1 ) ) or {}
 
end
 
end
  
local function getVideoGame( frame )
+
---------------------
local v = frame:getParent().args[ 1 ]
+
-- Wikitext interface
 +
---------------------
 +
 
 +
local D = {}
  
return DATA.getVideoGame( v ) or {}
+
function D.rg( frame )
 +
return getRegion( frame ).index or ''
 +
end
 +
 
 +
function D.region( frame )
 +
--[[
 +
short
 +
short2
 +
oceanic
 +
english
 +
after
 +
after2
 +
]]
 +
return getRegion( frame ).full or ''
 
end
 
end
  
Line 43: Line 60:
 
end
 
end
  
function D.rg( frame )
+
function D.rgo( frame )
return getRegion( frame ).index or ''
+
return getMedium( frame ).abbr or ''
 
end
 
end
  
function D.region( frame )
+
function D.vg( frame )
return getRegion( frame ).full or ''
+
local full = UTIL.trim( getArg( frame, 'full' ) )
 +
 
 +
local link = UTIL.trim( getArg( frame, 'link' ) )
 +
 
 +
local game = getVideoGameName( frame )
 +
 +
return full
 +
and ( link and game.full or UTIL.removeDab( game.full or '' ) )
 +
or game.abbr
 
end
 
end
  
function D.rgo( frame )
+
function D.name( frame )
return getMedium( frame ).abbr or ''
+
local language = DATA.getLanguage(
end
+
UTIL.trim( getArg( frame, 2 ) ) or 'en'
 +
)
  
function D.vg( frame )
+
return language
local full = mw.text.trim( frame:getParent().args[ 'full' ] or '' ) ~= ''
+
and DATA.getName( getArg( frame, 1 ) or '', language )
return getVideoGame( frame )[ full and 'full' or 'abbr' ] or ''
+
or '' -- case of invalid language: display empty
 
end
 
end
  
 
return D
 
return D
 
-- </pre>
 
-- </pre>

Latest revision as of 23:10, 21 January 2020

Module documentation[create]
-- <pre>
--[=[Doc
@module Data/Templates
@description Interface for template interaction.
@author [[User:Becasita]]
@contact [[User talk:Becasita]]
]=]

local DATA = require( 'Module:Data' )
local UTIL = require( 'Module:Util' )

local function getArg( frame, index )
	return frame:getParent().args[ index ]
end

local function getRegion( frame )
	return DATA.getRegion( getArg( frame, 1 ) ) or {}
end

local function getLanguage( frame )
	return DATA.getLanguage( getArg( frame, 1 ) ) or {}
end

local function getMedium( frame )
	return DATA.getMedium( getArg( frame, 1 ) ) or {}
end

local function getVideoGameName( frame )
	return DATA.videoGames.getName( getArg( frame, 1 ) ) or {}
end

---------------------
-- Wikitext interface
---------------------

local D = {}

function D.rg( frame )
	return getRegion( frame ).index or ''
end

function D.region( frame )
	--[[
		short
		short2
		oceanic
		english
		after
		after2
	]]
	return getRegion( frame ).full or ''
end

function D.ln( frame )
	return getLanguage( frame ).index or ''
end

function D.lang( frame )
	return getLanguage( frame ).full or ''
end

function D.rgo( frame )
	return getMedium( frame ).abbr or ''
end

function D.vg( frame )
	local full = UTIL.trim( getArg( frame, 'full' ) )

	local link = UTIL.trim( getArg( frame, 'link' ) )

	local game = getVideoGameName( frame )
	
	return full
		and ( link and game.full or UTIL.removeDab( game.full or '' ) )
		or game.abbr
end

function D.name( frame )
	local language = DATA.getLanguage(
		UTIL.trim( getArg( frame, 2 ) ) or 'en'
	)

	return language
		and DATA.getName( getArg( frame, 1 ) or '', language )
		or '' -- case of invalid language: display empty
end

return D
-- </pre>