Toggle menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

Module:Keyword: Difference between revisions

From EmissaryFGC
dustloop>TarkusLee
No edit summary
dustloop>TarkusLee
No edit summary
Line 40: Line 40:


local terms = {}
local terms = {}
for _, key in pairs( inputs ) do
local match = data[ term ]
local match = data[ key ]
if not match then
if not match then
        error( string.format( 'Could not find matching term: %s', term ) )
        error( string.format( 'Could not find matching term: %s', term ) )
end
terms[ key ] = data[ term ]
end
end
terms[ term ] = data[ term ]


     return terms
     return terms
Line 77: Line 75:
      
      
     if not term then
     if not term then
        error( 'No term specified for the template' )
        error( 'No term specified for the template' )
     end
     end


local term = getTerm( chara, gameSpecifier )
mw.log(term)
local term = getTerm( term, gameSpecifier )
local html = buildTooltip(term)
local html = buildTooltip(term)



Revision as of 16:32, 19 May 2024

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

local p = {}
local mArguments
local cargo
local cache = {}


--- Return the Moves data and cache the data for reuse on the same page
---
--- @return table
local function getGlossaryData( gameSpecifier )
    -- Return cached data
    if #cache > 0 then return cache end

    -- Lazy initalize Module:Cargo
    cargo = require( 'Module:Cargo' )

    local tables = 'Glossary'
    local fields = 'term,definition,gameSpecifier'
    local args = {
    	orderBy = 'Glossary._rowID',
        limit = "300",
    }

    local results = cargo.getQueryResults( tables, fields, args, false )

    local items = {}
    for _, result in pairs( results ) do
        items[result.term] = result
    end

    -- Save to cache
    cache = items
    -- mw.logObject(cache)

    return cache
end

local function getTerm( term, gameSpecifier )
    local data = getGlossaryData( gameSpecifier )

	local terms = {}
	local match = data[ term ]
	if not match then
        error( string.format( 'Could not find matching term: %s', term ) )
	end
	terms[ term ] = data[ term ]

    return terms
end

local function buildTooltip(term)
	local tooltipHTML = mw.html.create('span'):addClass('tooltip')
		:wikitext(term['term'])
		:tag('span'):addClass('tooltiptext')
			:wikitext(term['definition '])
		:done()
	:done()
	
	return tooltipHTML
end

function p.main(frame)
	mArguments = require( 'Module:Arguments' )
	local args = mArguments.getArgs(frame)
	return p._main(args)
end

--- Return the wikitext needed for the template
---
--- @return string
function p._main( args )
    
    local term = args['term']
    local gameSpecifier = args['gameSpecifier']
    
    if not term then
        error( 'No term specified for the template' )
    end

	mw.log(term)
	local term = getTerm( term, gameSpecifier )
	local html = buildTooltip(term)

    return tostring(html)
end

return p
MediaWiki Appliance - Powered by TurnKey Linux