Difference between revisions of "Module:Data/Templates"

From Yugipedia
Jump to: navigation, search
(Account for {{{link}}} in {{Vg}}.)
m (Correct parameter name.)
 
(3 intermediate revisions by the same user not shown)
Line 10: Line 10:
 
local UTIL = require( 'Module:Util' )
 
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 = {}
 +
 
 +
function D.rg( frame )
 +
return getRegion( frame ).index or ''
 +
end
  
return DATA.getVideoGame( v ) or {}
+
function D.region( frame )
 +
--[[
 +
short
 +
short2
 +
oceanic
 +
english
 +
after
 +
after2
 +
]]
 +
return getRegion( frame ).full or ''
 
end
 
end
  
Line 42: Line 58:
 
function D.lang( frame )
 
function D.lang( frame )
 
return getLanguage( frame ).full or ''
 
return getLanguage( frame ).full or ''
end
 
 
function D.rg( frame )
 
return getRegion( frame ).index or ''
 
end
 
 
function D.region( frame )
 
return getRegion( frame ).full or ''
 
 
end
 
end
  
Line 57: Line 65:
  
 
function D.vg( frame )
 
function D.vg( frame )
local full = UTIL.trim( frame:getParent().args[ 'full' ] )
+
local full = UTIL.trim( getArg( frame, 'full' ) )
  
local link = UTIL.trim( frame:getParent().args[ 'link' ] )
+
local link = UTIL.trim( getArg( frame, 'link' ) )
  
local game = getVideoGame( frame )
+
local game = getVideoGameName( frame )
 
 
 
return full
 
return full
and ( link and game.full or UTIL.removeDab( game.full ) )
+
and ( link and game.full or UTIL.removeDab( game.full or '' ) )
 
or game.abbr
 
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
 
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>